Commit 431aa2762339c7743af58c2a9c5e36faf3ab065e

Authored by Rafael Manzo
1 parent c7eaeb4a

Listing the recent projects on the homepage

It was necessary to update a lot of gems to get the latest kalibro_entities:

	atomic
	devise
	gherkin
	i18n
	mime-types
	multi_json
	rspec-core
	rspec-expectations
	rspec-mocks
	rubyntlm
	rvm-capistrano
	capistrano
	shoulda-matchers
	treetop
@@ -18,3 +18,4 @@ @@ -18,3 +18,4 @@
18 coverage 18 coverage
19 19
20 database.yml 20 database.yml
  21 +kalibro_cucumber_helpers.yml
21 \ No newline at end of file 22 \ No newline at end of file
@@ -5,6 +5,11 @@ rvm: @@ -5,6 +5,11 @@ rvm:
5 before_script: 5 before_script:
6 - "cp config/database.yml.sample config/database.yml" 6 - "cp config/database.yml.sample config/database.yml"
7 - "rake db:migrate RAILS_ENV=test" 7 - "rake db:migrate RAILS_ENV=test"
  8 + - wget https://gist.github.com/rafamanzo/6179925/raw/77653bd6229e99d5251180a4488e2fa54d0cd4ac/db_bootstrap.sql
  9 + - wget https://gist.github.com/rafamanzo/6179925/raw/172802a0db1ae88c3d5d3d3547833c45a5c9a7a2/install.sh
  10 + - chmod +x install.sh
  11 + - ./install.sh
  12 + - cp features/support/kalibro_cucumber_helpers.yml.sample features/support/kalibro_cucumber_helpers.yml
8 13
9 notifications: 14 notifications:
10 email: 15 email:
1 GIT 1 GIT
2 remote: https://github.com/mezuro/kalibro_entities.git 2 remote: https://github.com/mezuro/kalibro_entities.git
3 - revision: c16eb3fdebcdd95ba6bc4c12c89b5039b490ed41 3 + revision: de2d51db42ddb77f3842eec2223c00b68a48222f
4 specs: 4 specs:
5 kalibro_entities (0.0.1) 5 kalibro_entities (0.0.1)
6 savon (~> 2.3.0) 6 savon (~> 2.3.0)
@@ -36,7 +36,7 @@ GEM @@ -36,7 +36,7 @@ GEM
36 gyoku (>= 0.4.0) 36 gyoku (>= 0.4.0)
37 nokogiri (>= 1.4.0) 37 nokogiri (>= 1.4.0)
38 arel (4.0.0) 38 arel (4.0.0)
39 - atomic (1.1.12) 39 + atomic (1.1.13)
40 bcrypt-ruby (3.1.1) 40 bcrypt-ruby (3.1.1)
41 builder (3.1.4) 41 builder (3.1.4)
42 capistrano (2.15.5) 42 capistrano (2.15.5)
@@ -68,7 +68,7 @@ GEM @@ -68,7 +68,7 @@ GEM
68 cucumber (>= 1.1.8) 68 cucumber (>= 1.1.8)
69 nokogiri (>= 1.5.0) 69 nokogiri (>= 1.5.0)
70 database_cleaner (1.1.1) 70 database_cleaner (1.1.1)
71 - devise (3.0.1) 71 + devise (3.0.2)
72 bcrypt-ruby (~> 3.0) 72 bcrypt-ruby (~> 3.0)
73 orm_adapter (~> 0.1) 73 orm_adapter (~> 0.1)
74 railties (>= 3.2.6, < 5) 74 railties (>= 3.2.6, < 5)
@@ -82,7 +82,7 @@ GEM @@ -82,7 +82,7 @@ GEM
82 factory_girl_rails (4.2.1) 82 factory_girl_rails (4.2.1)
83 factory_girl (~> 4.2.0) 83 factory_girl (~> 4.2.0)
84 railties (>= 3.0.0) 84 railties (>= 3.0.0)
85 - gherkin (2.12.0) 85 + gherkin (2.12.1)
86 multi_json (~> 1.3) 86 multi_json (~> 1.3)
87 gyoku (1.1.0) 87 gyoku (1.1.0)
88 builder (>= 2.1.2) 88 builder (>= 2.1.2)
@@ -91,7 +91,7 @@ GEM @@ -91,7 +91,7 @@ GEM
91 httpi (2.1.0) 91 httpi (2.1.0)
92 rack 92 rack
93 rubyntlm (~> 0.3.2) 93 rubyntlm (~> 0.3.2)
94 - i18n (0.6.4) 94 + i18n (0.6.5)
95 jbuilder (1.5.0) 95 jbuilder (1.5.0)
96 activesupport (>= 3.0.0) 96 activesupport (>= 3.0.0)
97 multi_json (>= 1.2.0) 97 multi_json (>= 1.2.0)
@@ -104,12 +104,12 @@ GEM @@ -104,12 +104,12 @@ GEM
104 mime-types (~> 1.16) 104 mime-types (~> 1.16)
105 treetop (~> 1.4.8) 105 treetop (~> 1.4.8)
106 metaclass (0.0.1) 106 metaclass (0.0.1)
107 - mime-types (1.23) 107 + mime-types (1.24)
108 minitest (4.7.5) 108 minitest (4.7.5)
109 mocha (0.14.0) 109 mocha (0.14.0)
110 metaclass (~> 0.0.1) 110 metaclass (~> 0.0.1)
111 modernizr-rails (2.6.2.3) 111 modernizr-rails (2.6.2.3)
112 - multi_json (1.7.8) 112 + multi_json (1.7.9)
113 net-scp (1.1.2) 113 net-scp (1.1.2)
114 net-ssh (>= 2.6.5) 114 net-ssh (>= 2.6.5)
115 net-sftp (2.1.2) 115 net-sftp (2.1.2)
@@ -142,10 +142,10 @@ GEM @@ -142,10 +142,10 @@ GEM
142 rdoc (3.12.2) 142 rdoc (3.12.2)
143 json (~> 1.4) 143 json (~> 1.4)
144 ref (1.0.5) 144 ref (1.0.5)
145 - rspec-core (2.14.4)  
146 - rspec-expectations (2.14.0) 145 + rspec-core (2.14.5)
  146 + rspec-expectations (2.14.2)
