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