radiant-paperclipped-extension 0.8.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitmodules +3 -0
- data/HELP_admin.markdown +69 -0
- data/LICENSE +21 -0
- data/README.md +137 -0
- data/Rakefile +110 -0
- data/VERSION +1 -0
- data/app/controllers/admin/assets_controller.rb +124 -0
- data/app/helpers/admin/assets_helper.rb +5 -0
- data/app/models/asset.rb +279 -0
- data/app/models/asset_page_tags.rb +101 -0
- data/app/models/asset_tags.rb +272 -0
- data/app/models/old_page_attachment.rb +26 -0
- data/app/models/page_attachment.rb +8 -0
- data/app/views/admin/assets/_asset.html.haml +19 -0
- data/app/views/admin/assets/_asset_table.html.haml +49 -0
- data/app/views/admin/assets/_assets_bucket.html.haml +8 -0
- data/app/views/admin/assets/_assets_container.html.haml +72 -0
- data/app/views/admin/assets/_bucket.html.haml +11 -0
- data/app/views/admin/assets/_bucket_asset.html.haml +9 -0
- data/app/views/admin/assets/_errors.html.haml +3 -0
- data/app/views/admin/assets/_form.html.haml +20 -0
- data/app/views/admin/assets/_page_assets.html.haml +12 -0
- data/app/views/admin/assets/_search_results.html.haml +17 -0
- data/app/views/admin/assets/_show_bucket_link.html.haml +4 -0
- data/app/views/admin/assets/_upload_to_page.html.haml +16 -0
- data/app/views/admin/assets/edit.html.haml +53 -0
- data/app/views/admin/assets/index.html.haml +43 -0
- data/app/views/admin/assets/new.html.haml +27 -0
- data/app/views/admin/assets/remove.html.haml +21 -0
- data/app/views/admin/bucket/_iframe.html.haml +1 -0
- data/config/locales/en.yml +60 -0
- data/config/locales/nl.yml +60 -0
- data/config/locales/pl.yml +60 -0
- data/config/routes.rb +20 -0
- data/db/migrate/001_create_assets.rb +12 -0
- data/db/migrate/002_create_paperclip_attributes.rb +13 -0
- data/db/migrate/003_create_user_observer.rb +13 -0
- data/db/migrate/004_create_page_attachments.rb +19 -0
- data/db/migrate/005_rename_users.rb +13 -0
- data/db/migrate/006_add_default_configs.rb +29 -0
- data/db/migrate/007_add_default_content_types.rb +29 -0
- data/db/migrate/20090316132151_disable_file_types.rb +20 -0
- data/lib/assets_admin_ui.rb +38 -0
- data/lib/mime_type_ext.rb +7 -0
- data/lib/tasks/assets_extension_tasks.rake +123 -0
- data/lib/tasks/paperclip_tasks.rake +79 -0
- data/lib/url_additions.rb +10 -0
- data/paperclipped_extension.rb +56 -0
- data/psds/file_type_icons.psd +0 -0
- data/psds/file_type_icons_.psd +0 -0
- data/public/images/assets/_page_assets.html.haml +26 -0
- data/public/images/assets/add-to-bucket.png +0 -0
- data/public/images/assets/add.png +0 -0
- data/public/images/assets/audio_icon.png +0 -0
- data/public/images/assets/audio_thumbnail.png +0 -0
- data/public/images/assets/delete.png +0 -0
- data/public/images/assets/doc_icon.png +0 -0
- data/public/images/assets/doc_thumbnail.png +0 -0
- data/public/images/assets/edit.png +0 -0
- data/public/images/assets/movie_icon.png +0 -0
- data/public/images/assets/movie_thumbnail.png +0 -0
- data/public/images/assets/new-asset.png +0 -0
- data/public/images/assets/page_edit.png +0 -0
- data/public/images/assets/pdf_icon.png +0 -0
- data/public/images/assets/pdf_thumbnail.png +0 -0
- data/public/images/assets/reorder_assets.png +0 -0
- data/public/javascripts/admin/assets.js +173 -0
- data/public/stylesheets/admin/assets.css +163 -0
- data/spec/controllers/admin/assets_controller_spec.rb +10 -0
- data/spec/models/asset_spec.rb +68 -0
- data/spec/spec.opts +6 -0
- data/spec/spec_helper.rb +27 -0
- data/vendor/plugins/acts_as_list/README +23 -0
- data/vendor/plugins/acts_as_list/init.rb +3 -0
- data/vendor/plugins/acts_as_list/lib/active_record/acts/list.rb +256 -0
- data/vendor/plugins/acts_as_list/test/list_test.rb +332 -0
- data/vendor/plugins/paperclip/LICENSE +26 -0
- data/vendor/plugins/paperclip/README.rdoc +179 -0
- data/vendor/plugins/paperclip/Rakefile +76 -0
- data/vendor/plugins/paperclip/cucumber/paperclip_steps.rb +6 -0
- data/vendor/plugins/paperclip/generators/paperclip/USAGE +5 -0
- data/vendor/plugins/paperclip/generators/paperclip/paperclip_generator.rb +27 -0
- data/vendor/plugins/paperclip/generators/paperclip/templates/paperclip_migration.rb.erb +19 -0
- data/vendor/plugins/paperclip/init.rb +1 -0
- data/vendor/plugins/paperclip/lib/generators/paperclip/USAGE +8 -0
- data/vendor/plugins/paperclip/lib/generators/paperclip/paperclip_generator.rb +31 -0
- data/vendor/plugins/paperclip/lib/generators/paperclip/templates/paperclip_migration.rb.erb +19 -0
- data/vendor/plugins/paperclip/lib/paperclip.rb +397 -0
- data/vendor/plugins/paperclip/lib/paperclip/attachment.rb +326 -0
- data/vendor/plugins/paperclip/lib/paperclip/callback_compatability.rb +61 -0
- data/vendor/plugins/paperclip/lib/paperclip/geometry.rb +115 -0
- data/vendor/plugins/paperclip/lib/paperclip/interpolations.rb +108 -0
- data/vendor/plugins/paperclip/lib/paperclip/iostream.rb +59 -0
- data/vendor/plugins/paperclip/lib/paperclip/matchers.rb +33 -0
- data/vendor/plugins/paperclip/lib/paperclip/matchers/have_attached_file_matcher.rb +57 -0
- data/vendor/plugins/paperclip/lib/paperclip/matchers/validate_attachment_content_type_matcher.rb +74 -0
- data/vendor/plugins/paperclip/lib/paperclip/matchers/validate_attachment_presence_matcher.rb +54 -0
- data/vendor/plugins/paperclip/lib/paperclip/matchers/validate_attachment_size_matcher.rb +95 -0
- data/vendor/plugins/paperclip/lib/paperclip/processor.rb +49 -0
- data/vendor/plugins/paperclip/lib/paperclip/railtie.rb +24 -0
- data/vendor/plugins/paperclip/lib/paperclip/storage.rb +247 -0
- data/vendor/plugins/paperclip/lib/paperclip/style.rb +90 -0
- data/vendor/plugins/paperclip/lib/paperclip/thumbnail.rb +78 -0
- data/vendor/plugins/paperclip/lib/paperclip/upfile.rb +52 -0
- data/vendor/plugins/paperclip/lib/paperclip/version.rb +3 -0
- data/vendor/plugins/paperclip/lib/tasks/paperclip.rake +79 -0
- data/vendor/plugins/paperclip/paperclip.gemspec +34 -0
- data/vendor/plugins/paperclip/rails/init.rb +2 -0
- data/vendor/plugins/paperclip/shoulda_macros/paperclip.rb +119 -0
- data/vendor/plugins/paperclip/test/.gitignore +1 -0
- data/vendor/plugins/paperclip/test/attachment_test.rb +758 -0
- data/vendor/plugins/paperclip/test/database.yml +4 -0
- data/vendor/plugins/paperclip/test/fixtures/12k.png +0 -0
- data/vendor/plugins/paperclip/test/fixtures/50x50.png +0 -0
- data/vendor/plugins/paperclip/test/fixtures/5k.png +0 -0
- data/vendor/plugins/paperclip/test/fixtures/bad.png +1 -0
- data/vendor/plugins/paperclip/test/fixtures/s3.yml +8 -0
- data/vendor/plugins/paperclip/test/fixtures/text.txt +0 -0
- data/vendor/plugins/paperclip/test/fixtures/twopage.pdf +0 -0
- data/vendor/plugins/paperclip/test/geometry_test.rb +177 -0
- data/vendor/plugins/paperclip/test/helper.rb +148 -0
- data/vendor/plugins/paperclip/test/integration_test.rb +483 -0
- data/vendor/plugins/paperclip/test/interpolations_test.rb +124 -0
- data/vendor/plugins/paperclip/test/iostream_test.rb +78 -0
- data/vendor/plugins/paperclip/test/matchers/have_attached_file_matcher_test.rb +24 -0
- data/vendor/plugins/paperclip/test/matchers/validate_attachment_content_type_matcher_test.rb +37 -0
- data/vendor/plugins/paperclip/test/matchers/validate_attachment_presence_matcher_test.rb +26 -0
- data/vendor/plugins/paperclip/test/matchers/validate_attachment_size_matcher_test.rb +51 -0
- data/vendor/plugins/paperclip/test/paperclip_test.rb +317 -0
- data/vendor/plugins/paperclip/test/processor_test.rb +10 -0
- data/vendor/plugins/paperclip/test/storage_test.rb +343 -0
- data/vendor/plugins/paperclip/test/style_test.rb +141 -0
- data/vendor/plugins/paperclip/test/thumbnail_test.rb +227 -0
- data/vendor/plugins/paperclip/test/upfile_test.rb +36 -0
- data/vendor/plugins/responds_to_parent/MIT-LICENSE +20 -0
- data/vendor/plugins/responds_to_parent/README +42 -0
- data/vendor/plugins/responds_to_parent/Rakefile +22 -0
- data/vendor/plugins/responds_to_parent/init.rb +2 -0
- data/vendor/plugins/responds_to_parent/lib/parent_selector_assertion.rb +144 -0
- data/vendor/plugins/responds_to_parent/lib/responds_to_parent.rb +46 -0
- data/vendor/plugins/responds_to_parent/test/assert_select_parent_test.rb +318 -0
- data/vendor/plugins/responds_to_parent/test/responds_to_parent_test.rb +115 -0
- metadata +226 -0
@@ -0,0 +1,46 @@
|
|
1
|
+
# Module containing the methods useful for child IFRAME to parent window communication
|
2
|
+
module RespondsToParent
|
3
|
+
|
4
|
+
# Executes the response body as JavaScript in the context of the parent window.
|
5
|
+
# Use this method of you are posting a form to a hidden IFRAME or if you would like
|
6
|
+
# to use IFRAME base RPC.
|
7
|
+
def responds_to_parent(&block)
|
8
|
+
yield
|
9
|
+
|
10
|
+
if performed?
|
11
|
+
# We're returning HTML instead of JS or XML now
|
12
|
+
response.headers['Content-Type'] = 'text/html; charset=UTF-8'
|
13
|
+
|
14
|
+
# Either pull out a redirect or the request body
|
15
|
+
script = if location = erase_redirect_results
|
16
|
+
"document.location.href = #{location.to_s.inspect}"
|
17
|
+
else
|
18
|
+
response.body
|
19
|
+
end
|
20
|
+
|
21
|
+
# Escape quotes, linebreaks and slashes, maintaining previously escaped slashes
|
22
|
+
# Suggestions for improvement?
|
23
|
+
script = (script || '').
|
24
|
+
gsub('\\', '\\\\\\').
|
25
|
+
gsub(/\r\n|\r|\n/, '\\n').
|
26
|
+
gsub(/['"]/, '\\\\\&').
|
27
|
+
gsub('</script>','</scr"+"ipt>')
|
28
|
+
|
29
|
+
# Clear out the previous render to prevent double render
|
30
|
+
erase_results
|
31
|
+
|
32
|
+
# Eval in parent scope and replace document location of this frame
|
33
|
+
# so back button doesn't replay action on targeted forms
|
34
|
+
# loc = document.location to be set after parent is updated for IE
|
35
|
+
# with(window.parent) - pull in variables from parent window
|
36
|
+
# setTimeout - scope the execution in the windows parent for safari
|
37
|
+
# window.eval - legal eval for Opera
|
38
|
+
render :text => "<html><body><script type='text/javascript' charset='utf-8'>
|
39
|
+
var loc = document.location;
|
40
|
+
with(window.parent) { setTimeout(function() { window.eval('#{script}'); loc.replace('about:blank'); }, 1) }
|
41
|
+
</script></body></html>"
|
42
|
+
end
|
43
|
+
end
|
44
|
+
alias respond_to_parent responds_to_parent
|
45
|
+
end
|
46
|
+
|
@@ -0,0 +1,318 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../../../../config/environment'
|
2
|
+
require 'test/unit'
|
3
|
+
require 'test_help'
|
4
|
+
|
5
|
+
class AssertSelectParentTest < Test::Unit::TestCase
|
6
|
+
class AssertSelectParentController < 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
|
+
responds_to_parent do
|
17
|
+
render :update do |page|
|
18
|
+
@update.call page
|
19
|
+
end
|
20
|
+
end
|
21
|
+
@update = nil
|
22
|
+
end
|
23
|
+
|
24
|
+
def text
|
25
|
+
responds_to_parent do
|
26
|
+
render :text => @content, :layout => false
|
27
|
+
end
|
28
|
+
@content = nil
|
29
|
+
end
|
30
|
+
|
31
|
+
def not_respond_to_parent
|
32
|
+
render :nothing => true
|
33
|
+
end
|
34
|
+
|
35
|
+
def rescue_action(e)
|
36
|
+
raise e
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def setup
|
41
|
+
@controller = AssertSelectParentController.new
|
42
|
+
@request = ActionController::TestRequest.new
|
43
|
+
@response = ActionController::TestResponse.new
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_basic
|
47
|
+
render_rjs do |page|
|
48
|
+
page.replace "test", "<div id=\"1\">foo</div>"
|
49
|
+
end
|
50
|
+
|
51
|
+
found = false
|
52
|
+
assert_select_parent do
|
53
|
+
assert_select_rjs do
|
54
|
+
assert_select "#1"
|
55
|
+
found = true
|
56
|
+
end
|
57
|
+
end
|
58
|
+
assert found
|
59
|
+
end
|
60
|
+
|
61
|
+
def test_bubble_up_failure
|
62
|
+
render_rjs do |page|
|
63
|
+
page.replace "test", "<div id=\"1\">foo</div>"
|
64
|
+
end
|
65
|
+
|
66
|
+
assert_raise(Test::Unit::AssertionFailedError) do
|
67
|
+
assert_select_parent do
|
68
|
+
assert_select_rjs do
|
69
|
+
assert_select "#nonexistent"
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
def test_fail_if_no_content_for_parent
|
76
|
+
get :not_respond_to_parent
|
77
|
+
assert_raise(Test::Unit::AssertionFailedError) { assert_select_parent }
|
78
|
+
end
|
79
|
+
|
80
|
+
def test_quotes
|
81
|
+
do_test_with_text %(single' double" escaped\\' escaped\\" doubleescaped\\\\\\' doubleescaped\\\\\\")
|
82
|
+
end
|
83
|
+
|
84
|
+
def test_new_line
|
85
|
+
do_test_with_text "line1\nline2\\nline2\\\nline3\\\\nline3\\\\\nline4\\\\\\nline4"
|
86
|
+
end
|
87
|
+
|
88
|
+
protected
|
89
|
+
def render_rjs(&block)
|
90
|
+
@controller.response_with &block
|
91
|
+
get :rjs
|
92
|
+
end
|
93
|
+
|
94
|
+
def render_text(text)
|
95
|
+
@controller.response_with = text
|
96
|
+
get :text
|
97
|
+
end
|
98
|
+
|
99
|
+
def do_test_with_text(text)
|
100
|
+
render_text text
|
101
|
+
|
102
|
+
assert_select_parent do |text_for_parent|
|
103
|
+
assert_equal text, text_for_parent
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
require File.dirname(__FILE__) + '/../../../../config/environment'
|
108
|
+
require 'test/unit'
|
109
|
+
require 'test_help'
|
110
|
+
|
111
|
+
class AssertSelectParentTest < Test::Unit::TestCase
|
112
|
+
class AssertSelectParentController < ActionController::Base
|
113
|
+
def response_with=(content)
|
114
|
+
@content = content
|
115
|
+
end
|
116
|
+
|
117
|
+
def response_with(&block)
|
118
|
+
@update = block
|
119
|
+
end
|
120
|
+
|
121
|
+
def rjs
|
122
|
+
responds_to_parent do
|
123
|
+
render :update do |page|
|
124
|
+
@update.call page
|
125
|
+
end
|
126
|
+
end
|
127
|
+
@update = nil
|
128
|
+
end
|
129
|
+
|
130
|
+
def text
|
131
|
+
responds_to_parent do
|
132
|
+
render :text => @content, :layout => false
|
133
|
+
end
|
134
|
+
@content = nil
|
135
|
+
end
|
136
|
+
|
137
|
+
def not_respond_to_parent
|
138
|
+
render :nothing => true
|
139
|
+
end
|
140
|
+
|
141
|
+
def rescue_action(e)
|
142
|
+
raise e
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
def setup
|
147
|
+
@controller = AssertSelectParentController.new
|
148
|
+
@request = ActionController::TestRequest.new
|
149
|
+
@response = ActionController::TestResponse.new
|
150
|
+
end
|
151
|
+
|
152
|
+
def test_basic
|
153
|
+
render_rjs do |page|
|
154
|
+
page.replace "test", "<div id=\"1\">foo</div>"
|
155
|
+
end
|
156
|
+
|
157
|
+
found = false
|
158
|
+
assert_select_parent do
|
159
|
+
assert_select_rjs do
|
160
|
+
assert_select "#1"
|
161
|
+
found = true
|
162
|
+
end
|
163
|
+
end
|
164
|
+
assert found
|
165
|
+
end
|
166
|
+
|
167
|
+
def test_bubble_up_failure
|
168
|
+
render_rjs do |page|
|
169
|
+
page.replace "test", "<div id=\"1\">foo</div>"
|
170
|
+
end
|
171
|
+
|
172
|
+
assert_raise(Test::Unit::AssertionFailedError) do
|
173
|
+
assert_select_parent do
|
174
|
+
assert_select_rjs do
|
175
|
+
assert_select "#nonexistent"
|
176
|
+
end
|
177
|
+
end
|
178
|
+
end
|
179
|
+
end
|
180
|
+
|
181
|
+
def test_fail_if_no_content_for_parent
|
182
|
+
get :not_respond_to_parent
|
183
|
+
assert_raise(Test::Unit::AssertionFailedError) { assert_select_parent }
|
184
|
+
end
|
185
|
+
|
186
|
+
def test_quotes
|
187
|
+
do_test_with_text %(single' double" escaped\\' escaped\\" doubleescaped\\\\\\' doubleescaped\\\\\\")
|
188
|
+
end
|
189
|
+
|
190
|
+
def test_new_line
|
191
|
+
do_test_with_text "line1\nline2\\nline2\\\nline3\\\\nline3\\\\\nline4\\\\\\nline4"
|
192
|
+
end
|
193
|
+
|
194
|
+
protected
|
195
|
+
def render_rjs(&block)
|
196
|
+
@controller.response_with &block
|
197
|
+
get :rjs
|
198
|
+
end
|
199
|
+
|
200
|
+
def render_text(text)
|
201
|
+
@controller.response_with = text
|
202
|
+
get :text
|
203
|
+
end
|
204
|
+
|
205
|
+
def do_test_with_text(text)
|
206
|
+
render_text text
|
207
|
+
|
208
|
+
assert_select_parent do |text_for_parent|
|
209
|
+
assert_equal text, text_for_parent
|
210
|
+
end
|
211
|
+
end
|
212
|
+
end
|
213
|
+
require File.dirname(__FILE__) + '/../../../../config/environment'
|
214
|
+
require 'test/unit'
|
215
|
+
require 'test_help'
|
216
|
+
|
217
|
+
class AssertSelectParentTest < Test::Unit::TestCase
|
218
|
+
class AssertSelectParentController < ActionController::Base
|
219
|
+
def response_with=(content)
|
220
|
+
@content = content
|
221
|
+
end
|
222
|
+
|
223
|
+
def response_with(&block)
|
224
|
+
@update = block
|
225
|
+
end
|
226
|
+
|
227
|
+
def rjs
|
228
|
+
responds_to_parent do
|
229
|
+
render :update do |page|
|
230
|
+
@update.call page
|
231
|
+
end
|
232
|
+
end
|
233
|
+
@update = nil
|
234
|
+
end
|
235
|
+
|
236
|
+
def text
|
237
|
+
responds_to_parent do
|
238
|
+
render :text => @content, :layout => false
|
239
|
+
end
|
240
|
+
@content = nil
|
241
|
+
end
|
242
|
+
|
243
|
+
def not_respond_to_parent
|
244
|
+
render :nothing => true
|
245
|
+
end
|
246
|
+
|
247
|
+
def rescue_action(e)
|
248
|
+
raise e
|
249
|
+
end
|
250
|
+
end
|
251
|
+
|
252
|
+
def setup
|
253
|
+
@controller = AssertSelectParentController.new
|
254
|
+
@request = ActionController::TestRequest.new
|
255
|
+
@response = ActionController::TestResponse.new
|
256
|
+
end
|
257
|
+
|
258
|
+
def test_basic
|
259
|
+
render_rjs do |page|
|
260
|
+
page.replace "test", "<div id=\"1\">foo</div>"
|
261
|
+
end
|
262
|
+
|
263
|
+
found = false
|
264
|
+
assert_select_parent do
|
265
|
+
assert_select_rjs do
|
266
|
+
assert_select "#1"
|
267
|
+
found = true
|
268
|
+
end
|
269
|
+
end
|
270
|
+
assert found
|
271
|
+
end
|
272
|
+
|
273
|
+
def test_bubble_up_failure
|
274
|
+
render_rjs do |page|
|
275
|
+
page.replace "test", "<div id=\"1\">foo</div>"
|
276
|
+
end
|
277
|
+
|
278
|
+
assert_raise(Test::Unit::AssertionFailedError) do
|
279
|
+
assert_select_parent do
|
280
|
+
assert_select_rjs do
|
281
|
+
assert_select "#nonexistent"
|
282
|
+
end
|
283
|
+
end
|
284
|
+
end
|
285
|
+
end
|
286
|
+
|
287
|
+
def test_fail_if_no_content_for_parent
|
288
|
+
get :not_respond_to_parent
|
289
|
+
assert_raise(Test::Unit::AssertionFailedError) { assert_select_parent }
|
290
|
+
end
|
291
|
+
|
292
|
+
def test_quotes
|
293
|
+
do_test_with_text %(single' double" escaped\\' escaped\\" doubleescaped\\\\\\' doubleescaped\\\\\\")
|
294
|
+
end
|
295
|
+
|
296
|
+
def test_new_line
|
297
|
+
do_test_with_text "line1\nline2\\nline2\\\nline3\\\\nline3\\\\\nline4\\\\\\nline4"
|
298
|
+
end
|
299
|
+
|
300
|
+
protected
|
301
|
+
def render_rjs(&block)
|
302
|
+
@controller.response_with &block
|
303
|
+
get :rjs
|
304
|
+
end
|
305
|
+
|
306
|
+
def render_text(text)
|
307
|
+
@controller.response_with = text
|
308
|
+
get :text
|
309
|
+
end
|
310
|
+
|
311
|
+
def do_test_with_text(text)
|
312
|
+
render_text text
|
313
|
+
|
314
|
+
assert_select_parent do |text_for_parent|
|
315
|
+
assert_equal text, text_for_parent
|
316
|
+
end
|
317
|
+
end
|
318
|
+
end
|
@@ -0,0 +1,115 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../../../../config/environment'
|
2
|
+
require 'test/unit'
|
3
|
+
require 'test_help'
|
4
|
+
|
5
|
+
class IFrameController < ActionController::Base
|
6
|
+
def normal
|
7
|
+
render :update do |page|
|
8
|
+
page.alert "foo"
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def aliased
|
13
|
+
respond_to_parent do
|
14
|
+
render :text => 'woot'
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def redirect
|
19
|
+
responds_to_parent do
|
20
|
+
redirect_to '/another/place'
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def no_block
|
25
|
+
responds_to_parent
|
26
|
+
end
|
27
|
+
|
28
|
+
def empty_render
|
29
|
+
responds_to_parent do
|
30
|
+
end
|
31
|
+
|
32
|
+
render :text => ''
|
33
|
+
end
|
34
|
+
|
35
|
+
def quotes
|
36
|
+
responds_to_parent do
|
37
|
+
render :text => %(single' double" qs\\' qd\\" escaped\\\' doubleescaped\\\\')
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def newlines
|
42
|
+
responds_to_parent do
|
43
|
+
render :text => "line1\nline2\\nline2"
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def update
|
48
|
+
responds_to_parent do
|
49
|
+
render :update do |page|
|
50
|
+
page.alert 'foo'
|
51
|
+
page.alert 'bar'
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def rescue_action(e)
|
57
|
+
raise e
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
class RespondsToParentTest < Test::Unit::TestCase
|
62
|
+
def setup
|
63
|
+
@controller = IFrameController.new
|
64
|
+
@request = ActionController::TestRequest.new
|
65
|
+
@response = ActionController::TestResponse.new
|
66
|
+
end
|
67
|
+
|
68
|
+
def test_normal
|
69
|
+
get :normal
|
70
|
+
assert_match /alert\("foo"\)/, @response.body
|
71
|
+
assert_no_match /window\.parent/, @response.body
|
72
|
+
end
|
73
|
+
|
74
|
+
def test_quotes_should_be_escaped
|
75
|
+
render :quotes
|
76
|
+
assert_match %r{eval\('single\\' double\\" qs\\\\\\' qd\\\\\\" escaped\\\\\\' doubleescaped\\\\\\\\\\'}, @response.body
|
77
|
+
end
|
78
|
+
|
79
|
+
def test_newlines_should_be_escaped
|
80
|
+
render :newlines
|
81
|
+
assert_match %r{eval\('line1\\nline2\\\\nline2'\)}, @response.body
|
82
|
+
end
|
83
|
+
|
84
|
+
def test_no_block_should_raise
|
85
|
+
assert_raises LocalJumpError do
|
86
|
+
get :no_block
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
def test_empty_render_should_not_expand_javascript
|
91
|
+
get :empty_render
|
92
|
+
assert_equal '', @response.body
|
93
|
+
end
|
94
|
+
|
95
|
+
def test_update_should_perform_combined_rjs
|
96
|
+
render :update
|
97
|
+
assert_match /alert\(\\"foo\\"\);\\nalert\(\\"bar\\"\)/, @response.body
|
98
|
+
end
|
99
|
+
|
100
|
+
def test_aliased_method_should_not_raise
|
101
|
+
assert_nothing_raised do
|
102
|
+
render :aliased
|
103
|
+
assert_match /eval\('woot'\)/, @response.body
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
protected
|
108
|
+
|
109
|
+
def render(action)
|
110
|
+
get action
|
111
|
+
assert_match /<script type='text\/javascript'/, @response.body
|
112
|
+
assert_match /with\(window\.parent\)/, @response.body
|
113
|
+
assert_match /loc\.replace\('about:blank'\)/, @response.body
|
114
|
+
end
|
115
|
+
end
|