147 diff-lcs (>= 1.1.3, < 2.0) 147 diff-lcs (>= 1.1.3, < 2.0)
148 - rspec-mocks (2.14.2) 148 + rspec-mocks (2.14.3)
149 rspec-rails (2.14.0) 149 rspec-rails (2.14.0)
150 actionpack (>= 3.0) 150 actionpack (>= 3.0)
151 activesupport (>= 3.0) 151 activesupport (>= 3.0)
@@ -153,9 +153,9 @@ GEM @@ -153,9 +153,9 @@ GEM
153 rspec-core (~> 2.14.0) 153 rspec-core (~> 2.14.0)
154 rspec-expectations (~> 2.14.0) 154 rspec-expectations (~> 2.14.0)
155 rspec-mocks (~> 2.14.0) 155 rspec-mocks (~> 2.14.0)
156 - rubyntlm (0.3.3)  
157 - rvm-capistrano (1.4.1)  
158 - capistrano (>= 2.0.0) 156 + rubyntlm (0.3.4)
  157 + rvm-capistrano (1.4.4)
  158 + capistrano (>= 2.15.4)
159 sass (3.2.10) 159 sass (3.2.10)
160 sass-rails (4.0.0) 160 sass-rails (4.0.0)
161 railties (>= 4.0.0.beta, < 5.0) 161 railties (>= 4.0.0.beta, < 5.0)
@@ -172,7 +172,7 @@ GEM @@ -172,7 +172,7 @@ GEM
172 sdoc (0.3.20) 172 sdoc (0.3.20)
173 json (>= 1.1.3) 173 json (>= 1.1.3)
174 rdoc (~> 3.10) 174 rdoc (~> 3.10)
175 - shoulda-matchers (2.2.0) 175 + shoulda-matchers (2.3.0)
176 activesupport (>= 3.0.0) 176 activesupport (>= 3.0.0)
177 simplecov (0.7.1) 177 simplecov (0.7.1)
178 multi_json (~> 1.0) 178 multi_json (~> 1.0)
@@ -195,7 +195,7 @@ GEM @@ -195,7 +195,7 @@ GEM
195 thread_safe (0.1.2) 195 thread_safe (0.1.2)
196 atomic 196 atomic
197 tilt (1.4.1) 197 tilt (1.4.1)
198 - treetop (1.4.14) 198 + treetop (1.4.15)
199 polyglot 199 polyglot
200 polyglot (>= 0.3.1) 200 polyglot (>= 0.3.1)
201 turbolinks (1.3.0) 201 turbolinks (1.3.0)
app/controllers/home_controller.rb
1 class HomeController < ApplicationController 1 class HomeController < ApplicationController
2 def index 2 def index
  3 + @latest_projects = Project.latest(5)
3 end 4 end
4 end 5 end
app/models/project.rb
@@ -7,4 +7,8 @@ class Project &lt; KalibroEntities::Entities::Project @@ -7,4 +7,8 @@ class Project &lt; KalibroEntities::Entities::Project
7 def persisted? 7 def persisted?
8 false 8 false
9 end 9 end
  10 +
  11 + def self.latest(count = 1)
  12 + all.sort { |a,b| b.id <=> a.id }.first(count)
  13 + end
10 end 14 end
app/views/home/index.html.erb
@@ -5,4 +5,12 @@ @@ -5,4 +5,12 @@
5 <% else %> 5 <% else %>
6 <%= link_to('Login', new_user_session_path) %> 6 <%= link_to('Login', new_user_session_path) %>
7 <%= link_to('Sign Up', new_user_registration_path) %> 7 <%= link_to('Sign Up', new_user_registration_path) %>
8 -<% end %>  
9 \ No newline at end of file 8 \ No newline at end of file
  9 +<% end %>
  10 +
  11 +<p><h2>Latest Projects</h2></p>
  12 +<ul>
  13 + <% @latest_projects.each do |project| %>
  14 + <li><%= link_to(project.name, project_path(project.id)) %></li>
  15 + <% end %>
  16 +</ul>
  17 +<p><%= link_to('All Projects', projects_path) %></p>
