projects_controller_spec.rb
4.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
require 'spec_helper'
describe ProjectsController do
describe 'new' do
before :each do
get :new
end
it { should respond_with(:success) }
it { should render_template(:new) }
end
describe 'create' do
context 'with valid fields' do
before :each do
@subject = FactoryGirl.build(:project)
@subject_params = Hash[FactoryGirl.attributes_for(:project).map { |k,v| [k.to_s, v.to_s] }] #FIXME: Mocha is creating the expectations with strings, but FactoryGirl returns everything with sybols and integers
Project.expects(:new).at_least_once.with(@subject_params).returns(@subject)
Project.any_instance.expects(:save).returns(true)
end
context 'rendering the show' do
before :each do
Project.expects(:exists?).returns(true)
post :create, :project => @subject_params
end
it 'should redirect to the show view' do
response.should redirect_to project_path(@subject)
end
end
context 'without rendering the show view' do
before :each do
post :create, :project => @subject_params
end
it { should respond_with(:redirect) }
end
end
context 'with an invalid field' do
before :each do
@subject = FactoryGirl.build(:project)
@subject_params = Hash[FactoryGirl.attributes_for(:project).map { |k,v| [k.to_s, v.to_s] }] #FIXME: Mocha is creating the expectations with strings, but FactoryGirl returns everything with sybols and integers
Project.expects(:new).at_least_once.with(@subject_params).returns(@subject)
Project.any_instance.expects(:save).returns(false)
post :create, :project => @subject_params
end
it { should render_template(:new) }
end
end
describe 'show' do
before :each do
@subject = FactoryGirl.build(:project)
Project.expects(:find).with(@subject.id.to_s).returns(@subject)
get :show, :id => @subject.id
end
it { should render_template(:show) }
end
describe 'index' do
before :each do
@subject = FactoryGirl.build(:project)
Project.expects(:all).returns([@subject])
get :index
end
it { should render_template(:index) }
end
describe 'edit' do
before :each do
@subject = FactoryGirl.build(:project)
Project.expects(:find).with(@subject.id.to_s).returns(@subject)
get :edit, :id => @subject.id
end
it { should render_template(:edit) }
it 'should assign to @project the @subject' do
assigns(:project).should eq(@subject)
end
end
describe 'update' do
context 'with valid fields' do
before :each do
@subject = FactoryGirl.build(:project)
@subject_params = Hash[FactoryGirl.attributes_for(:project).map { |k,v| [k.to_s, v.to_s] }] #FIXME: Mocha is creating the expectations with strings, but FactoryGirl returns everything with sybols and integers
Project.expects(:find).with(@subject.id.to_s).returns(@subject)
Project.any_instance.expects(:update).with(@subject_params).returns(true)
end
context 'rendering the show' do
before :each do
Project.expects(:exists?).returns(true)
post :update, :id => @subject.id, :project => @subject_params
end
it 'should redirect to the show view' do
response.should redirect_to project_path(@subject)
end
end
context 'without rendering the show view' do
before :each do
post :update, :id => @subject.id, :project => @subject_params
end
it { should respond_with(:redirect) }
end
end
context 'with an invalid field' do
before :each do
@subject = FactoryGirl.build(:project)
@subject_params = Hash[FactoryGirl.attributes_for(:project).map { |k,v| [k.to_s, v.to_s] }] #FIXME: Mocha is creating the expectations with strings, but FactoryGirl returns everything with sybols and integers
Project.expects(:find).with(@subject.id.to_s).returns(@subject)
Project.any_instance.expects(:update).with(@subject_params).returns(false)
post :update, :id => @subject.id, :project => @subject_params
end
it { should render_template(:edit) }
end
end
end