Commit 0d4ed8358efeb37f90474868e41222befad1bc9a

Authored by João M. M. Silva + Rafael Reggiani Manzo
Committed by Rafael Manzo
1 parent af16f4c9

Fixed tests broken by the introduction of project ownerships

features/project/deletion.feature
... ... @@ -7,7 +7,7 @@ Feature: Project Deletion
7 7 Scenario: Should delete a project
8 8 Given I am a regular user
9 9 And I am signed in
10   - And I have a sample project
  10 + And I own a sample project
11 11 And I am at the Sample Project page
12 12 When I click the Destroy link
13 13 Then I should be in the All Projects page
... ...
features/step_definitions/project_steps.rb
... ... @@ -12,6 +12,11 @@ Given(/^I have a project named "(.*?)"$/) do |name|
12 12 @project = FactoryGirl.create(:project, {id: nil, name: name})
13 13 end
14 14  
  15 +Given(/^I own a sample project$/) do
  16 + @project = FactoryGirl.create(:project, {id: nil})
  17 + FactoryGirl.create(:project_ownership, {user_id: @user.id, project_id: @project.id})
  18 +end
  19 +
15 20 Given(/^I am at the Sample Project page$/) do
16 21 visit project_path(@project.id)
17 22 end
... ...
spec/controllers/projects_controller_spec.rb
... ... @@ -4,6 +4,7 @@ describe ProjectsController do
4 4  
5 5 describe 'new' do
6 6 before :each do
  7 + sign_in FactoryGirl.create(:user)
7 8 get :new
8 9 end
9 10  
... ... @@ -12,6 +13,9 @@ describe ProjectsController do
12 13 end
13 14  
14 15 describe 'create' do
  16 + before do
  17 + sign_in FactoryGirl.create(:user)
  18 + end
15 19  
16 20 context 'with valid fields' do
17 21 before :each do
... ... @@ -70,8 +74,17 @@ describe ProjectsController do
70 74  
71 75 describe 'delete' do
72 76 before :each do
  77 + sign_in FactoryGirl.create(:user)
  78 +
73 79 @subject = FactoryGirl.build(:project)
74 80 @subject.expects(:destroy)
  81 +
  82 + @ownership = FactoryGirl.build(:project_ownership)
  83 + @ownership.expects(:destroy)
  84 + @ownerships = []
  85 + @ownerships.expects(:find_by_project_id).with(@subject.id).returns(@ownership)
  86 + User.any_instance.expects(:project_ownerships).returns(@ownerships)
  87 +
75 88 Project.expects(:find).with(@subject.id.to_s).returns(@subject)
76 89 delete :destroy, :id => @subject.id
77 90 end
... ... @@ -95,6 +108,7 @@ describe ProjectsController do
95 108  
96 109 describe 'edit' do
97 110 before :each do
  111 + sign_in FactoryGirl.create(:user)
98 112 @subject = FactoryGirl.build(:project)
99 113 Project.expects(:find).with(@subject.id.to_s).returns(@subject)
100 114 get :edit, :id => @subject.id
... ... @@ -108,7 +122,10 @@ describe ProjectsController do
108 122 end
109 123  
110 124 describe 'update' do
111   -
  125 + before do
  126 + sign_in FactoryGirl.create(:user)
  127 + end
  128 +
112 129 context 'with valid fields' do
113 130 before :each do
114 131 @subject = FactoryGirl.build(:project)
... ...
spec/spec_helper.rb
... ... @@ -50,4 +50,6 @@ RSpec.configure do |config|
50 50 # the seed, which is printed after each run.
51 51 # --seed 1234
52 52 config.order = "random"
  53 +
  54 + config.include Devise::TestHelpers, :type => :controller
53 55 end
... ...