remarkable_rails 3.1.9 → 3.1.10

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,102 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
-
3
- describe 'redirect_to' do
4
- include FunctionalBuilder
5
-
6
- describe 'messages' do
7
- before(:each) do
8
- build_response { redirect_to projects_url }
9
- @matcher = redirect_to(project_tasks_url(1)).with(302)
10
- end
11
-
12
- it 'should contain a description message' do
13
- @matcher = redirect_to(project_tasks_url(1))
14
- @matcher.description.should == 'redirect to "http://test.host/projects/1/tasks"'
15
-
16
- @matcher.with(301)
17
- @matcher.description.should == 'redirect to "http://test.host/projects/1/tasks" with status 301'
18
- end
19
-
20
- it 'should set redirected? message' do
21
- build_response
22
- @matcher.matches?(@controller)
23
- @matcher.failure_message.should == 'Expected redirect to "http://test.host/projects/1/tasks", got no redirect'
24
- end
25
-
26
- it 'should set status_matches? message' do
27
- @matcher.with(200).matches?(@controller)
28
- @matcher.failure_message.should == 'Expected redirect to "http://test.host/projects/1/tasks" with status 200, got status 302'
29
- end
30
-
31
- it 'should set url_matches? message' do
32
- @matcher.matches?(@controller)
33
- @matcher.failure_message.should == 'Expected redirect to "http://test.host/projects/1/tasks", got redirect to "http://test.host/projects"'
34
- end
35
- end
36
-
37
- describe 'matcher' do
38
-
39
- {
40
- :hash => { :controller => 'tasks', :action => 'index', :project_id => 1 },
41
- :url => 'http://test.host/projects/1/tasks',
42
- :path => '/projects/1/tasks'
43
- }.each do |type, route|
44
- describe "redirecting to an #{type}" do
45
- before(:each){ build_response { redirect_to route } }
46
-
47
- it { should redirect_to(project_tasks_url(1)) }
48
- it { should redirect_to(project_tasks_path(1)) }
49
- it { should redirect_to(:controller => 'tasks', :action => 'index', :project_id => 1) }
50
- it { should redirect_to(:controller => 'tasks', :action => 'index', :project_id => 1).with(302) }
51
-
52
- it { should_not redirect_to(project_tasks_url(2)) }
53
- it { should_not redirect_to(project_tasks_path(2)) }
54
- it { should_not redirect_to(:controller => 'tasks', :action => 'index', :project_id => 2) }
55
- it { should_not redirect_to(:controller => 'tasks', :action => 'index', :project_id => 1).with(301) }
56
-
57
- it { response.should redirect_to(project_tasks_url(1)) }
58
- it { response.should redirect_to(project_tasks_path(1)) }
59
- it { response.should redirect_to(:controller => 'tasks', :action => 'index', :project_id => 1) }
60
- it { response.should redirect_to(:controller => 'tasks', :action => 'index', :project_id => 1).with(302) }
61
-
62
- it { response.should_not redirect_to(project_tasks_url(2)) }
63
- it { response.should_not redirect_to(project_tasks_path(2)) }
64
- it { response.should_not redirect_to(:controller => 'tasks', :action => 'index', :project_id => 2) }
65
- it { response.should_not redirect_to(:controller => 'tasks', :action => 'index', :project_id => 1).with(301) }
66
- end
67
- end
68
-
69
- end
70
-
71
- describe 'macro' do
72
-
73
- {
74
- :hash => { :controller => 'tasks', :action => 'index', :project_id => 1 },
75
- :url => 'http://test.host/projects/1/tasks',
76
- :path => '/projects/1/tasks'
77
- }.each do |type, route|
78
- describe "redirecting to an #{type}" do
79
- before(:each){ build_response { redirect_to route } }
80
-
81
- should_redirect_to{ project_tasks_url(1) }
82
- should_redirect_to{ project_tasks_path(1) }
83
- should_redirect_to proc{ project_tasks_url(1) }
84
- should_redirect_to proc{ project_tasks_path(1) }
85
- should_redirect_to proc{ project_tasks_url(1) }, :with => 302
86
- should_redirect_to proc{ project_tasks_path(1) }, :with => 302
87
- should_redirect_to :controller => 'tasks', :action => 'index', :project_id => 1
88
-
89
- should_not_redirect_to{ project_tasks_url(2) }
90
- should_not_redirect_to{ project_tasks_path(2) }
91
- should_not_redirect_to proc{ project_tasks_url(2) }
92
- should_not_redirect_to proc{ project_tasks_path(2) }
93
- should_not_redirect_to proc{ project_tasks_url(1) }, :with => 301
94
- should_not_redirect_to proc{ project_tasks_path(1) }, :with => 301
95
- should_not_redirect_to :controller => 'tasks', :action => 'index', :project_id => 2
96
- end
97
- end
98
-
99
- end
100
-
101
- generate_macro_stubs_specs_for(:redirect_to, 'http://google.com/')
102
- end
@@ -1,251 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
-
3
- describe 'render_template' do
4
- include FunctionalBuilder
5
-
6
- describe 'messages' do
7
- before(:each) do
8
- build_response { render :action => 'new' }
9
- @matcher = render_template('edit')
10
- end
11
-
12
- it 'should contain a description message' do
13
- @matcher.description.should == 'render template "edit"'
14
-
15
- @matcher.layout('application')
16
- @matcher.description.should == 'render template "edit" and with layout "application"'
17
-
18
- @matcher.layout(nil)
19
- @matcher.description.should == 'render template "edit" and with no layout'
20
-
21
- @matcher.content_type(Mime::XML).matches?(@controller)
22
- @matcher.description.should == 'render template "edit", with no layout, and with content type "application/xml"'
23
- end
24
-
25
- it 'should set rendered? message' do
26
- build_response
27
- @matcher.matches?(@controller)
28
- @matcher.failure_message.should == 'Expected template "edit" to be rendered, got no render'
29
- @matcher.negative_failure_message.should == 'Did not expect template "edit" to be rendered, got no render'
30
- end
31
-
32
- # Is not possible to check extensions on Rails 2.1
33
- unless RAILS_VERSION =~ /^2.1/
34
- it 'should set template_matches? message' do
35
- @matcher.matches?(@controller)
36
- @matcher.failure_message.should == 'Expected template "edit" to be rendered, got "examples/new.html.erb"'
37
- end
38
- end
39
-
40
- it 'should set layout_matches? message' do
41
- @matcher = render_template('new')
42
- @matcher.layout('users').matches?(@controller)
43
- @matcher.failure_message.should == 'Expected to render with layout "users", got nil'
44
- end
45
- end
46
-
47
- describe 'matcher' do
48
-
49
- [ :controller, :response ].each do |subject_name|
50
- describe "with #{subject_name} subject" do
51
-
52
- describe 'rendering a template' do
53
- before(:each) do
54
- build_response { render :action => :new }
55
- @subject = instance_variable_get("@#{subject_name}")
56
- end
57
-
58
- it { @subject.should render_template('new') }
59
- it { @subject.should render_template('new.html') }
60
- it { @subject.should render_template('new.html.erb') }
61
- it { @subject.should render_template('examples/new') }
62
- it { @subject.should render_template('examples/new.html') }
63
- it { @subject.should render_template('examples/new.html.erb') }
64
-
65
- it { @subject.should_not render_template('edit') }
66
- it { @subject.should_not render_template('projects/new') }
67
- it { @subject.should_not render_template('examples/edit') }
68
- end
69
-
70
- describe 'rendering a template with path' do
71
- before(:each) do
72
- build_response { render :template => 'projects/new' }
73
- @subject = instance_variable_get("@#{subject_name}")
74
- end
75
-
76
- it { @subject.should render_template('projects/new') }
77
- it { @subject.should render_template('projects/new.html') }
78
- it { @subject.should render_template('projects/new.html.erb') }
79
-
80
- it { @subject.should_not render_template('new') }
81
- it { @subject.should_not render_template('examples/new') }
82
- it { @subject.should_not render_template('projects/edit') }
83
- end
84
-
85
- describe 'rendering a template with extention xml.builder' do
86
- before(:each) do
87
- build_response { respond_to{ |format| format.xml } }
88
- @subject = instance_variable_get("@#{subject_name}")
89
- end
90
-
91
- it { @subject.should render_template('example') }
92
- it { @subject.should render_template('example.xml') }
93
- it { @subject.should render_template('example.xml.builder') }
94
- it { @subject.should render_template('examples/example') }
95
- it { @subject.should render_template('examples/example.xml') }
96
- it { @subject.should render_template('examples/example.xml.builder') }
97
-
98
- # Is not possible to check extensions on Rails 2.1
99
- unless RAILS_VERSION =~ /^2.1/
100
- it { @subject.should_not render_template('example.html') }
101
- it { @subject.should_not render_template('example.html.erb') }
102
- it { @subject.should_not render_template('example.html.builder') }
103
- it { @subject.should_not render_template('examples/example.html') }
104
- it { @subject.should_not render_template('examples/example.html') }
105
- it { @subject.should_not render_template('examples/example.html.erb') }
106
- end
107
- end
108
-
109
- describe 'rendering a partial' do
110
- before(:each) do
111
- build_response { render :partial => 'example' }
112
- @subject = instance_variable_get("@#{subject_name}")
113
- end
114
-
115
- it { @subject.should render_template('_example') }
116
- it { @subject.should render_template('_example.html') }
117
- it { @subject.should render_template('_example.html.erb') }
118
- it { @subject.should render_template('examples/_example') }
119
- it { @subject.should render_template('examples/_example.html') }
120
- it { @subject.should render_template('examples/_example.html.erb') }
121
-
122
- it { @subject.should_not render_template('example') }
123
- it { @subject.should_not render_template('example.html') }
124
- it { @subject.should_not render_template('example.html.erb') }
125
- it { @subject.should_not render_template('examples/example') }
126
- it { @subject.should_not render_template('examples/example.html') }
127
- it { @subject.should_not render_template('examples/example.html.erb') }
128
- end
129
-
130
- end
131
- end
132
-
133
- describe 'render_with_layout' do
134
- before(:each){ build_response { render :layout => 'examples' } }
135
-
136
- it { should render_with_layout('examples') }
137
- it { should_not render_with_layout('users') }
138
- it { should_not render_with_layout(nil) }
139
- it { should_not render_without_layout }
140
-
141
- it { should render_template.layout('examples') }
142
- it { should_not render_template.layout('users') }
143
- it { should_not render_template.layout(nil) }
144
- end
145
-
146
- describe 'render_without_layout' do
147
- before(:each){ build_response }
148
-
149
- it { should render_without_layout }
150
- it { should_not render_with_layout('examples') }
151
-
152
- it { should render_without_layout }
153
- it { should_not render_with_layout('examples') }
154
- end
155
- end
156
-
157
- describe 'macro' do
158
-
159
- describe 'rendering a template' do
160
- before(:each) { build_response { render :action => :new } }
161
-
162
- should_render_template 'new'
163
- should_render_template 'new.html'
164
- should_render_template 'new.html.erb'
165
- should_render_template 'examples/new'
166
- should_render_template 'examples/new.html'
167
- should_render_template 'examples/new.html.erb'
168
-
169
- should_not_render_template 'edit'
170
- should_not_render_template 'projects/new'
171
- should_not_render_template 'examples/edit'
172
- end
173
-
174
- describe 'rendering a template with path' do
175
- before(:each) { build_response { render :template => 'projects/new' } }
176
-
177
- should_render_template 'projects/new'
178
- should_render_template 'projects/new.html'
179
- should_render_template 'projects/new.html.erb'
180
-
181
- should_not_render_template 'new'
182
- should_not_render_template 'examples/new'
183
- should_not_render_template 'projects/edit'
184
- end
185
-
186
- describe 'rendering a template with extention xml.builder' do
187
- before(:each) { build_response { respond_to{ |format| format.xml } } }
188
-
189
- should_render_template 'example'
190
- should_render_template 'example.xml'
191
- should_render_template 'example.xml.builder'
192
- should_render_template 'examples/example'
193
- should_render_template 'examples/example.xml'
194
- should_render_template 'examples/example.xml.builder'
195
-
196
- # Is not possible to check extensions on Rails 2.1
197
- unless RAILS_VERSION =~ /^2.1/
198
- should_not_render_template 'example.html'
199
- should_not_render_template 'example.html.erb'
200
- should_not_render_template 'example.html.builder'
201
- should_not_render_template 'examples/example.html'
202
- should_not_render_template 'examples/example.html'
203
- should_not_render_template 'examples/example.html.erb'
204
- end
205
- end
206
-
207
- describe 'rendering a partial' do
208
- before(:each) { build_response { render :partial => 'example' } }
209
-
210
- should_render_template '_example'
211
- should_render_template '_example.html'
212
- should_render_template '_example.html.erb'
213
- should_render_template 'examples/_example'
214
- should_render_template 'examples/_example.html'
215
- should_render_template 'examples/_example.html.erb'
216
-
217
- should_not_render_template 'example'
218
- should_not_render_template 'example.html'
219
- should_not_render_template 'example.html.erb'
220
- should_not_render_template 'examples/example'
221
- should_not_render_template 'examples/example.html'
222
- should_not_render_template 'examples/example.html.erb'
223
- end
224
-
225
- describe 'render_with_layout' do
226
- before(:each){ build_response { render :layout => 'examples' } }
227
-
228
- should_render_with_layout 'examples'
229
- should_not_render_with_layout 'users'
230
- should_not_render_with_layout nil
231
-
232
- should_render_template :layout => 'examples'
233
- should_not_render_template :layout => 'users'
234
- should_not_render_template :layout => nil
235
- end
236
-
237
- describe 'render_without_layout' do
238
- before(:each){ build_response }
239
-
240
- should_render_without_layout
241
- should_not_render_with_layout 'examples'
242
-
243
- should_render_without_layout
244
- should_not_render_with_layout 'examples'
245
- end
246
- end
247
-
248
- generate_macro_stubs_specs_for(:render_template, 'new')
249
- generate_macro_stubs_specs_for(:render_with_layout, 'examples')
250
- generate_macro_stubs_specs_for(:render_without_layout)
251
- end
@@ -1,230 +0,0 @@
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
- it { should respond_with_body(/xml/) }
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
146
- should_respond_with 200..299, :content_type => Mime::HTML
147
-
148
- should_respond_with 200 do |m|
149
- m.body /\s*/
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