-
Notifications
You must be signed in to change notification settings - Fork 56
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
Closed
Laszlo-JFLMTCO
wants to merge
9
commits into
boulder-food-rescue:master
from
Laszlo-JFLMTCO:feature-absences-spec
Closed
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
d1a7b35
Change test database from sqlite3 to psql
Laszlo-JFLMTCO d8bdd38
Create volunteer_schedule_absence_spec file, comment out content of a…
Laszlo-JFLMTCO f583691
Add launchy gem to support save_and_open_page for debugging Capybara …
Laszlo-JFLMTCO 6d9b776
Add assigned=true to volunteer_with_region factory otherwise login_he…
Laszlo-JFLMTCO 68205c0
Clean up extra indentation within volunteer_schedule_absence_spec
Laszlo-JFLMTCO 1c197b4
Bring back database.yml.dist
Laszlo-JFLMTCO 51c2d31
Remove unnecessary coments from absences_controller_spec while focusi…
Laszlo-JFLMTCO 408f7b0
Fix incorrect indentation of volunteer_schedule_absence_spec
Laszlo-JFLMTCO 8f9d8a3
Add DS_Store to gitignore. Update volunteer absence spec with happy p…
Laszlo-JFLMTCO File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,3 +12,4 @@ log/*.log.* | |
.idea | ||
.bundle/* | ||
.byebug_history | ||
.DS_Store |
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,4 +24,4 @@ production: | |
host: localhost | ||
pool: 5 | ||
timeout: 5000 | ||
|
||
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
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 |
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
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
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 |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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 theAssignment
model. When the assignment is created on line 21, a new region is also created by this line in the Assignments factory.There was a problem hiding this comment.
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 anyassignment
is trying to schedule anabsence
. It means not having anassignment
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 haveassignments
either, but that noregions
assigned and its login fails with theYour 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)
withinvolunteer_schedule_absence_spec.rb
It is already being called asvolunteer_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?There was a problem hiding this comment.
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 aVolunteer
with anAssignment
.If we put a
binding.pry
in the test and poke around a bit, we can see there is in fact an associatedAssignment
:The
region = create(:region); v.regions << region
lines in thevolunteer_with_region
factory must create anAssignment
to link theRegion
to theVolunteer
. Because theregions
association onVolunteer
is ahas_many :through
, there is no way to have aVolunteer
associated to aRegion
without anAssignment
to join them, so those lines effectively create both aRegion
and anAssignment
linked to thatVolunteer
.This actually is the same outcome as the
volunteer_with_assignment
factory. Thea = create(:assignment,volunteer:v); v.assignments << a
lines will create both aRegion
and anAssignment
and associate them with theVolunteer
. This is because theassignment
factory is set up to build an associatedRegion
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.
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.