aboutsummaryrefslogtreecommitdiffstats
path: root/actionview
diff options
context:
space:
mode:
Diffstat (limited to 'actionview')
-rw-r--r--actionview/lib/action_view/helpers/form_options_helper.rb4
-rw-r--r--actionview/lib/action_view/helpers/text_helper.rb2
-rw-r--r--actionview/test/activerecord/relation_cache_test.rb17
-rw-r--r--actionview/test/template/form_options_helper_test.rb2
-rw-r--r--actionview/test/template/output_safety_helper_test.rb8
5 files changed, 27 insertions, 6 deletions
diff --git a/actionview/lib/action_view/helpers/form_options_helper.rb b/actionview/lib/action_view/helpers/form_options_helper.rb
index ad19426fff..cf8f7de931 100644
--- a/actionview/lib/action_view/helpers/form_options_helper.rb
+++ b/actionview/lib/action_view/helpers/form_options_helper.rb
@@ -569,7 +569,7 @@ module ActionView
# be obtained in Active Record as a value object). The +model+ parameter
# must respond to +all+ and return an array of objects that represent time
# zones; each object must respond to +name+. If a Regexp is given it will
- # attempt to match the zones using the <code>=~<code> operator.
+ # attempt to match the zones using <code>match?</code> method.
#
# NOTE: Only the option tags are returned, you have to wrap this call in
# a regular HTML select tag.
@@ -581,7 +581,7 @@ module ActionView
if priority_zones
if priority_zones.is_a?(Regexp)
- priority_zones = zones.select { |z| z =~ priority_zones }
+ priority_zones = zones.select { |z| z.match?(priority_zones) }
end
zone_options.safe_concat options_for_select(convert_zones[priority_zones], selected)
diff --git a/actionview/lib/action_view/helpers/text_helper.rb b/actionview/lib/action_view/helpers/text_helper.rb
index 8203a43239..980a89a7b6 100644
--- a/actionview/lib/action_view/helpers/text_helper.rb
+++ b/actionview/lib/action_view/helpers/text_helper.rb
@@ -228,7 +228,7 @@ module ActionView
# pluralize(2, 'Person', locale: :de)
# # => 2 Personen
def pluralize(count, singular, plural_arg = nil, plural: plural_arg, locale: I18n.locale)
- word = if count == 1 || count.to_s =~ /^1(\.0+)?$/
+ word = if count == 1 || count.to_s.match?(/^1(\.0+)?$/)
singular
else
plural || singular.pluralize(locale)
diff --git a/actionview/test/activerecord/relation_cache_test.rb b/actionview/test/activerecord/relation_cache_test.rb
index 6fe83dcb9a..26f3bfbcbc 100644
--- a/actionview/test/activerecord/relation_cache_test.rb
+++ b/actionview/test/activerecord/relation_cache_test.rb
@@ -17,9 +17,24 @@ class RelationCacheTest < ActionView::TestCase
end
def test_cache_relation_other
- cache(Project.all) { concat("Hello World") }
+ assert_queries(1) do
+ cache(Project.all) { concat("Hello World") }
+ end
assert_equal "Hello World", controller.cache_store.read("views/test/hello_world:fa9482a68ce25bf7589b8eddad72f736/projects-#{Project.count}")
end
def view_cache_dependencies; []; end
+
+ def assert_queries(num)
+ ActiveRecord::Base.connection.materialize_transactions
+ count = 0
+
+ ActiveSupport::Notifications.subscribe("sql.active_record") do |_name, _start, _finish, _id, payload|
+ count += 1 unless ["SCHEMA", "TRANSACTION"].include? payload[:name]
+ end
+
+ result = yield
+ assert_equal num, count, "#{count} instead of #{num} queries were executed."
+ result
+ end
end
diff --git a/actionview/test/template/form_options_helper_test.rb b/actionview/test/template/form_options_helper_test.rb
index d7a7b95ab3..273646b077 100644
--- a/actionview/test/template/form_options_helper_test.rb
+++ b/actionview/test/template/form_options_helper_test.rb
@@ -47,6 +47,7 @@ class FormOptionsHelperTest < ActionView::TestCase
FakeZone = Struct.new(:name) do
def to_s; name; end
def =~(_re); end
+ def match?(_re); end
end
module ClassMethods
@@ -1266,6 +1267,7 @@ class FormOptionsHelperTest < ActionView::TestCase
@fake_timezones.each do |tz|
def tz.=~(re); %(A D).include?(name) end
+ def tz.match?(re); %(A D).include?(name) end
end
html = time_zone_select("firm", "time_zone", /A|D/)
diff --git a/actionview/test/template/output_safety_helper_test.rb b/actionview/test/template/output_safety_helper_test.rb
index faeeded1c8..b2c6ae99ed 100644
--- a/actionview/test/template/output_safety_helper_test.rb
+++ b/actionview/test/template/output_safety_helper_test.rb
@@ -43,7 +43,9 @@ class OutputSafetyHelperTest < ActionView::TestCase
joined = safe_join(["a", "b"])
assert_equal "ab", joined
- $, = "|"
+ silence_warnings do
+ $, = "|"
+ end
joined = safe_join(["a", "b"])
assert_equal "a|b", joined
ensure
@@ -108,7 +110,9 @@ class OutputSafetyHelperTest < ActionView::TestCase
test "to_sentence is not affected by $," do
separator_was = $,
- $, = "|"
+ silence_warnings do
+ $, = "|"
+ end
begin
assert_equal "one and two", to_sentence(["one", "two"])
assert_equal "one, two, and three", to_sentence(["one", "two", "three"])