projects_controller_spec.rb
3.4 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
require 'spec_helper'
describe ProjectsController do
describe "GET /projects" do
it 'finds all projects' do
3.times { Factory(:project) }
projects = Project.all
get :index
assigns(:projects).should == projects
end
end
describe "GET /projects/:id" do
it 'finds the project' do
project = Factory(:project)
get :show, :id => project.id
assigns(:project).should == project
end
end
describe "GET /projects/new" do
it 'instantiates a new project with a prebuilt watcher' do
get :new
assigns(:project).should be_a(Project)
assigns(:project).should be_new_record
assigns(:project).watchers.should_not be_empty
end
end
describe "GET /projects/:id/edit" do
it 'finds the correct project' do
project = Factory(:project)
get :edit, :id => project.id
assigns(:project).should == project
end
end
describe "POST /projects" do
before do
@project = Factory(:project)
Project.stub(:new).and_return(@project)
end
context "when the create is successful" do
before do
@project.should_receive(:save).and_return(true)
end
it "should redirect to the project page" do
post :create, :project => {}
response.should redirect_to(project_path(@project))
end
it "should display a message" do
post :create, :project => {}
request.flash[:success].should match(/success/)
end
end
context "when the create is unsuccessful" do
it "should render the new page" do
@project.should_receive(:save).and_return(false)
post :create, :project => {}
response.should render_template(:new)
end
end
end
describe "PUT /projects/:id" do
before do
@project = Factory(:project)
Project.stub(:find).with(@project.id).and_return(@project)
end
context "when the update is successful" do
before do
@project.should_receive(:update_attributes).and_return(true)
end
it "should redirect to the project page" do
put :update, :id => @project.id, :project => {}
response.should redirect_to(project_path(@project))
end
it "should display a message" do
put :update, :id => @project.id, :project => {}
request.flash[:success].should match(/success/)
end
end
context "when the update is unsuccessful" do
it "should render the edit page" do
@project.should_receive(:update_attributes).and_return(false)
put :update, :id => @project.id, :project => {}
response.should render_template(:edit)
end
end
end
describe "DELETE /projects/:id" do
before do
@project = Factory(:project)
Project.stub(:find).with(@project.id).and_return(@project)
end
it "should find the project" do
delete :destroy, :id => @project.id
assigns(:project).should == @project
end
it "should destroy the project" do
@project.should_receive(:destroy)
delete :destroy, :id => @project.id
end
it "should display a message" do
delete :destroy, :id => @project.id
request.flash[:success].should match(/success/)
end
it "should redirect to the projects page" do
delete :destroy, :id => @project.id
response.should redirect_to(projects_path)
end
end
end