actionpack 2.1.2 → 2.2.2
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 +223 -7
- data/README +6 -12
- data/Rakefile +11 -11
- data/lib/action_controller.rb +9 -9
- data/lib/action_controller/assertions/response_assertions.rb +29 -78
- data/lib/action_controller/assertions/routing_assertions.rb +33 -33
- data/lib/action_controller/assertions/selector_assertions.rb +9 -5
- data/lib/action_controller/base.rb +227 -161
- data/lib/action_controller/benchmarking.rb +37 -24
- data/lib/action_controller/caching/actions.rb +53 -21
- data/lib/action_controller/caching/fragments.rb +10 -36
- data/lib/action_controller/caching/sweeping.rb +3 -3
- data/lib/action_controller/cgi_ext/session.rb +2 -22
- data/lib/action_controller/cgi_process.rb +8 -46
- data/lib/action_controller/components.rb +4 -1
- data/lib/action_controller/cookies.rb +10 -0
- data/lib/action_controller/dispatcher.rb +49 -15
- data/lib/action_controller/filters.rb +48 -10
- data/lib/action_controller/headers.rb +16 -14
- data/lib/action_controller/helpers.rb +2 -2
- data/lib/action_controller/http_authentication.rb +1 -1
- data/lib/action_controller/integration.rb +57 -60
- data/lib/action_controller/layout.rb +27 -53
- data/lib/action_controller/mime_responds.rb +5 -1
- data/lib/action_controller/mime_type.rb +64 -42
- data/lib/action_controller/mime_types.rb +2 -1
- data/lib/action_controller/performance_test.rb +16 -0
- data/lib/action_controller/polymorphic_routes.rb +16 -9
- data/lib/action_controller/rack_process.rb +303 -0
- data/lib/action_controller/request.rb +205 -97
- data/lib/action_controller/request_forgery_protection.rb +2 -2
- data/lib/action_controller/request_profiler.rb +0 -0
- data/lib/action_controller/rescue.rb +20 -115
- data/lib/action_controller/resources.rb +186 -83
- data/lib/action_controller/response.rb +140 -26
- data/lib/action_controller/routing.rb +28 -30
- data/lib/action_controller/routing/builder.rb +45 -54
- data/lib/action_controller/routing/optimisations.rb +31 -21
- data/lib/action_controller/routing/recognition_optimisation.rb +33 -27
- data/lib/action_controller/routing/route.rb +162 -147
- data/lib/action_controller/routing/route_set.rb +8 -7
- data/lib/action_controller/routing/routing_ext.rb +4 -1
- data/lib/action_controller/routing/segments.rb +50 -21
- data/lib/action_controller/session/cookie_store.rb +3 -2
- data/lib/action_controller/session/drb_server.rb +7 -7
- data/lib/action_controller/session_management.rb +6 -2
- data/lib/action_controller/streaming.rb +15 -8
- data/lib/action_controller/templates/rescues/diagnostics.erb +2 -2
- data/lib/action_controller/templates/rescues/template_error.erb +2 -2
- data/lib/action_controller/test_case.rb +66 -2
- data/lib/action_controller/test_process.rb +71 -66
- data/lib/action_controller/translation.rb +13 -0
- data/lib/action_controller/url_rewriter.rb +90 -13
- data/lib/action_controller/vendor/html-scanner/html/node.rb +9 -2
- data/lib/action_controller/vendor/html-scanner/html/sanitizer.rb +1 -1
- data/lib/action_controller/vendor/html-scanner/html/selector.rb +2 -2
- data/lib/action_controller/verification.rb +2 -2
- data/lib/action_pack/version.rb +1 -1
- data/lib/action_view.rb +19 -11
- data/lib/action_view/base.rb +184 -150
- data/lib/action_view/helpers.rb +38 -0
- data/lib/action_view/helpers/active_record_helper.rb +56 -27
- data/lib/action_view/helpers/asset_tag_helper.rb +356 -153
- data/lib/action_view/helpers/atom_feed_helper.rb +74 -19
- data/lib/action_view/helpers/benchmark_helper.rb +3 -3
- data/lib/action_view/helpers/cache_helper.rb +1 -2
- data/lib/action_view/helpers/capture_helper.rb +19 -44
- data/lib/action_view/helpers/date_helper.rb +486 -296
- data/lib/action_view/helpers/debug_helper.rb +20 -13
- data/lib/action_view/helpers/form_helper.rb +71 -30
- data/lib/action_view/helpers/form_options_helper.rb +15 -85
- data/lib/action_view/helpers/form_tag_helper.rb +61 -38
- data/lib/action_view/helpers/javascript_helper.rb +80 -89
- data/lib/action_view/helpers/number_helper.rb +179 -74
- data/lib/action_view/helpers/prototype_helper.rb +216 -201
- data/lib/action_view/helpers/record_tag_helper.rb +4 -5
- data/lib/action_view/helpers/sanitize_helper.rb +65 -33
- data/lib/action_view/helpers/scriptaculous_helper.rb +2 -2
- data/lib/action_view/helpers/tag_helper.rb +39 -22
- data/lib/action_view/helpers/text_helper.rb +212 -118
- data/lib/action_view/helpers/translation_helper.rb +21 -0
- data/lib/action_view/helpers/url_helper.rb +100 -58
- data/lib/action_view/inline_template.rb +13 -14
- data/lib/action_view/locale/en.yml +91 -0
- data/lib/action_view/partials.rb +100 -55
- data/lib/action_view/paths.rb +125 -0
- data/lib/action_view/renderable.rb +102 -0
- data/lib/action_view/renderable_partial.rb +48 -0
- data/lib/action_view/template.rb +90 -101
- data/lib/action_view/template_error.rb +11 -21
- data/lib/action_view/template_handler.rb +8 -28
- data/lib/action_view/template_handlers.rb +45 -0
- data/lib/action_view/template_handlers/builder.rb +5 -15
- data/lib/action_view/template_handlers/erb.rb +9 -6
- data/lib/action_view/template_handlers/rjs.rb +2 -17
- data/lib/action_view/test_case.rb +7 -4
- data/test/abstract_unit.rb +4 -1
- data/test/active_record_unit.rb +28 -30
- data/test/activerecord/render_partial_with_record_identification_test.rb +25 -12
- data/test/controller/action_pack_assertions_test.rb +8 -37
- data/test/controller/addresses_render_test.rb +0 -3
- data/test/controller/assert_select_test.rb +51 -24
- data/test/controller/base_test.rb +4 -4
- data/test/controller/caching_test.rb +136 -66
- data/test/controller/capture_test.rb +1 -21
- data/test/controller/cgi_test.rb +157 -10
- data/test/controller/components_test.rb +41 -25
- data/test/controller/content_type_test.rb +49 -17
- data/test/controller/cookie_test.rb +1 -1
- data/test/controller/deprecation/deprecated_base_methods_test.rb +0 -3
- data/test/controller/dispatcher_test.rb +9 -1
- data/test/controller/filter_params_test.rb +2 -2
- data/test/controller/filters_test.rb +13 -13
- data/test/controller/html-scanner/cdata_node_test.rb +15 -0
- data/test/controller/html-scanner/node_test.rb +21 -0
- data/test/controller/html-scanner/sanitizer_test.rb +14 -0
- data/test/controller/integration_test.rb +167 -6
- data/test/controller/layout_test.rb +11 -68
- data/test/controller/logging_test.rb +46 -0
- data/test/controller/mime_responds_test.rb +61 -59
- data/test/controller/mime_type_test.rb +6 -6
- data/test/controller/polymorphic_routes_test.rb +37 -2
- data/test/controller/rack_test.rb +323 -0
- data/test/controller/redirect_test.rb +72 -71
- data/test/controller/render_test.rb +1120 -108
- data/test/controller/request_forgery_protection_test.rb +66 -52
- data/test/controller/request_test.rb +103 -146
- data/test/controller/rescue_test.rb +20 -24
- data/test/controller/resources_test.rb +408 -25
- data/test/controller/routing_test.rb +1774 -1774
- data/test/controller/send_file_test.rb +0 -4
- data/test/controller/session/cookie_store_test.rb +53 -1
- data/test/controller/test_test.rb +15 -37
- data/test/controller/translation_test.rb +26 -0
- data/test/controller/url_rewriter_test.rb +27 -28
- data/test/controller/view_paths_test.rb +48 -47
- data/test/fixtures/_top_level_partial.html.erb +1 -0
- data/test/fixtures/_top_level_partial_only.erb +1 -0
- data/test/fixtures/developers/_developer.erb +1 -0
- data/test/fixtures/fun/games/_game.erb +1 -0
- data/test/fixtures/fun/serious/games/_game.erb +1 -0
- data/test/fixtures/functional_caching/formatted_fragment_cached.html.erb +3 -0
- data/test/fixtures/functional_caching/formatted_fragment_cached.js.rjs +6 -0
- data/test/fixtures/functional_caching/formatted_fragment_cached.xml.builder +5 -0
- data/test/fixtures/functional_caching/inline_fragment_cached.html.erb +2 -0
- data/test/fixtures/layouts/_column.html.erb +2 -0
- data/test/fixtures/projects/_project.erb +1 -0
- data/test/fixtures/public/javascripts/subdir/subdir.js +1 -0
- data/test/fixtures/public/stylesheets/subdir/subdir.css +1 -0
- data/test/fixtures/replies/_reply.erb +1 -0
- data/test/fixtures/test/_counter.html.erb +1 -0
- data/test/fixtures/test/_customer.erb +1 -1
- data/test/fixtures/test/_customer_with_var.erb +1 -0
- data/test/fixtures/test/_layout_for_block_with_args.html.erb +3 -0
- data/test/fixtures/test/_local_inspector.html.erb +1 -0
- data/test/fixtures/test/_partial_with_only_html_version.html.erb +1 -0
- data/test/fixtures/test/hello.builder +1 -1
- data/test/fixtures/test/hyphen-ated.erb +1 -0
- data/test/fixtures/test/implicit_content_type.atom.builder +2 -0
- data/test/fixtures/test/nested_layout.erb +3 -0
- data/test/fixtures/test/non_erb_block_content_for.builder +1 -1
- data/test/fixtures/test/sub_template_raise.html.erb +1 -0
- data/test/fixtures/test/template.erb +1 -0
- data/test/fixtures/test/using_layout_around_block_with_args.html.erb +1 -0
- data/test/template/active_record_helper_i18n_test.rb +46 -0
- data/test/template/active_record_helper_test.rb +24 -24
- data/test/template/asset_tag_helper_test.rb +161 -29
- data/test/template/atom_feed_helper_test.rb +114 -5
- data/test/template/compiled_templates_test.rb +59 -0
- data/test/template/date_helper_i18n_test.rb +113 -0
- data/test/template/date_helper_test.rb +403 -109
- data/test/template/form_helper_test.rb +213 -154
- data/test/template/form_options_helper_test.rb +249 -897
- data/test/template/form_tag_helper_test.rb +80 -32
- data/test/template/javascript_helper_test.rb +17 -18
- data/test/template/number_helper_i18n_test.rb +54 -0
- data/test/template/number_helper_test.rb +43 -13
- data/test/template/prototype_helper_test.rb +101 -84
- data/test/template/record_tag_helper_test.rb +24 -20
- data/test/template/render_test.rb +193 -0
- data/test/template/sanitize_helper_test.rb +3 -3
- data/test/template/tag_helper_test.rb +34 -14
- data/test/template/text_helper_test.rb +83 -9
- data/test/template/translation_helper_test.rb +28 -0
- data/test/template/url_helper_test.rb +55 -18
- metadata +57 -18
- data/lib/action_view/helpers/javascripts/controls.js +0 -963
- data/lib/action_view/helpers/javascripts/dragdrop.js +0 -972
- data/lib/action_view/helpers/javascripts/effects.js +0 -1120
- data/lib/action_view/helpers/javascripts/prototype.js +0 -4225
- data/lib/action_view/partial_template.rb +0 -70
- data/lib/action_view/template_finder.rb +0 -177
- data/lib/action_view/template_handlers/compilable.rb +0 -128
- data/test/controller/custom_handler_test.rb +0 -45
- data/test/controller/new_render_test.rb +0 -945
- data/test/fixtures/test/block_content_for.erb +0 -2
- data/test/fixtures/test/erb_content_for.erb +0 -2
- data/test/template/deprecated_erb_variable_test.rb +0 -9
- data/test/template/template_finder_test.rb +0 -73
- data/test/template/template_object_test.rb +0 -95
@@ -1,30 +1,26 @@
|
|
1
1
|
require 'abstract_unit'
|
2
2
|
|
3
3
|
class ViewLoadPathsTest < Test::Unit::TestCase
|
4
|
-
|
5
|
-
LOAD_PATH_ROOT = File.join(File.dirname(__FILE__), '..', 'fixtures')
|
6
|
-
|
7
|
-
ActionController::Base.view_paths = [ LOAD_PATH_ROOT ]
|
8
|
-
|
9
4
|
class TestController < ActionController::Base
|
10
5
|
def self.controller_path() "test" end
|
11
6
|
def rescue_action(e) raise end
|
12
|
-
|
7
|
+
|
13
8
|
before_filter :add_view_path, :only => :hello_world_at_request_time
|
14
|
-
|
9
|
+
|
15
10
|
def hello_world() end
|
16
11
|
def hello_world_at_request_time() render(:action => 'hello_world') end
|
12
|
+
|
17
13
|
private
|
18
|
-
|
19
|
-
|
20
|
-
|
14
|
+
def add_view_path
|
15
|
+
prepend_view_path "#{FIXTURE_LOAD_PATH}/override"
|
16
|
+
end
|
21
17
|
end
|
22
|
-
|
18
|
+
|
23
19
|
class Test::SubController < ActionController::Base
|
24
20
|
layout 'test/sub'
|
25
21
|
def hello_world; render(:template => 'test/hello_world'); end
|
26
22
|
end
|
27
|
-
|
23
|
+
|
28
24
|
def setup
|
29
25
|
TestController.view_paths = nil
|
30
26
|
|
@@ -41,100 +37,105 @@ class ViewLoadPathsTest < Test::Unit::TestCase
|
|
41
37
|
@last_message = nil
|
42
38
|
ActiveSupport::Deprecation.behavior = Proc.new { |message, callback| @last_message = message }
|
43
39
|
end
|
44
|
-
|
40
|
+
|
45
41
|
def teardown
|
46
42
|
ActiveSupport::Deprecation.behavior = @old_behavior
|
47
43
|
end
|
48
|
-
|
44
|
+
|
49
45
|
def test_template_load_path_was_set_correctly
|
50
|
-
assert_equal [
|
46
|
+
assert_equal [FIXTURE_LOAD_PATH], @controller.view_paths
|
51
47
|
end
|
52
|
-
|
48
|
+
|
53
49
|
def test_controller_appends_view_path_correctly
|
54
50
|
@controller.append_view_path 'foo'
|
55
|
-
assert_equal [
|
56
|
-
|
51
|
+
assert_equal [FIXTURE_LOAD_PATH, 'foo'], @controller.view_paths
|
52
|
+
|
57
53
|
@controller.append_view_path(%w(bar baz))
|
58
|
-
assert_equal [
|
54
|
+
assert_equal [FIXTURE_LOAD_PATH, 'foo', 'bar', 'baz'], @controller.view_paths
|
55
|
+
|
56
|
+
@controller.append_view_path(FIXTURE_LOAD_PATH)
|
57
|
+
assert_equal [FIXTURE_LOAD_PATH, 'foo', 'bar', 'baz', FIXTURE_LOAD_PATH], @controller.view_paths
|
59
58
|
end
|
60
|
-
|
59
|
+
|
61
60
|
def test_controller_prepends_view_path_correctly
|
62
61
|
@controller.prepend_view_path 'baz'
|
63
|
-
assert_equal ['baz',
|
64
|
-
|
62
|
+
assert_equal ['baz', FIXTURE_LOAD_PATH], @controller.view_paths
|
63
|
+
|
65
64
|
@controller.prepend_view_path(%w(foo bar))
|
66
|
-
assert_equal ['foo', 'bar', 'baz',
|
65
|
+
assert_equal ['foo', 'bar', 'baz', FIXTURE_LOAD_PATH], @controller.view_paths
|
66
|
+
|
67
|
+
@controller.prepend_view_path(FIXTURE_LOAD_PATH)
|
68
|
+
assert_equal [FIXTURE_LOAD_PATH, 'foo', 'bar', 'baz', FIXTURE_LOAD_PATH], @controller.view_paths
|
67
69
|
end
|
68
|
-
|
70
|
+
|
69
71
|
def test_template_appends_view_path_correctly
|
70
72
|
@controller.instance_variable_set :@template, ActionView::Base.new(TestController.view_paths, {}, @controller)
|
71
73
|
class_view_paths = TestController.view_paths
|
72
74
|
|
73
75
|
@controller.append_view_path 'foo'
|
74
|
-
assert_equal [
|
75
|
-
|
76
|
+
assert_equal [FIXTURE_LOAD_PATH, 'foo'], @controller.view_paths
|
77
|
+
|
76
78
|
@controller.append_view_path(%w(bar baz))
|
77
|
-
assert_equal [
|
79
|
+
assert_equal [FIXTURE_LOAD_PATH, 'foo', 'bar', 'baz'], @controller.view_paths
|
78
80
|
assert_equal class_view_paths, TestController.view_paths
|
79
81
|
end
|
80
|
-
|
82
|
+
|
81
83
|
def test_template_prepends_view_path_correctly
|
82
84
|
@controller.instance_variable_set :@template, ActionView::Base.new(TestController.view_paths, {}, @controller)
|
83
85
|
class_view_paths = TestController.view_paths
|
84
|
-
|
86
|
+
|
85
87
|
@controller.prepend_view_path 'baz'
|
86
|
-
assert_equal ['baz',
|
87
|
-
|
88
|
+
assert_equal ['baz', FIXTURE_LOAD_PATH], @controller.view_paths
|
89
|
+
|
88
90
|
@controller.prepend_view_path(%w(foo bar))
|
89
|
-
assert_equal ['foo', 'bar', 'baz',
|
91
|
+
assert_equal ['foo', 'bar', 'baz', FIXTURE_LOAD_PATH], @controller.view_paths
|
90
92
|
assert_equal class_view_paths, TestController.view_paths
|
91
93
|
end
|
92
|
-
|
94
|
+
|
93
95
|
def test_view_paths
|
94
96
|
get :hello_world
|
95
97
|
assert_response :success
|
96
98
|
assert_equal "Hello world!", @response.body
|
97
99
|
end
|
98
|
-
|
100
|
+
|
99
101
|
def test_view_paths_override
|
100
|
-
TestController.prepend_view_path "#{
|
102
|
+
TestController.prepend_view_path "#{FIXTURE_LOAD_PATH}/override"
|
101
103
|
get :hello_world
|
102
104
|
assert_response :success
|
103
105
|
assert_equal "Hello overridden world!", @response.body
|
104
106
|
end
|
105
|
-
|
107
|
+
|
106
108
|
def test_view_paths_override_for_layouts_in_controllers_with_a_module
|
107
109
|
@controller = Test::SubController.new
|
108
|
-
Test::SubController.view_paths = [ "#{
|
110
|
+
Test::SubController.view_paths = [ "#{FIXTURE_LOAD_PATH}/override", FIXTURE_LOAD_PATH, "#{FIXTURE_LOAD_PATH}/override2" ]
|
109
111
|
get :hello_world
|
110
112
|
assert_response :success
|
111
113
|
assert_equal "layout: Hello overridden world!", @response.body
|
112
114
|
end
|
113
|
-
|
115
|
+
|
114
116
|
def test_view_paths_override_at_request_time
|
115
117
|
get :hello_world_at_request_time
|
116
118
|
assert_response :success
|
117
119
|
assert_equal "Hello overridden world!", @response.body
|
118
120
|
end
|
119
|
-
|
121
|
+
|
120
122
|
def test_inheritance
|
121
123
|
original_load_paths = ActionController::Base.view_paths
|
122
|
-
|
124
|
+
|
123
125
|
self.class.class_eval %{
|
124
126
|
class A < ActionController::Base; end
|
125
127
|
class B < A; end
|
126
128
|
class C < ActionController::Base; end
|
127
129
|
}
|
128
|
-
|
129
|
-
A.view_paths = [
|
130
|
-
|
131
|
-
assert_equal [
|
132
|
-
assert_equal A.view_paths,
|
130
|
+
|
131
|
+
A.view_paths = ['a/path']
|
132
|
+
|
133
|
+
assert_equal ['a/path'], A.view_paths
|
134
|
+
assert_equal A.view_paths, B.view_paths
|
133
135
|
assert_equal original_load_paths, C.view_paths
|
134
|
-
|
136
|
+
|
135
137
|
C.view_paths = []
|
136
138
|
assert_nothing_raised { C.view_paths << 'c/path' }
|
137
139
|
assert_equal ['c/path'], C.view_paths
|
138
140
|
end
|
139
|
-
|
140
141
|
end
|
@@ -0,0 +1 @@
|
|
1
|
+
top level partial html
|
@@ -0,0 +1 @@
|
|
1
|
+
top level partial
|
@@ -0,0 +1 @@
|
|
1
|
+
<%= developer.name %>
|
@@ -0,0 +1 @@
|
|
1
|
+
<%= game.name %>
|
@@ -0,0 +1 @@
|
|
1
|
+
<%= game.name %>
|
@@ -0,0 +1 @@
|
|
1
|
+
<%= project.name %>
|
@@ -0,0 +1 @@
|
|
1
|
+
// subdir js
|
@@ -0,0 +1 @@
|
|
1
|
+
/* subdir.css */
|
@@ -0,0 +1 @@
|
|
1
|
+
<%= reply.content %>
|
@@ -0,0 +1 @@
|
|
1
|
+
<%= counter_counter %>
|
@@ -1 +1 @@
|
|
1
|
-
Hello: <%= customer.name %>
|
1
|
+
Hello: <%= customer.name rescue "Anonymous" %>
|
@@ -0,0 +1 @@
|
|
1
|
+
<%= customer.name %> <%= object.name %> <%= customer_with_var.name %>
|
@@ -0,0 +1 @@
|
|
1
|
+
<%= local_assigns.keys.map(&:to_s).sort.join(",") -%>
|
@@ -0,0 +1 @@
|
|
1
|
+
partial with only html version
|
@@ -0,0 +1 @@
|
|
1
|
+
Hello world!
|
@@ -0,0 +1 @@
|
|
1
|
+
<%= render :partial => "test/raise" %>
|
@@ -0,0 +1 @@
|
|
1
|
+
<%= template.path %>
|
@@ -0,0 +1 @@
|
|
1
|
+
<% render(:layout => "layout_for_block_with_args") do |*args| %><%= args.join %><% end %>
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'abstract_unit'
|
2
|
+
|
3
|
+
class ActiveRecordHelperI18nTest < Test::Unit::TestCase
|
4
|
+
include ActionView::Helpers::ActiveRecordHelper
|
5
|
+
|
6
|
+
attr_reader :request
|
7
|
+
uses_mocha 'active_record_helper_i18n_test' do
|
8
|
+
def setup
|
9
|
+
@object = stub :errors => stub(:count => 1, :full_messages => ['full_messages'])
|
10
|
+
@object_name = 'book'
|
11
|
+
stubs(:content_tag).returns 'content_tag'
|
12
|
+
|
13
|
+
I18n.stubs(:t).with(:'header', :locale => 'en', :scope => [:activerecord, :errors, :template], :count => 1, :model => '').returns "1 error prohibited this from being saved"
|
14
|
+
I18n.stubs(:t).with(:'body', :locale => 'en', :scope => [:activerecord, :errors, :template]).returns 'There were problems with the following fields:'
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_error_messages_for_given_a_header_option_it_does_not_translate_header_message
|
18
|
+
I18n.expects(:translate).with(:'header', :locale => 'en', :scope => [:activerecord, :errors, :template], :count => 1, :model => '').never
|
19
|
+
error_messages_for(:object => @object, :header_message => 'header message', :locale => 'en')
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_error_messages_for_given_no_header_option_it_translates_header_message
|
23
|
+
I18n.expects(:t).with(:'header', :locale => 'en', :scope => [:activerecord, :errors, :template], :count => 1, :model => '').returns 'header message'
|
24
|
+
I18n.expects(:t).with('', :default => '', :count => 1, :scope => [:activerecord, :models]).once.returns ''
|
25
|
+
error_messages_for(:object => @object, :locale => 'en')
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_error_messages_for_given_a_message_option_it_does_not_translate_message
|
29
|
+
I18n.expects(:t).with(:'body', :locale => 'en', :scope => [:activerecord, :errors, :template]).never
|
30
|
+
I18n.expects(:t).with('', :default => '', :count => 1, :scope => [:activerecord, :models]).once.returns ''
|
31
|
+
error_messages_for(:object => @object, :message => 'message', :locale => 'en')
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_error_messages_for_given_no_message_option_it_translates_message
|
35
|
+
I18n.expects(:t).with(:'body', :locale => 'en', :scope => [:activerecord, :errors, :template]).returns 'There were problems with the following fields:'
|
36
|
+
I18n.expects(:t).with('', :default => '', :count => 1, :scope => [:activerecord, :models]).once.returns ''
|
37
|
+
error_messages_for(:object => @object, :locale => 'en')
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_error_messages_for_given_object_name_it_translates_object_name
|
41
|
+
I18n.expects(:t).with(:header, :locale => 'en', :scope => [:activerecord, :errors, :template], :count => 1, :model => @object_name).returns "1 error prohibited this #{@object_name} from being saved"
|
42
|
+
I18n.expects(:t).with(@object_name, :default => @object_name, :count => 1, :scope => [:activerecord, :models]).once.returns @object_name
|
43
|
+
error_messages_for(:object => @object, :locale => 'en', :object_name => @object_name)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -10,17 +10,17 @@ class ActiveRecordHelperTest < ActionView::TestCase
|
|
10
10
|
alias_method :body_before_type_cast, :body unless respond_to?(:body_before_type_cast)
|
11
11
|
alias_method :author_name_before_type_cast, :author_name unless respond_to?(:author_name_before_type_cast)
|
12
12
|
end
|
13
|
-
|
13
|
+
|
14
14
|
User = Struct.new("User", :email)
|
15
15
|
User.class_eval do
|
16
16
|
alias_method :email_before_type_cast, :email unless respond_to?(:email_before_type_cast)
|
17
17
|
end
|
18
|
-
|
18
|
+
|
19
19
|
Column = Struct.new("Column", :type, :name, :human_name)
|
20
20
|
end
|
21
21
|
|
22
22
|
def setup_post
|
23
|
-
@post = Post.new
|
23
|
+
@post = Post.new
|
24
24
|
def @post.errors
|
25
25
|
Class.new {
|
26
26
|
def on(field)
|
@@ -33,12 +33,12 @@ class ActiveRecordHelperTest < ActionView::TestCase
|
|
33
33
|
false
|
34
34
|
end
|
35
35
|
end
|
36
|
-
def empty?() false end
|
37
|
-
def count() 1 end
|
36
|
+
def empty?() false end
|
37
|
+
def count() 1 end
|
38
38
|
def full_messages() [ "Author name can't be empty" ] end
|
39
39
|
}.new
|
40
40
|
end
|
41
|
-
|
41
|
+
|
42
42
|
def @post.new_record?() true end
|
43
43
|
def @post.to_param() nil end
|
44
44
|
|
@@ -58,16 +58,16 @@ class ActiveRecordHelperTest < ActionView::TestCase
|
|
58
58
|
end
|
59
59
|
|
60
60
|
def setup_user
|
61
|
-
@user = User.new
|
61
|
+
@user = User.new
|
62
62
|
def @user.errors
|
63
63
|
Class.new {
|
64
64
|
def on(field) field == "email" end
|
65
|
-
def empty?() false end
|
66
|
-
def count() 1 end
|
65
|
+
def empty?() false end
|
66
|
+
def count() 1 end
|
67
67
|
def full_messages() [ "User email can't be empty" ] end
|
68
68
|
}.new
|
69
69
|
end
|
70
|
-
|
70
|
+
|
71
71
|
def @user.new_record?() true end
|
72
72
|
def @user.to_param() nil end
|
73
73
|
|
@@ -81,7 +81,7 @@ class ActiveRecordHelperTest < ActionView::TestCase
|
|
81
81
|
|
82
82
|
@user.email = ""
|
83
83
|
end
|
84
|
-
|
84
|
+
|
85
85
|
def protect_against_forgery?
|
86
86
|
@protect_against_forgery ? true : false
|
87
87
|
end
|
@@ -92,7 +92,7 @@ class ActiveRecordHelperTest < ActionView::TestCase
|
|
92
92
|
setup_user
|
93
93
|
|
94
94
|
@response = ActionController::TestResponse.new
|
95
|
-
|
95
|
+
|
96
96
|
@controller = Object.new
|
97
97
|
def @controller.url_for(options)
|
98
98
|
options = options.symbolize_keys
|
@@ -111,7 +111,7 @@ class ActiveRecordHelperTest < ActionView::TestCase
|
|
111
111
|
assert_dom_equal(
|
112
112
|
%(<div class="fieldWithErrors"><textarea cols="40" id="post_body" name="post[body]" rows="20">Back to the hill and over it again!</textarea></div>),
|
113
113
|
text_area("post", "body")
|
114
|
-
)
|
114
|
+
)
|
115
115
|
end
|
116
116
|
|
117
117
|
def test_text_field_with_errors
|
@@ -140,7 +140,7 @@ class ActiveRecordHelperTest < ActionView::TestCase
|
|
140
140
|
form("post")
|
141
141
|
)
|
142
142
|
end
|
143
|
-
|
143
|
+
|
144
144
|
def test_form_with_protect_against_forgery
|
145
145
|
@protect_against_forgery = true
|
146
146
|
@request_forgery_protection_token = 'authenticity_token'
|
@@ -150,7 +150,7 @@ class ActiveRecordHelperTest < ActionView::TestCase
|
|
150
150
|
form("post")
|
151
151
|
)
|
152
152
|
end
|
153
|
-
|
153
|
+
|
154
154
|
def test_form_with_method_option
|
155
155
|
assert_dom_equal(
|
156
156
|
%(<form action="create" method="get"><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="Create" /></form>),
|
@@ -211,9 +211,9 @@ class ActiveRecordHelperTest < ActionView::TestCase
|
|
211
211
|
other_post = @post
|
212
212
|
assert_dom_equal "<div class=\"formError\">can't be empty</div>", error_message_on(other_post, :author_name)
|
213
213
|
end
|
214
|
-
|
215
|
-
def
|
216
|
-
assert_dom_equal "<div class=\"differentError\">beforecan't be emptyafter</div>", error_message_on(:post, :author_name,
|
214
|
+
|
215
|
+
def test_error_message_on_with_options_hash
|
216
|
+
assert_dom_equal "<div class=\"differentError\">beforecan't be emptyafter</div>", error_message_on(:post, :author_name, :css_class => 'differentError', :prepend_text => 'before', :append_text => 'after')
|
217
217
|
end
|
218
218
|
|
219
219
|
def test_error_messages_for_many_objects
|
@@ -224,10 +224,10 @@ class ActiveRecordHelperTest < ActionView::TestCase
|
|
224
224
|
|
225
225
|
# add the default to put post back in the title
|
226
226
|
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")
|
227
|
-
|
227
|
+
|
228
228
|
# symbols work as well
|
229
229
|
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)
|
230
|
-
|
230
|
+
|
231
231
|
# any default works too
|
232
232
|
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")
|
233
233
|
|
@@ -242,7 +242,7 @@ class ActiveRecordHelperTest < ActionView::TestCase
|
|
242
242
|
message = "Please fix the following fields and resubmit:"
|
243
243
|
assert_dom_equal %(<div class="errorExplanation" id="errorExplanation"><h2>#{header_message}</h2><p>#{message}</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, :header_message => header_message, :message => message)
|
244
244
|
end
|
245
|
-
|
245
|
+
|
246
246
|
def test_error_messages_for_non_instance_variable
|
247
247
|
actual_user = @user
|
248
248
|
actual_post = @post
|
@@ -251,14 +251,14 @@ class ActiveRecordHelperTest < ActionView::TestCase
|
|
251
251
|
|
252
252
|
#explicitly set object
|
253
253
|
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", :object => actual_post)
|
254
|
-
|
254
|
+
|
255
255
|
#multiple objects
|
256
256
|
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", :object => [actual_user, actual_post])
|
257
|
-
|
257
|
+
|
258
258
|
#nil object
|
259
259
|
assert_equal '', error_messages_for('user', :object => nil)
|
260
260
|
end
|
261
|
-
|
261
|
+
|
262
262
|
def test_form_with_string_multipart
|
263
263
|
assert_dom_equal(
|
264
264
|
%(<form action="create" enctype="multipart/form-data" method="post"><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="Create" /></form>),
|