Commit 46393ff96561d1865da2990204a57ae567376dba

Authored by Diego Camarinha
Committed by Rafael Manzo
1 parent f526e692

Project destroy.

In order to get acceptance test running, poltergeist has been installed.
Gemfile
... ... @@ -76,6 +76,7 @@ group :cucumber do
76 76 #Fixed the cumcumber version since the version 1.3.4 causes tests failure
77 77 gem 'cucumber', '1.3.2'
78 78 gem 'database_cleaner'
  79 + gem 'poltergeist', '~> 1.3.0'
79 80 end
80 81  
81 82 # Use ActiveModel has_secure_password
... ...
Gemfile.lock
... ... @@ -76,6 +76,7 @@ GEM
76 76 warden (~> 1.2.3)
77 77 diff-lcs (1.2.4)
78 78 erubis (2.7.0)
  79 + eventmachine (1.0.3)
79 80 execjs (1.4.0)
80 81 multi_json (~> 1.0)
81 82 factory_girl (4.2.0)
... ... @@ -83,12 +84,15 @@ GEM
83 84 factory_girl_rails (4.2.1)
84 85 factory_girl (~> 4.2.0)
85 86 railties (>= 3.0.0)
  87 + faye-websocket (0.4.7)
  88 + eventmachine (>= 0.12.0)
86 89 gherkin (2.12.1)
87 90 multi_json (~> 1.3)
88 91 gyoku (1.1.0)
89 92 builder (>= 2.1.2)
90 93 highline (1.6.19)
91 94 hike (1.2.3)
  95 + http_parser.rb (0.5.3)
92 96 httpi (2.1.0)
93 97 rack
94 98 rubyntlm (~> 0.3.2)
... ... @@ -122,6 +126,10 @@ GEM
122 126 nori (2.3.0)
123 127 orm_adapter (0.4.0)
124 128 pg (0.16.0)
  129 + poltergeist (1.3.0)
  130 + capybara (~> 2.1.0)
  131 + faye-websocket (>= 0.4.4, < 0.5.0)
  132 + http_parser.rb (~> 0.5.3)
125 133 polyglot (0.3.3)
126 134 rack (1.5.2)
127 135 rack-test (0.6.2)
... ... @@ -230,6 +238,7 @@ DEPENDENCIES
230 238 mocha
231 239 modernizr-rails
232 240 pg (~> 0.16.0)
  241 + poltergeist (~> 1.3.0)
233 242 rails (= 4.0.0)
234 243 rspec-rails
235 244 rvm-capistrano
... ...
app/controllers/projects_controller.rb
... ... @@ -48,6 +48,17 @@ class ProjectsController &lt; ApplicationController
48 48 end
49 49 end
50 50  
  51 + # DELETE /project/1
  52 + # DELETE /project/1.json
  53 + def destroy
  54 + set_project
  55 + @project.destroy
  56 + respond_to do |format|
  57 + format.html { redirect_to projects_url }
  58 + format.json { head :no_content }
  59 + end
  60 + end
  61 +
51 62 private
52 63 # Use callbacks to share common setup or constraints between actions.
53 64 def set_project
... ...
app/views/projects/show.html.erb
... ... @@ -8,4 +8,8 @@
8 8 <%= @project.description %>
9 9 </p>
10 10  
11   -<%= link_to 'Back', root_path %>
  11 +<p>
  12 + <%= link_to 'Destroy', project_path(@project.id), method: :delete, data: { confirm: 'Are you sure?' } %>
  13 +</p>
  14 +
  15 +<%= link_to 'Back', projects_path %>
... ...
features/project.feature
... ... @@ -48,7 +48,7 @@ Feature: Project
48 48 And the sample project should be there
49 49  
50 50 @wip @kalibro_restart
51   - Scenario: Should back to the All Projects page from show project view
  51 + Scenario: Should go back to the All Projects page from show project view
52 52 Given I am a regular user
53 53 And I am signed in
54 54 And I have a sample project
... ... @@ -64,7 +64,17 @@ Feature: Project
64 64 And I am at the All Projects page
65 65 When I click the Edit link
66 66 Then I should be in the Edit Project page
67   -
  67 +
  68 + @kalibro_restart
  69 + Scenario: Should delete a project
  70 + Given I am a regular user
  71 + And I am signed in
  72 + And I have a sample project
  73 + And I am at the Sample Project page
  74 + When I click the Destroy link
  75 + Then I should be in the All Projects page
  76 + And the sample project should not be there
  77 +
68 78 @kalibro_restart
69 79 Scenario: Should have the content filled in form
70 80 Given I am a regular user
... ...
features/step_definitions/project_steps.rb
  1 +require 'kalibro_entities/errors'
  2 +
1 3 Given(/^I am at the All Projects page$/) do
2 4 visit projects_path
3 5 end
... ... @@ -35,6 +37,10 @@ Then(/^I should be in the Edit Project page$/) do
35 37 page.should have_content("Edit Project")
36 38 end
37 39  
  40 +Then(/^the sample project should not be there$/) do
  41 + expect { Project.find(@project.id) }.to raise_error
  42 +end
  43 +
38 44 Then(/^The field "(.*?)" should be filled with the sample project "(.*?)"$/) do |field, value|
39 45 page.find_field(field).value.should eq(@project.send(value))
40 46 end
... ...
features/support/env.rb
... ... @@ -19,6 +19,9 @@ end
19 19 # files.
20 20  
21 21 require 'cucumber/rails'
  22 +require 'capybara/poltergeist'
  23 +#Capybara.default_driver = :poltergeist
  24 +Capybara.javascript_driver = :poltergeist
22 25  
23 26 #require 'kalibro_entities/kalibro_cucumber_helpers/hooks'
24 27  
... ... @@ -79,4 +82,4 @@ require &#39;kalibro_entities/kalibro_cucumber_helpers/hooks&#39;
79 82 KalibroEntities::KalibroCucumberHelpers.configure_from_yml("#{__dir__}/kalibro_cucumber_helpers.yml")
80 83  
81 84 # Warden test helpers so the user authentication can be as fast as possible
82   -include Warden::Test::Helpers
83 85 \ No newline at end of file
  86 +include Warden::Test::Helpers
... ...
spec/controllers/projects_controller_spec.rb
... ... @@ -68,6 +68,21 @@ describe ProjectsController do
68 68 it { should render_template(:show) }
69 69 end
70 70  
  71 + describe 'delete' do
  72 + before :each do
  73 + @subject = FactoryGirl.build(:project)
  74 + @subject.expects(:destroy)
  75 + Project.expects(:find).with(@subject.id.to_s).returns(@subject)
  76 + delete :destroy, :id => @subject.id
  77 + end
  78 +
  79 + it 'should redirect to the projects page' do
  80 + response.should redirect_to project_url
  81 + end
  82 +
  83 + it { should respond_with(:redirect) }
  84 + end
  85 +
71 86 describe 'index' do
72 87 before :each do
73 88 @subject = FactoryGirl.build(:project)
... ... @@ -139,4 +154,4 @@ describe ProjectsController do
139 154 end
140 155 end
141 156  
142   -end
143 157 \ No newline at end of file
  158 +end
... ...