From 46393ff96561d1865da2990204a57ae567376dba Mon Sep 17 00:00:00 2001 From: Diego Araújo + Rafael Manzo Date: Tue, 20 Aug 2013 18:49:28 -0300 Subject: [PATCH] Project destroy. --- Gemfile | 1 + Gemfile.lock | 9 +++++++++ app/controllers/projects_controller.rb | 11 +++++++++++ app/views/projects/show.html.erb | 6 +++++- features/project.feature | 14 ++++++++++++-- features/step_definitions/project_steps.rb | 6 ++++++ features/support/env.rb | 5 ++++- spec/controllers/projects_controller_spec.rb | 17 ++++++++++++++++- 8 files changed, 64 insertions(+), 5 deletions(-) diff --git a/Gemfile b/Gemfile index f54513e..ded6341 100644 --- a/Gemfile +++ b/Gemfile @@ -76,6 +76,7 @@ group :cucumber do #Fixed the cumcumber version since the version 1.3.4 causes tests failure gem 'cucumber', '1.3.2' gem 'database_cleaner' + gem 'poltergeist', '~> 1.3.0' end # Use ActiveModel has_secure_password diff --git a/Gemfile.lock b/Gemfile.lock index a50bb75..6a9822f 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -76,6 +76,7 @@ GEM warden (~> 1.2.3) diff-lcs (1.2.4) erubis (2.7.0) + eventmachine (1.0.3) execjs (1.4.0) multi_json (~> 1.0) factory_girl (4.2.0) @@ -83,12 +84,15 @@ GEM factory_girl_rails (4.2.1) factory_girl (~> 4.2.0) railties (>= 3.0.0) + faye-websocket (0.4.7) + eventmachine (>= 0.12.0) gherkin (2.12.1) multi_json (~> 1.3) gyoku (1.1.0) builder (>= 2.1.2) highline (1.6.19) hike (1.2.3) + http_parser.rb (0.5.3) httpi (2.1.0) rack rubyntlm (~> 0.3.2) @@ -122,6 +126,10 @@ GEM nori (2.3.0) orm_adapter (0.4.0) pg (0.16.0) + poltergeist (1.3.0) + capybara (~> 2.1.0) + faye-websocket (>= 0.4.4, < 0.5.0) + http_parser.rb (~> 0.5.3) polyglot (0.3.3) rack (1.5.2) rack-test (0.6.2) @@ -230,6 +238,7 @@ DEPENDENCIES mocha modernizr-rails pg (~> 0.16.0) + poltergeist (~> 1.3.0) rails (= 4.0.0) rspec-rails rvm-capistrano diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index 2752d9a..bf2d0a3 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -48,6 +48,17 @@ class ProjectsController < ApplicationController end end + # DELETE /project/1 + # DELETE /project/1.json + def destroy + set_project + @project.destroy + respond_to do |format| + format.html { redirect_to projects_url } + format.json { head :no_content } + end + end + private # Use callbacks to share common setup or constraints between actions. def set_project diff --git a/app/views/projects/show.html.erb b/app/views/projects/show.html.erb index d35d7fd..bbb21be 100644 --- a/app/views/projects/show.html.erb +++ b/app/views/projects/show.html.erb @@ -8,4 +8,8 @@ <%= @project.description %>

-<%= link_to 'Back', root_path %> +

+ <%= link_to 'Destroy', project_path(@project.id), method: :delete, data: { confirm: 'Are you sure?' } %> +

+ +<%= link_to 'Back', projects_path %> diff --git a/features/project.feature b/features/project.feature index f2e57d4..9c6c803 100644 --- a/features/project.feature +++ b/features/project.feature @@ -48,7 +48,7 @@ Feature: Project And the sample project should be there @wip @kalibro_restart - Scenario: Should back to the All Projects page from show project view + Scenario: Should go back to the All Projects page from show project view Given I am a regular user And I am signed in And I have a sample project @@ -64,7 +64,17 @@ Feature: Project And I am at the All Projects page When I click the Edit link Then I should be in the Edit Project page - + + @kalibro_restart + Scenario: Should delete a project + Given I am a regular user + And I am signed in + And I have a sample project + And I am at the Sample Project page + When I click the Destroy link + Then I should be in the All Projects page + And the sample project should not be there + @kalibro_restart Scenario: Should have the content filled in form Given I am a regular user diff --git a/features/step_definitions/project_steps.rb b/features/step_definitions/project_steps.rb index 2621ab0..41d7dd5 100644 --- a/features/step_definitions/project_steps.rb +++ b/features/step_definitions/project_steps.rb @@ -1,3 +1,5 @@ +require 'kalibro_entities/errors' + Given(/^I am at the All Projects page$/) do visit projects_path end @@ -35,6 +37,10 @@ Then(/^I should be in the Edit Project page$/) do page.should have_content("Edit Project") end +Then(/^the sample project should not be there$/) do + expect { Project.find(@project.id) }.to raise_error +end + Then(/^The field "(.*?)" should be filled with the sample project "(.*?)"$/) do |field, value| page.find_field(field).value.should eq(@project.send(value)) end diff --git a/features/support/env.rb b/features/support/env.rb index 5e6e884..4c406f1 100644 --- a/features/support/env.rb +++ b/features/support/env.rb @@ -19,6 +19,9 @@ end # files. require 'cucumber/rails' +require 'capybara/poltergeist' +#Capybara.default_driver = :poltergeist +Capybara.javascript_driver = :poltergeist #require 'kalibro_entities/kalibro_cucumber_helpers/hooks' @@ -79,4 +82,4 @@ require 'kalibro_entities/kalibro_cucumber_helpers/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 +include Warden::Test::Helpers diff --git a/spec/controllers/projects_controller_spec.rb b/spec/controllers/projects_controller_spec.rb index 32f677b..7333a06 100644 --- a/spec/controllers/projects_controller_spec.rb +++ b/spec/controllers/projects_controller_spec.rb @@ -68,6 +68,21 @@ describe ProjectsController do it { should render_template(:show) } end + describe 'delete' do + before :each do + @subject = FactoryGirl.build(:project) + @subject.expects(:destroy) + Project.expects(:find).with(@subject.id.to_s).returns(@subject) + delete :destroy, :id => @subject.id + end + + it 'should redirect to the projects page' do + response.should redirect_to project_url + end + + it { should respond_with(:redirect) } + end + describe 'index' do before :each do @subject = FactoryGirl.build(:project) @@ -139,4 +154,4 @@ describe ProjectsController do end end -end \ No newline at end of file +end -- libgit2 0.21.2