Commit 50c4dc64b93945dc0afbe68076fdc528bcd46b55
1 parent
d0369ac5
Exists in
colab
and in
2 other branches
Add latest KalibroConfigurations listing
This is a information that will get published at the homepage.
Showing
3 changed files
with
47 additions
and
8 deletions
Show diff stats
app/models/kalibro_configuration.rb
| ... | ... | @@ -28,4 +28,8 @@ class KalibroConfiguration < KalibroClient::Entities::Configurations::KalibroCon |
| 28 | 28 | @attributes = nil |
| 29 | 29 | super |
| 30 | 30 | end |
| 31 | + | |
| 32 | + def self.latest(count=1) | |
| 33 | + all.sort { |one, another| another.id <=> one.id }.select { |kalibro_configuration| kalibro_configuration.attributes.public }.first(count) | |
| 34 | + end | |
| 31 | 35 | end | ... | ... |
app/views/home/index.html.erb
| ... | ... | @@ -6,12 +6,24 @@ |
| 6 | 6 | </p> |
| 7 | 7 | </div> |
| 8 | 8 | |
| 9 | -<h2><%= t('latest_projects') %></h2> | |
| 9 | +<div class="container-fluid"> | |
| 10 | + <div class="row"> | |
| 11 | + <div class="col-md-4"> | |
| 12 | + <h2><%= t('latest_projects') %></h2> | |
| 10 | 13 | |
| 11 | -<ul> | |
| 12 | - <% cache do %> | |
| 13 | - <% @latest_projects.each do |project| %> | |
| 14 | - <li><%= link_to(project.name, project_path(project.id)) %></li> | |
| 15 | - <% end %> | |
| 16 | - <% end %> | |
| 17 | -</ul> | |
| 14 | + <ul> | |
| 15 | + <% cache do %> | |
| 16 | + <% @latest_projects.each do |project| %> | |
| 17 | + <li><%= link_to(project.name, project_path(project.id)) %></li> | |
| 18 | + <% end %> | |
| 19 | + <% end %> | |
| 20 | + </ul> | |
| 21 | + </div> | |
| 22 | + <div class="col-md-4"> | |
| 23 | + <h2><%= t('latest_projects') %></h2> | |
| 24 | + </div> | |
| 25 | + <div class="col-md-4"> | |
| 26 | + <h2><%= t('latest_projects') %></h2> | |
| 27 | + </div> | |
| 28 | + </div> | |
| 29 | +</div> | ... | ... |
spec/models/kalibro_configuration_spec.rb
| ... | ... | @@ -70,6 +70,29 @@ describe KalibroConfiguration, :type => :model do |
| 70 | 70 | end |
| 71 | 71 | end |
| 72 | 72 | end |
| 73 | + | |
| 74 | + describe 'latest' do | |
| 75 | + let!(:kalibro_configuration) { FactoryGirl.build(:kalibro_configuration, id: 1) } | |
| 76 | + let!(:another_kalibro_configuration) { FactoryGirl.build(:another_kalibro_configuration, id: 2) } | |
| 77 | + let!(:kalibro_configuration_attributes) { FactoryGirl.build(:kalibro_configuration_attributes) } | |
| 78 | + | |
| 79 | + before :each do | |
| 80 | + kalibro_configuration.expects(:attributes).returns(kalibro_configuration_attributes) | |
| 81 | + another_kalibro_configuration.expects(:attributes).returns(kalibro_configuration_attributes) | |
| 82 | + | |
| 83 | + KalibroConfiguration.expects(:all).returns([kalibro_configuration, another_kalibro_configuration]) | |
| 84 | + end | |
| 85 | + | |
| 86 | + it 'should return the two kalibro_configurations ordered' do | |
| 87 | + expect(KalibroConfiguration.latest(2)).to eq([another_kalibro_configuration, kalibro_configuration]) | |
| 88 | + end | |
| 89 | + | |
| 90 | + context 'when no parameter is passed' do | |
| 91 | + it 'should return just the most recent kalibro_configuration' do | |
| 92 | + expect(KalibroConfiguration.latest).to eq([another_kalibro_configuration]) | |
| 93 | + end | |
| 94 | + end | |
| 95 | + end | |
| 73 | 96 | end |
| 74 | 97 | |
| 75 | 98 | describe 'destroy' do | ... | ... |