10 \ No newline at end of file 18 \ No newline at end of file
features/homepage.feature
@@ -7,10 +7,14 @@ Feature: Homepage @@ -7,10 +7,14 @@ Feature: Homepage
7 Given I am at the homepage 7 Given I am at the homepage
8 Then I should see Login 8 Then I should see Login
9 And I should see Sign Up 9 And I should see Sign Up
  10 + And I should see Latest Projects
  11 + And I should see All Projects
10 12
11 Scenario: Signed in 13 Scenario: Signed in
12 Given I am a regular user 14 Given I am a regular user
13 And I am signed in 15 And I am signed in
14 And I am at the homepage 16 And I am at the homepage
15 Then I should see Edit 17 Then I should see Edit
16 - And I should see Logout  
17 \ No newline at end of file 18 \ No newline at end of file
  19 + And I should see Logout
  20 + And I should see Latest Projects
  21 + And I should see All Projects
18 \ No newline at end of file 22 \ No newline at end of file
features/support/env.rb
@@ -62,5 +62,11 @@ end @@ -62,5 +62,11 @@ end
62 # See https://github.com/cucumber/cucumber-rails/blob/master/features/choose_javascript_database_strategy.feature 62 # See https://github.com/cucumber/cucumber-rails/blob/master/features/choose_javascript_database_strategy.feature
63 Cucumber::Rails::Database.javascript_strategy = :truncation 63 Cucumber::Rails::Database.javascript_strategy = :truncation
64 64
  65 +# Kalibro hooks
  66 +require 'kalibro_entities/kalibro_cucumber_helpers/hooks'
  67 +
  68 +# Configuring the right hooks
  69 +KalibroEntities::KalibroCucumberHelpers.configure_from_yml("#{__dir__}/kalibro_cucumber_helpers.yml")
  70 +
65 # Warden test helpers so the user authentication can be as fast as possible 71 # Warden test helpers so the user authentication can be as fast as possible
66 include Warden::Test::Helpers 72 include Warden::Test::Helpers
67 \ No newline at end of file 73 \ No newline at end of file
features/support/kalibro_cucumber_helpers.yml.sample 0 → 100644
@@ -0,0 +1,10 @@ @@ -0,0 +1,10 @@
  1 +kalibro_cucumber_helpers:
  2 + database: "kalibro_test"
  3 + user: "kalibro"
  4 + password: "kalibro"
  5 + psql_file_path: "/tmp/PostgreSQL.sql"
  6 + query_file_path: "/tmp/query"
  7 + kalibro_home: "/usr/share/tomcat6/.kalibro"
  8 + tomcat_user: "tomcat6"
  9 + tomcat_group: "tomcat6"
  10 + tomcat_restart_command: "sudo\\ service\\ tomcat6\\ restart"
0 \ No newline at end of file 11 \ No newline at end of file
spec/controllers/home_controller_spec.rb
@@ -4,6 +4,8 @@ describe HomeController do @@ -4,6 +4,8 @@ describe HomeController do
4 context 'Method' do 4 context 'Method' do
5 context '#index' do 5 context '#index' do
6 before :each do 6 before :each do
  7 + Project.expects(:latest).with(5).returns([])
  8 +
7 get :index 9 get :index
8 end 10 end
9 11
spec/factories/projects.rb
@@ -6,4 +6,10 @@ FactoryGirl.define do @@ -6,4 +6,10 @@ FactoryGirl.define do
6 name "QT Calculator" 6 name "QT Calculator"
7 description "A simple calculator for us." 7 description "A simple calculator for us."
8 end 8 end
  9 +
  10 + factory :another_project, class: Project do
  11 + id 2
  12 + name "Kalibro"
  13 + description "Code Metrics"
  14 + end
9 end 15 end
spec/models/project_spec.rb
@@ -7,5 +7,24 @@ describe Project do @@ -7,5 +7,24 @@ describe Project do
7 subject.persisted?.should eq(false) 7 subject.persisted?.should eq(false)
8 end 8 end
9 end 9 end
  10 +
  11 + describe 'latest' do
  12 + before :each do
  13 + @qt = FactoryGirl.build(:project)
  14 + @kalibro = FactoryGirl.build(:another_project)
  15 +
  16 + Project.expects(:all).returns([@qt, @kalibro])
  17 + end
  18 +
  19 + it 'should return the two projects ordered' do
  20 + Project.latest(2).should eq([@kalibro, @qt])
  21 + end
  22 +
  23 + context 'when no parameter is passed' do
  24 + it 'should return just the most recent project' do
  25 + Project.latest.should eq([@kalibro])
  26 + end
  27 + end
  28 + end
10 end 29 end
11 end 30 end