apps_controller_spec.rb
3.58 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
require 'spec_helper'
describe AppsController do
it_requires_authentication
it_requires_admin_privileges :for => {:new => :get, :edit => :get, :create => :post, :update => :put, :destroy => :delete}
describe "GET /apps" do
it 'finds all apps' do
sign_in Factory(:user)
3.times { Factory(:app) }
apps = App.all
get :index
assigns(:apps).should == apps
end
end
describe "GET /apps/:id" do
it 'finds the app' do
sign_in Factory(:user)
app = Factory(:app)
get :show, :id => app.id
assigns(:app).should == app
end
end
context 'logged in as an admin' do
before do
sign_in Factory(:admin)
end
describe "GET /apps/new" do
it 'instantiates a new app with a prebuilt watcher' do
get :new
assigns(:app).should be_a(App)
assigns(:app).should be_new_record
assigns(:app).watchers.should_not be_empty
end
end
describe "GET /apps/:id/edit" do
it 'finds the correct app' do
app = Factory(:app)
get :edit, :id => app.id
assigns(:app).should == app
end
end
describe "POST /apps" do
before do
@app = Factory(:app)
App.stub(:new).and_return(@app)
end
context "when the create is successful" do
before do
@app.should_receive(:save).and_return(true)
end
it "should redirect to the app page" do
post :create, :app => {}
response.should redirect_to(app_path(@app))
end
it "should display a message" do
post :create, :app => {}
request.flash[:success].should match(/success/)
end
end
context "when the create is unsuccessful" do
it "should render the new page" do
@app.should_receive(:save).and_return(false)
post :create, :app => {}
response.should render_template(:new)
end
end
end
describe "PUT /apps/:id" do
before do
@app = Factory(:app)
App.stub(:find).with(@app.id).and_return(@app)
end
context "when the update is successful" do
before do
@app.should_receive(:update_attributes).and_return(true)
end
it "should redirect to the app page" do
put :update, :id => @app.id, :app => {}
response.should redirect_to(app_path(@app))
end
it "should display a message" do
put :update, :id => @app.id, :app => {}
request.flash[:success].should match(/success/)
end
end
context "when the update is unsuccessful" do
it "should render the edit page" do
@app.should_receive(:update_attributes).and_return(false)
put :update, :id => @app.id, :app => {}
response.should render_template(:edit)
end
end
end
describe "DELETE /apps/:id" do
before do
@app = Factory(:app)
App.stub(:find).with(@app.id).and_return(@app)
end
it "should find the app" do
delete :destroy, :id => @app.id
assigns(:app).should == @app
end
it "should destroy the app" do
@app.should_receive(:destroy)
delete :destroy, :id => @app.id
end
it "should display a message" do
delete :destroy, :id => @app.id
request.flash[:success].should match(/success/)
end
it "should redirect to the apps page" do
delete :destroy, :id => @app.id
response.should redirect_to(apps_path)
end
end
end
end