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

Fix crash when last updated by has nil ID #435

Merged
merged 6 commits into from
Feb 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/views/problem_reports/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
<%= submit_tag('Change Remark', :class=>'btn btn-large btn-light problem-report-btn') %>
<% end %></td>
<td class="last-updated-by">
<%= pb.reporter_user_id == nil \
<%= pb.last_update_user_id == nil \
? "(Deleted member)" \
: User.find(pb.last_update_user_id)&.username %>
</td>
Expand Down
4 changes: 2 additions & 2 deletions spec/mailers/generic_mailer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
let(:duties) do
user = create(:user)
@duties = (8..12)
.map { |n| format('%2d:00', n).in_time_zone }
.map { |n| format('%<hour>2d:00', hour: n).in_time_zone }
.map do |start_time|
create(:time_range, start_time: start_time,
end_time: start_time + 1.hour)
Expand Down Expand Up @@ -56,7 +56,7 @@
let(:duties) do
user = create(:user)
@duties = [8, 9, 12, 13]
.map { |n| format('%2d:00', n).in_time_zone }
.map { |n| format('%<hour>2d:00', hour: n).in_time_zone }
.map do |start_time|
create(:time_range, start_time: start_time,
end_time: start_time + 1.hour)
Expand Down
3 changes: 2 additions & 1 deletion spec/models/duty_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
RSpec.describe Duty, type: :model do
it { should belong_to(:user).optional }
it {
should belong_to(:request_user).class_name('User')
should belong_to(:request_user)
.class_name('User')
.optional.inverse_of(:duties)
}
it { should belong_to(:timeslot) }
Expand Down
3 changes: 2 additions & 1 deletion spec/models/timeslot_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
RSpec.describe Timeslot, type: :model do
it { should have_many(:duties).dependent(:destroy) }
it {
should belong_to(:default_user).class_name('User')
should belong_to(:default_user)
.class_name('User')
.optional.inverse_of(:timeslots)
}
it { should belong_to(:place) }
Expand Down
19 changes: 12 additions & 7 deletions spec/models/user_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,23 @@
RSpec.describe User, type: :model do
it { should have_many(:duties).dependent(:nullify) }
it {
should have_many(:timeslots).with_foreign_key(:default_user_id)
should have_many(:timeslots)
.with_foreign_key(:default_user_id)
.inverse_of(:default_user).dependent(:nullify)
}
it {
should have_many(:reported_problem_reports).class_name('ProblemReport')
.with_foreign_key('reporter_user_id').inverse_of(:reporter_user)
.dependent(:nullify)
should have_many(:reported_problem_reports)
.class_name('ProblemReport')
.with_foreign_key('reporter_user_id')
.inverse_of(:reporter_user)
.dependent(:nullify)
}
it {
should have_many(:last_updated_problem_reports).class_name('ProblemReport')
.with_foreign_key(:last_update_user_id).inverse_of(:last_update_user)
.dependent(:nullify)
should have_many(:last_updated_problem_reports)
.class_name('ProblemReport')
.with_foreign_key(:last_update_user_id)
.inverse_of(:last_update_user)
.dependent(:nullify)
}
it { should have_many(:availabilities).dependent(:destroy) }
it { should validate_presence_of(:cell) }
Expand Down