actionpack 1.12.5 → 1.13.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of actionpack might be problematic. Click here for more details.
- data/CHANGELOG +517 -15
- data/MIT-LICENSE +1 -1
- data/README +18 -20
- data/Rakefile +7 -4
- data/examples/address_book_controller.rb +3 -3
- data/examples/blog_controller.cgi +3 -3
- data/examples/debate_controller.cgi +5 -5
- data/lib/action_controller.rb +2 -2
- data/lib/action_controller/assertions.rb +73 -311
- data/lib/action_controller/{deprecated_assertions.rb → assertions/deprecated_assertions.rb} +32 -8
- data/lib/action_controller/assertions/dom_assertions.rb +25 -0
- data/lib/action_controller/assertions/model_assertions.rb +12 -0
- data/lib/action_controller/assertions/response_assertions.rb +140 -0
- data/lib/action_controller/assertions/routing_assertions.rb +82 -0
- data/lib/action_controller/assertions/selector_assertions.rb +571 -0
- data/lib/action_controller/assertions/tag_assertions.rb +117 -0
- data/lib/action_controller/base.rb +334 -163
- data/lib/action_controller/benchmarking.rb +3 -6
- data/lib/action_controller/caching.rb +83 -22
- data/lib/action_controller/cgi_ext/cgi_ext.rb +0 -7
- data/lib/action_controller/cgi_ext/cgi_methods.rb +167 -173
- data/lib/action_controller/cgi_ext/raw_post_data_fix.rb +43 -22
- data/lib/action_controller/cgi_process.rb +50 -27
- data/lib/action_controller/components.rb +21 -25
- data/lib/action_controller/cookies.rb +10 -9
- data/lib/action_controller/{dependencies.rb → deprecated_dependencies.rb} +9 -27
- data/lib/action_controller/filters.rb +448 -225
- data/lib/action_controller/flash.rb +24 -20
- data/lib/action_controller/helpers.rb +2 -5
- data/lib/action_controller/integration.rb +40 -16
- data/lib/action_controller/layout.rb +11 -8
- data/lib/action_controller/macros/auto_complete.rb +3 -2
- data/lib/action_controller/macros/in_place_editing.rb +3 -2
- data/lib/action_controller/mime_responds.rb +41 -29
- data/lib/action_controller/mime_type.rb +68 -10
- data/lib/action_controller/pagination.rb +4 -3
- data/lib/action_controller/request.rb +22 -14
- data/lib/action_controller/rescue.rb +25 -22
- data/lib/action_controller/resources.rb +302 -0
- data/lib/action_controller/response.rb +20 -2
- data/lib/action_controller/response.rb.rej +17 -0
- data/lib/action_controller/routing.rb +1165 -567
- data/lib/action_controller/scaffolding.rb +30 -31
- data/lib/action_controller/session/active_record_store.rb +2 -0
- data/lib/action_controller/session/drb_store.rb +4 -0
- data/lib/action_controller/session/mem_cache_store.rb +4 -0
- data/lib/action_controller/session_management.rb +6 -9
- data/lib/action_controller/status_codes.rb +89 -0
- data/lib/action_controller/streaming.rb +6 -15
- data/lib/action_controller/templates/rescues/_request_and_response.rhtml +5 -5
- data/lib/action_controller/templates/rescues/diagnostics.rhtml +2 -2
- data/lib/action_controller/templates/rescues/routing_error.rhtml +4 -4
- data/lib/action_controller/templates/rescues/template_error.rhtml +1 -1
- data/lib/action_controller/templates/scaffolds/list.rhtml +1 -1
- data/lib/action_controller/test_process.rb +52 -30
- data/lib/action_controller/url_rewriter.rb +63 -29
- data/lib/action_controller/vendor/html-scanner/html/document.rb +1 -0
- data/lib/action_controller/vendor/html-scanner/html/node.rb +3 -4
- data/lib/action_controller/vendor/html-scanner/html/selector.rb +822 -0
- data/lib/action_controller/verification.rb +22 -11
- data/lib/action_pack.rb +1 -1
- data/lib/action_pack/version.rb +2 -2
- data/lib/action_view.rb +1 -1
- data/lib/action_view/base.rb +46 -43
- data/lib/action_view/compiled_templates.rb +1 -1
- data/lib/action_view/helpers/active_record_helper.rb +54 -17
- data/lib/action_view/helpers/asset_tag_helper.rb +97 -46
- data/lib/action_view/helpers/capture_helper.rb +1 -1
- data/lib/action_view/helpers/date_helper.rb +258 -136
- data/lib/action_view/helpers/debug_helper.rb +1 -1
- data/lib/action_view/helpers/deprecated_helper.rb +34 -0
- data/lib/action_view/helpers/form_helper.rb +75 -35
- data/lib/action_view/helpers/form_options_helper.rb +7 -5
- data/lib/action_view/helpers/form_tag_helper.rb +44 -6
- data/lib/action_view/helpers/java_script_macros_helper.rb +59 -46
- data/lib/action_view/helpers/javascript_helper.rb +71 -10
- data/lib/action_view/helpers/javascripts/controls.js +41 -23
- data/lib/action_view/helpers/javascripts/dragdrop.js +105 -76
- data/lib/action_view/helpers/javascripts/effects.js +293 -163
- data/lib/action_view/helpers/javascripts/prototype.js +897 -389
- data/lib/action_view/helpers/javascripts/prototype.js.rej +561 -0
- data/lib/action_view/helpers/number_helper.rb +111 -65
- data/lib/action_view/helpers/prototype_helper.rb +84 -109
- data/lib/action_view/helpers/scriptaculous_helper.rb +5 -0
- data/lib/action_view/helpers/tag_helper.rb +69 -16
- data/lib/action_view/helpers/text_helper.rb +149 -112
- data/lib/action_view/helpers/url_helper.rb +200 -107
- data/lib/action_view/template_error.rb +66 -42
- data/test/abstract_unit.rb +4 -2
- data/test/active_record_unit.rb +84 -56
- data/test/activerecord/active_record_assertions_test.rb +26 -18
- data/test/activerecord/active_record_store_test.rb +4 -36
- data/test/activerecord/pagination_test.rb +1 -6
- data/test/controller/action_pack_assertions_test.rb +230 -113
- data/test/controller/addresses_render_test.rb +2 -6
- data/test/controller/assert_select_test.rb +576 -0
- data/test/controller/base_test.rb +73 -3
- data/test/controller/caching_test.rb +228 -0
- data/test/controller/capture_test.rb +12 -10
- data/test/controller/cgi_test.rb +89 -12
- data/test/controller/components_test.rb +24 -2
- data/test/controller/content_type_test.rb +139 -0
- data/test/controller/controller_fixtures/app/controllers/admin/user_controller.rb +0 -0
- data/test/controller/controller_fixtures/app/controllers/user_controller.rb +0 -0
- data/test/controller/controller_fixtures/vendor/plugins/bad_plugin/lib/plugin_controller.rb +0 -0
- data/test/controller/cookie_test.rb +33 -25
- data/test/controller/deprecated_instance_variables_test.rb +48 -0
- data/test/controller/deprecation/deprecated_base_methods_test.rb +60 -0
- data/test/controller/fake_controllers.rb +0 -1
- data/test/controller/filters_test.rb +301 -16
- data/test/controller/flash_test.rb +19 -2
- data/test/controller/helper_test.rb +2 -2
- data/test/controller/integration_test.rb +154 -0
- data/test/controller/layout_test.rb +115 -1
- data/test/controller/mime_responds_test.rb +94 -0
- data/test/controller/mime_type_test.rb +9 -0
- data/test/controller/new_render_test.rb +161 -11
- data/test/controller/raw_post_test.rb +52 -15
- data/test/controller/redirect_test.rb +27 -14
- data/test/controller/render_test.rb +76 -29
- data/test/controller/request_test.rb +55 -4
- data/test/controller/resources_test.rb +274 -0
- data/test/controller/routing_test.rb +1533 -824
- data/test/controller/selector_test.rb +628 -0
- data/test/controller/send_file_test.rb +9 -1
- data/test/controller/session_management_test.rb +51 -0
- data/test/controller/test_test.rb +113 -29
- data/test/controller/url_rewriter_test.rb +86 -17
- data/test/controller/verification_test.rb +19 -17
- data/test/controller/webservice_test.rb +0 -7
- data/test/fixtures/content_type/render_default_content_types_for_respond_to.rhtml +1 -0
- data/test/fixtures/content_type/render_default_for_rhtml.rhtml +1 -0
- data/test/fixtures/content_type/render_default_for_rjs.rjs +1 -0
- data/test/fixtures/content_type/render_default_for_rxml.rxml +1 -0
- data/test/fixtures/deprecated_instance_variables/_cookies_ivar.rhtml +1 -0
- data/test/fixtures/deprecated_instance_variables/_cookies_method.rhtml +1 -0
- data/test/fixtures/deprecated_instance_variables/_flash_ivar.rhtml +1 -0
- data/test/fixtures/deprecated_instance_variables/_flash_method.rhtml +1 -0
- data/test/fixtures/deprecated_instance_variables/_headers_ivar.rhtml +1 -0
- data/test/fixtures/deprecated_instance_variables/_headers_method.rhtml +1 -0
- data/test/fixtures/deprecated_instance_variables/_params_ivar.rhtml +1 -0
- data/test/fixtures/deprecated_instance_variables/_params_method.rhtml +1 -0
- data/test/fixtures/deprecated_instance_variables/_request_ivar.rhtml +1 -0
- data/test/fixtures/deprecated_instance_variables/_request_method.rhtml +1 -0
- data/test/fixtures/deprecated_instance_variables/_response_ivar.rhtml +1 -0
- data/test/fixtures/deprecated_instance_variables/_response_method.rhtml +1 -0
- data/test/fixtures/deprecated_instance_variables/_session_ivar.rhtml +1 -0
- data/test/fixtures/deprecated_instance_variables/_session_method.rhtml +1 -0
- data/test/fixtures/multipart/binary_file +0 -0
- data/test/fixtures/public/javascripts/application.js +1 -0
- data/test/fixtures/test/_hello.rxml +1 -0
- data/test/fixtures/test/hello_world_container.rxml +3 -0
- data/test/fixtures/topic.rb +2 -2
- data/test/template/active_record_helper_test.rb +83 -12
- data/test/template/asset_tag_helper_test.rb +75 -95
- data/test/template/compiled_templates_test.rb +1 -0
- data/test/template/date_helper_test.rb +873 -181
- data/test/template/deprecated_helper_test.rb +36 -0
- data/test/template/deprecated_instance_variables_test.rb +43 -0
- data/test/template/form_helper_test.rb +77 -1
- data/test/template/form_options_helper_test.rb +4 -0
- data/test/template/form_tag_helper_test.rb +66 -2
- data/test/template/java_script_macros_helper_test.rb +4 -1
- data/test/template/javascript_helper_test.rb +29 -0
- data/test/template/number_helper_test.rb +63 -27
- data/test/template/prototype_helper_test.rb +77 -34
- data/test/template/tag_helper_test.rb +34 -6
- data/test/template/text_helper_test.rb +69 -34
- data/test/template/url_helper_test.rb +168 -16
- data/test/testing_sandbox.rb +7 -22
- metadata +66 -20
- data/filler.txt +0 -50
- data/lib/action_controller/code_generation.rb +0 -235
- data/lib/action_controller/vendor/xml_simple.rb +0 -1019
- data/test/controller/caching_filestore.rb +0 -74
- data/test/fixtures/application_root/app/controllers/a_class_that_contains_a_controller/poorly_placed_controller.rb +0 -7
- data/test/fixtures/application_root/app/controllers/module_that_holds_controllers/nested_controller.rb +0 -3
- data/test/fixtures/application_root/app/models/a_class_that_contains_a_controller.rb +0 -7
- data/test/fixtures/dont_load.rb +0 -3
@@ -3,13 +3,14 @@ require File.dirname(__FILE__) + '/../abstract_unit'
|
|
3
3
|
class VerificationTest < Test::Unit::TestCase
|
4
4
|
class TestController < ActionController::Base
|
5
5
|
verify :only => :guarded_one, :params => "one",
|
6
|
+
:add_flash => { :error => 'unguarded' },
|
6
7
|
:redirect_to => { :action => "unguarded" }
|
7
8
|
|
8
9
|
verify :only => :guarded_two, :params => %w( one two ),
|
9
10
|
:redirect_to => { :action => "unguarded" }
|
10
11
|
|
11
12
|
verify :only => :guarded_with_flash, :params => "one",
|
12
|
-
:add_flash => {
|
13
|
+
:add_flash => { :notice => "prereqs failed" },
|
13
14
|
:redirect_to => { :action => "unguarded" }
|
14
15
|
|
15
16
|
verify :only => :guarded_in_session, :session => "one",
|
@@ -31,46 +32,46 @@ class VerificationTest < Test::Unit::TestCase
|
|
31
32
|
verify :only => :two_redirects, :method => :post,
|
32
33
|
:redirect_to => { :action => "unguarded" }
|
33
34
|
|
34
|
-
verify :only => :must_be_post, :method => :post, :render => { :status =>
|
35
|
+
verify :only => :must_be_post, :method => :post, :render => { :status => 405, :text => "Must be post" }, :add_headers => { "Allow" => "POST" }
|
35
36
|
|
36
37
|
def guarded_one
|
37
|
-
render :text => "#{
|
38
|
+
render :text => "#{params[:one]}"
|
38
39
|
end
|
39
40
|
|
40
41
|
def guarded_with_flash
|
41
|
-
render :text => "#{
|
42
|
+
render :text => "#{params[:one]}"
|
42
43
|
end
|
43
44
|
|
44
45
|
def guarded_two
|
45
|
-
render :text => "#{
|
46
|
+
render :text => "#{params[:one]}:#{params[:two]}"
|
46
47
|
end
|
47
48
|
|
48
49
|
def guarded_in_session
|
49
|
-
render :text => "#{
|
50
|
+
render :text => "#{session["one"]}"
|
50
51
|
end
|
51
52
|
|
52
53
|
def multi_one
|
53
|
-
render :text => "#{
|
54
|
+
render :text => "#{session["one"]}:#{session["two"]}"
|
54
55
|
end
|
55
56
|
|
56
57
|
def multi_two
|
57
|
-
render :text => "#{
|
58
|
+
render :text => "#{session["two"]}:#{session["one"]}"
|
58
59
|
end
|
59
60
|
|
60
61
|
def guarded_by_method
|
61
|
-
render :text => "#{
|
62
|
+
render :text => "#{request.method}"
|
62
63
|
end
|
63
64
|
|
64
65
|
def guarded_by_xhr
|
65
|
-
render :text => "#{
|
66
|
+
render :text => "#{request.xhr?}"
|
66
67
|
end
|
67
68
|
|
68
69
|
def guarded_by_not_xhr
|
69
|
-
render :text => "#{
|
70
|
+
render :text => "#{request.xhr?}"
|
70
71
|
end
|
71
72
|
|
72
73
|
def unguarded
|
73
|
-
render :text => "#{
|
74
|
+
render :text => "#{params[:one]}"
|
74
75
|
end
|
75
76
|
|
76
77
|
def two_redirects
|
@@ -103,18 +104,19 @@ class VerificationTest < Test::Unit::TestCase
|
|
103
104
|
def test_guarded_one_without_prereqs
|
104
105
|
get :guarded_one
|
105
106
|
assert_redirected_to :action => "unguarded"
|
107
|
+
assert_equal 'unguarded', flash[:error]
|
106
108
|
end
|
107
109
|
|
108
110
|
def test_guarded_with_flash_with_prereqs
|
109
111
|
get :guarded_with_flash, :one => "here"
|
110
112
|
assert_equal "here", @response.body
|
111
|
-
|
113
|
+
assert flash.empty?
|
112
114
|
end
|
113
115
|
|
114
116
|
def test_guarded_with_flash_without_prereqs
|
115
117
|
get :guarded_with_flash
|
116
118
|
assert_redirected_to :action => "unguarded"
|
117
|
-
|
119
|
+
assert_equal "prereqs failed", flash[:notice]
|
118
120
|
end
|
119
121
|
|
120
122
|
def test_guarded_two_with_prereqs
|
@@ -212,13 +214,13 @@ class VerificationTest < Test::Unit::TestCase
|
|
212
214
|
assert_equal "Was a post!", @response.body
|
213
215
|
end
|
214
216
|
|
215
|
-
def
|
217
|
+
def test_guarded_post_and_calls_render_fails_and_sets_allow_header
|
216
218
|
get :must_be_post
|
217
|
-
assert_response
|
219
|
+
assert_response 405
|
218
220
|
assert_equal "Must be post", @response.body
|
221
|
+
assert_equal "POST", @response.headers["Allow"]
|
219
222
|
end
|
220
223
|
|
221
|
-
|
222
224
|
def test_second_redirect
|
223
225
|
assert_nothing_raised { get :two_redirects }
|
224
226
|
end
|
@@ -148,13 +148,6 @@ class WebServiceTest < Test::Unit::TestCase
|
|
148
148
|
assert_equal %(<foo "bar's" & friends>), @controller.params[:data]
|
149
149
|
end
|
150
150
|
|
151
|
-
def test_dasherized_keys_as_yaml
|
152
|
-
ActionController::Base.param_parsers[Mime::YAML] = :yaml
|
153
|
-
process('POST', 'application/x-yaml', "---\nfirst-key:\n sub-key: ...\n", true)
|
154
|
-
assert_equal 'action, controller, first_key(sub_key), full', @controller.response.body
|
155
|
-
assert_equal "...", @controller.params[:first_key][:sub_key]
|
156
|
-
end
|
157
|
-
|
158
151
|
def test_typecast_as_yaml
|
159
152
|
ActionController::Base.param_parsers[Mime::YAML] = :yaml
|
160
153
|
process('POST', 'application/x-yaml', <<-YAML)
|
@@ -0,0 +1 @@
|
|
1
|
+
<hello>world</hello>
|
@@ -0,0 +1 @@
|
|
1
|
+
<%= 'hello world!' %>
|
@@ -0,0 +1 @@
|
|
1
|
+
page.alert 'hello world!'
|
@@ -0,0 +1 @@
|
|
1
|
+
xml.p "Hello world!"
|
@@ -0,0 +1 @@
|
|
1
|
+
<%= @cookies[:test] %>
|
@@ -0,0 +1 @@
|
|
1
|
+
<%= cookies[:test] %>
|
@@ -0,0 +1 @@
|
|
1
|
+
<%= @flash[:test] %>
|
@@ -0,0 +1 @@
|
|
1
|
+
<%= flash[:test] %>
|
@@ -0,0 +1 @@
|
|
1
|
+
<%= @headers[:test] %>
|
@@ -0,0 +1 @@
|
|
1
|
+
<%= headers[:test] %>
|
@@ -0,0 +1 @@
|
|
1
|
+
<%= @params[:test] %>
|
@@ -0,0 +1 @@
|
|
1
|
+
<%= params[:test] %>
|
@@ -0,0 +1 @@
|
|
1
|
+
<%= @request.method %>
|
@@ -0,0 +1 @@
|
|
1
|
+
<%= request.method %>
|
@@ -0,0 +1 @@
|
|
1
|
+
<%= @response.body %>
|
@@ -0,0 +1 @@
|
|
1
|
+
<%= response.body %>
|
@@ -0,0 +1 @@
|
|
1
|
+
<%= @session[:test] %>
|
@@ -0,0 +1 @@
|
|
1
|
+
<%= session[:test] %>
|
Binary file
|
@@ -0,0 +1 @@
|
|
1
|
+
# Test file for javascript_include_tag
|
@@ -0,0 +1 @@
|
|
1
|
+
xm.hello
|
data/test/fixtures/topic.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
1
|
class Topic < ActiveRecord::Base
|
2
|
-
has_many :replies, :include => [:user], :dependent =>
|
3
|
-
end
|
2
|
+
has_many :replies, :include => [:user], :dependent => :destroy
|
3
|
+
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require '
|
1
|
+
require File.dirname(__FILE__) + '/../abstract_unit'
|
2
2
|
require File.dirname(__FILE__) + '/../../lib/action_view/helpers/date_helper'
|
3
3
|
require File.dirname(__FILE__) + '/../../lib/action_view/helpers/form_helper'
|
4
4
|
require File.dirname(__FILE__) + '/../../lib/action_view/helpers/text_helper'
|
@@ -22,10 +22,16 @@ class ActiveRecordHelperTest < Test::Unit::TestCase
|
|
22
22
|
alias_method :body_before_type_cast, :body unless respond_to?(:body_before_type_cast)
|
23
23
|
alias_method :author_name_before_type_cast, :author_name unless respond_to?(:author_name_before_type_cast)
|
24
24
|
end
|
25
|
+
|
26
|
+
User = Struct.new("User", :email)
|
27
|
+
User.class_eval do
|
28
|
+
alias_method :email_before_type_cast, :email unless respond_to?(:email_before_type_cast)
|
29
|
+
end
|
30
|
+
|
25
31
|
Column = Struct.new("Column", :type, :name, :human_name)
|
26
32
|
end
|
27
33
|
|
28
|
-
def
|
34
|
+
def setup_post
|
29
35
|
@post = Post.new
|
30
36
|
def @post.errors
|
31
37
|
Class.new {
|
@@ -43,13 +49,45 @@ class ActiveRecordHelperTest < Test::Unit::TestCase
|
|
43
49
|
Post.content_columns.select { |column| column.name == attr_name }.first
|
44
50
|
end
|
45
51
|
|
46
|
-
|
52
|
+
silence_warnings do
|
53
|
+
def Post.content_columns() [ Column.new(:string, "title", "Title"), Column.new(:text, "body", "Body") ] end
|
54
|
+
end
|
47
55
|
|
48
56
|
@post.title = "Hello World"
|
49
57
|
@post.author_name = ""
|
50
58
|
@post.body = "Back to the hill and over it again!"
|
51
59
|
@post.secret = 1
|
52
60
|
@post.written_on = Date.new(2004, 6, 15)
|
61
|
+
end
|
62
|
+
|
63
|
+
def setup_user
|
64
|
+
@user = User.new
|
65
|
+
def @user.errors
|
66
|
+
Class.new {
|
67
|
+
def on(field) field == "email" end
|
68
|
+
def empty?() false end
|
69
|
+
def count() 1 end
|
70
|
+
def full_messages() [ "User email can't be empty" ] end
|
71
|
+
}.new
|
72
|
+
end
|
73
|
+
|
74
|
+
def @user.new_record?() true end
|
75
|
+
def @user.to_param() nil end
|
76
|
+
|
77
|
+
def @user.column_for_attribute(attr_name)
|
78
|
+
User.content_columns.select { |column| column.name == attr_name }.first
|
79
|
+
end
|
80
|
+
|
81
|
+
silence_warnings do
|
82
|
+
def User.content_columns() [ Column.new(:string, "email", "Email") ] end
|
83
|
+
end
|
84
|
+
|
85
|
+
@user.email = ""
|
86
|
+
end
|
87
|
+
|
88
|
+
def setup
|
89
|
+
setup_post
|
90
|
+
setup_user
|
53
91
|
|
54
92
|
@controller = Object.new
|
55
93
|
def @controller.url_for(options, *parameters_for_method_reference)
|
@@ -85,11 +123,14 @@ class ActiveRecordHelperTest < Test::Unit::TestCase
|
|
85
123
|
form("post")
|
86
124
|
)
|
87
125
|
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
126
|
+
silence_warnings do
|
127
|
+
class << @post
|
128
|
+
def new_record?() false end
|
129
|
+
def to_param() id end
|
130
|
+
def id() 1 end
|
131
|
+
end
|
92
132
|
end
|
133
|
+
|
93
134
|
assert_dom_equal(
|
94
135
|
%(<form action="update/1" method="post"><input id="post_id" name="post[id]" type="hidden" value="1" /><p><label for="post_title">Title</label><br /><input id="post_title" name="post[title]" size="30" type="text" value="Hello World" /></p>\n<p><label for="post_body">Body</label><br /><div class="fieldWithErrors"><textarea cols="40" id="post_body" name="post[body]" rows="20">Back to the hill and over it again!</textarea></div></p><input name="commit" type="submit" value="Update" /></form>),
|
95
136
|
form("post")
|
@@ -97,20 +138,24 @@ class ActiveRecordHelperTest < Test::Unit::TestCase
|
|
97
138
|
end
|
98
139
|
|
99
140
|
def test_form_with_date
|
100
|
-
|
141
|
+
silence_warnings do
|
142
|
+
def Post.content_columns() [ Column.new(:date, "written_on", "Written on") ] end
|
143
|
+
end
|
101
144
|
|
102
145
|
assert_dom_equal(
|
103
|
-
%(<form action="create" method="post"><p><label for="post_written_on">Written on</label><br /><select name="post[written_on(1i)]">\n<option value="1999">1999</option>\n<option value="2000">2000</option>\n<option value="2001">2001</option>\n<option value="2002">2002</option>\n<option value="2003">2003</option>\n<option value="2004" selected="selected">2004</option>\n<option value="2005">2005</option>\n<option value="2006">2006</option>\n<option value="2007">2007</option>\n<option value="2008">2008</option>\n<option value="2009">2009</option>\n</select>\n<select name="post[written_on(2i)]">\n<option value="1">January</option>\n<option value="2">February</option>\n<option value="3">March</option>\n<option value="4">April</option>\n<option value="5">May</option>\n<option value="6" selected="selected">June</option>\n<option value="7">July</option>\n<option value="8">August</option>\n<option value="9">September</option>\n<option value="10">October</option>\n<option value="11">November</option>\n<option value="12">December</option>\n</select>\n<select name="post[written_on(3i)]">\n<option value="1">1</option>\n<option value="2">2</option>\n<option value="3">3</option>\n<option value="4">4</option>\n<option value="5">5</option>\n<option value="6">6</option>\n<option value="7">7</option>\n<option value="8">8</option>\n<option value="9">9</option>\n<option value="10">10</option>\n<option value="11">11</option>\n<option value="12">12</option>\n<option value="13">13</option>\n<option value="14">14</option>\n<option value="15" selected="selected">15</option>\n<option value="16">16</option>\n<option value="17">17</option>\n<option value="18">18</option>\n<option value="19">19</option>\n<option value="20">20</option>\n<option value="21">21</option>\n<option value="22">22</option>\n<option value="23">23</option>\n<option value="24">24</option>\n<option value="25">25</option>\n<option value="26">26</option>\n<option value="27">27</option>\n<option value="28">28</option>\n<option value="29">29</option>\n<option value="30">30</option>\n<option value="31">31</option>\n</select>\n</p><input name="commit" type="submit" value="Create" /></form>),
|
146
|
+
%(<form action="create" method="post"><p><label for="post_written_on">Written on</label><br /><select id="post_written_on_1i" name="post[written_on(1i)]">\n<option value="1999">1999</option>\n<option value="2000">2000</option>\n<option value="2001">2001</option>\n<option value="2002">2002</option>\n<option value="2003">2003</option>\n<option value="2004" selected="selected">2004</option>\n<option value="2005">2005</option>\n<option value="2006">2006</option>\n<option value="2007">2007</option>\n<option value="2008">2008</option>\n<option value="2009">2009</option>\n</select>\n<select id="post_written_on_2i" name="post[written_on(2i)]">\n<option value="1">January</option>\n<option value="2">February</option>\n<option value="3">March</option>\n<option value="4">April</option>\n<option value="5">May</option>\n<option value="6" selected="selected">June</option>\n<option value="7">July</option>\n<option value="8">August</option>\n<option value="9">September</option>\n<option value="10">October</option>\n<option value="11">November</option>\n<option value="12">December</option>\n</select>\n<select id="post_written_on_3i" name="post[written_on(3i)]">\n<option value="1">1</option>\n<option value="2">2</option>\n<option value="3">3</option>\n<option value="4">4</option>\n<option value="5">5</option>\n<option value="6">6</option>\n<option value="7">7</option>\n<option value="8">8</option>\n<option value="9">9</option>\n<option value="10">10</option>\n<option value="11">11</option>\n<option value="12">12</option>\n<option value="13">13</option>\n<option value="14">14</option>\n<option value="15" selected="selected">15</option>\n<option value="16">16</option>\n<option value="17">17</option>\n<option value="18">18</option>\n<option value="19">19</option>\n<option value="20">20</option>\n<option value="21">21</option>\n<option value="22">22</option>\n<option value="23">23</option>\n<option value="24">24</option>\n<option value="25">25</option>\n<option value="26">26</option>\n<option value="27">27</option>\n<option value="28">28</option>\n<option value="29">29</option>\n<option value="30">30</option>\n<option value="31">31</option>\n</select>\n</p><input name="commit" type="submit" value="Create" /></form>),
|
104
147
|
form("post")
|
105
148
|
)
|
106
149
|
end
|
107
|
-
|
150
|
+
|
108
151
|
def test_form_with_datetime
|
109
|
-
|
152
|
+
silence_warnings do
|
153
|
+
def Post.content_columns() [ Column.new(:datetime, "written_on", "Written on") ] end
|
154
|
+
end
|
110
155
|
@post.written_on = Time.gm(2004, 6, 15, 16, 30)
|
111
156
|
|
112
157
|
assert_dom_equal(
|
113
|
-
%(<form action="create" method="post"><p><label for="post_written_on">Written on</label><br /><select name="post[written_on(1i)]">\n<option value="1999">1999</option>\n<option value="2000">2000</option>\n<option value="2001">2001</option>\n<option value="2002">2002</option>\n<option value="2003">2003</option>\n<option value="2004" selected="selected">2004</option>\n<option value="2005">2005</option>\n<option value="2006">2006</option>\n<option value="2007">2007</option>\n<option value="2008">2008</option>\n<option value="2009">2009</option>\n</select>\n<select name="post[written_on(2i)]">\n<option value="1">January</option>\n<option value="2">February</option>\n<option value="3">March</option>\n<option value="4">April</option>\n<option value="5">May</option>\n<option value="6" selected="selected">June</option>\n<option value="7">July</option>\n<option value="8">August</option>\n<option value="9">September</option>\n<option value="10">October</option>\n<option value="11">November</option>\n<option value="12">December</option>\n</select>\n<select name="post[written_on(3i)]">\n<option value="1">1</option>\n<option value="2">2</option>\n<option value="3">3</option>\n<option value="4">4</option>\n<option value="5">5</option>\n<option value="6">6</option>\n<option value="7">7</option>\n<option value="8">8</option>\n<option value="9">9</option>\n<option value="10">10</option>\n<option value="11">11</option>\n<option value="12">12</option>\n<option value="13">13</option>\n<option value="14">14</option>\n<option value="15" selected="selected">15</option>\n<option value="16">16</option>\n<option value="17">17</option>\n<option value="18">18</option>\n<option value="19">19</option>\n<option value="20">20</option>\n<option value="21">21</option>\n<option value="22">22</option>\n<option value="23">23</option>\n<option value="24">24</option>\n<option value="25">25</option>\n<option value="26">26</option>\n<option value="27">27</option>\n<option value="28">28</option>\n<option value="29">29</option>\n<option value="30">30</option>\n<option value="31">31</option>\n</select>\n — <select name="post[written_on(4i)]">\n<option value="00">00</option>\n<option value="01">01</option>\n<option value="02">02</option>\n<option value="03">03</option>\n<option value="04">04</option>\n<option value="05">05</option>\n<option value="06">06</option>\n<option value="07">07</option>\n<option value="08">08</option>\n<option value="09">09</option>\n<option value="10">10</option>\n<option value="11">11</option>\n<option value="12">12</option>\n<option value="13">13</option>\n<option value="14">14</option>\n<option value="15">15</option>\n<option value="16" selected="selected">16</option>\n<option value="17">17</option>\n<option value="18">18</option>\n<option value="19">19</option>\n<option value="20">20</option>\n<option value="21">21</option>\n<option value="22">22</option>\n<option value="23">23</option>\n</select>\n : <select name="post[written_on(5i)]">\n<option value="00">00</option>\n<option value="01">01</option>\n<option value="02">02</option>\n<option value="03">03</option>\n<option value="04">04</option>\n<option value="05">05</option>\n<option value="06">06</option>\n<option value="07">07</option>\n<option value="08">08</option>\n<option value="09">09</option>\n<option value="10">10</option>\n<option value="11">11</option>\n<option value="12">12</option>\n<option value="13">13</option>\n<option value="14">14</option>\n<option value="15">15</option>\n<option value="16">16</option>\n<option value="17">17</option>\n<option value="18">18</option>\n<option value="19">19</option>\n<option value="20">20</option>\n<option value="21">21</option>\n<option value="22">22</option>\n<option value="23">23</option>\n<option value="24">24</option>\n<option value="25">25</option>\n<option value="26">26</option>\n<option value="27">27</option>\n<option value="28">28</option>\n<option value="29">29</option>\n<option value="30" selected="selected">30</option>\n<option value="31">31</option>\n<option value="32">32</option>\n<option value="33">33</option>\n<option value="34">34</option>\n<option value="35">35</option>\n<option value="36">36</option>\n<option value="37">37</option>\n<option value="38">38</option>\n<option value="39">39</option>\n<option value="40">40</option>\n<option value="41">41</option>\n<option value="42">42</option>\n<option value="43">43</option>\n<option value="44">44</option>\n<option value="45">45</option>\n<option value="46">46</option>\n<option value="47">47</option>\n<option value="48">48</option>\n<option value="49">49</option>\n<option value="50">50</option>\n<option value="51">51</option>\n<option value="52">52</option>\n<option value="53">53</option>\n<option value="54">54</option>\n<option value="55">55</option>\n<option value="56">56</option>\n<option value="57">57</option>\n<option value="58">58</option>\n<option value="59">59</option>\n</select>\n</p><input name="commit" type="submit" value="Create" /></form>),
|
158
|
+
%(<form action="create" method="post"><p><label for="post_written_on">Written on</label><br /><select id="post_written_on_1i" name="post[written_on(1i)]">\n<option value="1999">1999</option>\n<option value="2000">2000</option>\n<option value="2001">2001</option>\n<option value="2002">2002</option>\n<option value="2003">2003</option>\n<option value="2004" selected="selected">2004</option>\n<option value="2005">2005</option>\n<option value="2006">2006</option>\n<option value="2007">2007</option>\n<option value="2008">2008</option>\n<option value="2009">2009</option>\n</select>\n<select id="post_written_on_2i" name="post[written_on(2i)]">\n<option value="1">January</option>\n<option value="2">February</option>\n<option value="3">March</option>\n<option value="4">April</option>\n<option value="5">May</option>\n<option value="6" selected="selected">June</option>\n<option value="7">July</option>\n<option value="8">August</option>\n<option value="9">September</option>\n<option value="10">October</option>\n<option value="11">November</option>\n<option value="12">December</option>\n</select>\n<select id="post_written_on_3i" name="post[written_on(3i)]">\n<option value="1">1</option>\n<option value="2">2</option>\n<option value="3">3</option>\n<option value="4">4</option>\n<option value="5">5</option>\n<option value="6">6</option>\n<option value="7">7</option>\n<option value="8">8</option>\n<option value="9">9</option>\n<option value="10">10</option>\n<option value="11">11</option>\n<option value="12">12</option>\n<option value="13">13</option>\n<option value="14">14</option>\n<option value="15" selected="selected">15</option>\n<option value="16">16</option>\n<option value="17">17</option>\n<option value="18">18</option>\n<option value="19">19</option>\n<option value="20">20</option>\n<option value="21">21</option>\n<option value="22">22</option>\n<option value="23">23</option>\n<option value="24">24</option>\n<option value="25">25</option>\n<option value="26">26</option>\n<option value="27">27</option>\n<option value="28">28</option>\n<option value="29">29</option>\n<option value="30">30</option>\n<option value="31">31</option>\n</select>\n — <select id="post_written_on_4i" name="post[written_on(4i)]">\n<option value="00">00</option>\n<option value="01">01</option>\n<option value="02">02</option>\n<option value="03">03</option>\n<option value="04">04</option>\n<option value="05">05</option>\n<option value="06">06</option>\n<option value="07">07</option>\n<option value="08">08</option>\n<option value="09">09</option>\n<option value="10">10</option>\n<option value="11">11</option>\n<option value="12">12</option>\n<option value="13">13</option>\n<option value="14">14</option>\n<option value="15">15</option>\n<option value="16" selected="selected">16</option>\n<option value="17">17</option>\n<option value="18">18</option>\n<option value="19">19</option>\n<option value="20">20</option>\n<option value="21">21</option>\n<option value="22">22</option>\n<option value="23">23</option>\n</select>\n : <select id="post_written_on_5i" name="post[written_on(5i)]">\n<option value="00">00</option>\n<option value="01">01</option>\n<option value="02">02</option>\n<option value="03">03</option>\n<option value="04">04</option>\n<option value="05">05</option>\n<option value="06">06</option>\n<option value="07">07</option>\n<option value="08">08</option>\n<option value="09">09</option>\n<option value="10">10</option>\n<option value="11">11</option>\n<option value="12">12</option>\n<option value="13">13</option>\n<option value="14">14</option>\n<option value="15">15</option>\n<option value="16">16</option>\n<option value="17">17</option>\n<option value="18">18</option>\n<option value="19">19</option>\n<option value="20">20</option>\n<option value="21">21</option>\n<option value="22">22</option>\n<option value="23">23</option>\n<option value="24">24</option>\n<option value="25">25</option>\n<option value="26">26</option>\n<option value="27">27</option>\n<option value="28">28</option>\n<option value="29">29</option>\n<option value="30" selected="selected">30</option>\n<option value="31">31</option>\n<option value="32">32</option>\n<option value="33">33</option>\n<option value="34">34</option>\n<option value="35">35</option>\n<option value="36">36</option>\n<option value="37">37</option>\n<option value="38">38</option>\n<option value="39">39</option>\n<option value="40">40</option>\n<option value="41">41</option>\n<option value="42">42</option>\n<option value="43">43</option>\n<option value="44">44</option>\n<option value="45">45</option>\n<option value="46">46</option>\n<option value="47">47</option>\n<option value="48">48</option>\n<option value="49">49</option>\n<option value="50">50</option>\n<option value="51">51</option>\n<option value="52">52</option>\n<option value="53">53</option>\n<option value="54">54</option>\n<option value="55">55</option>\n<option value="56">56</option>\n<option value="57">57</option>\n<option value="58">58</option>\n<option value="59">59</option>\n</select>\n</p><input name="commit" type="submit" value="Create" /></form>),
|
114
159
|
form("post")
|
115
160
|
)
|
116
161
|
end
|
@@ -118,11 +163,37 @@ class ActiveRecordHelperTest < Test::Unit::TestCase
|
|
118
163
|
def test_error_for_block
|
119
164
|
assert_dom_equal %(<div class="errorExplanation" id="errorExplanation"><h2>1 error prohibited this post from being saved</h2><p>There were problems with the following fields:</p><ul><li>Author name can't be empty</li></ul></div>), error_messages_for("post")
|
120
165
|
assert_equal %(<div class="errorDeathByClass" id="errorDeathById"><h1>1 error prohibited this post from being saved</h1><p>There were problems with the following fields:</p><ul><li>Author name can't be empty</li></ul></div>), error_messages_for("post", :class => "errorDeathByClass", :id => "errorDeathById", :header_tag => "h1")
|
166
|
+
assert_equal %(<div id="errorDeathById"><h1>1 error prohibited this post from being saved</h1><p>There were problems with the following fields:</p><ul><li>Author name can't be empty</li></ul></div>), error_messages_for("post", :class => nil, :id => "errorDeathById", :header_tag => "h1")
|
167
|
+
assert_equal %(<div class="errorDeathByClass"><h1>1 error prohibited this post from being saved</h1><p>There were problems with the following fields:</p><ul><li>Author name can't be empty</li></ul></div>), error_messages_for("post", :class => "errorDeathByClass", :id => nil, :header_tag => "h1")
|
121
168
|
end
|
122
169
|
|
123
170
|
def test_error_messages_for_handles_nil
|
124
171
|
assert_equal "", error_messages_for("notthere")
|
125
172
|
end
|
173
|
+
|
174
|
+
def test_error_message_on_handles_nil
|
175
|
+
assert_equal "", error_message_on("notthere", "notthere")
|
176
|
+
end
|
177
|
+
|
178
|
+
def test_error_message_on
|
179
|
+
assert error_message_on(:post, :author_name)
|
180
|
+
end
|
181
|
+
|
182
|
+
def test_error_messages_for_many_objects
|
183
|
+
assert_dom_equal %(<div class="errorExplanation" id="errorExplanation"><h2>2 errors prohibited this post from being saved</h2><p>There were problems with the following fields:</p><ul><li>Author name can't be empty</li><li>User email can't be empty</li></ul></div>), error_messages_for("post", "user")
|
184
|
+
|
185
|
+
# reverse the order, error order changes and so does the title
|
186
|
+
assert_dom_equal %(<div class="errorExplanation" id="errorExplanation"><h2>2 errors prohibited this user from being saved</h2><p>There were problems with the following fields:</p><ul><li>User email can't be empty</li><li>Author name can't be empty</li></ul></div>), error_messages_for("user", "post")
|
187
|
+
|
188
|
+
# add the default to put post back in the title
|
189
|
+
assert_dom_equal %(<div class="errorExplanation" id="errorExplanation"><h2>2 errors prohibited this post from being saved</h2><p>There were problems with the following fields:</p><ul><li>User email can't be empty</li><li>Author name can't be empty</li></ul></div>), error_messages_for("user", "post", :object_name => "post")
|
190
|
+
|
191
|
+
# symbols work as well
|
192
|
+
assert_dom_equal %(<div class="errorExplanation" id="errorExplanation"><h2>2 errors prohibited this post from being saved</h2><p>There were problems with the following fields:</p><ul><li>User email can't be empty</li><li>Author name can't be empty</li></ul></div>), error_messages_for(:user, :post, :object_name => :post)
|
193
|
+
|
194
|
+
# any default works too
|
195
|
+
assert_dom_equal %(<div class="errorExplanation" id="errorExplanation"><h2>2 errors prohibited this monkey from being saved</h2><p>There were problems with the following fields:</p><ul><li>User email can't be empty</li><li>Author name can't be empty</li></ul></div>), error_messages_for(:user, :post, :object_name => "monkey")
|
196
|
+
end
|
126
197
|
|
127
198
|
def test_form_with_string_multipart
|
128
199
|
assert_dom_equal(
|
@@ -34,6 +34,7 @@ class AssetTagHelperTest < Test::Unit::TestCase
|
|
34
34
|
|
35
35
|
AutoDiscoveryToTag = {
|
36
36
|
%(auto_discovery_link_tag) => %(<link href="http://www.example.com" rel="alternate" title="RSS" type="application/rss+xml" />),
|
37
|
+
%(auto_discovery_link_tag(:rss)) => %(<link href="http://www.example.com" rel="alternate" title="RSS" type="application/rss+xml" />),
|
37
38
|
%(auto_discovery_link_tag(:atom)) => %(<link href="http://www.example.com" rel="alternate" title="ATOM" type="application/atom+xml" />),
|
38
39
|
%(auto_discovery_link_tag(:rss, :action => "feed")) => %(<link href="http://www.example.com" rel="alternate" title="RSS" type="application/rss+xml" />),
|
39
40
|
%(auto_discovery_link_tag(:rss, "http://localhost/feed")) => %(<link href="http://localhost/feed" rel="alternate" title="RSS" type="application/rss+xml" />),
|
@@ -47,11 +48,13 @@ class AssetTagHelperTest < Test::Unit::TestCase
|
|
47
48
|
|
48
49
|
JavascriptPathToTag = {
|
49
50
|
%(javascript_path("xmlhr")) => %(/javascripts/xmlhr.js),
|
50
|
-
%(javascript_path("super/xmlhr")) => %(/javascripts/super/xmlhr.js)
|
51
|
+
%(javascript_path("super/xmlhr")) => %(/javascripts/super/xmlhr.js),
|
52
|
+
%(javascript_path("/super/xmlhr.js")) => %(/super/xmlhr.js)
|
51
53
|
}
|
52
54
|
|
53
55
|
JavascriptIncludeToTag = {
|
54
56
|
%(javascript_include_tag("xmlhr")) => %(<script src="/javascripts/xmlhr.js" type="text/javascript"></script>),
|
57
|
+
%(javascript_include_tag("xmlhr.js")) => %(<script src="/javascripts/xmlhr.js" type="text/javascript"></script>),
|
55
58
|
%(javascript_include_tag("xmlhr", :lang => "vbscript")) => %(<script lang="vbscript" src="/javascripts/xmlhr.js" type="text/javascript"></script>),
|
56
59
|
%(javascript_include_tag("common.javascript", "/elsewhere/cools")) => %(<script src="/javascripts/common.javascript" type="text/javascript"></script>\n<script src="/elsewhere/cools.js" type="text/javascript"></script>),
|
57
60
|
%(javascript_include_tag(:defaults)) => %(<script src="/javascripts/prototype.js" type="text/javascript"></script>\n<script src="/javascripts/effects.js" type="text/javascript"></script>\n<script src="/javascripts/dragdrop.js" type="text/javascript"></script>\n<script src="/javascripts/controls.js" type="text/javascript"></script>),
|
@@ -61,31 +64,44 @@ class AssetTagHelperTest < Test::Unit::TestCase
|
|
61
64
|
|
62
65
|
StylePathToTag = {
|
63
66
|
%(stylesheet_path("style")) => %(/stylesheets/style.css),
|
67
|
+
%(stylesheet_path("style.css")) => %(/stylesheets/style.css),
|
64
68
|
%(stylesheet_path('dir/file')) => %(/stylesheets/dir/file.css),
|
65
|
-
%(stylesheet_path('/dir/file')) => %(/dir/file.
|
69
|
+
%(stylesheet_path('/dir/file.rcss')) => %(/dir/file.rcss)
|
66
70
|
}
|
67
71
|
|
68
72
|
StyleLinkToTag = {
|
69
73
|
%(stylesheet_link_tag("style")) => %(<link href="/stylesheets/style.css" media="screen" rel="Stylesheet" type="text/css" />),
|
74
|
+
%(stylesheet_link_tag("style.css")) => %(<link href="/stylesheets/style.css" media="screen" rel="Stylesheet" type="text/css" />),
|
70
75
|
%(stylesheet_link_tag("/dir/file")) => %(<link href="/dir/file.css" media="screen" rel="Stylesheet" type="text/css" />),
|
71
76
|
%(stylesheet_link_tag("dir/file")) => %(<link href="/stylesheets/dir/file.css" media="screen" rel="Stylesheet" type="text/css" />),
|
72
77
|
%(stylesheet_link_tag("style", :media => "all")) => %(<link href="/stylesheets/style.css" media="all" rel="Stylesheet" type="text/css" />),
|
73
|
-
%(stylesheet_link_tag("random.styles", "/css/stylish")) => %(<link href="/stylesheets/random.styles" media="screen" rel="Stylesheet" type="text/css" />\n<link href="/css/stylish.css" media="screen" rel="Stylesheet" type="text/css" />)
|
78
|
+
%(stylesheet_link_tag("random.styles", "/css/stylish")) => %(<link href="/stylesheets/random.styles" media="screen" rel="Stylesheet" type="text/css" />\n<link href="/css/stylish.css" media="screen" rel="Stylesheet" type="text/css" />),
|
79
|
+
%(stylesheet_link_tag("http://www.example.com/styles/style")) => %(<link href="http://www.example.com/styles/style.css" media="screen" rel="Stylesheet" type="text/css" />)
|
74
80
|
}
|
75
81
|
|
76
82
|
ImagePathToTag = {
|
77
|
-
%(image_path("xml")) => %(/images/xml.png),
|
83
|
+
%(image_path("xml.png")) => %(/images/xml.png),
|
84
|
+
%(image_path("dir/xml.png")) => %(/images/dir/xml.png),
|
85
|
+
%(image_path("/dir/xml.png")) => %(/dir/xml.png)
|
78
86
|
}
|
79
87
|
|
80
88
|
ImageLinkToTag = {
|
81
|
-
%(image_tag("xml")) => %(<img alt="Xml" src="/images/xml.png" />),
|
82
|
-
%(image_tag("rss", :alt => "rss syndication")) => %(<img alt="rss syndication" src="/images/rss.
|
83
|
-
%(image_tag("gold", :size => "45x70")) => %(<img alt="Gold" height="70" src="/images/gold.png" width="45" />),
|
84
|
-
%(image_tag("
|
85
|
-
%(image_tag("
|
89
|
+
%(image_tag("xml.png")) => %(<img alt="Xml" src="/images/xml.png" />),
|
90
|
+
%(image_tag("rss.gif", :alt => "rss syndication")) => %(<img alt="rss syndication" src="/images/rss.gif" />),
|
91
|
+
%(image_tag("gold.png", :size => "45x70")) => %(<img alt="Gold" height="70" src="/images/gold.png" width="45" />),
|
92
|
+
%(image_tag("gold.png", "size" => "45x70")) => %(<img alt="Gold" height="70" src="/images/gold.png" width="45" />),
|
93
|
+
%(image_tag("error.png", "size" => "45")) => %(<img alt="Error" src="/images/error.png" />),
|
94
|
+
%(image_tag("error.png", "size" => "45 x 70")) => %(<img alt="Error" src="/images/error.png" />),
|
95
|
+
%(image_tag("error.png", "size" => "x")) => %(<img alt="Error" src="/images/error.png" />),
|
96
|
+
%(image_tag("http://www.rubyonrails.com/images/rails.png")) => %(<img alt="Rails" src="http://www.rubyonrails.com/images/rails.png" />)
|
86
97
|
}
|
87
98
|
|
88
|
-
|
99
|
+
DeprecatedImagePathToTag = {
|
100
|
+
%(image_path("xml")) => %(/images/xml.png)
|
101
|
+
}
|
102
|
+
|
103
|
+
|
104
|
+
def test_auto_discovery_link_tag
|
89
105
|
AutoDiscoveryToTag.each { |method, tag| assert_dom_equal(tag, eval(method)) }
|
90
106
|
end
|
91
107
|
|
@@ -93,8 +109,12 @@ class AssetTagHelperTest < Test::Unit::TestCase
|
|
93
109
|
JavascriptPathToTag.each { |method, tag| assert_dom_equal(tag, eval(method)) }
|
94
110
|
end
|
95
111
|
|
96
|
-
def
|
112
|
+
def test_javascript_include_tag
|
97
113
|
JavascriptIncludeToTag.each { |method, tag| assert_dom_equal(tag, eval(method)) }
|
114
|
+
|
115
|
+
Object.send(:const_set, :RAILS_ROOT, File.dirname(__FILE__) + "/../fixtures/")
|
116
|
+
ENV["RAILS_ASSET_ID"] = "1"
|
117
|
+
assert_dom_equal(%(<script src="/javascripts/prototype.js?1" type="text/javascript"></script>\n<script src="/javascripts/effects.js?1" type="text/javascript"></script>\n<script src="/javascripts/dragdrop.js?1" type="text/javascript"></script>\n<script src="/javascripts/controls.js?1" type="text/javascript"></script>\n<script src="/javascripts/application.js?1" type="text/javascript"></script>), javascript_include_tag(:defaults))
|
98
118
|
end
|
99
119
|
|
100
120
|
def test_register_javascript_include_default
|
@@ -104,38 +124,57 @@ class AssetTagHelperTest < Test::Unit::TestCase
|
|
104
124
|
assert_dom_equal %(<script src="/javascripts/prototype.js" type="text/javascript"></script>\n<script src="/javascripts/effects.js" type="text/javascript"></script>\n<script src="/javascripts/dragdrop.js" type="text/javascript"></script>\n<script src="/javascripts/controls.js" type="text/javascript"></script>\n<script src="/javascripts/slider.js" type="text/javascript"></script>\n<script src="/javascripts/lib1.js" type="text/javascript"></script>\n<script src="/elsewhere/blub/lib2.js" type="text/javascript"></script>), javascript_include_tag(:defaults)
|
105
125
|
end
|
106
126
|
|
107
|
-
def
|
127
|
+
def test_stylesheet_path
|
108
128
|
StylePathToTag.each { |method, tag| assert_dom_equal(tag, eval(method)) }
|
109
129
|
end
|
110
130
|
|
111
|
-
def
|
131
|
+
def test_stylesheet_link_tag
|
112
132
|
StyleLinkToTag.each { |method, tag| assert_dom_equal(tag, eval(method)) }
|
113
133
|
end
|
114
134
|
|
115
135
|
def test_image_path
|
116
136
|
ImagePathToTag.each { |method, tag| assert_dom_equal(tag, eval(method)) }
|
117
137
|
end
|
118
|
-
|
138
|
+
|
119
139
|
def test_image_tag
|
120
140
|
ImageLinkToTag.each { |method, tag| assert_dom_equal(tag, eval(method)) }
|
121
141
|
end
|
122
142
|
|
143
|
+
def test_should_deprecate_image_filename_with_no_extension
|
144
|
+
DeprecatedImagePathToTag.each do |method, tag|
|
145
|
+
assert_deprecated("image_path") { assert_dom_equal(tag, eval(method)) }
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
123
149
|
def test_timebased_asset_id
|
124
150
|
Object.send(:const_set, :RAILS_ROOT, File.dirname(__FILE__) + "/../fixtures/")
|
125
151
|
expected_time = File.stat(File.expand_path(File.dirname(__FILE__) + "/../fixtures/public/images/rails.png")).mtime.to_i.to_s
|
126
152
|
assert_equal %(<img alt="Rails" src="/images/rails.png?#{expected_time}" />), image_tag("rails.png")
|
127
153
|
end
|
128
154
|
|
129
|
-
def
|
155
|
+
def test_should_skip_asset_id_on_complete_url
|
130
156
|
Object.send(:const_set, :RAILS_ROOT, File.dirname(__FILE__) + "/../fixtures/")
|
131
157
|
assert_equal %(<img alt="Rails" src="http://www.example.com/rails.png" />), image_tag("http://www.example.com/rails.png")
|
132
158
|
end
|
133
159
|
|
134
|
-
def
|
160
|
+
def test_should_use_preset_asset_id
|
135
161
|
Object.send(:const_set, :RAILS_ROOT, File.dirname(__FILE__) + "/../fixtures/")
|
136
162
|
ENV["RAILS_ASSET_ID"] = "4500"
|
137
163
|
assert_equal %(<img alt="Rails" src="/images/rails.png?4500" />), image_tag("rails.png")
|
138
164
|
end
|
165
|
+
|
166
|
+
def test_preset_empty_asset_id
|
167
|
+
Object.send(:const_set, :RAILS_ROOT, File.dirname(__FILE__) + "/../fixtures/")
|
168
|
+
ENV["RAILS_ASSET_ID"] = ""
|
169
|
+
assert_equal %(<img alt="Rails" src="/images/rails.png" />), image_tag("rails.png")
|
170
|
+
end
|
171
|
+
|
172
|
+
def test_should_not_modify_source_string
|
173
|
+
source = '/images/rails.png'
|
174
|
+
copy = source.dup
|
175
|
+
image_tag(source)
|
176
|
+
assert_equal copy, source
|
177
|
+
end
|
139
178
|
end
|
140
179
|
|
141
180
|
class AssetTagHelperNonVhostTest < Test::Unit::TestCase
|
@@ -145,18 +184,16 @@ class AssetTagHelperNonVhostTest < Test::Unit::TestCase
|
|
145
184
|
|
146
185
|
def setup
|
147
186
|
@controller = Class.new do
|
148
|
-
|
149
187
|
attr_accessor :request
|
150
188
|
|
151
189
|
def url_for(options, *parameters_for_method_reference)
|
152
|
-
"http://www.example.com/
|
190
|
+
"http://www.example.com/collaboration/hieraki"
|
153
191
|
end
|
154
|
-
|
155
192
|
end.new
|
156
193
|
|
157
194
|
@request = Class.new do
|
158
195
|
def relative_url_root
|
159
|
-
"/
|
196
|
+
"/collaboration/hieraki"
|
160
197
|
end
|
161
198
|
end.new
|
162
199
|
|
@@ -165,88 +202,31 @@ class AssetTagHelperNonVhostTest < Test::Unit::TestCase
|
|
165
202
|
ActionView::Helpers::AssetTagHelper::reset_javascript_include_default
|
166
203
|
end
|
167
204
|
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
JavascriptPathToTag = {
|
175
|
-
%(javascript_path("xmlhr")) => %(/calloboration/hieraki/javascripts/xmlhr.js),
|
176
|
-
}
|
177
|
-
|
178
|
-
JavascriptIncludeToTag = {
|
179
|
-
%(javascript_include_tag("xmlhr")) => %(<script src="/calloboration/hieraki/javascripts/xmlhr.js" type="text/javascript"></script>),
|
180
|
-
%(javascript_include_tag("common.javascript", "/elsewhere/cools")) => %(<script src="/calloboration/hieraki/javascripts/common.javascript" type="text/javascript"></script>\n<script src="/calloboration/hieraki/elsewhere/cools.js" type="text/javascript"></script>),
|
181
|
-
%(javascript_include_tag(:defaults)) => %(<script src="/calloboration/hieraki/javascripts/prototype.js" type="text/javascript"></script>\n<script src="/calloboration/hieraki/javascripts/effects.js" type="text/javascript"></script>\n<script src="/calloboration/hieraki/javascripts/dragdrop.js" type="text/javascript"></script>\n<script src="/calloboration/hieraki/javascripts/controls.js" type="text/javascript"></script>)
|
182
|
-
}
|
183
|
-
|
184
|
-
StylePathToTag = {
|
185
|
-
%(stylesheet_path("style")) => %(/calloboration/hieraki/stylesheets/style.css),
|
186
|
-
}
|
187
|
-
|
188
|
-
StyleLinkToTag = {
|
189
|
-
%(stylesheet_link_tag("style")) => %(<link href="/calloboration/hieraki/stylesheets/style.css" media="screen" rel="Stylesheet" type="text/css" />),
|
190
|
-
%(stylesheet_link_tag("random.styles", "/css/stylish")) => %(<link href="/calloboration/hieraki/stylesheets/random.styles" media="screen" rel="Stylesheet" type="text/css" />\n<link href="/calloboration/hieraki/css/stylish.css" media="screen" rel="Stylesheet" type="text/css" />)
|
191
|
-
}
|
192
|
-
|
193
|
-
ImagePathToTag = {
|
194
|
-
%(image_path("xml")) => %(/calloboration/hieraki/images/xml.png),
|
195
|
-
}
|
196
|
-
|
197
|
-
ImageLinkToTag = {
|
198
|
-
%(image_tag("xml")) => %(<img alt="Xml" src="/calloboration/hieraki/images/xml.png" />),
|
199
|
-
%(image_tag("rss", :alt => "rss syndication")) => %(<img alt="rss syndication" src="/calloboration/hieraki/images/rss.png" />),
|
200
|
-
%(image_tag("gold", :size => "45x70")) => %(<img alt="Gold" height="70" src="/calloboration/hieraki/images/gold.png" width="45" />),
|
201
|
-
%(image_tag("http://www.example.com/images/icon.gif")) => %(<img alt="Icon" src="http://www.example.com/images/icon.gif" />),
|
202
|
-
%(image_tag("symbolize", "size" => "45x70")) => %(<img alt="Symbolize" height="70" src="/calloboration/hieraki/images/symbolize.png" width="45" />)
|
203
|
-
}
|
204
|
-
|
205
|
-
def test_auto_discovery
|
206
|
-
AutoDiscoveryToTag.each { |method, tag| assert_dom_equal(tag, eval(method)) }
|
207
|
-
end
|
208
|
-
|
209
|
-
def test_javascript_path
|
210
|
-
JavascriptPathToTag.each { |method, tag| assert_dom_equal(tag, eval(method)) }
|
211
|
-
end
|
212
|
-
|
213
|
-
def test_javascript_include
|
214
|
-
JavascriptIncludeToTag.each { |method, tag| assert_dom_equal(tag, eval(method)) }
|
205
|
+
def test_should_compute_proper_path
|
206
|
+
assert_dom_equal(%(<link href="http://www.example.com/collaboration/hieraki" rel="alternate" title="RSS" type="application/rss+xml" />), auto_discovery_link_tag)
|
207
|
+
assert_dom_equal(%(/collaboration/hieraki/javascripts/xmlhr.js), javascript_path("xmlhr"))
|
208
|
+
assert_dom_equal(%(/collaboration/hieraki/stylesheets/style.css), stylesheet_path("style"))
|
209
|
+
assert_dom_equal(%(/collaboration/hieraki/images/xml.png), image_path("xml.png"))
|
215
210
|
end
|
216
211
|
|
217
|
-
def
|
218
|
-
|
219
|
-
assert_dom_equal %(<script src="/calloboration/hieraki/javascripts/prototype.js" type="text/javascript"></script>\n<script src="/calloboration/hieraki/javascripts/effects.js" type="text/javascript"></script>\n<script src="/calloboration/hieraki/javascripts/dragdrop.js" type="text/javascript"></script>\n<script src="/calloboration/hieraki/javascripts/controls.js" type="text/javascript"></script>\n<script src="/calloboration/hieraki/javascripts/slider.js" type="text/javascript"></script>), javascript_include_tag(:defaults)
|
220
|
-
ActionView::Helpers::AssetTagHelper::register_javascript_include_default 'lib1', '/elsewhere/blub/lib2'
|
221
|
-
assert_dom_equal %(<script src="/calloboration/hieraki/javascripts/prototype.js" type="text/javascript"></script>\n<script src="/calloboration/hieraki/javascripts/effects.js" type="text/javascript"></script>\n<script src="/calloboration/hieraki/javascripts/dragdrop.js" type="text/javascript"></script>\n<script src="/calloboration/hieraki/javascripts/controls.js" type="text/javascript"></script>\n<script src="/calloboration/hieraki/javascripts/slider.js" type="text/javascript"></script>\n<script src="/calloboration/hieraki/javascripts/lib1.js" type="text/javascript"></script>\n<script src="/calloboration/hieraki/elsewhere/blub/lib2.js" type="text/javascript"></script>), javascript_include_tag(:defaults)
|
212
|
+
def test_should_ignore_relative_root_path_on_complete_url
|
213
|
+
assert_dom_equal(%(http://www.example.com/images/xml.png), image_path("http://www.example.com/images/xml.png"))
|
222
214
|
end
|
223
215
|
|
224
|
-
def
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
216
|
+
def test_should_compute_proper_path_with_asset_host
|
217
|
+
ActionController::Base.asset_host = "http://assets.example.com"
|
218
|
+
assert_dom_equal(%(<link href="http://www.example.com/collaboration/hieraki" rel="alternate" title="RSS" type="application/rss+xml" />), auto_discovery_link_tag)
|
219
|
+
assert_dom_equal(%(http://assets.example.com/collaboration/hieraki/javascripts/xmlhr.js), javascript_path("xmlhr"))
|
220
|
+
assert_dom_equal(%(http://assets.example.com/collaboration/hieraki/stylesheets/style.css), stylesheet_path("style"))
|
221
|
+
assert_dom_equal(%(http://assets.example.com/collaboration/hieraki/images/xml.png), image_path("xml.png"))
|
222
|
+
ensure
|
223
|
+
ActionController::Base.asset_host = ""
|
230
224
|
end
|
231
225
|
|
232
|
-
def
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
def test_image_tag
|
237
|
-
ImageLinkToTag.each { |method, tag| assert_dom_equal(tag, eval(method)) }
|
238
|
-
# Assigning a default alt tag should not cause an exception to be raised
|
239
|
-
assert_nothing_raised { image_tag('') }
|
240
|
-
end
|
241
|
-
|
242
|
-
def test_stylesheet_with_asset_host_already_encoded
|
243
|
-
ActionController::Base.asset_host = "http://foo.example.com"
|
244
|
-
result = stylesheet_link_tag("http://bar.example.com/stylesheets/style.css")
|
245
|
-
assert_dom_equal(
|
246
|
-
%(<link href="http://bar.example.com/stylesheets/style.css" media="screen" rel="Stylesheet" type="text/css" />),
|
247
|
-
result)
|
226
|
+
def test_should_ignore_asset_host_on_complete_url
|
227
|
+
ActionController::Base.asset_host = "http://assets.example.com"
|
228
|
+
assert_dom_equal(%(<link href="http://bar.example.com/stylesheets/style.css" media="screen" rel="Stylesheet" type="text/css" />), stylesheet_link_tag("http://bar.example.com/stylesheets/style.css"))
|
248
229
|
ensure
|
249
230
|
ActionController::Base.asset_host = ""
|
250
231
|
end
|
251
|
-
|
252
232
|
end
|