From caf90765f3119d1f60bcf0eb6bbf3487d5e51e40 Mon Sep 17 00:00:00 2001 From: Louis Rose Date: Tue, 6 May 2014 14:43:28 +0100 Subject: [PATCH] Remove scripts that automate the where(...).first to find_by(...)refactoring. This reverts commit f1369e4503256fde9854a0c2f310bc824a3ee9f2. --- Gemfile | 1 - .../where_dot_first_to_find_by/app.rb | 50 ------------------- .../refactorers/refactor_where_first_mocks.rb | 31 ------------ ...tor_where_first_not_called_expectations.rb | 14 ------ .../refactor_where_first_strict_mocks.rb | 27 ---------- .../refactor_where_first_to_find_by.rb | 14 ------ 6 files changed, 137 deletions(-) delete mode 100644 refactorings/where_dot_first_to_find_by/app.rb delete mode 100644 refactorings/where_dot_first_to_find_by/refactorers/refactor_where_first_mocks.rb delete mode 100644 refactorings/where_dot_first_to_find_by/refactorers/refactor_where_first_not_called_expectations.rb delete mode 100644 refactorings/where_dot_first_to_find_by/refactorers/refactor_where_first_strict_mocks.rb delete mode 100644 refactorings/where_dot_first_to_find_by/refactorers/refactor_where_first_to_find_by.rb diff --git a/Gemfile b/Gemfile index 192f350a0f6..f6df068e2a2 100644 --- a/Gemfile +++ b/Gemfile @@ -188,7 +188,6 @@ group :development do gem 'librarian', '>= 0.0.25', require: false gem 'annotate' gem 'foreman', require: false - gem 'metamorpher', '~> 0.1.0' end # Gem that enables support for plugins. It is required. diff --git a/refactorings/where_dot_first_to_find_by/app.rb b/refactorings/where_dot_first_to_find_by/app.rb deleted file mode 100644 index 7645623eea6..00000000000 --- a/refactorings/where_dot_first_to_find_by/app.rb +++ /dev/null @@ -1,50 +0,0 @@ -require "optparse" -require_relative "refactorers/refactor_where_first_to_find_by.rb" -require_relative "refactorers/refactor_where_first_not_called_expectations.rb" -require_relative "refactorers/refactor_where_first_mocks.rb" -require_relative "refactorers/refactor_where_first_strict_mocks.rb" - -options = { overwrite: true } -OptionParser.new do |opts| - opts.banner = "Usage: refactorer.rb [options]" - - opts.on("-d", "--dry-run", "Write changes to console, rather than to source files.") do |v| - options[:overwrite] = false - end -end.parse! - -source_dir = ARGV.first || "." -base = File.expand_path(File.join("**", "*.rb"), source_dir) -puts "Refactoring in source directory: #{base}" - -[ - # Refactor "where(...).first -> find_by(...)" - RefactorWhereFirstToFindBy, - - # Refactor ".expect(:where).never" to ".expect(:find_by).never" - RefactorWhereFirstNotCalledExpectations, - - # Refactor ".expect(:where).return([X])" to ".expect(:find_by).return(X)" - # and ".stubs(:where).return([X])" to ".stubs(:find_by).return(X)" - RefactorWhereFirstMocks, - - # Refactor ".expect(:where).with(...).return([X])" to ".expect(:find_by).with(...).return(X)" - RefactorWhereFirstStrictMocks - -].each do |refactorer| - refactorer.new.refactor_files(Dir.glob(base)) do |path, refactored, changes| - if changes.empty? - puts "No changes in #{path}" - - else - puts "In #{path}:" - - changes.each do |change| - puts "\tAt #{change.original_position}, inserting:\n\t\t#{change.refactored_code}" - puts "" - end - - File.open(path, "w") { |f| f.write(refactored) } if options[:overwrite] - end - end -end diff --git a/refactorings/where_dot_first_to_find_by/refactorers/refactor_where_first_mocks.rb b/refactorings/where_dot_first_to_find_by/refactorers/refactor_where_first_mocks.rb deleted file mode 100644 index 628fdaa3a30..00000000000 --- a/refactorings/where_dot_first_to_find_by/refactorers/refactor_where_first_mocks.rb +++ /dev/null @@ -1,31 +0,0 @@ -require "metamorpher" - -class RefactorWhereFirstMocks - include Metamorpher::Refactorer - include Metamorpher::Builders::Ruby - - def pattern - builder - .build("TYPE.DOUBLE_METHOD(:where).returns(ARRAY_VALUE)") - .ensuring("DOUBLE_METHOD") { |m| m.name == :expects || m.name == :stubs } - .ensuring("ARRAY_VALUE") { |v| v.name == :array } - # Doesn't match non-array return types, such as Topic.stubs(:where).returns(Topic) - end - - def replacement - builder - .build("TYPE.DOUBLE_METHOD(:find_by).returns(SINGLE_VALUE)") - .deriving("SINGLE_VALUE", "ARRAY_VALUE") { |array_value| take_first(array_value) } - end - - private - - # Refactor the argument from [] to nil, or from [X] to X - def take_first(array_value) - if array_value.children.empty? - builder.build("nil") - else - array_value.children.first - end - end -end diff --git a/refactorings/where_dot_first_to_find_by/refactorers/refactor_where_first_not_called_expectations.rb b/refactorings/where_dot_first_to_find_by/refactorers/refactor_where_first_not_called_expectations.rb deleted file mode 100644 index 6edf5f4e8c7..00000000000 --- a/refactorings/where_dot_first_to_find_by/refactorers/refactor_where_first_not_called_expectations.rb +++ /dev/null @@ -1,14 +0,0 @@ -require "metamorpher" - -class RefactorWhereFirstNotCalledExpectations - include Metamorpher::Refactorer - include Metamorpher::Builders::Ruby - - def pattern - builder.build("TYPE.expects(:where).never") - end - - def replacement - builder.build("TYPE.expects(:find_by).never") - end -end diff --git a/refactorings/where_dot_first_to_find_by/refactorers/refactor_where_first_strict_mocks.rb b/refactorings/where_dot_first_to_find_by/refactorers/refactor_where_first_strict_mocks.rb deleted file mode 100644 index 51470f2b2e8..00000000000 --- a/refactorings/where_dot_first_to_find_by/refactorers/refactor_where_first_strict_mocks.rb +++ /dev/null @@ -1,27 +0,0 @@ -require "metamorpher" - -class RefactorWhereFirstStrictMocks - include Metamorpher::Refactorer - include Metamorpher::Builders::Ruby - - def pattern - builder.build("TYPE.expects(:where).with(PARAMS_).returns(ARRAY_VALUE)") - end - - def replacement - builder - .build("TYPE.expects(:find_by).with(PARAMS_).returns(SINGLE_VALUE)") - .deriving("SINGLE_VALUE", "ARRAY_VALUE") { |array_value| take_first(array_value) } - end - - private - - # Refactor the argument from [] to nil, or from [X] to X - def take_first(array_value) - if array_value.children.empty? - builder.build("nil") - else - array_value.children.first - end - end -end diff --git a/refactorings/where_dot_first_to_find_by/refactorers/refactor_where_first_to_find_by.rb b/refactorings/where_dot_first_to_find_by/refactorers/refactor_where_first_to_find_by.rb deleted file mode 100644 index 4632deeba0a..00000000000 --- a/refactorings/where_dot_first_to_find_by/refactorers/refactor_where_first_to_find_by.rb +++ /dev/null @@ -1,14 +0,0 @@ -require "metamorpher" - -class RefactorWhereFirstToFindBy - include Metamorpher::Refactorer - include Metamorpher::Builders::Ruby - - def pattern - builder.build("TYPE.where(PARAMS_).first") - end - - def replacement - builder.build("TYPE.find_by(PARAMS_)") - end -end