diff --git a/.gitignore b/.gitignore index 342b3a1..dae924b 100644 --- a/.gitignore +++ b/.gitignore @@ -18,3 +18,4 @@ coverage database.yml +kalibro_cucumber_helpers.yml \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index f748098..91008d9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,6 +5,11 @@ rvm: before_script: - "cp config/database.yml.sample config/database.yml" - "rake db:migrate RAILS_ENV=test" + - wget https://gist.github.com/rafamanzo/6179925/raw/77653bd6229e99d5251180a4488e2fa54d0cd4ac/db_bootstrap.sql + - wget https://gist.github.com/rafamanzo/6179925/raw/172802a0db1ae88c3d5d3d3547833c45a5c9a7a2/install.sh + - chmod +x install.sh + - ./install.sh + - cp features/support/kalibro_cucumber_helpers.yml.sample features/support/kalibro_cucumber_helpers.yml notifications: email: diff --git a/Gemfile.lock b/Gemfile.lock index c1189f3..f930c96 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,6 +1,6 @@ GIT remote: https://github.com/mezuro/kalibro_entities.git - revision: c16eb3fdebcdd95ba6bc4c12c89b5039b490ed41 + revision: de2d51db42ddb77f3842eec2223c00b68a48222f specs: kalibro_entities (0.0.1) savon (~> 2.3.0) @@ -36,7 +36,7 @@ GEM gyoku (>= 0.4.0) nokogiri (>= 1.4.0) arel (4.0.0) - atomic (1.1.12) + atomic (1.1.13) bcrypt-ruby (3.1.1) builder (3.1.4) capistrano (2.15.5) @@ -68,7 +68,7 @@ GEM cucumber (>= 1.1.8) nokogiri (>= 1.5.0) database_cleaner (1.1.1) - devise (3.0.1) + devise (3.0.2) bcrypt-ruby (~> 3.0) orm_adapter (~> 0.1) railties (>= 3.2.6, < 5) @@ -82,7 +82,7 @@ GEM factory_girl_rails (4.2.1) factory_girl (~> 4.2.0) railties (>= 3.0.0) - gherkin (2.12.0) + gherkin (2.12.1) multi_json (~> 1.3) gyoku (1.1.0) builder (>= 2.1.2) @@ -91,7 +91,7 @@ GEM httpi (2.1.0) rack rubyntlm (~> 0.3.2) - i18n (0.6.4) + i18n (0.6.5) jbuilder (1.5.0) activesupport (>= 3.0.0) multi_json (>= 1.2.0) @@ -104,12 +104,12 @@ GEM mime-types (~> 1.16) treetop (~> 1.4.8) metaclass (0.0.1) - mime-types (1.23) + mime-types (1.24) minitest (4.7.5) mocha (0.14.0) metaclass (~> 0.0.1) modernizr-rails (2.6.2.3) - multi_json (1.7.8) + multi_json (1.7.9) net-scp (1.1.2) net-ssh (>= 2.6.5) net-sftp (2.1.2) @@ -142,10 +142,10 @@ GEM rdoc (3.12.2) json (~> 1.4) ref (1.0.5) - rspec-core (2.14.4) - rspec-expectations (2.14.0) + rspec-core (2.14.5) + rspec-expectations (2.14.2) diff-lcs (>= 1.1.3, < 2.0) - rspec-mocks (2.14.2) + rspec-mocks (2.14.3) rspec-rails (2.14.0) actionpack (>= 3.0) activesupport (>= 3.0) @@ -153,9 +153,9 @@ GEM rspec-core (~> 2.14.0) rspec-expectations (~> 2.14.0) rspec-mocks (~> 2.14.0) - rubyntlm (0.3.3) - rvm-capistrano (1.4.1) - capistrano (>= 2.0.0) + rubyntlm (0.3.4) + rvm-capistrano (1.4.4) + capistrano (>= 2.15.4) sass (3.2.10) sass-rails (4.0.0) railties (>= 4.0.0.beta, < 5.0) @@ -172,7 +172,7 @@ GEM sdoc (0.3.20) json (>= 1.1.3) rdoc (~> 3.10) - shoulda-matchers (2.2.0) + shoulda-matchers (2.3.0) activesupport (>= 3.0.0) simplecov (0.7.1) multi_json (~> 1.0) @@ -195,7 +195,7 @@ GEM thread_safe (0.1.2) atomic tilt (1.4.1) - treetop (1.4.14) + treetop (1.4.15) polyglot polyglot (>= 0.3.1) turbolinks (1.3.0) diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb index 95f2992..c44b798 100644 --- a/app/controllers/home_controller.rb +++ b/app/controllers/home_controller.rb @@ -1,4 +1,5 @@ class HomeController < ApplicationController def index + @latest_projects = Project.latest(5) end end diff --git a/app/models/project.rb b/app/models/project.rb index 16a7074..9994bdf 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -7,4 +7,8 @@ class Project < KalibroEntities::Entities::Project def persisted? false end + + def self.latest(count = 1) + all.sort { |a,b| b.id <=> a.id }.first(count) + end end diff --git a/app/views/home/index.html.erb b/app/views/home/index.html.erb index d4e2a9c..3fab7c9 100644 --- a/app/views/home/index.html.erb +++ b/app/views/home/index.html.erb @@ -5,4 +5,12 @@ <% else %> <%= link_to('Login', new_user_session_path) %> <%= link_to('Sign Up', new_user_registration_path) %> -<% end %> \ No newline at end of file +<% end %> + +
<%= link_to('All Projects', projects_path) %>
\ No newline at end of file diff --git a/features/homepage.feature b/features/homepage.feature index 470515f..e02928b 100644 --- a/features/homepage.feature +++ b/features/homepage.feature @@ -7,10 +7,14 @@ Feature: Homepage Given I am at the homepage Then I should see Login And I should see Sign Up + And I should see Latest Projects + And I should see All Projects Scenario: Signed in Given I am a regular user And I am signed in And I am at the homepage Then I should see Edit - And I should see Logout \ No newline at end of file + And I should see Logout + And I should see Latest Projects + And I should see All Projects \ No newline at end of file diff --git a/features/support/env.rb b/features/support/env.rb index dec5de8..dca2c1f 100644 --- a/features/support/env.rb +++ b/features/support/env.rb @@ -62,5 +62,11 @@ end # See https://github.com/cucumber/cucumber-rails/blob/master/features/choose_javascript_database_strategy.feature Cucumber::Rails::Database.javascript_strategy = :truncation +# Kalibro hooks +require 'kalibro_entities/kalibro_cucumber_helpers/hooks' + +# Configuring the right hooks +KalibroEntities::KalibroCucumberHelpers.configure_from_yml("#{__dir__}/kalibro_cucumber_helpers.yml") + # Warden test helpers so the user authentication can be as fast as possible include Warden::Test::Helpers \ No newline at end of file diff --git a/features/support/kalibro_cucumber_helpers.yml.sample b/features/support/kalibro_cucumber_helpers.yml.sample new file mode 100644 index 0000000..755d171 --- /dev/null +++ b/features/support/kalibro_cucumber_helpers.yml.sample @@ -0,0 +1,10 @@ +kalibro_cucumber_helpers: + database: "kalibro_test" + user: "kalibro" + password: "kalibro" + psql_file_path: "/tmp/PostgreSQL.sql" + query_file_path: "/tmp/query" + kalibro_home: "/usr/share/tomcat6/.kalibro" + tomcat_user: "tomcat6" + tomcat_group: "tomcat6" + tomcat_restart_command: "sudo\\ service\\ tomcat6\\ restart" \ No newline at end of file diff --git a/spec/controllers/home_controller_spec.rb b/spec/controllers/home_controller_spec.rb index a3d5d2a..4f2c99f 100644 --- a/spec/controllers/home_controller_spec.rb +++ b/spec/controllers/home_controller_spec.rb @@ -4,6 +4,8 @@ describe HomeController do context 'Method' do context '#index' do before :each do + Project.expects(:latest).with(5).returns([]) + get :index end diff --git a/spec/factories/projects.rb b/spec/factories/projects.rb index 58aa7d8..3a59dd4 100644 --- a/spec/factories/projects.rb +++ b/spec/factories/projects.rb @@ -6,4 +6,10 @@ FactoryGirl.define do name "QT Calculator" description "A simple calculator for us." end + + factory :another_project, class: Project do + id 2 + name "Kalibro" + description "Code Metrics" + end end diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb index a0efad5..149997e 100644 --- a/spec/models/project_spec.rb +++ b/spec/models/project_spec.rb @@ -7,5 +7,24 @@ describe Project do subject.persisted?.should eq(false) end end + + describe 'latest' do + before :each do + @qt = FactoryGirl.build(:project) + @kalibro = FactoryGirl.build(:another_project) + + Project.expects(:all).returns([@qt, @kalibro]) + end + + it 'should return the two projects ordered' do + Project.latest(2).should eq([@kalibro, @qt]) + end + + context 'when no parameter is passed' do + it 'should return just the most recent project' do + Project.latest.should eq([@kalibro]) + end + end + end end end -- libgit2 0.21.2