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:
parent
fbcf3bd3fc
commit
01620dd7e7
|
@ -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?
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue