diff --git a/.rubocop.yml b/.rubocop.yml index 967448ba..06b6444f 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,5 +1,8 @@ --- +require: + - rubocop-performance + AllCops: DisabledByDefault: true @@ -43,5 +46,163 @@ Layout/TrailingWhitespace: Layout/TrailingEmptyLines: Enabled: true +Performance: + Enabled: true + +Performance/AncestorsInclude: + Enabled: false + +Performance/ArraySemiInfiniteRangeSlice: + Enabled: false + +Performance/BigDecimalWithNumericArgument: + Enabled: true + +Performance/BindCall: + Enabled: true + +Performance/BlockGivenWithExplicitBlock: + Enabled: true + +Performance/Caller: + Enabled: true + +Performance/CaseWhenSplat: + Enabled: true + +Performance/Casecmp: + Enabled: false + +Performance/ChainArrayAllocation: + Enabled: false + +Performance/CollectionLiteralInLoop: + Enabled: true + Exclude: + - spec/**/* + +Performance/CompareWithBlock: + Enabled: true + +Performance/ConcurrentMonotonicTime: + Enabled: true + +Performance/ConstantRegexp: + Enabled: true + +Performance/Count: + Enabled: true + +Performance/DeletePrefix: + Enabled: true + +Performance/DeleteSuffix: + Enabled: true + +Performance/Detect: + Enabled: true + +Performance/DoubleStartEndWith: + Enabled: true + IncludeActiveSupportAliases: true + +Performance/EndWith: + Enabled: true + +Performance/FixedSize: + Enabled: true + +Performance/FlatMap: + Enabled: true + EnabledForFlattenWithoutParams: false + +Performance/InefficientHashSearch: + Enabled: true + +Performance/IoReadlines: + Enabled: true + +Performance/MapCompact: + Enabled: false + +Performance/MapMethodChain: + Enabled: false + +Performance/MethodObjectAsBlock: + Enabled: true + +Performance/OpenStruct: + Enabled: true + +Performance/RangeInclude: + Enabled: true + +Performance/RedundantBlockCall: + Enabled: false + +Performance/RedundantEqualityComparisonBlock: + Enabled: false + +Performance/RedundantMatch: + Enabled: true + +Performance/RedundantMerge: + Enabled: true + MaxKeyValuePairs: 2 + +Performance/RedundantSortBlock: + Enabled: true + +Performance/RedundantSplitRegexpArgument: + Enabled: true + +Performance/RedundantStringChars: + Enabled: true + +Performance/RegexpMatch: + Enabled: true + +Performance/ReverseEach: + Enabled: true + +Performance/ReverseFirst: + Enabled: true + +Performance/SelectMap: + Enabled: false + +Performance/Size: + Enabled: true + +Performance/SortReverse: + Enabled: true + +Performance/Squeeze: + Enabled: true + +Performance/StartWith: + Enabled: true + +Performance/StringIdentifierArgument: + Enabled: true + +Performance/StringInclude: + Enabled: true + +Performance/StringReplacement: + Enabled: true + +Performance/Sum: + Enabled: false + +Performance/TimesMap: + Enabled: true + +Performance/UnfreezeString: + Enabled: true + +Performance/UriDefaultParser: + Enabled: true + Style/HashSyntax: Enabled: true diff --git a/Gemfile b/Gemfile index c429ac8d..a69e7b80 100644 --- a/Gemfile +++ b/Gemfile @@ -15,4 +15,5 @@ end group :rubocop do gem 'rubocop' + gem 'rubocop-performance' end diff --git a/Gemfile.lock b/Gemfile.lock index 30167e3b..4f4b8a89 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -124,6 +124,7 @@ GEM net-smtp marcel (1.0.2) mini_mime (1.1.5) + mini_portile2 (2.8.5) minitest (5.20.0) minitest-reporters (1.6.1) ansi @@ -144,6 +145,9 @@ GEM net-protocol nio4r (2.5.9) nio4r (2.5.9-java) + nokogiri (1.15.4) + mini_portile2 (~> 2.8.2) + racc (~> 1.4) nokogiri (1.15.4-arm64-darwin) racc (~> 1.4) nokogiri (1.15.4-java) @@ -226,6 +230,9 @@ GEM unicode-display_width (>= 2.4.0, < 3.0) rubocop-ast (1.29.0) parser (>= 3.2.1.0) + rubocop-performance (1.19.1) + rubocop (>= 1.7.0, < 2.0) + rubocop-ast (>= 0.4.0) ruby-progressbar (1.13.0) ruby2_keywords (0.0.5) simplecov (0.22.0) @@ -254,6 +261,7 @@ GEM PLATFORMS arm64-darwin-22 java + ruby x86_64-linux DEPENDENCIES @@ -264,6 +272,7 @@ DEPENDENCIES rails (~> 7.1.0) rails-controller-testing rubocop + rubocop-performance simplecov simplecov-cobertura diff --git a/bin/rake b/bin/rake index 9275675e..54108613 100755 --- a/bin/rake +++ b/bin/rake @@ -15,7 +15,7 @@ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", bundle_binstub = File.expand_path("../bundle", __FILE__) if File.file?(bundle_binstub) - if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/ + if File.read(bundle_binstub, 300).include?('This file was generated by Bundler') load(bundle_binstub) else abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run. diff --git a/gemfiles/rails_61/Gemfile.lock b/gemfiles/rails_61/Gemfile.lock index 609c8f9e..d4bc4a2c 100644 --- a/gemfiles/rails_61/Gemfile.lock +++ b/gemfiles/rails_61/Gemfile.lock @@ -95,6 +95,7 @@ GEM marcel (1.0.2) method_source (1.0.0) mini_mime (1.1.5) + mini_portile2 (2.8.5) minitest (5.20.0) minitest-reporters (1.6.1) ansi @@ -114,6 +115,9 @@ GEM net-protocol nio4r (2.5.9) nio4r (2.5.9-java) + nokogiri (1.15.4) + mini_portile2 (~> 2.8.2) + racc (~> 1.4) nokogiri (1.15.4-arm64-darwin) racc (~> 1.4) nokogiri (1.15.4-java) @@ -194,6 +198,7 @@ GEM PLATFORMS arm64-darwin-22 java + ruby x86_64-linux DEPENDENCIES diff --git a/gemfiles/rails_70/Gemfile b/gemfiles/rails_70/Gemfile index 80c62f5b..d6073c5a 100644 --- a/gemfiles/rails_70/Gemfile +++ b/gemfiles/rails_70/Gemfile @@ -12,7 +12,3 @@ group :development do gem 'simplecov', require: false gem 'simplecov-cobertura' end - -group :rubocop do - gem 'rubocop' -end diff --git a/gemfiles/rails_70/Gemfile.lock b/gemfiles/rails_70/Gemfile.lock index c8e8e94f..e90ae0c6 100644 --- a/gemfiles/rails_70/Gemfile.lock +++ b/gemfiles/rails_70/Gemfile.lock @@ -76,8 +76,6 @@ GEM minitest (>= 5.1) tzinfo (~> 2.0) ansi (1.5.0) - ast (2.4.2) - base64 (0.1.1) builder (3.2.4) concurrent-ruby (1.2.2) crass (1.0.6) @@ -92,9 +90,6 @@ GEM activesupport (>= 5.2) i18n (1.14.1) concurrent-ruby (~> 1.0) - json (2.6.3) - json (2.6.3-java) - language_server-protocol (3.17.0.3) loofah (2.21.4) crass (~> 1.0.2) nokogiri (>= 1.12.0) @@ -106,6 +101,7 @@ GEM marcel (1.0.2) method_source (1.0.0) mini_mime (1.1.5) + mini_portile2 (2.8.5) minitest (5.20.0) minitest-reporters (1.6.1) ansi @@ -125,16 +121,15 @@ GEM net-protocol nio4r (2.5.9) nio4r (2.5.9-java) + nokogiri (1.15.4) + mini_portile2 (~> 2.8.2) + racc (~> 1.4) nokogiri (1.15.4-arm64-darwin) racc (~> 1.4) nokogiri (1.15.4-java) racc (~> 1.4) nokogiri (1.15.4-x86_64-linux) racc (~> 1.4) - parallel (1.23.0) - parser (3.2.2.4) - ast (~> 2.4.1) - racc racc (1.7.1) racc (1.7.1-java) rack (2.2.8) @@ -172,27 +167,11 @@ GEM rake (>= 12.2) thor (~> 1.0) zeitwerk (~> 2.5) - rainbow (3.1.1) rake (13.0.6) - regexp_parser (2.8.2) responders (3.1.1) actionpack (>= 5.2) railties (>= 5.2) rexml (3.2.6) - rubocop (1.57.1) - base64 (~> 0.1.1) - json (~> 2.3) - language_server-protocol (>= 3.17.0) - parallel (~> 1.10) - parser (>= 3.2.2.4) - rainbow (>= 2.2.2, < 4.0) - regexp_parser (>= 1.8, < 3.0) - rexml (>= 3.2.5, < 4.0) - rubocop-ast (>= 1.28.1, < 2.0) - ruby-progressbar (~> 1.7) - unicode-display_width (>= 2.4.0, < 3.0) - rubocop-ast (1.29.0) - parser (>= 3.2.1.0) ruby-progressbar (1.13.0) ruby2_keywords (0.0.5) simplecov (0.22.0) @@ -208,7 +187,6 @@ GEM timeout (0.4.0) tzinfo (2.0.6) concurrent-ruby (~> 1.0) - unicode-display_width (2.5.0) websocket-driver (0.7.6) websocket-extensions (>= 0.1.0) websocket-driver (0.7.6-java) @@ -219,6 +197,7 @@ GEM PLATFORMS arm64-darwin-22 java + ruby x86_64-linux DEPENDENCIES @@ -228,7 +207,6 @@ DEPENDENCIES mocha rails (~> 7.0.0) rails-controller-testing - rubocop simplecov simplecov-cobertura diff --git a/lib/inherited_resources/blank_slate.rb b/lib/inherited_resources/blank_slate.rb index 96b9bae1..35400f9e 100644 --- a/lib/inherited_resources/blank_slate.rb +++ b/lib/inherited_resources/blank_slate.rb @@ -4,7 +4,7 @@ module InheritedResources # An object from BlankSlate simply discards all messages sent to it. class BlankSlate instance_methods.each do |m| - undef_method m unless m =~ /^(__|object_id)/ + undef_method m unless /^(__|object_id)/.match?(m) end def method_missing(*args) diff --git a/lib/inherited_resources/class_methods.rb b/lib/inherited_resources/class_methods.rb index 0f61b2e2..7ad9d770 100644 --- a/lib/inherited_resources/class_methods.rb +++ b/lib/inherited_resources/class_methods.rb @@ -55,7 +55,7 @@ def defaults(options) config[:request_name] = begin request_name = self.resource_class request_name = request_name.model_name.param_key if request_name.respond_to?(:model_name) - request_name.to_s.underscore.gsub('/', '_') + request_name.to_s.underscore.tr('/', '_') end options.delete(:resource_class) and options.delete(:class_name) end @@ -217,7 +217,7 @@ def belongs_to(*symbols, &block) config[:finder] = finder || :find end - if block_given? + if block class_eval(&block) else create_resources_url_helpers! @@ -229,7 +229,7 @@ def belongs_to(*symbols, &block) # def polymorphic_belongs_to(*symbols, &block) options = symbols.extract_options! - options.merge!(polymorphic: true) + options[:polymorphic] = true belongs_to(*symbols, options, &block) end @@ -237,7 +237,7 @@ def polymorphic_belongs_to(*symbols, &block) # def singleton_belongs_to(*symbols, &block) options = symbols.extract_options! - options.merge!(singleton: true) + options[:singleton] = true belongs_to(*symbols, options, &block) end @@ -245,7 +245,7 @@ def singleton_belongs_to(*symbols, &block) # def optional_belongs_to(*symbols, &block) options = symbols.extract_options! - options.merge!(optional: true) + options[:optional] = true belongs_to(*symbols, options, &block) end @@ -386,7 +386,7 @@ def initialize_resources_class_accessors! #:nodoc: # Forum::Thread#create will properly pick up the request parameter # which will be forum_thread, and not thread # Additionally make this work orthogonally with instance_name - config[:request_name] = self.resource_class.to_s.underscore.gsub('/', '_') + config[:request_name] = self.resource_class.to_s.underscore.tr('/', '_') # Initialize polymorphic, singleton, scopes and belongs_to parameters polymorphic = self.resources_configuration[:polymorphic] || { symbols: [], optional: false } diff --git a/lib/inherited_resources/shallow_helpers.rb b/lib/inherited_resources/shallow_helpers.rb index 6b8b2619..dff19cfb 100644 --- a/lib/inherited_resources/shallow_helpers.rb +++ b/lib/inherited_resources/shallow_helpers.rb @@ -35,7 +35,7 @@ def symbols_for_association_chain #:nodoc: end def load_parents(instance, parent_symbols) - parent_symbols.reverse.each do |parent| + parent_symbols.reverse_each do |parent| instance = instance.send(parent) config = resources_configuration[parent] params[config[:param]] = instance.to_param diff --git a/test/url_helpers_test.rb b/test/url_helpers_test.rb index dfe9fdcd..3fa1110f 100644 --- a/test/url_helpers_test.rb +++ b/test/url_helpers_test.rb @@ -106,7 +106,7 @@ class Spot < ModelBase end class SpotsController < InheritedResources::Base belongs_to :house do - belongs_to :dishwasher, singleton: true do + singleton_belongs_to :dishwasher do polymorphic_belongs_to :dish, :fork end end @@ -161,7 +161,7 @@ def mock_polymorphic(controller, route) def test_url_helpers_on_simple_inherited_resource controller = HousesController.new - controller.instance_variable_set('@house', :house) + controller.instance_variable_set(:@house, :house) [:url, :path].each do |path_or_url| controller.expects("houses_#{path_or_url}").with({}).once @@ -191,7 +191,7 @@ def test_url_helpers_on_simple_inherited_resource def test_url_helpers_on_simple_inherited_resource_using_uncountable controller = NewsController.new - controller.instance_variable_set('@news', :news) + controller.instance_variable_set(:@news, :news) [:url, :path].each do |path_or_url| controller.expects("news_index_#{path_or_url}").with({}).once @@ -221,7 +221,7 @@ def test_url_helpers_on_simple_inherited_resource_using_uncountable def test_url_helpers_on_simple_inherited_namespaced_resource controller = Admin::BackpacksController.new - controller.instance_variable_set('@backpack', :backpack) + controller.instance_variable_set(:@backpack, :backpack) assert_equal :admin, controller.class.resources_configuration[:self][:route_prefix] @@ -253,7 +253,7 @@ def test_url_helpers_on_simple_inherited_namespaced_resource def test_url_helpers_on_simple_inherited_singleton_resource controller = UniversesController.new - controller.instance_variable_set('@universe', :universe) + controller.instance_variable_set(:@universe, :universe) [:url, :path].each do |path_or_url| controller.expects("root_#{path_or_url}").with({}).once @@ -277,9 +277,9 @@ def test_url_helpers_on_simple_inherited_singleton_resource def test_url_helpers_on_singleton_belongs_to controller = FlamesController.new - controller.instance_variable_set('@house', :house) - controller.instance_variable_set('@fireplace', :fireplace) - controller.instance_variable_set('@flame', :flame) + controller.instance_variable_set(:@house, :house) + controller.instance_variable_set(:@fireplace, :fireplace) + controller.instance_variable_set(:@flame, :flame) [:url, :path].each do |path_or_url| controller.expects("house_fireplace_flames_#{path_or_url}").with(:house, {}).once @@ -309,8 +309,8 @@ def test_url_helpers_on_singleton_belongs_to def test_url_helpers_on_belongs_to controller = TablesController.new - controller.instance_variable_set('@house', :house) - controller.instance_variable_set('@table', :table) + controller.instance_variable_set(:@house, :house) + controller.instance_variable_set(:@table, :table) [:url, :path].each do |path_or_url| controller.expects("house_tables_#{path_or_url}").with(:house, {}).once @@ -349,8 +349,8 @@ def test_url_helpers_on_belongs_to def test_url_helpers_on_not_default_belongs_to controller = RoomsController.new - controller.instance_variable_set('@house', :house) - controller.instance_variable_set('@room', :room) + controller.instance_variable_set(:@house, :house) + controller.instance_variable_set(:@room, :room) [:url, :path].each do |path_or_url| controller.expects("big_house_rooms_#{path_or_url}").with(:house, {}).once @@ -389,9 +389,9 @@ def test_url_helpers_on_not_default_belongs_to def test_url_helpers_on_nested_belongs_to controller = ChairsController.new - controller.instance_variable_set('@house', :house) - controller.instance_variable_set('@table', :table) - controller.instance_variable_set('@chair', :chair) + controller.instance_variable_set(:@house, :house) + controller.instance_variable_set(:@table, :table) + controller.instance_variable_set(:@chair, :chair) [:url, :path].each do |path_or_url| controller.expects("house_table_chairs_#{path_or_url}").with(:house, :table, {}).once @@ -430,8 +430,8 @@ def test_url_helpers_on_nested_belongs_to def test_url_helpers_on_singletons_with_belongs_to controller = OwnersController.new - controller.instance_variable_set('@house', :house) - controller.instance_variable_set('@owner', :owner) + controller.instance_variable_set(:@house, :house) + controller.instance_variable_set(:@owner, :owner) [:url, :path].each do |path_or_url| controller.expects("house_#{path_or_url}").with(:house, {}).once @@ -472,11 +472,11 @@ def test_url_helpers_on_singleton_and_polymorphic_belongs_to new_spot.stubs(:persisted?).returns(false) controller = SpotsController.new - controller.instance_variable_set('@parent_type', :fork) - controller.instance_variable_set('@house', house) - controller.instance_variable_set('@dishwasher', dishwasher) - controller.instance_variable_set('@fork', fork) - controller.instance_variable_set('@spot', spot) + controller.instance_variable_set(:@parent_type, :fork) + controller.instance_variable_set(:@house, house) + controller.instance_variable_set(:@dishwasher, dishwasher) + controller.instance_variable_set(:@fork, fork) + controller.instance_variable_set(:@spot, spot) [:url, :path].each do |path_or_url| mock_polymorphic(controller, "house_dishwasher_fork_spots_#{path_or_url}").with(house, fork).once @@ -510,9 +510,9 @@ def test_url_helpers_on_polymorphic_belongs_to new_bed.stubs(:persisted?).returns(false) controller = BedsController.new - controller.instance_variable_set('@parent_type', :house) - controller.instance_variable_set('@house', house) - controller.instance_variable_set('@bed', bed) + controller.instance_variable_set(:@parent_type, :house) + controller.instance_variable_set(:@house, house) + controller.instance_variable_set(:@bed, bed) [:url, :path].each do |path_or_url| mock_polymorphic(controller, "house_beds_#{path_or_url}").with(house).once @@ -536,23 +536,23 @@ def test_url_helpers_on_polymorphic_belongs_to # With options mock_polymorphic(controller, "house_bed_url").with(house, bed, page: 1).once - controller.send("resource_url", page: 1) + controller.send(:resource_url, page: 1) mock_polymorphic(controller, "house_url").with(house, page: 1).once - controller.send("parent_url", page: 1) + controller.send(:parent_url, page: 1) # With args controller.expects("polymorphic_url").with([:arg, new_bed], {}).once - controller.send("collection_url", :arg) + controller.send(:collection_url, :arg) controller.expects("polymorphic_url").with([house, :arg], {}).once - controller.send("resource_url", :arg) + controller.send(:resource_url, :arg) controller.expects("edit_polymorphic_url").with([house, :arg], {}).once - controller.send("edit_resource_url", :arg) + controller.send(:edit_resource_url, :arg) controller.expects("polymorphic_url").with([:arg], {}).once - controller.send("parent_url", :arg) + controller.send(:parent_url, :arg) end def test_url_helpers_on_polymorphic_belongs_to_using_uncountable @@ -566,9 +566,9 @@ def test_url_helpers_on_polymorphic_belongs_to_using_uncountable new_sheep.stubs(:persisted?).returns(false) controller = SheepController.new - controller.instance_variable_set('@parent_type', :news) - controller.instance_variable_set('@news', news) - controller.instance_variable_set('@sheep', sheep) + controller.instance_variable_set(:@parent_type, :news) + controller.instance_variable_set(:@news, news) + controller.instance_variable_set(:@sheep, sheep) [:url, :path].each do |path_or_url| mock_polymorphic(controller, "news_sheep_index_#{path_or_url}").with(news).once @@ -592,23 +592,23 @@ def test_url_helpers_on_polymorphic_belongs_to_using_uncountable # With options mock_polymorphic(controller, "news_sheep_url").with(news, sheep, page: 1).once - controller.send("resource_url", page: 1) + controller.send(:resource_url, page: 1) mock_polymorphic(controller, "news_url").with(news, page: 1).once - controller.send("parent_url", page: 1) + controller.send(:parent_url, page: 1) # With args controller.expects("polymorphic_url").with([:arg, new_sheep], {}).once - controller.send("collection_url", :arg) + controller.send(:collection_url, :arg) controller.expects("polymorphic_url").with([news, :arg], {}).once - controller.send("resource_url", :arg) + controller.send(:resource_url, :arg) controller.expects("edit_polymorphic_url").with([news, :arg], {}).once - controller.send("edit_resource_url", :arg) + controller.send(:edit_resource_url, :arg) controller.expects("polymorphic_url").with([:arg], {}).once - controller.send("parent_url", :arg) + controller.send(:parent_url, :arg) end def test_url_helpers_on_shallow_belongs_to_using_uncountable @@ -620,8 +620,8 @@ def test_url_helpers_on_shallow_belongs_to_using_uncountable Sheep.stubs(:new).returns(new_fish) controller = FishController.new - controller.instance_variable_set('@bed', bed) - controller.instance_variable_set('@fish', fish) + controller.instance_variable_set(:@bed, bed) + controller.instance_variable_set(:@fish, fish) [:url, :path].each do |path_or_url| controller.expects("bed_fish_index_#{path_or_url}").with(bed, {}).once @@ -655,9 +655,9 @@ def test_url_helpers_on_namespaced_polymorphic_belongs_to new_desk.stubs(:persisted?).returns(false) controller = Admin::DesksController.new - controller.instance_variable_set('@parent_type', :house) - controller.instance_variable_set('@house', house) - controller.instance_variable_set('@desk', desk) + controller.instance_variable_set(:@parent_type, :house) + controller.instance_variable_set(:@house, house) + controller.instance_variable_set(:@desk, desk) [:url, :path].each do |path_or_url| mock_polymorphic(controller, "admin_house_desks_#{path_or_url}").with(house).once @@ -681,23 +681,23 @@ def test_url_helpers_on_namespaced_polymorphic_belongs_to # With options mock_polymorphic(controller, "admin_house_desk_url").with(house, desk, page: 1).once - controller.send("resource_url", page: 1) + controller.send(:resource_url, page: 1) mock_polymorphic(controller, "admin_house_url").with(house, page: 1).once - controller.send("parent_url", page: 1) + controller.send(:parent_url, page: 1) # With args controller.expects("polymorphic_url").with([:admin, :arg, new_desk], {}).once - controller.send("collection_url", :arg) + controller.send(:collection_url, :arg) controller.expects("polymorphic_url").with([:admin, house, :arg], {}).once - controller.send("resource_url", :arg) + controller.send(:resource_url, :arg) controller.expects("edit_polymorphic_url").with([:admin, house, :arg], {}).once - controller.send("edit_resource_url", :arg) + controller.send(:edit_resource_url, :arg) controller.expects("polymorphic_url").with([:admin, :arg], {}).once - controller.send("parent_url", :arg) + controller.send(:parent_url, :arg) end def test_url_helpers_on_nested_polymorphic_belongs_to @@ -712,10 +712,10 @@ def test_url_helpers_on_nested_polymorphic_belongs_to new_dish.stubs(:persisted?).returns(false) controller = DishesController.new - controller.instance_variable_set('@parent_type', :table) - controller.instance_variable_set('@house', house) - controller.instance_variable_set('@table', table) - controller.instance_variable_set('@dish', dish) + controller.instance_variable_set(:@parent_type, :table) + controller.instance_variable_set(:@house, house) + controller.instance_variable_set(:@table, table) + controller.instance_variable_set(:@dish, dish) [:url, :path].each do |path_or_url| mock_polymorphic(controller, "house_table_dishes_#{path_or_url}").with(house, table).once @@ -739,20 +739,20 @@ def test_url_helpers_on_nested_polymorphic_belongs_to # With options mock_polymorphic(controller, "house_table_dish_url").with(house, table, dish, page: 1).once - controller.send("resource_url", page: 1) + controller.send(:resource_url, page: 1) mock_polymorphic(controller, "house_table_url").with(house, table, page: 1).once - controller.send("parent_url", page: 1) + controller.send(:parent_url, page: 1) # With args controller.expects("polymorphic_url").with([house, table, :arg], {}).once - controller.send("resource_url", :arg) + controller.send(:resource_url, :arg) controller.expects("edit_polymorphic_url").with([house, table, :arg], {}).once - controller.send("edit_resource_url", :arg) + controller.send(:edit_resource_url, :arg) controller.expects("polymorphic_url").with([house, :arg], {}).once - controller.send("parent_url", :arg) + controller.send(:parent_url, :arg) end def test_url_helpers_on_singleton_nested_polymorphic_belongs_to @@ -764,9 +764,9 @@ def test_url_helpers_on_singleton_nested_polymorphic_belongs_to table.stubs(:persisted?).returns(true) controller = CentersController.new - controller.instance_variable_set('@parent_type', :table) - controller.instance_variable_set('@house', house) - controller.instance_variable_set('@table', table) + controller.instance_variable_set(:@parent_type, :table) + controller.instance_variable_set(:@house, house) + controller.instance_variable_set(:@table, table) # This must not be useful in singleton controllers... # controller.instance_variable_set('@center', :center) @@ -793,17 +793,17 @@ def test_url_helpers_on_singleton_nested_polymorphic_belongs_to # With options mock_polymorphic(controller, "house_table_center_url").with(house, table, page: 1) - controller.send("resource_url", page: 1) + controller.send(:resource_url, page: 1) mock_polymorphic(controller, "house_table_url").with(house, table, page: 1) - controller.send("parent_url", page: 1) + controller.send(:parent_url, page: 1) # With args controller.expects("polymorphic_url").with([house, table, :center], {}).once - controller.send("resource_url", :arg) + controller.send(:resource_url, :arg) controller.expects("polymorphic_url").with([house, :arg], {}).once - controller.send("parent_url", :arg) + controller.send(:parent_url, :arg) end def test_url_helpers_on_optional_polymorphic_belongs_to @@ -815,7 +815,7 @@ def test_url_helpers_on_optional_polymorphic_belongs_to controller = BedsController.new controller.stubs(:parent_type).returns(nil) - controller.instance_variable_set('@bed', bed) + controller.instance_variable_set(:@bed, bed) [:url, :path].each do |path_or_url| mock_polymorphic(controller, "beds_#{path_or_url}").with().once @@ -833,20 +833,20 @@ def test_url_helpers_on_optional_polymorphic_belongs_to # With options mock_polymorphic(controller, "bed_url").with(bed, page: 1).once - controller.send("resource_url", page: 1) + controller.send(:resource_url, page: 1) # With args controller.expects("polymorphic_url").with([:arg], {}).once - controller.send("resource_url", :arg) + controller.send(:resource_url, :arg) controller.expects("edit_polymorphic_url").with([:arg], {}).once - controller.send("edit_resource_url", :arg) + controller.send(:edit_resource_url, :arg) end def test_url_helpers_on_belongs_to_with_shallowed_route controller = MirrorsController.new - controller.instance_variable_set('@house', :house) - controller.instance_variable_set('@mirror', :mirror) + controller.instance_variable_set(:@house, :house) + controller.instance_variable_set(:@mirror, :mirror) [:url, :path].each do |path_or_url| controller.expects("house_mirrors_#{path_or_url}").with(:house, {}).once @@ -871,9 +871,9 @@ def test_url_helpers_on_belongs_to_with_shallowed_route def test_url_helpers_on_nested_belongs_to_with_shallowed_route controller = ButtonsController.new - controller.instance_variable_set('@display', :display) - controller.instance_variable_set('@window', :window) - controller.instance_variable_set('@button', :button) + controller.instance_variable_set(:@display, :display) + controller.instance_variable_set(:@window, :window) + controller.instance_variable_set(:@button, :button) [:url, :path].each do |path_or_url| controller.expects("window_buttons_#{path_or_url}").with(:window, {}).once @@ -898,9 +898,9 @@ def test_url_helpers_on_nested_belongs_to_with_shallowed_route def test_url_helpers_with_custom_actions controller = ButtonsController.new - controller.instance_variable_set('@display', :display) - controller.instance_variable_set('@window', :window) - controller.instance_variable_set('@button', :button) + controller.instance_variable_set(:@display, :display) + controller.instance_variable_set(:@window, :window) + controller.instance_variable_set(:@button, :button) [:url, :path].each do |path_or_url| controller.expects("delete_button_#{path_or_url}").with(:button, {}).once controller.send("delete_resource_#{path_or_url}") @@ -922,15 +922,15 @@ def test_helper_methods_with_custom_actions def test_helpers_on_inherited_controller controller = ImageButtonsController.new controller.expects("edit_image_button_path").once - controller.send("edit_resource_path") + controller.send(:edit_resource_path) controller.expects("delete_image_button_path").once - controller.send("delete_resource_path") + controller.send(:delete_resource_path) end def test_url_helpers_on_namespaced_resource_with_shallowed_route controller = Admin::MirrorsController.new - controller.instance_variable_set('@house', :house) - controller.instance_variable_set('@mirror', :mirror) + controller.instance_variable_set(:@house, :house) + controller.instance_variable_set(:@mirror, :mirror) [:url, :path].each do |path_or_url| @@ -959,7 +959,7 @@ def test_url_helpers_with_action_controller_parameters parameters.permit! controller = HousesController.new - controller.instance_variable_set('@house', :house) + controller.instance_variable_set(:@house, :house) [:url, :path].each do |path_or_url| controller.expects("houses_#{path_or_url}").with({'page' => 2}).once