Skip to content

Commit

Permalink
Rubocop fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Kostas Sklias committed Dec 6, 2023
1 parent 55e6266 commit c21fac8
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 39 deletions.
18 changes: 9 additions & 9 deletions app/controllers/activities_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion app/models/activity.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 ------------------------------------------------------------
Expand Down
20 changes: 10 additions & 10 deletions spec/features/activity_pages/activity_pages_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,44 +101,44 @@
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

visit project_activities_path(current_project, period_start: period_start, period_end: period_end)
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
Expand Down
38 changes: 19 additions & 19 deletions spec/models/activity_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -34,23 +34,23 @@
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
end
end
end

describe "#filter_by_type" do
describe '#filter_by_type' do
before do
issue = create(:issue)
card = create(:card)
Expand All @@ -59,31 +59,31 @@
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)
activity2 = create(:activity, trackable: issue, created_at: DateTime.now.beginning_of_year - 1.year)
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
Expand Down

0 comments on commit c21fac8

Please sign in to comment.