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
.gitignore
... ... @@ -18,3 +18,4 @@
18 18 coverage
19 19  
20 20 database.yml
  21 +kalibro_cucumber_helpers.yml
21 22 \ No newline at end of file
... ...
.travis.yml
... ... @@ -5,6 +5,11 @@ rvm:
5 5 before_script:
6 6 - "cp config/database.yml.sample config/database.yml"
7 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 14 notifications:
10 15 email:
... ...
Gemfile.lock
1 1 GIT
2 2 remote: https://github.com/mezuro/kalibro_entities.git
3   - revision: c16eb3fdebcdd95ba6bc4c12c89b5039b490ed41
  3 + revision: de2d51db42ddb77f3842eec2223c00b68a48222f
4 4 specs:
5 5 kalibro_entities (0.0.1)
6 6 savon (~> 2.3.0)
... ... @@ -36,7 +36,7 @@ GEM
36 36 gyoku (>= 0.4.0)
37 37 nokogiri (>= 1.4.0)
38 38 arel (4.0.0)
39   - atomic (1.1.12)
  39 + atomic (1.1.13)
40 40 bcrypt-ruby (3.1.1)
41 41 builder (3.1.4)
42 42 capistrano (2.15.5)
... ... @@ -68,7 +68,7 @@ GEM
68 68 cucumber (>= 1.1.8)
69 69 nokogiri (>= 1.5.0)
70 70 database_cleaner (1.1.1)
71   - devise (3.0.1)
  71 + devise (3.0.2)
72 72 bcrypt-ruby (~> 3.0)
73 73 orm_adapter (~> 0.1)
74 74 railties (>= 3.2.6, < 5)
... ... @@ -82,7 +82,7 @@ GEM
82 82 factory_girl_rails (4.2.1)
83 83 factory_girl (~> 4.2.0)
84 84 railties (>= 3.0.0)
85   - gherkin (2.12.0)
  85 + gherkin (2.12.1)
86 86 multi_json (~> 1.3)
87 87 gyoku (1.1.0)
88 88 builder (>= 2.1.2)
... ... @@ -91,7 +91,7 @@ GEM
91 91 httpi (2.1.0)
92 92 rack
93 93 rubyntlm (~> 0.3.2)
94   - i18n (0.6.4)
  94 + i18n (0.6.5)
95 95 jbuilder (1.5.0)
96 96 activesupport (>= 3.0.0)
97 97 multi_json (>= 1.2.0)
... ... @@ -104,12 +104,12 @@ GEM
104 104 mime-types (~> 1.16)
105 105 treetop (~> 1.4.8)
106 106 metaclass (0.0.1)
107   - mime-types (1.23)
  107 + mime-types (1.24)
108 108 minitest (4.7.5)
109 109 mocha (0.14.0)
110 110 metaclass (~> 0.0.1)
111 111 modernizr-rails (2.6.2.3)
112   - multi_json (1.7.8)
  112 + multi_json (1.7.9)
113 113 net-scp (1.1.2)
114 114 net-ssh (>= 2.6.5)
115 115 net-sftp (2.1.2)
... ... @@ -142,10 +142,10 @@ GEM
142 142 rdoc (3.12.2)
143 143 json (~> 1.4)
144 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 147 diff-lcs (>= 1.1.3, < 2.0)
148   - rspec-mocks (2.14.2)
  148 + rspec-mocks (2.14.3)
149 149 rspec-rails (2.14.0)
150 150 actionpack (>= 3.0)
151 151 activesupport (>= 3.0)
... ... @@ -153,9 +153,9 @@ GEM
153 153 rspec-core (~> 2.14.0)
154 154 rspec-expectations (~> 2.14.0)
155 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 159 sass (3.2.10)
160 160 sass-rails (4.0.0)
161 161 railties (>= 4.0.0.beta, < 5.0)
... ... @@ -172,7 +172,7 @@ GEM
172 172 sdoc (0.3.20)
173 173 json (>= 1.1.3)
174 174 rdoc (~> 3.10)
175   - shoulda-matchers (2.2.0)
  175 + shoulda-matchers (2.3.0)
176 176 activesupport (>= 3.0.0)
177 177 simplecov (0.7.1)
178 178 multi_json (~> 1.0)
... ... @@ -195,7 +195,7 @@ GEM
195 195 thread_safe (0.1.2)
196 196 atomic
197 197 tilt (1.4.1)
198   - treetop (1.4.14)
  198 + treetop (1.4.15)
199 199 polyglot
200 200 polyglot (>= 0.3.1)
201 201 turbolinks (1.3.0)
... ...
app/controllers/home_controller.rb
1 1 class HomeController < ApplicationController
2 2 def index
  3 + @latest_projects = Project.latest(5)
3 4 end
4 5 end
... ...
app/models/project.rb
... ... @@ -7,4 +7,8 @@ class Project &lt; KalibroEntities::Entities::Project
7 7 def persisted?
8 8 false
9 9 end
  10 +
  11 + def self.latest(count = 1)
  12 + all.sort { |a,b| b.id <=> a.id }.first(count)
  13 + end
10 14 end
... ...
app/views/home/index.html.erb
... ... @@ -5,4 +5,12 @@
5 5 <% else %>
6 6 <%= link_to('Login', new_user_session_path) %>
7 7 <%= link_to('Sign Up', new_user_registration_path) %>
8   -<% end %>
9 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 18 \ No newline at end of file
... ...
features/homepage.feature
... ... @@ -7,10 +7,14 @@ Feature: Homepage
7 7 Given I am at the homepage
8 8 Then I should see Login
9 9 And I should see Sign Up
  10 + And I should see Latest Projects
  11 + And I should see All Projects
10 12  
11 13 Scenario: Signed in
12 14 Given I am a regular user
13 15 And I am signed in
14 16 And I am at the homepage
15 17 Then I should see Edit
16   - And I should see Logout
17 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 22 \ No newline at end of file
... ...
features/support/env.rb
... ... @@ -62,5 +62,11 @@ end
62 62 # See https://github.com/cucumber/cucumber-rails/blob/master/features/choose_javascript_database_strategy.feature
63 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 71 # Warden test helpers so the user authentication can be as fast as possible
66 72 include Warden::Test::Helpers
67 73 \ No newline at end of file
... ...
features/support/kalibro_cucumber_helpers.yml.sample 0 → 100644
... ... @@ -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 11 \ No newline at end of file
... ...
spec/controllers/home_controller_spec.rb
... ... @@ -4,6 +4,8 @@ describe HomeController do
4 4 context 'Method' do
5 5 context '#index' do
6 6 before :each do
  7 + Project.expects(:latest).with(5).returns([])
  8 +
7 9 get :index
8 10 end
9 11  
... ...
spec/factories/projects.rb
... ... @@ -6,4 +6,10 @@ FactoryGirl.define do
6 6 name "QT Calculator"
7 7 description "A simple calculator for us."
8 8 end
  9 +
  10 + factory :another_project, class: Project do
  11 + id 2
  12 + name "Kalibro"
  13 + description "Code Metrics"
  14 + end
9 15 end
... ...
spec/models/project_spec.rb
... ... @@ -7,5 +7,24 @@ describe Project do
7 7 subject.persisted?.should eq(false)
8 8 end
9 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 29 end
11 30 end
... ...