Added Event.limit_recent

This will be used to move some querying logic from the users controller
to the Event model (where it belongs).
This commit is contained in:
Yorick Peterse 2015-11-18 12:25:37 +01:00
parent fbcf3bd3fc
commit 01620dd7e7
2 changed files with 21 additions and 0 deletions

View File

@ -69,6 +69,10 @@ class Event < ActiveRecord::Base
row ? row.updated_at : nil
end
def limit_recent(limit = 20, offset = nil)
recent.limit(limit).offset(offset)
end
end
def proper?

View File

@ -85,4 +85,21 @@ describe Event do
end
end
end
describe '.limit_recent' do
let!(:event1) { create(:closed_issue_event) }
let!(:event2) { create(:closed_issue_event) }
describe 'without an explicit limit' do
subject { Event.limit_recent }
it { is_expected.to eq([event2, event1]) }
end
describe 'with an explicit limit' do
subject { Event.limit_recent(1) }
it { is_expected.to eq([event2]) }
end
end
end