clicks_controller_spec.rb
4.15 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
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
describe ClicksController do
def sign_in_as(user)
@controller.current_user = user
return user
end
before(:each) do
sign_in_as(@user = Factory(:email_confirmed_user))
end
def mock_click(stubs={})
@mock_click ||= mock_model(Click, stubs)
end
describe "GET index" do
it "assigns all clicks as @clicks" do
Click.stub!(:find).with(:all).and_return([mock_click])
get :index
assigns[:clicks].should == [mock_click]
end
end
describe "GET show" do
it "assigns the requested click as @click" do
Click.stub!(:find).with("37").and_return(mock_click)
get :show, :id => "37"
assigns[:click].should equal(mock_click)
end
end
describe "GET new" do
it "assigns a new click as @click" do
Click.stub!(:new).and_return(mock_click)
get :new
assigns[:click].should equal(mock_click)
end
end
describe "GET edit" do
it "assigns the requested click as @click" do
Click.stub!(:find).with("37").and_return(mock_click)
get :edit, :id => "37"
assigns[:click].should equal(mock_click)
end
end
describe "POST create" do
describe "with valid params" do
it "assigns a newly created click as @click" do
Click.stub!(:new).with({'these' => 'params'}).and_return(mock_click(:save => true))
post :create, :click => {:these => 'params'}
assigns[:click].should equal(mock_click)
end
it "redirects to the created click" do
Click.stub!(:new).and_return(mock_click(:save => true))
post :create, :click => {}
response.should redirect_to(click_url(mock_click))
end
end
describe "with invalid params" do
it "assigns a newly created but unsaved click as @click" do
Click.stub!(:new).with({'these' => 'params'}).and_return(mock_click(:save => false))
post :create, :click => {:these => 'params'}
assigns[:click].should equal(mock_click)
end
it "re-renders the 'new' template" do
Click.stub!(:new).and_return(mock_click(:save => false))
post :create, :click => {}
response.should render_template('new')
end
end
end
describe "PUT update" do
describe "with valid params" do
it "updates the requested click" do
Click.should_receive(:find).with("37").and_return(mock_click)
mock_click.should_receive(:update_attributes).with({'these' => 'params'})
put :update, :id => "37", :click => {:these => 'params'}
end
it "assigns the requested click as @click" do
Click.stub!(:find).and_return(mock_click(:update_attributes => true))
put :update, :id => "1"
assigns[:click].should equal(mock_click)
end
it "redirects to the click" do
Click.stub!(:find).and_return(mock_click(:update_attributes => true))
put :update, :id => "1"
response.should redirect_to(click_url(mock_click))
end
end
describe "with invalid params" do
it "updates the requested click" do
Click.should_receive(:find).with("37").and_return(mock_click)
mock_click.should_receive(:update_attributes).with({'these' => 'params'})
put :update, :id => "37", :click => {:these => 'params'}
end
it "assigns the click as @click" do
Click.stub!(:find).and_return(mock_click(:update_attributes => false))
put :update, :id => "1"
assigns[:click].should equal(mock_click)
end
it "re-renders the 'edit' template" do
Click.stub!(:find).and_return(mock_click(:update_attributes => false))
put :update, :id => "1"
response.should render_template('edit')
end
end
end
describe "DELETE destroy" do
it "destroys the requested click" do
Click.should_receive(:find).with("37").and_return(mock_click)
mock_click.should_receive(:destroy)
delete :destroy, :id => "37"
end
it "redirects to the clicks list" do
Click.stub!(:find).and_return(mock_click(:destroy => true))
delete :destroy, :id => "1"
response.should redirect_to(clicks_url)
end
end
end