Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] - Feature absences spec #82

1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ log/*.log.*
.idea
.bundle/*
.byebug_history
.DS_Store
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ group :test do
gem 'rspec-rails', '~> 3.5'
gem 'factory_girl_rails'
gem 'capybara'
gem 'launchy'
gem 'poltergeist', '~> 1.12'
gem 'rack-test'
gem 'test-unit', '~> 3.0'
Expand Down
8 changes: 7 additions & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,8 @@ GEM
json_pure (1.8.3)
jstz-rails (1.0.4.1)
railties (~> 3.1)
launchy (2.4.3)
addressable (~> 2.3)
less (2.6.0)
commonjs (~> 0.2.7)
less-rails (2.6.0)
Expand Down Expand Up @@ -359,6 +361,7 @@ DEPENDENCIES
jquery-datatables-rails!
jquery-rails (= 2.1.4)
json
launchy
newrelic_rpm
paperclip!
pg
Expand Down Expand Up @@ -386,5 +389,8 @@ DEPENDENCIES
uglifier (>= 1.0.3)
yaml_db

RUBY VERSION
ruby 2.1.5p273

BUNDLED WITH
1.13.6
1.13.7
2 changes: 1 addition & 1 deletion config/database.yml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ production:
host: localhost
pool: 5
timeout: 5000

3 changes: 2 additions & 1 deletion spec/controllers/absences_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
require 'rails_helper'

RSpec.describe AbsencesController do
let(:volunteer) { create :volunteer_with_assignment }
let(:volunteer_with_assignment) { create :volunteer_with_assignment }

it_behaves_like 'an authenticated indexable resource'

end
11 changes: 10 additions & 1 deletion spec/factories/volunteers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@
waiver_signed true
waiver_signed_at Time.zone.now

factory :volunteer_with_region do
after(:create) do |v|
region = create(:region)
v.regions << region
v.assigned = true
v.save
end
end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this added factory actually ends up doing the same thing as the :volunteer_with_assignment factory. Volunteers are assigned to regions through the Assignment model. When the assignment is created on line 21, a new region is also created by this line in the Assignments factory.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @ericfreese
For this particular test case this is being used to evaluate functionaliry when a volunteer without any assignment is trying to schedule an absence. It means not having an assignment is a precondition.
Since other tests are relying on the already existing, previously created factories, I didn't want to rename any previously created volunteer factories.
First I tried to rely on volunteer factory as it does not have assignments either, but that no regions assigned and its login fails with the Your account has not been assigned to a region yet. A region administrator must do this before you can sign in. error message.
This new factory is being called under let(:volunteer_without_assignment) within volunteer_schedule_absence_spec.rb It is already being called as volunteer_without_assignment, hoping that would clear up any possible confusion around the purpose of this factory.
Is there another factory I might have missed that already has volunteer with regions assigned without assignments?

Copy link
Member

@ericfreese ericfreese Mar 11, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like the new factory (volunteer_with_region) actually does end up producing a Volunteer with an Assignment.

If we put a binding.pry in the test and poke around a bit, we can see there is in fact an associated Assignment:

> volunteer_without_assignment.assignments.count
=> 1

The region = create(:region); v.regions << region lines in the volunteer_with_region factory must create an Assignment to link the Region to the Volunteer. Because the regions association on Volunteer is a has_many :through, there is no way to have a Volunteer associated to a Region without an Assignment to join them, so those lines effectively create both a Region and an Assignment linked to that Volunteer.

This actually is the same outcome as the volunteer_with_assignment factory. The a = create(:assignment,volunteer:v); v.assignments << a lines will create both a Region and an Assignment and associate them with the Volunteer. This is because the assignment factory is set up to build an associated Region by default.


This explains why you're not seeing the login failure error for this user. If the user truly had no assignments, they would never be able to log in.

For this particular test case this is being used to evaluate functionaliry when a volunteer without any assignment is trying to schedule an absence.

Because it is not possible for a volunteer with no assignments to log into the system to get to the "Schedule an Absence" form, I think it would be best to test other cases. I think it would be best to start with the happy path: A volunteer with a shift successfully scheduling an absence for that shift.


factory :volunteer_with_assignment do
after(:create) do |v|
a = create(:assignment,volunteer:v)
Expand All @@ -15,7 +24,7 @@
v.save
end
end

trait :not_waived do
waiver_signed false
waiver_signed_at nil
Expand Down
55 changes: 55 additions & 0 deletions spec/features/volunteer_schedule_absence_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
require 'rails_helper'

RSpec.describe 'Scheduling an Absence' do

# let(:admin) { create :volunteer_with_assignment, admin: true }
let(:today) { Time.zone.today }
let(:in_two_days) { Time.zone.today + 2 }
let(:in_four_days) { Time.zone.today + 4 }
let(:volunteer_with_assignment) { create :volunteer_with_assignment }

let!(:chain_too_soon) { create(:schedule_chain, day_of_week: in_two_days.wday, detailed_date: today) }
let!(:schedule_volunteer_too_soon) { create(:schedule_volunteer, schedule_chain: chain_too_soon, volunteer: volunteer_with_assignment) }
let!(:recipient_too_soon) { create(:recipient_schedule, schedule_chain: chain_too_soon, position: 1) }
let!(:donor_too_soon) { create(:donation_schedule, schedule_chain: chain_too_soon, position: 2) }
let!(:log_too_soon) { create(:log, when: in_two_days, schedule_chain: chain_too_soon) }

let!(:chain_ok) { create(:schedule_chain, day_of_week: in_four_days.wday, detailed_date: today) }
let!(:schedule_volunteer_ok) { create(:schedule_volunteer, schedule_chain: chain_ok, volunteer: volunteer_with_assignment) }
let!(:recipient_ok) { create(:recipient_schedule, schedule_chain: chain_ok, position: 1) }
let!(:donor_ok) { create(:donation_schedule, schedule_chain: chain_ok, position: 2) }
let!(:log_ok) { create(:log, when: in_four_days, schedule_chain: chain_ok) }

let!(:filter_start_day) { (Time.zone.today).strftime('%e') }
let!(:filter_start_month) { (Time.zone.today).strftime('%B') }
let!(:filter_start_year) { (Time.zone.today).strftime('%Y') }

let!(:filter_end_day) { (Time.zone.today + 30).strftime('%e') }
let!(:filter_end_month) { (Time.zone.today + 30).strftime('%B') }
let!(:filter_end_year) { (Time.zone.today + 30).strftime('%Y') }

context 'non-admin user' do
context 'WITH assignment' do
it 'can schedule' do
login volunteer_with_assignment

visit new_absence_path

select filter_end_month, from: 'absence[stop_date(2i)]'
select filter_end_day, from: 'absence[stop_date(3i)]'
select filter_end_year, from: 'absence[stop_date(1i)]'


click_on 'Save changes'

binding.pry
save_and_open_page

expect(current_path).to eq(absences_path)
within('.alert') do
expect(page).to have_content('No shifts of yours was found in that timeframe')
end
end
end
end
end