-
-
Save jccarbonfive/4591747 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'spec_helper' | |
describe 'Importing accounts' do | |
context 'given a CSV file of accounts' do | |
before do | |
visit '/' | |
within '#new_accounts' do | |
attach_file 'File', Rails.root.join('spec', 'fixtures', 'accounts.csv') | |
click_button 'Import' | |
end | |
end | |
it 'imports each account' do | |
expect(page).to have_content('3 accounts imported') | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
alice | checking | 100 | |
---|---|---|---|
bob | savings | 50 | |
sam | savings | 200 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ rspec spec/requests/importing_accounts_spec.rb | |
1) Importing accounts given a CSV file of accounts imports each account | |
Failure/Error: visit '/' | |
ActionController::RoutingError: | |
No route matches [GET] "/" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sample::Application.routes.draw do | |
resources :accounts, only: [:index, :create] | |
root to: 'accounts#index' | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
= form_for :accounts, url: accounts_path, html: { id: 'new_accounts', multipart: true } do |form| | |
= form.label :file | |
= form.file_field :file | |
= form.submit 'Import' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class AccountsController < ApplicationController | |
def index | |
end | |
def create | |
@imported = Account.import params[:accounts][:file] | |
redirect_to accounts_path, | |
notice: "#{@imported} accounts imported" | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ rspec spec/requests/importing_accounts_spec.rb | |
F | |
Failures: | |
1) Importing accounts given a CSV file of accounts imports each account | |
Failure/Error: click_button 'Import' | |
NoMethodError: | |
undefined method `import' for #<Class:0x007ffddc82eda8> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'spec_helper' | |
describe Account do | |
describe 'importing' do | |
context 'given a file of accounts' do | |
before do | |
file = double 'accounts file' | |
account_importer = double 'account importer' | |
account_importer | |
.stub(:import) | |
.with(file) | |
.and_return(3) | |
@imported = Account.import file, account_importer | |
end | |
it 'returns the total number of accounts imported' do | |
expect(@imported).to eq(3) | |
end | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ rspec spec/models/account_spec.rb | |
F | |
Failures: | |
1) Account importing given a file of accounts returns the total number of accounts imported | |
Failure/Error: @imported = Account.import file, account_importer | |
NoMethodError: | |
undefined method `import' for #<Class:0x007fe574fac4c0> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment