prototype-rails 0.1

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.
Files changed (51) hide show
  1. data/Gemfile +7 -0
  2. data/README +20 -0
  3. data/Rakefile +10 -0
  4. data/lib/action_view/helpers/prototype_helper.rb +852 -0
  5. data/lib/action_view/helpers/scriptaculous_helper.rb +263 -0
  6. data/lib/action_view/template/handlers/rjs.rb +14 -0
  7. data/lib/prototype-rails.rb +17 -0
  8. data/lib/prototype-rails/javascript_helper.rb +65 -0
  9. data/lib/prototype-rails/on_load_action_controller.rb +2 -0
  10. data/lib/prototype-rails/on_load_action_view.rb +22 -0
  11. data/lib/prototype-rails/renderers.rb +12 -0
  12. data/lib/prototype-rails/rendering.rb +13 -0
  13. data/lib/prototype-rails/selector_assertions.rb +208 -0
  14. data/test/abstract_unit.rb +235 -0
  15. data/test/assert_select_test.rb +452 -0
  16. data/test/controller/caching_test.rb +46 -0
  17. data/test/controller/content_type_test.rb +16 -0
  18. data/test/controller/mime_responds_test.rb +213 -0
  19. data/test/controller/new_base/content_type_test.rb +19 -0
  20. data/test/controller/new_base/render_rjs_test.rb +71 -0
  21. data/test/controller/render_js_test.rb +22 -0
  22. data/test/fixtures/functional_caching/_partial.erb +3 -0
  23. data/test/fixtures/functional_caching/formatted_fragment_cached.js.rjs +6 -0
  24. data/test/fixtures/functional_caching/js_fragment_cached_with_partial.js.rjs +1 -0
  25. data/test/fixtures/old_content_type/render_default_for_rjs.rjs +1 -0
  26. data/test/fixtures/respond_to/all_types_with_layout.js.rjs +1 -0
  27. data/test/fixtures/respond_to/layouts/standard.html.erb +1 -0
  28. data/test/fixtures/respond_to/using_defaults.js.rjs +1 -0
  29. data/test/fixtures/respond_to/using_defaults_with_type_list.js.rjs +1 -0
  30. data/test/fixtures/respond_with/using_resource.js.rjs +1 -0
  31. data/test/fixtures/test/_one.html.erb +1 -0
  32. data/test/fixtures/test/_partial.html.erb +1 -0
  33. data/test/fixtures/test/_partial.js.erb +1 -0
  34. data/test/fixtures/test/_two.html.erb +1 -0
  35. data/test/fixtures/test/delete_with_js.rjs +2 -0
  36. data/test/fixtures/test/enum_rjs_test.rjs +6 -0
  37. data/test/fixtures/test/greeting.js.rjs +1 -0
  38. data/test/fixtures/test/render_explicit_html_template.js.rjs +1 -0
  39. data/test/fixtures/test/render_implicit_html_template.js.rjs +1 -0
  40. data/test/javascript_helper_test.rb +61 -0
  41. data/test/lib/controller/fake_models.rb +29 -0
  42. data/test/render_other_test.rb +257 -0
  43. data/test/template/prototype_helper_test.rb +476 -0
  44. data/test/template/render_test.rb +24 -0
  45. data/test/template/scriptaculous_helper_test.rb +86 -0
  46. data/vendor/assets/javascripts/controls.js +965 -0
  47. data/vendor/assets/javascripts/dragdrop.js +974 -0
  48. data/vendor/assets/javascripts/effects.js +1123 -0
  49. data/vendor/assets/javascripts/prototype.js +6082 -0
  50. data/vendor/assets/javascripts/prototype_ujs.js +208 -0
  51. metadata +127 -0
@@ -0,0 +1,235 @@
1
+ lib = File.expand_path("#{File.dirname(__FILE__)}/../lib")
2
+ $:.unshift(lib) unless $:.include?('lib') || $:.include?(lib)
3
+
4
+ $:.unshift(File.dirname(__FILE__) + '/lib')
5
+
6
+ if defined? Gem
7
+ Gem.source_index
8
+ gem 'bundler'
9
+ else
10
+ require 'rubygems'
11
+ end
12
+ require 'bundler'
13
+ Bundler.setup
14
+
15
+ require 'test/unit'
16
+ require 'active_support'
17
+ require 'action_controller'
18
+ require 'action_view'
19
+ require 'action_view/testing/resolvers'
20
+
21
+ require 'prototype-rails/on_load_action_controller'
22
+ require 'prototype-rails/on_load_action_view'
23
+
24
+ FIXTURE_LOAD_PATH = File.join(File.dirname(__FILE__), 'fixtures')
25
+ FIXTURES = Pathname.new(FIXTURE_LOAD_PATH)
26
+
27
+
28
+ module SetupOnce
29
+ extend ActiveSupport::Concern
30
+
31
+ included do
32
+ cattr_accessor :setup_once_block
33
+ self.setup_once_block = nil
34
+
35
+ setup :run_setup_once
36
+ end
37
+
38
+ module ClassMethods
39
+ def setup_once(&block)
40
+ self.setup_once_block = block
41
+ end
42
+ end
43
+
44
+ private
45
+ def run_setup_once
46
+ if self.setup_once_block
47
+ self.setup_once_block.call
48
+ self.setup_once_block = nil
49
+ end
50
+ end
51
+ end
52
+
53
+ SharedTestRoutes = ActionDispatch::Routing::RouteSet.new
54
+
55
+ module ActiveSupport
56
+ class TestCase
57
+ include SetupOnce
58
+ # Hold off drawing routes until all the possible controller classes
59
+ # have been loaded.
60
+ setup_once do
61
+ SharedTestRoutes.draw do
62
+ match ':controller(/:action)'
63
+ end
64
+
65
+ ActionDispatch::IntegrationTest.app.routes.draw do
66
+ match ':controller(/:action)'
67
+ end
68
+ end
69
+ end
70
+ end
71
+
72
+ class RoutedRackApp
73
+ attr_reader :routes
74
+
75
+ def initialize(routes, &blk)
76
+ @routes = routes
77
+ @stack = ActionDispatch::MiddlewareStack.new(&blk).build(@routes)
78
+ end
79
+
80
+ def call(env)
81
+ @stack.call(env)
82
+ end
83
+ end
84
+
85
+ class BasicController
86
+ attr_accessor :request
87
+
88
+ def config
89
+ @config ||= ActiveSupport::InheritableOptions.new(ActionController::Base.config).tap do |config|
90
+ # VIEW TODO: View tests should not require a controller
91
+ public_dir = File.expand_path("../fixtures/public", __FILE__)
92
+ config.assets_dir = public_dir
93
+ config.javascripts_dir = "#{public_dir}/javascripts"
94
+ config.stylesheets_dir = "#{public_dir}/stylesheets"
95
+ config
96
+ end
97
+ end
98
+ end
99
+
100
+ class ActionDispatch::IntegrationTest < ActiveSupport::TestCase
101
+ setup do
102
+ @routes = SharedTestRoutes
103
+ end
104
+
105
+ def self.build_app(routes = nil)
106
+ RoutedRackApp.new(routes || ActionDispatch::Routing::RouteSet.new) do |middleware|
107
+ middleware.use "ActionDispatch::ShowExceptions"
108
+ middleware.use "ActionDispatch::Callbacks"
109
+ middleware.use "ActionDispatch::ParamsParser"
110
+ middleware.use "ActionDispatch::Cookies"
111
+ middleware.use "ActionDispatch::Flash"
112
+ middleware.use "ActionDispatch::Head"
113
+ yield(middleware) if block_given?
114
+ end
115
+ end
116
+
117
+ self.app = build_app
118
+
119
+ # Stub Rails dispatcher so it does not get controller references and
120
+ # simply return the controller#action as Rack::Body.
121
+ class StubDispatcher < ::ActionDispatch::Routing::RouteSet::Dispatcher
122
+ protected
123
+ def controller_reference(controller_param)
124
+ controller_param
125
+ end
126
+
127
+ def dispatch(controller, action, env)
128
+ [200, {'Content-Type' => 'text/html'}, ["#{controller}##{action}"]]
129
+ end
130
+ end
131
+
132
+ def self.stub_controllers
133
+ old_dispatcher = ActionDispatch::Routing::RouteSet::Dispatcher
134
+ ActionDispatch::Routing::RouteSet.module_eval { remove_const :Dispatcher }
135
+ ActionDispatch::Routing::RouteSet.module_eval { const_set :Dispatcher, StubDispatcher }
136
+ yield ActionDispatch::Routing::RouteSet.new
137
+ ensure
138
+ ActionDispatch::Routing::RouteSet.module_eval { remove_const :Dispatcher }
139
+ ActionDispatch::Routing::RouteSet.module_eval { const_set :Dispatcher, old_dispatcher }
140
+ end
141
+
142
+ def with_routing(&block)
143
+ temporary_routes = ActionDispatch::Routing::RouteSet.new
144
+ old_app, self.class.app = self.class.app, self.class.build_app(temporary_routes)
145
+ old_routes = SharedTestRoutes
146
+ silence_warnings { Object.const_set(:SharedTestRoutes, temporary_routes) }
147
+
148
+ yield temporary_routes
149
+ ensure
150
+ self.class.app = old_app
151
+ silence_warnings { Object.const_set(:SharedTestRoutes, old_routes) }
152
+ end
153
+
154
+ def with_autoload_path(path)
155
+ path = File.join(File.dirname(__FILE__), "fixtures", path)
156
+ if ActiveSupport::Dependencies.autoload_paths.include?(path)
157
+ yield
158
+ else
159
+ begin
160
+ ActiveSupport::Dependencies.autoload_paths << path
161
+ yield
162
+ ensure
163
+ ActiveSupport::Dependencies.autoload_paths.reject! {|p| p == path}
164
+ ActiveSupport::Dependencies.clear
165
+ end
166
+ end
167
+ end
168
+ end
169
+
170
+ # Temporary base class
171
+ class Rack::TestCase < ActionDispatch::IntegrationTest
172
+ def self.testing(klass = nil)
173
+ if klass
174
+ @testing = "/#{klass.name.underscore}".sub!(/_controller$/, '')
175
+ else
176
+ @testing
177
+ end
178
+ end
179
+
180
+ def get(thing, *args)
181
+ if thing.is_a?(Symbol)
182
+ super("#{self.class.testing}/#{thing}", *args)
183
+ else
184
+ super
185
+ end
186
+ end
187
+
188
+ def assert_body(body)
189
+ assert_equal body, Array.wrap(response.body).join
190
+ end
191
+
192
+ def assert_status(code)
193
+ assert_equal code, response.status
194
+ end
195
+
196
+ def assert_response(body, status = 200, headers = {})
197
+ assert_body body
198
+ assert_status status
199
+ headers.each do |header, value|
200
+ assert_header header, value
201
+ end
202
+ end
203
+
204
+ def assert_content_type(type)
205
+ assert_equal type, response.headers["Content-Type"]
206
+ end
207
+
208
+ def assert_header(name, value)
209
+ assert_equal value, response.headers[name]
210
+ end
211
+ end
212
+
213
+ module ActionController
214
+ class Base
215
+ include ActionController::Testing
216
+ # This stub emulates the Railtie including the URL helpers from a Rails application
217
+ include SharedTestRoutes.url_helpers
218
+
219
+ self.view_paths = FIXTURE_LOAD_PATH
220
+
221
+ def self.test_routes(&block)
222
+ routes = ActionDispatch::Routing::RouteSet.new
223
+ routes.draw(&block)
224
+ include routes.url_helpers
225
+ end
226
+ end
227
+
228
+ class TestCase
229
+ include ActionDispatch::TestProcess
230
+
231
+ setup do
232
+ @routes = SharedTestRoutes
233
+ end
234
+ end
235
+ end
@@ -0,0 +1,452 @@
1
+ require 'abstract_unit'
2
+
3
+ class AssertSelectTest < ActionController::TestCase
4
+ Assertion = ActiveSupport::TestCase::Assertion
5
+
6
+ class AssertSelectController < ActionController::Base
7
+ def response_with=(content)
8
+ @content = content
9
+ end
10
+
11
+ def response_with(&block)
12
+ @update = block
13
+ end
14
+
15
+ def rjs
16
+ render :update do |page|
17
+ @update.call page
18
+ end
19
+ @update = nil
20
+ end
21
+
22
+ def rescue_action(e)
23
+ raise e
24
+ end
25
+ end
26
+
27
+ tests AssertSelectController
28
+
29
+ def assert_failure(message, &block)
30
+ e = assert_raise(Assertion, &block)
31
+ assert_match(message, e.message) if Regexp === message
32
+ assert_equal(message, e.message) if String === message
33
+ end
34
+
35
+ # With single result.
36
+ def test_assert_select_from_rjs_with_single_result
37
+ render_rjs do |page|
38
+ page.replace_html "test", "<div id=\"1\">foo</div>\n<div id=\"2\">foo</div>"
39
+ end
40
+ assert_select "div" do |elements|
41
+ assert elements.size == 2
42
+ assert_select "#1"
43
+ assert_select "#2"
44
+ end
45
+ assert_select "div#?", /\d+/ do |elements|
46
+ assert_select "#1"
47
+ assert_select "#2"
48
+ end
49
+ end
50
+
51
+ # With multiple results.
52
+ def test_assert_select_from_rjs_with_multiple_results
53
+ render_rjs do |page|
54
+ page.replace_html "test", "<div id=\"1\">foo</div>"
55
+ page.replace_html "test2", "<div id=\"2\">foo</div>"
56
+ end
57
+ assert_select "div" do |elements|
58
+ assert elements.size == 2
59
+ assert_select "#1"
60
+ assert_select "#2"
61
+ end
62
+ end
63
+
64
+ # With one result.
65
+ def test_css_select_from_rjs_with_single_result
66
+ render_rjs do |page|
67
+ page.replace_html "test", "<div id=\"1\">foo</div>\n<div id=\"2\">foo</div>"
68
+ end
69
+ assert_equal 2, css_select("div").size
70
+ assert_equal 1, css_select("#1").size
71
+ assert_equal 1, css_select("#2").size
72
+ end
73
+
74
+ # With multiple results.
75
+ def test_css_select_from_rjs_with_multiple_results
76
+ render_rjs do |page|
77
+ page.replace_html "test", "<div id=\"1\">foo</div>"
78
+ page.replace_html "test2", "<div id=\"2\">foo</div>"
79
+ end
80
+
81
+ assert_equal 2, css_select("div").size
82
+ assert_equal 1, css_select("#1").size
83
+ assert_equal 1, css_select("#2").size
84
+ end
85
+
86
+ #
87
+ # Test assert_select_rjs.
88
+ #
89
+
90
+ def test_assert_select_rjs_for_positioned_insert_should_fail_when_mixing_arguments
91
+ render_rjs do |page|
92
+ page.insert_html :top, "test1", "<div id=\"1\">foo</div>"
93
+ page.insert_html :bottom, "test2", "<div id=\"2\">foo</div>"
94
+ end
95
+ assert_raise(Assertion) {assert_select_rjs :insert, :top, "test2"}
96
+ end
97
+
98
+ # Test that we can pick up all statements in the result.
99
+ def test_assert_select_rjs_picks_up_all_statements
100
+ render_rjs do |page|
101
+ page.replace "test", "<div id=\"1\">foo</div>"
102
+ page.replace_html "test2", "<div id=\"2\">foo</div>"
103
+ page.insert_html :top, "test3", "<div id=\"3\">foo</div>"
104
+ end
105
+
106
+ found = false
107
+ assert_select_rjs do
108
+ assert_select "#1"
109
+ assert_select "#2"
110
+ assert_select "#3"
111
+ found = true
112
+ end
113
+ assert found
114
+ end
115
+
116
+ # Test that we fail if there is nothing to pick.
117
+ def test_assert_select_rjs_fails_if_nothing_to_pick
118
+ render_rjs { }
119
+ assert_raise(Assertion) { assert_select_rjs }
120
+ end
121
+
122
+ def test_assert_select_rjs_with_unicode
123
+ # Test that non-ascii characters (which are converted into \uXXXX in RJS) are decoded correctly.
124
+ render_rjs do |page|
125
+ page.replace "test", "<div id=\"1\">\343\203\201\343\202\261\343\203\203\343\203\210</div>"
126
+ end
127
+ assert_select_rjs do
128
+ str = "#1"
129
+ assert_select str, :text => "\343\203\201\343\202\261\343\203\203\343\203\210"
130
+ assert_select str, "\343\203\201\343\202\261\343\203\203\343\203\210"
131
+ if str.respond_to?(:force_encoding)
132
+ assert_select str, /\343\203\201..\343\203\210/u
133
+ assert_raise(Assertion) { assert_select str, /\343\203\201.\343\203\210/u }
134
+ else
135
+ assert_select str, Regexp.new("\343\203\201..\343\203\210",0,'U')
136
+ assert_raise(Assertion) { assert_select str, Regexp.new("\343\203\201.\343\203\210",0,'U') }
137
+ end
138
+ end
139
+ end
140
+
141
+ def test_assert_select_rjs_with_id
142
+ # Test that we can pick up all statements in the result.
143
+ render_rjs do |page|
144
+ page.replace "test1", "<div id=\"1\">foo</div>"
145
+ page.replace_html "test2", "<div id=\"2\">foo</div>"
146
+ page.insert_html :top, "test3", "<div id=\"3\">foo</div>"
147
+ end
148
+ assert_select_rjs "test1" do
149
+ assert_select "div", 1
150
+ assert_select "#1"
151
+ end
152
+ assert_select_rjs "test2" do
153
+ assert_select "div", 1
154
+ assert_select "#2"
155
+ end
156
+ assert_select_rjs "test3" do
157
+ assert_select "div", 1
158
+ assert_select "#3"
159
+ end
160
+ assert_raise(Assertion) { assert_select_rjs "test4" }
161
+ end
162
+
163
+ def test_assert_select_rjs_for_replace
164
+ render_rjs do |page|
165
+ page.replace "test1", "<div id=\"1\">foo</div>"
166
+ page.replace_html "test2", "<div id=\"2\">foo</div>"
167
+ page.insert_html :top, "test3", "<div id=\"3\">foo</div>"
168
+ end
169
+ # Replace.
170
+ assert_select_rjs :replace do
171
+ assert_select "div", 1
172
+ assert_select "#1"
173
+ end
174
+ assert_select_rjs :replace, "test1" do
175
+ assert_select "div", 1
176
+ assert_select "#1"
177
+ end
178
+ assert_raise(Assertion) { assert_select_rjs :replace, "test2" }
179
+ # Replace HTML.
180
+ assert_select_rjs :replace_html do
181
+ assert_select "div", 1
182
+ assert_select "#2"
183
+ end
184
+ assert_select_rjs :replace_html, "test2" do
185
+ assert_select "div", 1
186
+ assert_select "#2"
187
+ end
188
+ assert_raise(Assertion) { assert_select_rjs :replace_html, "test1" }
189
+ end
190
+
191
+ def test_assert_select_rjs_for_chained_replace
192
+ render_rjs do |page|
193
+ page['test1'].replace "<div id=\"1\">foo</div>"
194
+ page['test2'].replace_html "<div id=\"2\">foo</div>"
195
+ page.insert_html :top, "test3", "<div id=\"3\">foo</div>"
196
+ end
197
+ # Replace.
198
+ assert_select_rjs :chained_replace do
199
+ assert_select "div", 1
200
+ assert_select "#1"
201
+ end
202
+ assert_select_rjs :chained_replace, "test1" do
203
+ assert_select "div", 1
204
+ assert_select "#1"
205
+ end
206
+ assert_raise(Assertion) { assert_select_rjs :chained_replace, "test2" }
207
+ # Replace HTML.
208
+ assert_select_rjs :chained_replace_html do
209
+ assert_select "div", 1
210
+ assert_select "#2"
211
+ end
212
+ assert_select_rjs :chained_replace_html, "test2" do
213
+ assert_select "div", 1
214
+ assert_select "#2"
215
+ end
216
+ assert_raise(Assertion) { assert_select_rjs :replace_html, "test1" }
217
+ end
218
+
219
+ # Simple remove
220
+ def test_assert_select_rjs_for_remove
221
+ render_rjs do |page|
222
+ page.remove "test1"
223
+ end
224
+
225
+ assert_select_rjs :remove, "test1"
226
+ end
227
+
228
+ def test_assert_select_rjs_for_remove_offers_useful_error_when_assertion_fails
229
+ render_rjs do |page|
230
+ page.remove "test_with_typo"
231
+ end
232
+
233
+ assert_select_rjs :remove, "test1"
234
+
235
+ rescue Assertion => e
236
+ assert_equal "No RJS statement that removes 'test1' was rendered.", e.message
237
+ end
238
+
239
+ def test_assert_select_rjs_for_remove_ignores_block
240
+ render_rjs do |page|
241
+ page.remove "test1"
242
+ end
243
+
244
+ assert_nothing_raised do
245
+ assert_select_rjs :remove, "test1" do
246
+ assert_select "p"
247
+ end
248
+ end
249
+ end
250
+
251
+ # Simple show
252
+ def test_assert_select_rjs_for_show
253
+ render_rjs do |page|
254
+ page.show "test1"
255
+ end
256
+
257
+ assert_select_rjs :show, "test1"
258
+ end
259
+
260
+ def test_assert_select_rjs_for_show_offers_useful_error_when_assertion_fails
261
+ render_rjs do |page|
262
+ page.show "test_with_typo"
263
+ end
264
+
265
+ assert_select_rjs :show, "test1"
266
+
267
+ rescue Assertion => e
268
+ assert_equal "No RJS statement that shows 'test1' was rendered.", e.message
269
+ end
270
+
271
+ def test_assert_select_rjs_for_show_ignores_block
272
+ render_rjs do |page|
273
+ page.show "test1"
274
+ end
275
+
276
+ assert_nothing_raised do
277
+ assert_select_rjs :show, "test1" do
278
+ assert_select "p"
279
+ end
280
+ end
281
+ end
282
+
283
+ # Simple hide
284
+ def test_assert_select_rjs_for_hide
285
+ render_rjs do |page|
286
+ page.hide "test1"
287
+ end
288
+
289
+ assert_select_rjs :hide, "test1"
290
+ end
291
+
292
+ def test_assert_select_rjs_for_hide_offers_useful_error_when_assertion_fails
293
+ render_rjs do |page|
294
+ page.hide "test_with_typo"
295
+ end
296
+
297
+ assert_select_rjs :hide, "test1"
298
+
299
+ rescue Assertion => e
300
+ assert_equal "No RJS statement that hides 'test1' was rendered.", e.message
301
+ end
302
+
303
+ def test_assert_select_rjs_for_hide_ignores_block
304
+ render_rjs do |page|
305
+ page.hide "test1"
306
+ end
307
+
308
+ assert_nothing_raised do
309
+ assert_select_rjs :hide, "test1" do
310
+ assert_select "p"
311
+ end
312
+ end
313
+ end
314
+
315
+ # Simple toggle
316
+ def test_assert_select_rjs_for_toggle
317
+ render_rjs do |page|
318
+ page.toggle "test1"
319
+ end
320
+
321
+ assert_select_rjs :toggle, "test1"
322
+ end
323
+
324
+ def test_assert_select_rjs_for_toggle_offers_useful_error_when_assertion_fails
325
+ render_rjs do |page|
326
+ page.toggle "test_with_typo"
327
+ end
328
+
329
+ assert_select_rjs :toggle, "test1"
330
+
331
+ rescue Assertion => e
332
+ assert_equal "No RJS statement that toggles 'test1' was rendered.", e.message
333
+ end
334
+
335
+ def test_assert_select_rjs_for_toggle_ignores_block
336
+ render_rjs do |page|
337
+ page.toggle "test1"
338
+ end
339
+
340
+ assert_nothing_raised do
341
+ assert_select_rjs :toggle, "test1" do
342
+ assert_select "p"
343
+ end
344
+ end
345
+ end
346
+
347
+ # Non-positioned insert.
348
+ def test_assert_select_rjs_for_nonpositioned_insert
349
+ render_rjs do |page|
350
+ page.replace "test1", "<div id=\"1\">foo</div>"
351
+ page.replace_html "test2", "<div id=\"2\">foo</div>"
352
+ page.insert_html :top, "test3", "<div id=\"3\">foo</div>"
353
+ end
354
+ assert_select_rjs :insert_html do
355
+ assert_select "div", 1
356
+ assert_select "#3"
357
+ end
358
+ assert_select_rjs :insert_html, "test3" do
359
+ assert_select "div", 1
360
+ assert_select "#3"
361
+ end
362
+ assert_raise(Assertion) { assert_select_rjs :insert_html, "test1" }
363
+ end
364
+
365
+ # Positioned insert.
366
+ def test_assert_select_rjs_for_positioned_insert
367
+ render_rjs do |page|
368
+ page.insert_html :top, "test1", "<div id=\"1\">foo</div>"
369
+ page.insert_html :bottom, "test2", "<div id=\"2\">foo</div>"
370
+ page.insert_html :before, "test3", "<div id=\"3\">foo</div>"
371
+ page.insert_html :after, "test4", "<div id=\"4\">foo</div>"
372
+ end
373
+ assert_select_rjs :insert, :top do
374
+ assert_select "div", 1
375
+ assert_select "#1"
376
+ end
377
+ assert_select_rjs :insert, :bottom do
378
+ assert_select "div", 1
379
+ assert_select "#2"
380
+ end
381
+ assert_select_rjs :insert, :before do
382
+ assert_select "div", 1
383
+ assert_select "#3"
384
+ end
385
+ assert_select_rjs :insert, :after do
386
+ assert_select "div", 1
387
+ assert_select "#4"
388
+ end
389
+ assert_select_rjs :insert_html do
390
+ assert_select "div", 4
391
+ end
392
+ end
393
+
394
+ def test_assert_select_rjs_raise_errors
395
+ assert_raise(ArgumentError) { assert_select_rjs(:destroy) }
396
+ assert_raise(ArgumentError) { assert_select_rjs(:insert, :left) }
397
+ end
398
+
399
+ # Simple selection from a single result.
400
+ def test_nested_assert_select_rjs_with_single_result
401
+ render_rjs do |page|
402
+ page.replace_html "test", "<div id=\"1\">foo</div>\n<div id=\"2\">foo</div>"
403
+ end
404
+
405
+ assert_select_rjs "test" do |elements|
406
+ assert_equal 2, elements.size
407
+ assert_select "#1"
408
+ assert_select "#2"
409
+ end
410
+ end
411
+
412
+ # Deal with two results.
413
+ def test_nested_assert_select_rjs_with_two_results
414
+ render_rjs do |page|
415
+ page.replace_html "test", "<div id=\"1\">foo</div>"
416
+ page.replace_html "test2", "<div id=\"2\">foo</div>"
417
+ end
418
+
419
+ assert_select_rjs "test" do |elements|
420
+ assert_equal 1, elements.size
421
+ assert_select "#1"
422
+ end
423
+
424
+ assert_select_rjs "test2" do |elements|
425
+ assert_equal 1, elements.size
426
+ assert_select "#2"
427
+ end
428
+ end
429
+
430
+ def test_assert_select_rjs_for_redirect_to
431
+ render_rjs do |page|
432
+ page.redirect_to '/'
433
+ end
434
+ assert_select_rjs :redirect, '/'
435
+ end
436
+
437
+ protected
438
+ def render_html(html)
439
+ @controller.response_with = html
440
+ get :html
441
+ end
442
+
443
+ def render_rjs(&block)
444
+ @controller.response_with(&block)
445
+ get :rjs
446
+ end
447
+
448
+ def render_xml(xml)
449
+ @controller.response_with = xml
450
+ get :xml
451
+ end
452
+ end