Skip to content

Commit

Permalink
Spec donation approval
Browse files Browse the repository at this point in the history
Specs for #36 and contributes to #23.
  • Loading branch information
harigopal committed Mar 28, 2017
1 parent 14b457f commit fb39adf
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,9 @@ group :test do

# Automatically save screen shots when a Capybara scenario fails. https://github.com/mattheworiordan/capybara-screenshot
gem 'capybara-screenshot', '~> 1.0', require: false

# Test ActionMailer and Mailer messages with Capybara. https://github.com/DockYard/capybara-email
gem 'capybara-email', '~> 2.5', require: false
end

# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
Expand Down
4 changes: 4 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ GEM
rack (>= 1.0.0)
rack-test (>= 0.5.4)
xpath (~> 2.0)
capybara-email (2.5.0)
capybara (~> 2.4)
mail
capybara-screenshot (1.0.14)
capybara (>= 1.0, < 3)
launchy
Expand Down Expand Up @@ -341,6 +344,7 @@ DEPENDENCIES
bootstrap_form (~> 2.6)!
byebug (~> 9.0)
capybara (~> 2.13)
capybara-email (~> 2.5)
capybara-screenshot (~> 1.0)
coffee-rails (~> 4.2)
coveralls (~> 0.8)
Expand Down
1 change: 1 addition & 0 deletions app/controllers/donations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ def approve
donation = Donation.find(params[:id])
authorize donation
Donations::ApprovalService.new(donation, current_user).approve
flash[:notice] = 'Your approval of the donation has been recorded.'
redirect_back fallback_location: donations_path
end

Expand Down
33 changes: 33 additions & 0 deletions spec/features/donations/approval_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
require 'rails_helper'

feature 'Approve donation' do
include UserSpecHelper

let(:donation) { create :donation }
let(:national_finance_head) { donation.volunteer.national_finance_head }

scenario 'Volunteer creates donation' do
sign_in_user national_finance_head.user

expect(page).to have_content('Dashboard')

visit donation_path(donation)

click_link('Approve')

expect(page).to have_content('Your approval of the donation has been recorded.')

# The receipt should be sent to the donor.
open_email(donation.email)

expect(current_email.subject).to eq('GoDreams Donation Receipt')
expect(current_email).to have_content('As promised, please find attached the e-receipt of your contribution to Guardians of Dreams Foundation.')
expect(current_email.attachments.first.filename).to eq('godreams_receipt.pdf')

# The receipt should also be delivered to receipts@godreams.org.
open_email('receipts@godreams.org')

expect(current_email.subject).to eq('GoDreams Donation Receipt')
expect(current_email.attachments.first.filename).to eq('godreams_receipt.pdf')
end
end
3 changes: 3 additions & 0 deletions spec/rails_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
# Enable capybara-screenshot.
require 'capybara-screenshot/rspec'

# Enable capybara-email.
require 'capybara/email/rspec'

# Requires supporting ruby files with custom matchers and macros, etc, in
# spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are
# run as spec files by default. This means that files in spec/support that end
Expand Down

0 comments on commit fb39adf

Please sign in to comment.