-
Notifications
You must be signed in to change notification settings - Fork 1
checkout all validation #5
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -153,16 +153,26 @@ def check_out_all | |
| if workday_volunteer.end_time.nil? | ||
| workday_volunteer.end_time = Time.parse(@check_out_all_form.check_out_time) | ||
| if !workday_volunteer.is_end_time_valid | ||
| unupdated_volunteers[workday_volunteer.volunteer_id.to_s] = 'End time is before start time.' | ||
| elsif [email protected]_overlapping_volunteer(workday_volunteer) | ||
| unupdated_volunteers[workday_volunteer.volunteer_id.to_s] = 'End time overlaps another workday entry for this volunteer' | ||
| unupdated_volunteers[workday_volunteer.id.to_s] = 'End time is before start time.' | ||
| else | ||
| workday_volunteer.save | ||
| overlapped_workday = @workday.get_overlapping_workday(workday_volunteer); | ||
| if !overlapped_workday.nil? | ||
| unupdated_volunteers[workday_volunteer.id.to_s] = 'End time overlaps the workday:' << overlapped_workday.name | ||
| else | ||
| if @workday.is_overlapping_volunteer(workday_volunteer) | ||
| unupdated_volunteers[workday_volunteer.id.to_s] = 'End time overlaps another workday entry for this volunteer' | ||
| else | ||
| workday_volunteer.save | ||
| end | ||
| end | ||
| end | ||
| end | ||
| end | ||
|
|
||
| if unupdated_volunteers.length == 0 | ||
| session.delete(:unupdated_message) | ||
| session.delete(:unupdated_date) | ||
|
|
||
| redirect_to self_tracking_index_path | ||
| else | ||
| session[:unupdated_date] = Time.parse(@check_out_all_form.check_out_time).strftime("%l:%M %p") | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -154,8 +154,6 @@ def setup | |
| # Confirm no one is checked in yet. | ||
| assert @workday.workday_volunteers.empty? | ||
|
|
||
|
|
||
|
|
||
| # Check-in at 8am. | ||
| get :check_in, id: @volunteer.id, :check_in_form => {check_in_time: "8:00 AM"} | ||
| assert_response :success | ||
|
|
@@ -286,6 +284,91 @@ def setup | |
| end | ||
| end | ||
|
|
||
| test "should validate checkout all functionality" do | ||
| self.setup_self_tracking_session | ||
|
|
||
| # Confirm no one is checked in yet. | ||
| assert @workday.workday_volunteers.empty? | ||
|
|
||
| # Check-in two volunteers and then check them out. | ||
| get :check_in, id: @volunteer.id, :check_in_form => {check_in_time: "12:30 PM"} | ||
| get :check_in, id: @volunteer.id, :check_in_form => {check_in_time: "8:00 AM"} | ||
| get :check_in, id: @pending_volunteer.id, :check_in_form => {check_in_time: "1:20 PM"} | ||
| assert_equal 3, @workday.workday_volunteers.count | ||
|
|
||
| workdate = @workday.workdate | ||
| # Using .change so we retain the timezone. | ||
| target_date_time = DateTime.now.change( | ||
| :year => workdate.year, :month => workdate.month, :day => workdate.day, :hour => 17, :minute => 0 | ||
| ) | ||
| Timecop.freeze(target_date_time) do | ||
|
|
||
| # Get the original records | ||
| volunteer_workday = @workday.workday_volunteers.where(:volunteer_id => @volunteer.id).order(:start_time).first | ||
| pending_volunteer_workday = @workday.workday_volunteers.where(:volunteer_id => @pending_volunteer.id).first | ||
|
|
||
| # Checkout before the check-in time. | ||
| get :check_out_all, :check_out_all_form => { check_out_time: "6:00 AM" } | ||
| assert_redirected_to self_tracking_index_path | ||
| assert !session[:unupdated_message].empty? | ||
| assert session[:unupdated_message].has_value?("End time is before start time.") | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should there be three of these messages? |
||
|
|
||
| # Checkout after the start of next shift | ||
| get :check_out_all, :check_out_all_form => {check_out_time: "2:00 PM"} | ||
| assert_redirected_to self_tracking_index_path | ||
| assert_equal 1, session[:unupdated_message].count | ||
| assert session[:unupdated_message].has_value?("End time overlaps another workday entry for this volunteer") | ||
|
|
||
| # Valid checkout | ||
| get :check_out_all, :check_out_all_form => {check_out_time: "11:46 AM"} | ||
| assert_redirected_to self_tracking_index_path | ||
|
|
||
| end | ||
| end | ||
|
|
||
| test "Should check out all overlapp another workday" do | ||
|
|
||
| self.setup_self_tracking_session | ||
| assert @workday.workday_volunteers.empty? | ||
| get :check_in, id: @volunteer.id, :check_in_form => {check_in_time: "3:00 PM"} | ||
| assert_equal 1, @workday.workday_volunteers.count | ||
|
|
||
| @workday = workdays(:two) | ||
| self.setup_self_tracking_session | ||
| assert @workday.workday_volunteers.empty? | ||
| get :check_in, id: @volunteer.id, :check_in_form => {check_in_time: "12:30 PM"} | ||
| get :check_in, id: @volunteer.id, :check_in_form => {check_in_time: "8:00 AM"} | ||
| get :check_in, id: @pending_volunteer.id, :check_in_form => {check_in_time: "1:20 PM"} | ||
| assert_equal 3, @workday.workday_volunteers.count | ||
|
|
||
| workdate = @workday.workdate | ||
| # Using .change so we retain the timezone. | ||
| target_date_time = DateTime.now.change( | ||
| :year => workdate.year, :month => workdate.month, :day => workdate.day, :hour => 17, :minute => 0 | ||
| ) | ||
| Timecop.freeze(target_date_time) do | ||
|
|
||
| # Overlaps workday | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On here, can you check the actual message text rather than just the message count? Want to make sure the right messages are showing up. |
||
| get :check_out_all, :check_out_all_form => {check_out_time: "3:01 PM"} | ||
| assert_redirected_to self_tracking_index_path | ||
| assert_equal 2, session[:unupdated_message].count | ||
|
|
||
| # Overlaps 8:00 AM and checks out 12:00 PM | ||
| get :check_out_all, :check_out_all_form => {check_out_time: "2:00 PM"} | ||
| assert_redirected_to self_tracking_index_path | ||
| assert_equal 1, session[:unupdated_message].count | ||
|
|
||
| # End time overlaps checked out item | ||
| get :check_out_all, :check_out_all_form => {check_out_time: "1:00 PM"} | ||
| assert_redirected_to self_tracking_index_path | ||
| assert_equal 1, session[:unupdated_message].count | ||
|
|
||
| # Check out 08:00 AM | ||
| get :check_out_all, :check_out_all_form => {check_out_time: "12:29 PM"} | ||
| assert_redirected_to self_tracking_index_path | ||
| assert session[:unupdated_message].nil? | ||
| end | ||
| end | ||
|
|
||
| def setup_self_tracking_session | ||
| session[:self_tracking_workday_id] = @workday.id | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,22 @@ | ||
| require 'test_helper' | ||
|
|
||
| class SelfTrackingTest < ActionDispatch::IntegrationTest | ||
|
|
||
| def setup | ||
| @user = users(:one) | ||
| @project = projects(:one) | ||
| @workday = Workday.new(project: @project, workdate: Date.today.to_s(:db), name: "Example") | ||
| @workday.save | ||
| end | ||
|
|
||
| def teardown | ||
| @workday.destroy | ||
| end | ||
|
|
||
| test "should redirect to check out all" do | ||
| log_in_as(@user) | ||
| get self_tracking_launch_path(:check_out_all => true, :id => @workday.id), session: { user_id: @user.id } | ||
| assert_redirected_to self_tracking_check_out_all_path | ||
| end | ||
|
|
||
| end |
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.
What's the reason for only checking if end_time is null? They could also overlap if end_time is not null.
Uh oh!
There was an error while loading. Please reload this page.
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.
Here the idea is check the overlap in shifts that were not checked out yet. But sounds like I missed to check when there are start_time and end_time.