|
3b1ae5e4
»
|
ianwhite |
2008-09-13 |
API change and rewrite. Va... |
1 |
require File.expand_path(File.join(File.dirname(__FILE__), '../spec_helper')) |
| |
2 |
|
| |
3 |
module InheritedControllerSpec |
| |
4 |
# example setup |
| |
5 |
class SuperController < ActionController::Base |
| |
6 |
response_for :a_response do |format| |
| |
7 |
format.html { super_inside_a_response } |
| |
8 |
end |
| |
9 |
|
| |
10 |
def an_action |
| |
11 |
inside_an_action |
| |
12 |
end |
| |
13 |
|
| |
14 |
def performing_action |
| |
15 |
respond_to do |format| |
| |
16 |
format.html { redirect_to 'http://redirected.from.an_action_which_performs' } |
| |
17 |
end |
| |
18 |
end |
| |
19 |
|
| |
20 |
protected |
| |
21 |
def super_inside_a_response; end |
| |
22 |
def inside_an_action; end |
| |
23 |
end |
| |
24 |
|
| |
25 |
class SubController < SuperController |
| |
26 |
response_for :a_response do |format| |
| |
27 |
format.html { sub_inside_a_response } |
| |
28 |
end |
| |
29 |
|
| |
30 |
response_for :an_action do |format| |
| |
31 |
format.html do |
| |
32 |
redirect_to 'http://redirected.from.response_for' |
| |
33 |
end |
| |
34 |
end |
| |
35 |
|
| |
36 |
response_for :performing_action do |format| |
| |
37 |
never_reached_because_action_performs |
| |
38 |
end |
| |
39 |
|
| |
40 |
protected |
| |
41 |
def sub_inside_a_response; end |
| |
42 |
end |
| |
43 |
|
| |
44 |
# specs |
| |
45 |
describe "action_responses", :type => :spec do |
| |
46 |
it "SuperController.action_responses should not == SubController.action_responses" do |
| |
47 |
SuperController.action_responses.should_not == SubController.action_responses |
| |
48 |
end |
| |
49 |
|
| |
50 |
it "SuperController should have one action_response for 'a_response'" do |
| |
51 |
SuperController.action_responses.keys.should == ['a_response'] |
| |
52 |
SuperController.action_responses['a_response'].size.should == 1 |
| |
53 |
end |
| |
54 |
|
| |
55 |
it "SubController should have two action_responses for 'a_response', and one each for 'an_action', and 'performing_action'" do |
| |
56 |
SubController.action_responses.keys.sort.should == ['a_response', 'an_action', 'performing_action'] |
| |
57 |
SubController.action_responses['a_response'].size.should == 2 |
| |
58 |
SubController.action_responses['an_action'].size.should == 1 |
| |
59 |
SubController.action_responses['performing_action'].size.should == 1 |
| |
60 |
end |
| |
61 |
end |
| |
62 |
|
| |
63 |
describe SuperController do |
| |
64 |
describe "GET :an_action" do |
| |
65 |
it "should execute action" do |
| |
66 |
@controller.should_receive :inside_an_action |
| |
67 |
get :an_action |
| |
68 |
end |
| |
69 |
|
| |
70 |
it "should render :an_action" do |
| |
71 |
get :an_action |
|
b655450b
»
|
ianwhite |
2008-10-09 |
Branching code in spec for ... |
72 |
# different rails/rspec behaviour catered for |
| |
73 |
begin |
| |
74 |
response.should render_template('an_action') |
| |
75 |
rescue |
| |
76 |
response.should render_template('inherited_spec/super/an_action') |
| |
77 |
end |
|
3b1ae5e4
»
|
ianwhite |
2008-09-13 |
API change and rewrite. Va... |
78 |
end |
| |
79 |
end |
| |
80 |
|
| |
81 |
describe "GET :a_response" do |
| |
82 |
it "should execute inside the super response block" do |
| |
83 |
@controller.should_receive :super_inside_a_response |
| |
84 |
get :a_response |
| |
85 |
end |
| |
86 |
|
| |
87 |
it "should NOT execute inside the sub response block" do |
| |
88 |
@controller.should_not_receive :sub_inside_a_response |
| |
89 |
get :a_response |
| |
90 |
end |
| |
91 |
end |
| |
92 |
|
| |
93 |
describe "GET :performing_action" do |
| |
94 |
it "should redirect" do |
| |
95 |
get :performing_action |
| |
96 |
response.should redirect_to('http://redirected.from.an_action_which_performs') |
| |
97 |
end |
| |
98 |
end |
| |
99 |
end |
| |
100 |
|
| |
101 |
describe SubController do |
| |
102 |
describe "GET :an_action (decorated with redirecting response_for)" do |
| |
103 |
it "should execute action" do |
| |
104 |
@controller.should_receive :inside_an_action |
| |
105 |
get :an_action |
| |
106 |
end |
| |
107 |
|
| |
108 |
it "should redirect" do |
| |
109 |
get :an_action |
| |
110 |
response.should redirect_to('http://redirected.from.response_for') |
| |
111 |
end |
| |
112 |
end |
| |
113 |
|
| |
114 |
describe "GET :a_response (decorated with a new response)" do |
| |
115 |
it "should NOT execute the super response" do |
| |
116 |
@controller.should_not_receive :super_inside_a_response |
| |
117 |
get :a_response |
| |
118 |
end |
| |
119 |
|
| |
120 |
it "should execute the sub response" do |
| |
121 |
@controller.should_receive :sub_inside_a_response |
| |
122 |
get :a_response |
| |
123 |
end |
| |
124 |
end |
| |
125 |
|
| |
126 |
describe "GET :performing_action" do |
| |
127 |
it "should NOT execute the sub response" do |
| |
128 |
@controller.should_not_receive :never_reached_because_action_performs |
| |
129 |
get :performing_action |
| |
130 |
end |
| |
131 |
|
| |
132 |
it "should redirect as per the super def" do |
| |
133 |
get :performing_action |
| |
134 |
response.should redirect_to('http://redirected.from.an_action_which_performs') |
| |
135 |
end |
| |
136 |
end |
| |
137 |
end |
| |
138 |
end |