remarkable_rails 3.1.8 → 3.1.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG +91 -88
- data/LICENSE +20 -20
- data/README +80 -80
- data/lib/remarkable_rails/action_controller/base.rb +29 -29
- data/lib/remarkable_rails/action_controller/macro_stubs.rb +459 -457
- data/lib/remarkable_rails/action_controller/matchers/assign_to_matcher.rb +92 -92
- data/lib/remarkable_rails/action_controller/matchers/filter_params_matcher.rb +41 -41
- data/lib/remarkable_rails/action_controller/matchers/redirect_to_matcher.rb +119 -119
- data/lib/remarkable_rails/action_controller/matchers/render_template_matcher.rb +146 -146
- data/lib/remarkable_rails/action_controller/matchers/respond_with_matcher.rb +126 -126
- data/lib/remarkable_rails/action_controller/matchers/route_matcher.rb +135 -109
- data/lib/remarkable_rails/action_controller/matchers/set_cookies_matcher.rb +49 -49
- data/lib/remarkable_rails/action_controller/matchers/set_session_matcher.rb +106 -106
- data/lib/remarkable_rails/action_controller/matchers/set_the_flash_matcher.rb +54 -54
- data/lib/remarkable_rails/action_controller.rb +22 -22
- data/lib/remarkable_rails/action_view/base.rb +7 -7
- data/lib/remarkable_rails/action_view.rb +18 -18
- data/lib/remarkable_rails/active_orm.rb +19 -19
- data/lib/remarkable_rails.rb +30 -30
- data/locale/en.yml +110 -110
- data/spec/action_controller/assign_to_matcher_spec.rb +142 -142
- data/spec/action_controller/filter_params_matcher_spec.rb +64 -64
- data/spec/action_controller/macro_stubs_spec.rb +234 -208
- data/spec/action_controller/redirect_to_matcher_spec.rb +102 -102
- data/spec/action_controller/render_template_matcher_spec.rb +251 -251
- data/spec/action_controller/respond_with_matcher_spec.rb +223 -223
- data/spec/action_controller/route_matcher_spec.rb +96 -79
- data/spec/action_controller/set_cookies_matcher_spec.rb +149 -149
- data/spec/action_controller/set_session_matcher_spec.rb +141 -141
- data/spec/action_controller/set_the_flash_matcher_spec.rb +93 -93
- data/spec/application/application.rb +15 -15
- data/spec/application/tasks_controller.rb +34 -34
- data/spec/functional_builder.rb +88 -88
- data/spec/rcov.opts +2 -2
- data/spec/remarkable_rails_spec.rb +5 -5
- data/spec/spec.opts +4 -4
- data/spec/spec_helper.rb +42 -42
- metadata +7 -7
@@ -1,230 +1,230 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
-
|
3
|
-
describe 'respond_with' do
|
4
|
-
include FunctionalBuilder
|
5
|
-
|
6
|
-
describe 'messages' do
|
7
|
-
before(:each) do
|
8
|
-
build_response
|
9
|
-
@matcher = respond_with(:error)
|
10
|
-
end
|
11
|
-
|
12
|
-
it 'should contain a description message' do
|
13
|
-
respond_with(404).description.should == 'respond with 404'
|
14
|
-
respond_with(:error).description.should == 'respond with error'
|
15
|
-
respond_with(500..599).description.should == 'respond with 500..599'
|
16
|
-
|
17
|
-
@matcher.body(/anything/)
|
18
|
-
@matcher.description.should == 'respond with error and with body /anything/'
|
19
|
-
|
20
|
-
@matcher.content_type(Mime::XML).matches?(@controller)
|
21
|
-
@matcher.description.should == 'respond with error, with body /anything/, and with content type "application/xml"'
|
22
|
-
end
|
23
|
-
|
24
|
-
it 'should set status_matches? message' do
|
25
|
-
@matcher.matches?(@controller)
|
26
|
-
@matcher.failure_message.should == 'Expected to respond with status :error, got 200'
|
27
|
-
end
|
28
|
-
|
29
|
-
it 'should set content_type_matches? message' do
|
30
|
-
@matcher = respond_with(:success)
|
31
|
-
@matcher.body(/anything/).matches?(@controller)
|
32
|
-
@matcher.failure_message.should == 'Expected to respond with body /anything/, got " "'
|
33
|
-
end
|
34
|
-
|
35
|
-
it 'should set content_type_matches? message' do
|
36
|
-
@matcher = respond_with(:success)
|
37
|
-
@matcher.content_type(Mime::XML).matches?(@controller)
|
38
|
-
@matcher.failure_message.should == 'Expected to respond with content type "application/xml", got "text/html"'
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
describe 'matcher' do
|
43
|
-
|
44
|
-
describe 'on success' do
|
45
|
-
before(:each){ build_response }
|
46
|
-
|
47
|
-
it { should respond_with(200) }
|
48
|
-
it { should respond_with(:ok) }
|
49
|
-
it { should respond_with(:success) }
|
50
|
-
it { should respond_with(200..299) }
|
51
|
-
|
52
|
-
it { should respond_with(200, :content_type => Mime::HTML) }
|
53
|
-
it { should respond_with(:ok, :content_type => Mime::HTML) }
|
54
|
-
it { should respond_with(:success, :content_type => Mime::HTML) }
|
55
|
-
it { should respond_with(200..299, :content_type => Mime::HTML) }
|
56
|
-
|
57
|
-
it { should_not respond_with(404) }
|
58
|
-
it { should_not respond_with(:not_found) }
|
59
|
-
it { should_not respond_with(300..400) }
|
60
|
-
end
|
61
|
-
|
62
|
-
describe 'on missing' do
|
63
|
-
before(:each){ build_response { render :text => "404 Not Found", :status => 404 } }
|
64
|
-
|
65
|
-
it { should respond_with(404) }
|
66
|
-
it { should respond_with(:not_found) }
|
67
|
-
it { should respond_with(:missing) }
|
68
|
-
it { should respond_with(400..405) }
|
69
|
-
|
70
|
-
it { should_not respond_with(302) }
|
71
|
-
it { should_not respond_with(:found) }
|
72
|
-
it { should_not respond_with(:redirect) }
|
73
|
-
it { should_not respond_with(300..305) }
|
74
|
-
end
|
75
|
-
|
76
|
-
describe 'respond_with_body' do
|
77
|
-
before(:each) { build_response { respond_to{ |format| format.xml { render :xml => [].to_xml } } } }
|
78
|
-
|
79
|
-
it { should respond_with_body(%{<?xml version="1.0" encoding="UTF-8"?>\n<nil-classes type="array"/>\n}) }
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe 'respond_with' do
|
4
|
+
include FunctionalBuilder
|
5
|
+
|
6
|
+
describe 'messages' do
|
7
|
+
before(:each) do
|
8
|
+
build_response
|
9
|
+
@matcher = respond_with(:error)
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'should contain a description message' do
|
13
|
+
respond_with(404).description.should == 'respond with 404'
|
14
|
+
respond_with(:error).description.should == 'respond with error'
|
15
|
+
respond_with(500..599).description.should == 'respond with 500..599'
|
16
|
+
|
17
|
+
@matcher.body(/anything/)
|
18
|
+
@matcher.description.should == 'respond with error and with body /anything/'
|
19
|
+
|
20
|
+
@matcher.content_type(Mime::XML).matches?(@controller)
|
21
|
+
@matcher.description.should == 'respond with error, with body /anything/, and with content type "application/xml"'
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'should set status_matches? message' do
|
25
|
+
@matcher.matches?(@controller)
|
26
|
+
@matcher.failure_message.should == 'Expected to respond with status :error, got 200'
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'should set content_type_matches? message' do
|
30
|
+
@matcher = respond_with(:success)
|
31
|
+
@matcher.body(/anything/).matches?(@controller)
|
32
|
+
@matcher.failure_message.should == 'Expected to respond with body /anything/, got " "'
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'should set content_type_matches? message' do
|
36
|
+
@matcher = respond_with(:success)
|
37
|
+
@matcher.content_type(Mime::XML).matches?(@controller)
|
38
|
+
@matcher.failure_message.should == 'Expected to respond with content type "application/xml", got "text/html"'
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
describe 'matcher' do
|
43
|
+
|
44
|
+
describe 'on success' do
|
45
|
+
before(:each){ build_response }
|
46
|
+
|
47
|
+
it { should respond_with(200) }
|
48
|
+
it { should respond_with(:ok) }
|
49
|
+
it { should respond_with(:success) }
|
50
|
+
it { should respond_with(200..299) }
|
51
|
+
|
52
|
+
it { should respond_with(200, :content_type => Mime::HTML) }
|
53
|
+
it { should respond_with(:ok, :content_type => Mime::HTML) }
|
54
|
+
it { should respond_with(:success, :content_type => Mime::HTML) }
|
55
|
+
it { should respond_with(200..299, :content_type => Mime::HTML) }
|
56
|
+
|
57
|
+
it { should_not respond_with(404) }
|
58
|
+
it { should_not respond_with(:not_found) }
|
59
|
+
it { should_not respond_with(300..400) }
|
60
|
+
end
|
61
|
+
|
62
|
+
describe 'on missing' do
|
63
|
+
before(:each){ build_response { render :text => "404 Not Found", :status => 404 } }
|
64
|
+
|
65
|
+
it { should respond_with(404) }
|
66
|
+
it { should respond_with(:not_found) }
|
67
|
+
it { should respond_with(:missing) }
|
68
|
+
it { should respond_with(400..405) }
|
69
|
+
|
70
|
+
it { should_not respond_with(302) }
|
71
|
+
it { should_not respond_with(:found) }
|
72
|
+
it { should_not respond_with(:redirect) }
|
73
|
+
it { should_not respond_with(300..305) }
|
74
|
+
end
|
75
|
+
|
76
|
+
describe 'respond_with_body' do
|
77
|
+
before(:each) { build_response { respond_to{ |format| format.xml { render :xml => [].to_xml } } } }
|
78
|
+
|
79
|
+
it { should respond_with_body(%{<?xml version="1.0" encoding="UTF-8"?>\n<nil-classes type="array"/>\n}) }
|
80
80
|
it { should respond_with_body(/xml/) }
|
81
81
|
it { should respond_with_body{/xml/} }
|
82
|
-
it { should respond_with_body proc{/xml/} }
|
83
|
-
it { should_not respond_with_body('html') }
|
84
|
-
it { should_not respond_with_body(/html/) }
|
85
|
-
end
|
86
|
-
|
87
|
-
describe 'on redirect' do
|
88
|
-
before(:each){ build_response { redirect_to project_tasks_url(1) } }
|
89
|
-
|
90
|
-
it { should respond_with(302) }
|
91
|
-
it { should respond_with(:found) }
|
92
|
-
it { should respond_with(:redirect) }
|
93
|
-
it { should respond_with(300..305) }
|
94
|
-
|
95
|
-
it { should_not respond_with(200) }
|
96
|
-
it { should_not respond_with(:ok) }
|
97
|
-
it { should_not respond_with(:success) }
|
98
|
-
it { should_not respond_with(200..299) }
|
99
|
-
end
|
100
|
-
|
101
|
-
describe 'respond_with_content_type' do
|
102
|
-
describe 'and Mime::HTML' do
|
103
|
-
before(:each){ build_response { render :action => :new } }
|
104
|
-
|
105
|
-
it { should respond_with_content_type(:html) }
|
106
|
-
it { should respond_with_content_type(/html/) }
|
107
|
-
it { should respond_with_content_type(Mime::HTML) }
|
108
|
-
it { should respond_with_content_type('text/html') }
|
109
|
-
|
110
|
-
it { should_not respond_with_content_type(:xml) }
|
111
|
-
it { should_not respond_with_content_type(/xml/) }
|
112
|
-
it { should_not respond_with_content_type(Mime::XML) }
|
113
|
-
it { should_not respond_with_content_type('application/xml') }
|
114
|
-
end
|
115
|
-
|
116
|
-
describe 'and Mime::XML' do
|
117
|
-
before(:each) { build_response { respond_to{ |format| format.xml } } }
|
118
|
-
|
119
|
-
it { should respond_with_content_type(:xml) }
|
120
|
-
it { should respond_with_content_type(/xml/) }
|
121
|
-
it { should respond_with_content_type(Mime::XML) }
|
122
|
-
it { should respond_with_content_type('application/xml') }
|
123
|
-
|
124
|
-
it { should_not respond_with_content_type(:html) }
|
125
|
-
it { should_not respond_with_content_type(/html/) }
|
126
|
-
it { should_not respond_with_content_type(Mime::HTML) }
|
127
|
-
it { should_not respond_with_content_type('text/html') }
|
128
|
-
end
|
129
|
-
end
|
130
|
-
|
131
|
-
end
|
132
|
-
|
133
|
-
describe 'macro' do
|
134
|
-
|
135
|
-
describe 'on success' do
|
136
|
-
before(:each){ build_response }
|
137
|
-
|
138
|
-
should_respond_with 200
|
139
|
-
should_respond_with :ok
|
140
|
-
should_respond_with :success
|
141
|
-
should_respond_with 200..299
|
142
|
-
|
143
|
-
should_respond_with 200, :content_type => Mime::HTML
|
144
|
-
should_respond_with :ok, :content_type => Mime::HTML
|
145
|
-
should_respond_with :success, :content_type => Mime::HTML
|
82
|
+
it { should respond_with_body proc{/xml/} }
|
83
|
+
it { should_not respond_with_body('html') }
|
84
|
+
it { should_not respond_with_body(/html/) }
|
85
|
+
end
|
86
|
+
|
87
|
+
describe 'on redirect' do
|
88
|
+
before(:each){ build_response { redirect_to project_tasks_url(1) } }
|
89
|
+
|
90
|
+
it { should respond_with(302) }
|
91
|
+
it { should respond_with(:found) }
|
92
|
+
it { should respond_with(:redirect) }
|
93
|
+
it { should respond_with(300..305) }
|
94
|
+
|
95
|
+
it { should_not respond_with(200) }
|
96
|
+
it { should_not respond_with(:ok) }
|
97
|
+
it { should_not respond_with(:success) }
|
98
|
+
it { should_not respond_with(200..299) }
|
99
|
+
end
|
100
|
+
|
101
|
+
describe 'respond_with_content_type' do
|
102
|
+
describe 'and Mime::HTML' do
|
103
|
+
before(:each){ build_response { render :action => :new } }
|
104
|
+
|
105
|
+
it { should respond_with_content_type(:html) }
|
106
|
+
it { should respond_with_content_type(/html/) }
|
107
|
+
it { should respond_with_content_type(Mime::HTML) }
|
108
|
+
it { should respond_with_content_type('text/html') }
|
109
|
+
|
110
|
+
it { should_not respond_with_content_type(:xml) }
|
111
|
+
it { should_not respond_with_content_type(/xml/) }
|
112
|
+
it { should_not respond_with_content_type(Mime::XML) }
|
113
|
+
it { should_not respond_with_content_type('application/xml') }
|
114
|
+
end
|
115
|
+
|
116
|
+
describe 'and Mime::XML' do
|
117
|
+
before(:each) { build_response { respond_to{ |format| format.xml } } }
|
118
|
+
|
119
|
+
it { should respond_with_content_type(:xml) }
|
120
|
+
it { should respond_with_content_type(/xml/) }
|
121
|
+
it { should respond_with_content_type(Mime::XML) }
|
122
|
+
it { should respond_with_content_type('application/xml') }
|
123
|
+
|
124
|
+
it { should_not respond_with_content_type(:html) }
|
125
|
+
it { should_not respond_with_content_type(/html/) }
|
126
|
+
it { should_not respond_with_content_type(Mime::HTML) }
|
127
|
+
it { should_not respond_with_content_type('text/html') }
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
end
|
132
|
+
|
133
|
+
describe 'macro' do
|
134
|
+
|
135
|
+
describe 'on success' do
|
136
|
+
before(:each){ build_response }
|
137
|
+
|
138
|
+
should_respond_with 200
|
139
|
+
should_respond_with :ok
|
140
|
+
should_respond_with :success
|
141
|
+
should_respond_with 200..299
|
142
|
+
|
143
|
+
should_respond_with 200, :content_type => Mime::HTML
|
144
|
+
should_respond_with :ok, :content_type => Mime::HTML
|
145
|
+
should_respond_with :success, :content_type => Mime::HTML
|
146
146
|
should_respond_with 200..299, :content_type => Mime::HTML
|
147
147
|
|
148
148
|
should_respond_with 200 do |m|
|
149
149
|
m.body /\s*/
|
150
150
|
m.content_type Mime::HTML
|
151
|
-
end
|
152
|
-
|
153
|
-
should_not_respond_with 404
|
154
|
-
should_not_respond_with :not_found
|
155
|
-
should_not_respond_with 300..400
|
156
|
-
end
|
157
|
-
|
158
|
-
describe 'on missing' do
|
159
|
-
before(:each){ build_response { render :text => "404 Not Found", :status => 404 } }
|
160
|
-
|
161
|
-
should_respond_with 404
|
162
|
-
should_respond_with :not_found
|
163
|
-
should_respond_with :missing
|
164
|
-
should_respond_with 400..405
|
165
|
-
|
166
|
-
should_not_respond_with 302
|
167
|
-
should_not_respond_with :found
|
168
|
-
should_not_respond_with :redirect
|
169
|
-
should_not_respond_with 300..305
|
170
|
-
end
|
171
|
-
|
172
|
-
describe 'on redirect' do
|
173
|
-
before(:each){ build_response { redirect_to project_tasks_url(1) } }
|
174
|
-
|
175
|
-
should_respond_with 302
|
176
|
-
should_respond_with :found
|
177
|
-
should_respond_with :redirect
|
178
|
-
should_respond_with 300..305
|
179
|
-
|
180
|
-
should_not_respond_with 200
|
181
|
-
should_not_respond_with :ok
|
182
|
-
should_not_respond_with :success
|
183
|
-
should_not_respond_with 200..299
|
184
|
-
end
|
185
|
-
|
186
|
-
describe 'respond_with_body' do
|
187
|
-
before(:each) { build_response { respond_to{ |format| format.xml { render :xml => [].to_xml } } } }
|
188
|
-
|
189
|
-
should_respond_with_body %{<?xml version="1.0" encoding="UTF-8"?>\n<nil-classes type="array"/>\n}
|
190
|
-
should_respond_with_body /xml/
|
191
|
-
should_not_respond_with_body 'html'
|
192
|
-
should_not_respond_with_body /html/
|
193
|
-
end
|
194
|
-
|
195
|
-
describe 'respond_with_content_type' do
|
196
|
-
describe 'and Mime::HTML' do
|
197
|
-
before(:each){ build_response { render :action => :new } }
|
198
|
-
|
199
|
-
should_respond_with_content_type :html
|
200
|
-
should_respond_with_content_type /html/
|
201
|
-
should_respond_with_content_type Mime::HTML
|
202
|
-
should_respond_with_content_type 'text/html'
|
203
|
-
|
204
|
-
should_not_respond_with_content_type :xml
|
205
|
-
should_not_respond_with_content_type /xml/
|
206
|
-
should_not_respond_with_content_type Mime::XML
|
207
|
-
should_not_respond_with_content_type 'application/xml'
|
208
|
-
end
|
209
|
-
|
210
|
-
describe 'and Mime::XML' do
|
211
|
-
before(:each) { build_response { respond_to{ |format| format.xml } } }
|
212
|
-
|
213
|
-
should_respond_with_content_type :xml
|
214
|
-
should_respond_with_content_type /xml/
|
215
|
-
should_respond_with_content_type Mime::XML
|
216
|
-
should_respond_with_content_type 'application/xml'
|
217
|
-
|
218
|
-
should_not_respond_with_content_type :html
|
219
|
-
should_not_respond_with_content_type /html/
|
220
|
-
should_not_respond_with_content_type Mime::HTML
|
221
|
-
should_not_respond_with_content_type 'text/html'
|
222
|
-
end
|
223
|
-
end
|
224
|
-
|
225
|
-
end
|
226
|
-
|
227
|
-
generate_macro_stubs_specs_for(:respond_with, 200)
|
228
|
-
generate_macro_stubs_specs_for(:respond_with_body, /xml/)
|
229
|
-
generate_macro_stubs_specs_for(:respond_with_content_type, Mime::HTML)
|
230
|
-
end
|
151
|
+
end
|
152
|
+
|
153
|
+
should_not_respond_with 404
|
154
|
+
should_not_respond_with :not_found
|
155
|
+
should_not_respond_with 300..400
|
156
|
+
end
|
157
|
+
|
158
|
+
describe 'on missing' do
|
159
|
+
before(:each){ build_response { render :text => "404 Not Found", :status => 404 } }
|
160
|
+
|
161
|
+
should_respond_with 404
|
162
|
+
should_respond_with :not_found
|
163
|
+
should_respond_with :missing
|
164
|
+
should_respond_with 400..405
|
165
|
+
|
166
|
+
should_not_respond_with 302
|
167
|
+
should_not_respond_with :found
|
168
|
+
should_not_respond_with :redirect
|
169
|
+
should_not_respond_with 300..305
|
170
|
+
end
|
171
|
+
|
172
|
+
describe 'on redirect' do
|
173
|
+
before(:each){ build_response { redirect_to project_tasks_url(1) } }
|
174
|
+
|
175
|
+
should_respond_with 302
|
176
|
+
should_respond_with :found
|
177
|
+
should_respond_with :redirect
|
178
|
+
should_respond_with 300..305
|
179
|
+
|
180
|
+
should_not_respond_with 200
|
181
|
+
should_not_respond_with :ok
|
182
|
+
should_not_respond_with :success
|
183
|
+
should_not_respond_with 200..299
|
184
|
+
end
|
185
|
+
|
186
|
+
describe 'respond_with_body' do
|
187
|
+
before(:each) { build_response { respond_to{ |format| format.xml { render :xml => [].to_xml } } } }
|
188
|
+
|
189
|
+
should_respond_with_body %{<?xml version="1.0" encoding="UTF-8"?>\n<nil-classes type="array"/>\n}
|
190
|
+
should_respond_with_body /xml/
|
191
|
+
should_not_respond_with_body 'html'
|
192
|
+
should_not_respond_with_body /html/
|
193
|
+
end
|
194
|
+
|
195
|
+
describe 'respond_with_content_type' do
|
196
|
+
describe 'and Mime::HTML' do
|
197
|
+
before(:each){ build_response { render :action => :new } }
|
198
|
+
|
199
|
+
should_respond_with_content_type :html
|
200
|
+
should_respond_with_content_type /html/
|
201
|
+
should_respond_with_content_type Mime::HTML
|
202
|
+
should_respond_with_content_type 'text/html'
|
203
|
+
|
204
|
+
should_not_respond_with_content_type :xml
|
205
|
+
should_not_respond_with_content_type /xml/
|
206
|
+
should_not_respond_with_content_type Mime::XML
|
207
|
+
should_not_respond_with_content_type 'application/xml'
|
208
|
+
end
|
209
|
+
|
210
|
+
describe 'and Mime::XML' do
|
211
|
+
before(:each) { build_response { respond_to{ |format| format.xml } } }
|
212
|
+
|
213
|
+
should_respond_with_content_type :xml
|
214
|
+
should_respond_with_content_type /xml/
|
215
|
+
should_respond_with_content_type Mime::XML
|
216
|
+
should_respond_with_content_type 'application/xml'
|
217
|
+
|
218
|
+
should_not_respond_with_content_type :html
|
219
|
+
should_not_respond_with_content_type /html/
|
220
|
+
should_not_respond_with_content_type Mime::HTML
|
221
|
+
should_not_respond_with_content_type 'text/html'
|
222
|
+
end
|
223
|
+
end
|
224
|
+
|
225
|
+
end
|
226
|
+
|
227
|
+
generate_macro_stubs_specs_for(:respond_with, 200)
|
228
|
+
generate_macro_stubs_specs_for(:respond_with_body, /xml/)
|
229
|
+
generate_macro_stubs_specs_for(:respond_with_content_type, Mime::HTML)
|
230
|
+
end
|
@@ -1,83 +1,100 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
-
|
3
|
-
describe '
|
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
|
-
it { should route(:
|
34
|
-
|
35
|
-
#
|
36
|
-
it { should route(:get, '/projects
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
it {
|
43
|
-
it {
|
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
|
-
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe ApplicationController, 'routing', :type => :routing do
|
4
|
+
|
5
|
+
def controller
|
6
|
+
@controller ||= ApplicationController.new
|
7
|
+
end
|
8
|
+
|
9
|
+
describe 'messages' do
|
10
|
+
before(:each) do
|
11
|
+
@matcher = route(:get, '/projects', :controller => 'boo', :action => 'index')
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'should contain a description message' do
|
15
|
+
@matcher.description.should match(/route GET "\/projects" to\/from/)
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'should set map_to_path? message' do
|
19
|
+
@matcher.matches?(nil)
|
20
|
+
@matcher.failure_message.should match(/Expected to map/)
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'should set generate_params? message' do
|
24
|
+
@matcher.stub!(:map_to_path?).and_return(true)
|
25
|
+
@matcher.matches?(controller)
|
26
|
+
@matcher.failure_message.should match(/Expected to generate params/)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe 'matchers' do
|
31
|
+
it { should route(:get, '/projects', :controller => :projects, :action => :index) }
|
32
|
+
it { should route(:delete, '/projects/1', :controller => :projects, :action => :destroy, :id => 1) }
|
33
|
+
it { should route(:get, '/projects/new', :controller => :projects, :action => :new) }
|
34
|
+
|
35
|
+
# to syntax
|
36
|
+
it { should route(:get, '/projects').to(:controller => :projects, :action => :index) }
|
37
|
+
it { should route(:delete, '/projects/1').to(:controller => :projects, :action => :destroy, :id => 1) }
|
38
|
+
it { should route(:get, '/projects/new').to(:controller => :projects, :action => :new) }
|
39
|
+
|
40
|
+
# from syntax
|
41
|
+
it { should route(:get, :controller => :projects, :action => :index).from('/projects') }
|
42
|
+
it { should route(:delete, :controller => :projects, :action => :destroy, :id => 1).from('/projects/1') }
|
43
|
+
it { should route(:get, :controller => :projects, :action => :new).from('/projects/new') }
|
44
|
+
|
45
|
+
# explicitly specify :controller
|
46
|
+
it { should route(:post, '/projects', :controller => :projects, :action => :create) }
|
47
|
+
|
48
|
+
# non-string parameter
|
49
|
+
it { should route(:get, '/projects/1', :controller => :projects, :action => :show, :id => 1) }
|
50
|
+
|
51
|
+
# string-parameter
|
52
|
+
it { should route(:put, '/projects/1', :controller => :projects, :action => :update, :id => "1") }
|
53
|
+
|
54
|
+
# failing case
|
55
|
+
it { should_not route(:get, '/projects', :controller => :projects, :action => :show) }
|
56
|
+
it { should_not route(:xyz, '/projects', :controller => :projects, :action => :index) }
|
57
|
+
end
|
58
|
+
|
59
|
+
describe 'macros' do
|
60
|
+
should_route :get, '/projects', :controller => :projects, :action => :index
|
61
|
+
should_route :delete, '/projects/1', :controller => :projects, :action => :destroy, :id => 1
|
62
|
+
should_route :get, '/projects/new', :controller => :projects, :action => :new
|
63
|
+
|
64
|
+
# explicitly specify :controller
|
65
|
+
should_route :post, '/projects', :controller => :projects, :action => :create
|
66
|
+
|
67
|
+
# non-string parameter
|
68
|
+
should_route :get, '/projects/1', :controller => :projects, :action => :show, :id => 1
|
69
|
+
|
70
|
+
# string-parameter
|
71
|
+
should_route :put, '/projects/1', :controller => :projects, :action => :update, :id => "1"
|
72
|
+
|
73
|
+
# failing case
|
74
|
+
should_not_route :get, '/projects', :controller => :projects, :action => :show
|
75
|
+
should_not_route :xyz, '/projects', :controller => :projects, :action => :index
|
76
|
+
end
|
77
|
+
|
78
|
+
describe 'using controller.request' do
|
79
|
+
it "should extract environment from controller request" do
|
80
|
+
ActionController::Routing::Routes.should_receive(:extract_request_environment).with(controller.request).and_return({:subdomain => "foo"})
|
81
|
+
ActionController::Routing::Routes.should_receive(:recognize_path).with("/projects", {:subdomain => "foo", :method => :get})
|
82
|
+
route(:get, '/projects', :controller => 'projects', :action => 'index').matches?(controller)
|
83
|
+
end
|
84
|
+
end
|
73
85
|
end
|
74
|
-
|
86
|
+
|
75
87
|
# Test implicit controller
|
76
88
|
describe TasksController, :type => :routing do
|
77
|
-
should_route :get, '/projects/5/tasks', :action => :index, :project_id => 5
|
78
|
-
should_route :post, '/projects/5/tasks', :action => :create, :project_id => 5
|
79
|
-
should_route :get, '/projects/5/tasks/1', :action => :show, :id => 1, :project_id => 5
|
80
|
-
should_route :delete, '/projects/5/tasks/1', :action => :destroy, :id => 1, :project_id => 5
|
81
|
-
should_route :get, '/projects/5/tasks/new', :action => :new, :project_id => 5
|
82
|
-
should_route :put, '/projects/5/tasks/1', :action => :update, :id => 1, :project_id => 5
|
89
|
+
should_route :get, '/projects/5/tasks', :action => :index, :project_id => 5
|
90
|
+
should_route :post, '/projects/5/tasks', :action => :create, :project_id => 5
|
91
|
+
should_route :get, '/projects/5/tasks/1', :action => :show, :id => 1, :project_id => 5
|
92
|
+
should_route :delete, '/projects/5/tasks/1', :action => :destroy, :id => 1, :project_id => 5
|
93
|
+
should_route :get, '/projects/5/tasks/new', :action => :new, :project_id => 5
|
94
|
+
should_route :put, '/projects/5/tasks/1', :action => :update, :id => 1, :project_id => 5
|
95
|
+
|
96
|
+
it "should use another controller name if it's given" do
|
97
|
+
self.should_receive(:controller).and_return(ApplicationController.new)
|
98
|
+
route(:get, '/').send(:controller_name).should == 'applications'
|
99
|
+
end
|
83
100
|
end
|