From 3c2d043b715e378b62d0bc9aa149a97cac818dd0 Mon Sep 17 00:00:00 2001 From: NicholasCF Date: Sat, 1 Feb 2020 10:43:52 +0800 Subject: [PATCH 1/4] Fix nil ID guard for last updating user --- app/views/problem_reports/index.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/problem_reports/index.html.erb b/app/views/problem_reports/index.html.erb index c2570495..089140a8 100644 --- a/app/views/problem_reports/index.html.erb +++ b/app/views/problem_reports/index.html.erb @@ -50,7 +50,7 @@ <%= submit_tag('Change Remark', :class=>'btn btn-large btn-light problem-report-btn') %> <% end %> - <%= pb.reporter_user_id == nil \ + <%= pb.last_update_user_id == nil \ ? "(Deleted member)" \ : User.find(pb.last_update_user_id)&.username %> From cc81e88ba0e53cf22e7c55134ce3877b15b72cad Mon Sep 17 00:00:00 2001 From: NicholasCF Date: Sat, 1 Feb 2020 11:03:23 +0800 Subject: [PATCH 2/4] Fix rubocop violations --- spec/mailers/generic_mailer_spec.rb | 4 ++-- spec/models/duty_spec.rb | 2 +- spec/models/timeslot_spec.rb | 2 +- spec/models/user_spec.rb | 18 +++++++++++------- 4 files changed, 15 insertions(+), 11 deletions(-) diff --git a/spec/mailers/generic_mailer_spec.rb b/spec/mailers/generic_mailer_spec.rb index 264a5a51..2aeff307 100644 --- a/spec/mailers/generic_mailer_spec.rb +++ b/spec/mailers/generic_mailer_spec.rb @@ -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('%2d:00', n).in_time_zone } .map do |start_time| create(:time_range, start_time: start_time, end_time: start_time + 1.hour) @@ -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('%2d:00', n).in_time_zone } .map do |start_time| create(:time_range, start_time: start_time, end_time: start_time + 1.hour) diff --git a/spec/models/duty_spec.rb b/spec/models/duty_spec.rb index e7e9c484..fa60d3e0 100644 --- a/spec/models/duty_spec.rb +++ b/spec/models/duty_spec.rb @@ -31,7 +31,7 @@ it { should belong_to(:user).optional } it { should belong_to(:request_user).class_name('User') - .optional.inverse_of(:duties) + .optional.inverse_of(:duties) } it { should belong_to(:timeslot) } it { should have_one(:time_range).through(:timeslot) } diff --git a/spec/models/timeslot_spec.rb b/spec/models/timeslot_spec.rb index 234cadbb..c09b577e 100644 --- a/spec/models/timeslot_spec.rb +++ b/spec/models/timeslot_spec.rb @@ -32,7 +32,7 @@ it { should have_many(:duties).dependent(:destroy) } it { should belong_to(:default_user).class_name('User') - .optional.inverse_of(:timeslots) + .optional.inverse_of(:timeslots) } it { should belong_to(:place) } it { should belong_to(:time_range) } diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 0182e1d1..f459dbb6 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -40,17 +40,21 @@ it { should have_many(:duties).dependent(:nullify) } it { should have_many(:timeslots).with_foreign_key(:default_user_id) - .inverse_of(:default_user).dependent(:nullify) + .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) } From 79978920007fe16ec56e5beb6f169d43fedbfa9f Mon Sep 17 00:00:00 2001 From: NicholasCF Date: Sat, 1 Feb 2020 11:13:09 +0800 Subject: [PATCH 3/4] Fix hound violations --- spec/models/duty_spec.rb | 5 +++-- spec/models/timeslot_spec.rb | 5 +++-- spec/models/user_spec.rb | 5 +++-- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/spec/models/duty_spec.rb b/spec/models/duty_spec.rb index fa60d3e0..a323839a 100644 --- a/spec/models/duty_spec.rb +++ b/spec/models/duty_spec.rb @@ -30,8 +30,9 @@ RSpec.describe Duty, type: :model do it { should belong_to(:user).optional } it { - should belong_to(:request_user).class_name('User') - .optional.inverse_of(:duties) + should belong_to(:request_user) + .class_name('User') + .optional.inverse_of(:duties) } it { should belong_to(:timeslot) } it { should have_one(:time_range).through(:timeslot) } diff --git a/spec/models/timeslot_spec.rb b/spec/models/timeslot_spec.rb index c09b577e..dc6bd887 100644 --- a/spec/models/timeslot_spec.rb +++ b/spec/models/timeslot_spec.rb @@ -31,8 +31,9 @@ RSpec.describe Timeslot, type: :model do it { should have_many(:duties).dependent(:destroy) } it { - should belong_to(:default_user).class_name('User') - .optional.inverse_of(:timeslots) + should belong_to(:default_user) + .class_name('User') + .optional.inverse_of(:timeslots) } it { should belong_to(:place) } it { should belong_to(:time_range) } diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index f459dbb6..c1051ff7 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -39,8 +39,9 @@ RSpec.describe User, type: :model do it { should have_many(:duties).dependent(:nullify) } it { - should have_many(:timeslots).with_foreign_key(:default_user_id) - .inverse_of(:default_user).dependent(:nullify) + should have_many(:timeslots) + .with_foreign_key(:default_user_id) + .inverse_of(:default_user).dependent(:nullify) } it { should have_many(:reported_problem_reports) From b2a227c83849f532f65694fa7d6200d328c29049 Mon Sep 17 00:00:00 2001 From: NicholasCF Date: Fri, 7 Feb 2020 14:56:20 +0800 Subject: [PATCH 4/4] Fix string format error --- spec/mailers/generic_mailer_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/mailers/generic_mailer_spec.rb b/spec/mailers/generic_mailer_spec.rb index 2aeff307..be67c56f 100644 --- a/spec/mailers/generic_mailer_spec.rb +++ b/spec/mailers/generic_mailer_spec.rb @@ -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('%2d:00', hour: n).in_time_zone } .map do |start_time| create(:time_range, start_time: start_time, end_time: start_time + 1.hour) @@ -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('%2d:00', hour: n).in_time_zone } .map do |start_time| create(:time_range, start_time: start_time, end_time: start_time + 1.hour)