From c21fac80a7a8bbb46a03cef0426ea9db50d02176 Mon Sep 17 00:00:00 2001 From: Kostas Sklias <> Date: Wed, 29 Nov 2023 13:55:18 +0200 Subject: [PATCH] Rubocop fixes --- app/controllers/activities_controller.rb | 18 ++++----- app/models/activity.rb | 2 +- .../activity_pages/activity_pages_spec.rb | 20 +++++----- spec/models/activity_spec.rb | 38 +++++++++---------- 4 files changed, 39 insertions(+), 39 deletions(-) diff --git a/app/controllers/activities_controller.rb b/app/controllers/activities_controller.rb index dc1d482c20..903260bfa6 100644 --- a/app/controllers/activities_controller.rb +++ b/app/controllers/activities_controller.rb @@ -34,15 +34,15 @@ def poll private - def period_start - DateTime.parse params[:period_start] - end + def period_start + DateTime.parse params[:period_start] + end - def period_end - if params[:period_end].empty? - DateTime.now - else - DateTime.parse params[:period_end] - end + def period_end + if params[:period_end].empty? + DateTime.now + else + DateTime.parse params[:period_end] end + end end diff --git a/app/models/activity.rb b/app/models/activity.rb index 216cb1f0be..7f5666ef7c 100644 --- a/app/models/activity.rb +++ b/app/models/activity.rb @@ -29,7 +29,7 @@ def project=(new_project); end scope :filter_by_user_id, -> (id) { where user_id: id } scope :filter_by_type, -> (type) { where trackable_type: type } scope :filter_by_date, -> (period_start, period_end) { - where("created_at >= ? AND created_at <= ?", period_start.beginning_of_day, period_end.end_of_day ) + where('created_at >= ? AND created_at <= ?', period_start.beginning_of_day, period_end.end_of_day) } # -- Callbacks ------------------------------------------------------------ diff --git a/spec/features/activity_pages/activity_pages_spec.rb b/spec/features/activity_pages/activity_pages_spec.rb index 9cafe1c0f2..47902bf488 100644 --- a/spec/features/activity_pages/activity_pages_spec.rb +++ b/spec/features/activity_pages/activity_pages_spec.rb @@ -101,30 +101,30 @@ end describe 'filters' do - it "has user filter" do + it 'has user filter' do expect(page).to have_selector('#user', count: 1) end - it "user filter works" do + it 'user filter works' do visit project_activities_path(current_project, user: second_user.id) expect(page).to have_selector('.activity', count: 10) end - it "has type filter" do + it 'has type filter' do expect(page).to have_selector('#type', count: 1) end - it "type filter works" do - visit project_activities_path(current_project, type: "Card") + it 'type filter works' do + visit project_activities_path(current_project, type: 'Card') expect(page).to have_selector('.activity', count: 15) end - it "has daterange filter" do + it 'has daterange filter' do expect(page).to have_selector('#period_start', count: 1) expect(page).to have_selector('#period_end', count: 1) end - it "daterange filter works" do + it 'daterange filter works' do period_start = Time.current - 3.days period_end = Time.current @@ -132,13 +132,13 @@ expect(page).to have_selector('.activity', count: 15) end - it "daterange filter works for single day" do + it 'daterange filter works for single day' do visit project_activities_path(current_project, period_start: Time.current, period_end: Time.current) expect(page).to have_selector('.activity', count: 10) end - it "combined filter works" do - visit project_activities_path(current_project, type: "Card", user: second_user.id) + it 'combined filter works' do + visit project_activities_path(current_project, type: 'Card', user: second_user.id) expect(page).to have_selector('.activity', count: 10) end end diff --git a/spec/models/activity_spec.rb b/spec/models/activity_spec.rb index 086da8ce02..1d99cbe154 100644 --- a/spec/models/activity_spec.rb +++ b/spec/models/activity_spec.rb @@ -11,21 +11,21 @@ it { should validate_inclusion_of(:action).in_array %i[create update destroy] } - describe "#trackable=" do - context "when passed an Issue" do - it "sets trackable_type as Issue, not Note" do + describe '#trackable=' do + context 'when passed an Issue' do + it 'sets trackable_type as Issue, not Note' do # Default Rails behaviour is to set trackable_type to 'Note' when you # pass an Issue, meaning that it gets loaded as a Note, not an Issue, # when you call #trackable later. issue = create(:issue) activity = create(:activity, trackable: issue) - expect(activity.trackable_type).to eq "Issue" + expect(activity.trackable_type).to eq 'Issue' expect(activity.reload.trackable).to eq issue end end end - describe "#filter_by_user_id" do + describe '#filter_by_user_id' do before do issue = create(:issue) @user = create(:user) @@ -34,15 +34,15 @@ activity3 = create(:activity, trackable: issue) end - context "when passed a valid user id" do - it "returns activities of this user" do + context 'when passed a valid user id' do + it 'returns activities of this user' do expect(Activity.filter_by_user_id(@user.id).count).to eq 2 expect(Activity.all.count).to eq 3 end end - context "when passed a non valid user id" do - it "returns an empty collection" do + context 'when passed a non valid user id' do + it 'returns an empty collection' do user_id = User.last.id + 1 expect(Activity.filter_by_user_id(user_id).count).to eq 0 expect(Activity.all.count).to eq 3 @@ -50,7 +50,7 @@ end end - describe "#filter_by_type" do + describe '#filter_by_type' do before do issue = create(:issue) card = create(:card) @@ -59,22 +59,22 @@ activity3 = create(:activity, trackable: card) end - context "when passed a valid type" do - it "returns activities of this user" do - expect(Activity.filter_by_type("Card").count).to eq 2 + context 'when passed a valid type' do + it 'returns activities of this user' do + expect(Activity.filter_by_type('Card').count).to eq 2 expect(Activity.all.count).to eq 3 end end - context "when passed a non valid type" do - it "returns an empty collection" do - expect(Activity.filter_by_type("galaxy").count).to eq 0 + context 'when passed a non valid type' do + it 'returns an empty collection' do + expect(Activity.filter_by_type('galaxy').count).to eq 0 expect(Activity.all.count).to eq 3 end end end - describe "#filter_by_date" do + describe '#filter_by_date' do before do issue = create(:issue) activity = create(:activity, trackable: issue) @@ -82,8 +82,8 @@ activity3 = create(:activity, trackable: issue, created_at: DateTime.now.beginning_of_year - 1.year) end - context "when passed a valid date" do - it "returns activities within the date" do + context 'when passed a valid date' do + it 'returns activities within the date' do year_start = DateTime.now.beginning_of_year last_year_start = year_start - 1.year period_end = DateTime.now.end_of_day