actionpack 2.3.8.pre1 → 2.3.8
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/lib/action_view/helpers/form_tag_helper.rb +1 -1
- data/lib/action_view/helpers/translation_helper.rb +22 -7
- data/test/active_record_unit.rb +1 -1
- data/test/controller/assert_select_test.rb +5 -5
- data/test/controller/helper_test.rb +1 -1
- data/test/template/form_tag_helper_test.rb +6 -0
- data/test/template/translation_helper_test.rb +40 -11
- metadata +6 -10
@@ -265,7 +265,7 @@ module ActionView
|
|
265
265
|
escape = options.key?("escape") ? options.delete("escape") : true
|
266
266
|
content = html_escape(content) if escape
|
267
267
|
|
268
|
-
content_tag :textarea, content.html_safe, { "name" => name, "id" => sanitize_to_id(name) }.update(options.stringify_keys)
|
268
|
+
content_tag :textarea, content.to_s.html_safe, { "name" => name, "id" => sanitize_to_id(name) }.update(options.stringify_keys)
|
269
269
|
end
|
270
270
|
|
271
271
|
# Creates a check box form input tag.
|
@@ -11,13 +11,22 @@ module ActionView
|
|
11
11
|
# to translate many keys within the same partials and gives you a simple framework for scoping them consistently. If you don't
|
12
12
|
# prepend the key with a period, nothing is converted.
|
13
13
|
def translate(keys, options = {})
|
14
|
-
|
15
|
-
|
14
|
+
if multiple_keys = keys.is_a?(Array)
|
15
|
+
ActiveSupport::Deprecation.warn "Giving an array to translate is deprecated, please give a symbol or a string instead", caller
|
16
|
+
end
|
17
|
+
|
18
|
+
options[:raise] = true
|
16
19
|
keys = scope_keys_by_partial(keys)
|
17
20
|
|
18
21
|
translations = I18n.translate(keys, options)
|
19
|
-
translations =
|
20
|
-
|
22
|
+
translations = [translations] if !multiple_keys && translations.size > 1
|
23
|
+
translations = html_safe_translation_keys(keys, translations)
|
24
|
+
|
25
|
+
if multiple_keys || translations.size > 1
|
26
|
+
translations
|
27
|
+
else
|
28
|
+
translations.first
|
29
|
+
end
|
21
30
|
rescue I18n::MissingTranslationData => e
|
22
31
|
keys = I18n.send(:normalize_translation_keys, e.locale, e.key, e.options[:scope])
|
23
32
|
content_tag('span', keys.join(', '), :class => 'translation_missing')
|
@@ -34,8 +43,10 @@ module ActionView
|
|
34
43
|
private
|
35
44
|
def scope_keys_by_partial(keys)
|
36
45
|
Array.wrap(keys).map do |key|
|
37
|
-
|
38
|
-
|
46
|
+
key = key.to_s
|
47
|
+
|
48
|
+
if key.first == "."
|
49
|
+
template.path_without_format_and_extension.gsub(%r{/_?}, ".") + key
|
39
50
|
else
|
40
51
|
key
|
41
52
|
end
|
@@ -44,7 +55,11 @@ module ActionView
|
|
44
55
|
|
45
56
|
def html_safe_translation_keys(keys, translations)
|
46
57
|
keys.zip(translations).map do |key, translation|
|
47
|
-
key =~ /(\b|_|\.)html$/
|
58
|
+
if key =~ /(\b|_|\.)html$/ && translation.respond_to?(:html_safe)
|
59
|
+
translation.html_safe
|
60
|
+
else
|
61
|
+
translation
|
62
|
+
end
|
48
63
|
end
|
49
64
|
end
|
50
65
|
end
|
data/test/active_record_unit.rb
CHANGED
@@ -16,7 +16,7 @@ if defined?(ActiveRecord) && defined?(Fixtures)
|
|
16
16
|
else
|
17
17
|
$stderr.print 'Attempting to load Active Record... '
|
18
18
|
begin
|
19
|
-
PATH_TO_AR =
|
19
|
+
PATH_TO_AR = File.expand_path('../../../activerecord/lib', __FILE__)
|
20
20
|
raise LoadError, "#{PATH_TO_AR} doesn't exist" unless File.directory?(PATH_TO_AR)
|
21
21
|
$LOAD_PATH.unshift PATH_TO_AR
|
22
22
|
require 'active_record'
|
@@ -210,13 +210,13 @@ class AssertSelectTest < ActionController::TestCase
|
|
210
210
|
assert_nothing_raised { assert_select "div", "foo" }
|
211
211
|
assert_nothing_raised { assert_select "div", "bar" }
|
212
212
|
assert_nothing_raised { assert_select "div", /\w*/ }
|
213
|
-
assert_nothing_raised { assert_select "div", /\w*/, :count=>2 }
|
214
|
-
assert_raise(Assertion)
|
213
|
+
assert_nothing_raised { assert_select "div", :text => /\w*/, :count=>2 }
|
214
|
+
assert_raise(Assertion) { assert_select "div", :text=>"foo", :count=>2 }
|
215
215
|
assert_nothing_raised { assert_select "div", :html=>"<span>bar</span>" }
|
216
216
|
assert_nothing_raised { assert_select "div", :html=>"<span>bar</span>" }
|
217
217
|
assert_nothing_raised { assert_select "div", :html=>/\w*/ }
|
218
218
|
assert_nothing_raised { assert_select "div", :html=>/\w*/, :count=>2 }
|
219
|
-
assert_raise(Assertion)
|
219
|
+
assert_raise(Assertion) { assert_select "div", :html=>"<span>foo</span>", :count=>2 }
|
220
220
|
end
|
221
221
|
end
|
222
222
|
|
@@ -268,8 +268,8 @@ class AssertSelectTest < ActionController::TestCase
|
|
268
268
|
|
269
269
|
def test_css_select
|
270
270
|
render_html %Q{<div id="1"></div><div id="2"></div>}
|
271
|
-
|
272
|
-
|
271
|
+
assert_equal 2, css_select("div").size
|
272
|
+
assert_equal 0, css_select("p").size
|
273
273
|
end
|
274
274
|
|
275
275
|
def test_nested_css_select
|
@@ -176,6 +176,12 @@ class FormTagHelperTest < ActionView::TestCase
|
|
176
176
|
assert_dom_equal expected, actual
|
177
177
|
end
|
178
178
|
|
179
|
+
def test_text_area_tag_unescaped_nil_content
|
180
|
+
actual = text_area_tag "body", nil, :escape => false
|
181
|
+
expected = %(<textarea id="body" name="body"></textarea>)
|
182
|
+
assert_dom_equal expected, actual
|
183
|
+
end
|
184
|
+
|
179
185
|
def test_text_field_tag
|
180
186
|
actual = text_field_tag "title", "Hello!"
|
181
187
|
expected = %(<input id="title" name="title" type="text" value="Hello!" />)
|
@@ -9,7 +9,7 @@ class TranslationHelperTest < ActiveSupport::TestCase
|
|
9
9
|
end
|
10
10
|
|
11
11
|
def test_delegates_to_i18n_setting_the_raise_option
|
12
|
-
I18n.expects(:translate).with([
|
12
|
+
I18n.expects(:translate).with(['foo'], :locale => 'en', :raise => true).returns([""])
|
13
13
|
translate :foo, :locale => 'en'
|
14
14
|
end
|
15
15
|
|
@@ -18,17 +18,33 @@ class TranslationHelperTest < ActiveSupport::TestCase
|
|
18
18
|
assert_equal expected, translate(:foo)
|
19
19
|
end
|
20
20
|
|
21
|
+
def test_translation_returning_an_array
|
22
|
+
I18n.expects(:translate).with(["foo"], :raise => true).returns(["foo", "bar"])
|
23
|
+
assert_equal ["foo", "bar"], translate(:foo)
|
24
|
+
end
|
25
|
+
|
21
26
|
def test_translation_of_an_array
|
22
|
-
|
23
|
-
|
27
|
+
assert_deprecated do
|
28
|
+
I18n.expects(:translate).with(["foo", "bar"], :raise => true).returns(["foo", "bar"])
|
29
|
+
assert_equal ["foo", "bar"], translate(["foo", "bar"])
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_translation_of_an_array_returning_an_array
|
34
|
+
assert_deprecated do
|
35
|
+
I18n.expects(:translate).with(["foo", "bar"], :raise => true).returns(["foo", ["bar", "baz"]])
|
36
|
+
assert_equal ["foo", ["bar", "baz"]], translate(["foo", "bar"])
|
37
|
+
end
|
24
38
|
end
|
25
39
|
|
26
40
|
def test_translation_of_an_array_with_html
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
41
|
+
assert_deprecated do
|
42
|
+
translate_expected = ['<a href="#">foo</a>', '<a href="#">bar</a>', '<a href="#">baz</a>']
|
43
|
+
I18n.expects(:translate).with(["foo", "bar", "baz_html"], :raise => true).returns(translate_expected)
|
44
|
+
@view = ActionView::Base.new(ActionController::Base.view_paths, {})
|
45
|
+
expected = '<a href="#">foo</a>, <a href="#">bar</a>, <a href="#">baz</a>'
|
46
|
+
assert_equal expected, @view.render(:file => "test/array_translation")
|
47
|
+
end
|
32
48
|
end
|
33
49
|
|
34
50
|
def test_delegates_localize_to_i18n
|
@@ -44,11 +60,19 @@ class TranslationHelperTest < ActiveSupport::TestCase
|
|
44
60
|
end
|
45
61
|
|
46
62
|
def test_scoping_by_partial_of_an_array
|
47
|
-
|
48
|
-
|
49
|
-
|
63
|
+
assert_deprecated do
|
64
|
+
I18n.expects(:translate).with(["test.scoped_array_translation.foo", "test.scoped_array_translation.bar"], :raise => true).returns(["foo", "bar"])
|
65
|
+
@view = ActionView::Base.new(ActionController::Base.view_paths, {})
|
66
|
+
assert_equal "foo, bar", @view.render(:file => "test/scoped_array_translation")
|
67
|
+
end
|
50
68
|
end
|
51
69
|
|
70
|
+
def test_translate_works_with_symbols
|
71
|
+
I18n.expects(:translate).with(["hello"], :raise => true).returns(["Hello World"])
|
72
|
+
assert_equal "Hello World", translate(:hello)
|
73
|
+
end
|
74
|
+
|
75
|
+
|
52
76
|
def test_translate_does_not_mark_plain_text_as_safe_html
|
53
77
|
I18n.expects(:translate).with(["hello"], :raise => true).returns(["Hello World"])
|
54
78
|
assert_equal false, translate("hello").html_safe?
|
@@ -63,4 +87,9 @@ class TranslationHelperTest < ActiveSupport::TestCase
|
|
63
87
|
I18n.expects(:translate).with(["hello_html"], :raise => true).returns(["<a>Hello World</a>"])
|
64
88
|
assert translate("hello_html").html_safe?
|
65
89
|
end
|
90
|
+
|
91
|
+
def test_translation_returning_an_array_ignores_html_suffix
|
92
|
+
I18n.expects(:translate).with(["foo_html"], :raise => true).returns(["foo", "bar"])
|
93
|
+
assert_equal ["foo", "bar"], translate(:foo_html)
|
94
|
+
end
|
66
95
|
end
|
metadata
CHANGED
@@ -1,13 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: actionpack
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
prerelease:
|
4
|
+
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 2
|
7
7
|
- 3
|
8
8
|
- 8
|
9
|
-
|
10
|
-
version: 2.3.8.pre1
|
9
|
+
version: 2.3.8
|
11
10
|
platform: ruby
|
12
11
|
authors:
|
13
12
|
- David Heinemeier Hansson
|
@@ -29,8 +28,7 @@ dependencies:
|
|
29
28
|
- 2
|
30
29
|
- 3
|
31
30
|
- 8
|
32
|
-
|
33
|
-
version: 2.3.8.pre1
|
31
|
+
version: 2.3.8
|
34
32
|
type: :runtime
|
35
33
|
version_requirements: *id001
|
36
34
|
- !ruby/object:Gem::Dependency
|
@@ -511,13 +509,11 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
511
509
|
version: "0"
|
512
510
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
513
511
|
requirements:
|
514
|
-
- - "
|
512
|
+
- - ">="
|
515
513
|
- !ruby/object:Gem::Version
|
516
514
|
segments:
|
517
|
-
-
|
518
|
-
|
519
|
-
- 1
|
520
|
-
version: 1.3.1
|
515
|
+
- 0
|
516
|
+
version: "0"
|
521
517
|
requirements:
|
522
518
|
- none
|
523
519
|
rubyforge_project: actionpack
|