-
Notifications
You must be signed in to change notification settings - Fork 0
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
Prevent non-MC from grabbing more than 16 hours #391
Conversation
spec/helpers/duties_helper_spec.rb
Outdated
sign_in user | ||
duties = create_list(:duty, 10, user: user) | ||
start_date = duties[0].date | ||
end_date = duties[9].date |
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.
Lint/UselessAssignment: Useless assignment to variable - end_date.
spec/helpers/duties_helper_spec.rb
Outdated
user = create(:user) | ||
sign_in user | ||
duties = create_list(:duty, 10, user: user) | ||
start_date = duties[0].date |
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.
Lint/UselessAssignment: Useless assignment to variable - start_date.
spec/helpers/duties_helper_spec.rb
Outdated
end | ||
|
||
describe '#sum_hours' do | ||
it 'calculate hours correctly' do |
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.
Layout/TrailingWhitespace: Trailing whitespace detected.
spec/helpers/duties_helper_spec.rb
Outdated
end | ||
end | ||
|
||
describe '#sum_hours' do |
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.
Layout/TrailingWhitespace: Trailing whitespace detected.
app/helpers/duties_helper.rb
Outdated
end | ||
|
||
def sum_hours(duties) | ||
total_seconds = duties.map do |d| |
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.
Layout/TrailingWhitespace: Trailing whitespace detected.
app/controllers/duties_controller.rb
Outdated
count = 0 | ||
result = {} | ||
|
||
while count < num_duties do |
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.
Style/WhileUntilDo: Do not use do with multi-line while.
app/controllers/duties_controller.rb
Outdated
if total_hours > 16 && wk_duties.length > 0 | ||
redirect_to duties_path(start_date: start_of_week), | ||
alert: 'Cannot duty for more than 16 hours!' | ||
return |
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.
Lint/NonLocalExitFromIterator: Non-local exit from iterator, without return value. next, break, Array#find, Array#any?, etc. is preferred.
app/controllers/duties_controller.rb
Outdated
start_date = start.to_date | ||
end_date = start_date + 6.days | ||
total_hours = helpers.current_user_hours(start_date, end_date) + helpers.sum_hours(wk_duties) | ||
if total_hours > 16 && wk_duties.length > 0 |
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.
Style/Next: Use next to skip iteration.
Style/NumericPredicate: Use wk_duties.length.positive? instead of wk_duties.length > 0.
Style/ZeroLengthPredicate: Use !empty? instead of length > 0.
app/controllers/duties_controller.rb
Outdated
weeks.each do |start, wk_duties| | ||
start_date = start.to_date | ||
end_date = start_date + 6.days | ||
total_hours = helpers.current_user_hours(start_date, end_date) + helpers.sum_hours(wk_duties) |
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.
Metrics/LineLength: Line is too long. [103/80]
app/controllers/duties_controller.rb
Outdated
@@ -137,7 +137,22 @@ def prepare_announcements | |||
|
|||
def grab_duty(grab_duty_ids, start_of_week) | |||
Duty.transaction do | |||
Duty.find(grab_duty_ids).each do |duty| | |||
duties = Duty.find(grab_duty_ids) | |||
unless current_user.mc |
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.
Layout/TrailingWhitespace: Trailing whitespace detected.
Pull Request Test Coverage Report for Build 2430
💛 - Coveralls |
Note to those who want to pick up this: You need to abstract away some methods from the duty controller because it's getting fatter. Otherwise rubocop won't let you pass |
Close #299
It should check each week independently, but if one week has more than 16 hours, no duties will be grabbed at all.
I cannot check this from the browser, since for some reason there are hidden duties (when I dropped all duties for a member at a week, the total number of hours is non-zero). But the rspec works