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

Prevent non-MC from grabbing more than 16 hours #391

Closed
wants to merge 7 commits into from

Conversation

NicholasCF
Copy link
Contributor

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

sign_in user
duties = create_list(:duty, 10, user: user)
start_date = duties[0].date
end_date = duties[9].date

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.

user = create(:user)
sign_in user
duties = create_list(:duty, 10, user: user)
start_date = duties[0].date

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.

end

describe '#sum_hours' do
it 'calculate hours correctly' do

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.

end
end

describe '#sum_hours' do

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.

end

def sum_hours(duties)
total_seconds = duties.map do |d|

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.

count = 0
result = {}

while count < num_duties do

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.

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

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.

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

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.

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)

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]

@@ -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

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.

@indocomsoft indocomsoft temporarily deployed to dutycommit-pr-391 October 25, 2019 04:28 Inactive
@coveralls
Copy link

Pull Request Test Coverage Report for Build 2430

  • 26 of 26 (100.0%) changed or added relevant lines in 2 files are covered.
  • 2 unchanged lines in 1 file lost coverage.
  • Overall coverage increased (+0.1%) to 96.457%

Files with Coverage Reduction New Missed Lines %
app/controllers/duties_controller.rb 2 97.3%
Totals Coverage Status
Change from base Build 2414: 0.1%
Covered Lines: 599
Relevant Lines: 621

💛 - Coveralls

@NicholasCF
Copy link
Contributor Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Prevent non-mc from grabbing beyond 16 hours
4 participants