Commit a9dd14ea80280dff7036a4930dfbd042cee36372
1 parent
50c4dc64
Exists in
colab
and in
2 other branches
Create latest Repositories listing method
This is a information that will get published at the homepage.
Showing
2 changed files
with
28 additions
and
0 deletions
Show diff stats
app/models/repository.rb
| 1 | class Repository < KalibroClient::Entities::Processor::Repository | 1 | class Repository < KalibroClient::Entities::Processor::Repository |
| 2 | include KalibroRecord | 2 | include KalibroRecord |
| 3 | + | ||
| 4 | + def self.latest(count=1) | ||
| 5 | + all.sort { |one, another| another.id <=> one.id }.first(count) | ||
| 6 | + end | ||
| 3 | end | 7 | end |
| @@ -0,0 +1,24 @@ | @@ -0,0 +1,24 @@ | ||
| 1 | +require 'rails_helper' | ||
| 2 | + | ||
| 3 | +describe Repository do | ||
| 4 | + describe 'class method' do | ||
| 5 | + describe 'latest' do | ||
| 6 | + let!(:repository) { FactoryGirl.build(:repository, id: 1) } | ||
| 7 | + let!(:another_repository) { FactoryGirl.build(:another_repository, id: 2) } | ||
| 8 | + | ||
| 9 | + before do | ||
| 10 | + Repository.expects(:all).returns([repository, another_repository]) | ||
| 11 | + end | ||
| 12 | + | ||
| 13 | + it 'should return the two repositorys ordered' do | ||
| 14 | + expect(Repository.latest(2)).to eq([another_repository, repository]) | ||
| 15 | + end | ||
| 16 | + | ||
| 17 | + context 'when no parameter is passed' do | ||
| 18 | + it 'should return just the most recent repository' do | ||
| 19 | + expect(Repository.latest).to eq([another_repository]) | ||
| 20 | + end | ||
| 21 | + end | ||
| 22 | + end | ||
| 23 | + end | ||
| 24 | +end | ||
| 0 | \ No newline at end of file | 25 | \ No newline at end of file |