diff options
author | Xavier Noria <fxn@hashref.com> | 2012-08-06 00:27:56 +0200 |
---|---|---|
committer | Xavier Noria <fxn@hashref.com> | 2012-08-06 00:30:02 +0200 |
commit | 447b6a4e678ab1618bdcd130e30c288b0a25297a (patch) | |
tree | 6d9cb3417996517a5b237d3950c25ab32a5db098 /actionpack/test | |
parent | 6126f02cf903fa206b11d2dc2eeb5f197a29b965 (diff) | |
download | rails-447b6a4e678ab1618bdcd130e30c288b0a25297a.tar.gz rails-447b6a4e678ab1618bdcd130e30c288b0a25297a.tar.bz2 rails-447b6a4e678ab1618bdcd130e30c288b0a25297a.zip |
removes usage of Object#in? from the code base (the method remains defined by Active Support)
Selecting which key extensions to include in active_support/rails
made apparent the systematic usage of Object#in? in the code base.
After some discussion in
https://github.com/rails/rails/commit/5ea6b0df9a36d033f21b52049426257a4637028d
we decided to remove it and use plain Ruby, which seems enough
for this particular idiom.
In this commit the refactor has been made case by case. Sometimes
include? is the natural alternative, others a simple || is the
way you actually spell the condition in your head, others a case
statement seems more appropriate. I have chosen the one I liked
the most in each case.
Diffstat (limited to 'actionpack/test')
-rw-r--r-- | actionpack/test/controller/mime_responds_test.rb | 9 | ||||
-rw-r--r-- | actionpack/test/controller/resources_test.rb | 6 | ||||
-rw-r--r-- | actionpack/test/dispatch/routing_test.rb | 2 | ||||
-rw-r--r-- | actionpack/test/template/erb_util_test.rb | 2 | ||||
-rw-r--r-- | actionpack/test/template/form_helper_test.rb | 2 | ||||
-rw-r--r-- | actionpack/test/template/form_options_helper_test.rb | 2 | ||||
-rw-r--r-- | actionpack/test/template/form_tag_helper_test.rb | 2 |
7 files changed, 13 insertions, 12 deletions
diff --git a/actionpack/test/controller/mime_responds_test.rb b/actionpack/test/controller/mime_responds_test.rb index 6f9dd44e21..b21d35c846 100644 --- a/actionpack/test/controller/mime_responds_test.rb +++ b/actionpack/test/controller/mime_responds_test.rb @@ -151,10 +151,11 @@ class RespondToController < ActionController::Base protected def set_layout - if action_name.in?(["all_types_with_layout", "iphone_with_html_response_type"]) - "respond_to/layouts/standard" - elsif action_name == "iphone_with_html_response_type_without_layout" - "respond_to/layouts/missing" + case action_name + when "all_types_with_layout", "iphone_with_html_response_type" + "respond_to/layouts/standard" + when "iphone_with_html_response_type_without_layout" + "respond_to/layouts/missing" end end end diff --git a/actionpack/test/controller/resources_test.rb b/actionpack/test/controller/resources_test.rb index c7c367f18a..236e16c68e 100644 --- a/actionpack/test/controller/resources_test.rb +++ b/actionpack/test/controller/resources_test.rb @@ -1307,7 +1307,7 @@ class ResourcesTest < ActionController::TestCase def assert_resource_methods(expected, resource, action_method, method) assert_equal expected.length, resource.send("#{action_method}_methods")[method].size, "#{resource.send("#{action_method}_methods")[method].inspect}" expected.each do |action| - assert action.in?(resource.send("#{action_method}_methods")[method]) + assert resource.send("#{action_method}_methods")[method].include?(action) "#{method} not in #{action_method} methods: #{resource.send("#{action_method}_methods")[method].inspect}" end end @@ -1344,9 +1344,9 @@ class ResourcesTest < ActionController::TestCase options = options.merge(:action => action.to_s) path_options = { :path => path, :method => method } - if action.in?(Array(allowed)) + if Array(allowed).include?(action) assert_recognizes options, path_options - elsif action.in?(Array(not_allowed)) + elsif Array(not_allowed).include?(action) assert_not_recognizes options, path_options end end diff --git a/actionpack/test/dispatch/routing_test.rb b/actionpack/test/dispatch/routing_test.rb index d0308b0e74..b029131ad8 100644 --- a/actionpack/test/dispatch/routing_test.rb +++ b/actionpack/test/dispatch/routing_test.rb @@ -511,7 +511,7 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest resources :todos, :id => /\d+/ end - scope '/countries/:country', :constraints => lambda { |params, req| params[:country].in?(["all", "France"]) } do + scope '/countries/:country', :constraints => lambda { |params, req| %w(all France).include?(params[:country]) } do get '/', :to => 'countries#index' get '/cities', :to => 'countries#cities' end diff --git a/actionpack/test/template/erb_util_test.rb b/actionpack/test/template/erb_util_test.rb index 4132c8ca04..f1cb920963 100644 --- a/actionpack/test/template/erb_util_test.rb +++ b/actionpack/test/template/erb_util_test.rb @@ -39,7 +39,7 @@ class ErbUtilTest < ActiveSupport::TestCase def test_rest_in_ascii (0..127).to_a.map {|int| int.chr }.each do |chr| - next if chr.in?('&"<>\'') + next if %('"&<>).include?(chr) assert_equal chr, html_escape(chr) end end diff --git a/actionpack/test/template/form_helper_test.rb b/actionpack/test/template/form_helper_test.rb index ab22dbfa44..a20a68c1b2 100644 --- a/actionpack/test/template/form_helper_test.rb +++ b/actionpack/test/template/form_helper_test.rb @@ -2659,7 +2659,7 @@ class FormHelperTest < ActionView::TestCase def hidden_fields(method = nil) txt = %{<div style="margin:0;padding:0;display:inline">} txt << %{<input name="utf8" type="hidden" value="✓" />} - if method && !method.to_s.in?(['get', 'post']) + if method && !%w(get post).include?(method.to_s) txt << %{<input name="_method" type="hidden" value="#{method}" />} end txt << %{</div>} diff --git a/actionpack/test/template/form_options_helper_test.rb b/actionpack/test/template/form_options_helper_test.rb index 66a572e719..682ffdcc18 100644 --- a/actionpack/test/template/form_options_helper_test.rb +++ b/actionpack/test/template/form_options_helper_test.rb @@ -82,7 +82,7 @@ class FormOptionsHelperTest < ActionView::TestCase def test_collection_options_with_proc_for_disabled assert_dom_equal( "<option value=\"<Abe>\"><Abe> went home</option>\n<option value=\"Babe\" disabled=\"disabled\">Babe went home</option>\n<option value=\"Cabe\" disabled=\"disabled\">Cabe went home</option>", - options_from_collection_for_select(dummy_posts, "author_name", "title", :disabled => lambda{|p| p.author_name.in?(["Babe", "Cabe"]) }) + options_from_collection_for_select(dummy_posts, "author_name", "title", :disabled => lambda {|p| %w(Babe Cabe).include?(p.author_name)}) ) end diff --git a/actionpack/test/template/form_tag_helper_test.rb b/actionpack/test/template/form_tag_helper_test.rb index dcae5b2352..9a85b1b553 100644 --- a/actionpack/test/template/form_tag_helper_test.rb +++ b/actionpack/test/template/form_tag_helper_test.rb @@ -15,7 +15,7 @@ class FormTagHelperTest < ActionView::TestCase txt = %{<div style="margin:0;padding:0;display:inline">} txt << %{<input name="utf8" type="hidden" value="✓" />} - if method && !method.to_s.in?(['get','post']) + if method && !%w(get post).include?(method.to_s) txt << %{<input name="_method" type="hidden" value="#{method}" />} end txt << %{</div>} |