class RailsRefactorTest
Public Instance Methods
assert_file_changed(path, from, to)
click to toggle source
# File bin/rails_refactor.rb, line 125 def assert_file_changed(path, from, to) contents = File.read(path) assert contents.include?(to) assert !contents.include?(from) end
rename(from, to)
click to toggle source
# File bin/rails_refactor.rb, line 121 def rename(from, to) `../bin/rails_refactor.rb rename #{from} #{to}` end
setup()
click to toggle source
# File bin/rails_refactor.rb, line 111 def setup raise "Run tests in 'dummy' rails project" if !Dir.pwd.end_with? "dummy" end
teardown()
click to toggle source
# File bin/rails_refactor.rb, line 115 def teardown `git checkout .` `git clean -f` `rm -rf app/views/hello_world` end
test_controller_action_rename()
click to toggle source
# File bin/rails_refactor.rb, line 152 def test_controller_action_rename rename('DummiesController.index', 'new_action') assert_file_changed("app/controllers/dummies_controller.rb", "index", "new_action") assert File.exists?("app/views/dummies/new_action.html.erb") assert !File.exists?("app/views/dummies/index.html.erb") end
test_controller_rename()
click to toggle source
# File bin/rails_refactor.rb, line 159 def test_controller_rename rename("DummiesController", "HelloWorldController") assert File.exist?("app/controllers/hello_world_controller.rb") assert !File.exist?("app/controllers/dummies_controller.rb") assert File.exist?("app/views/hello_world/index.html.erb") assert !File.exist?("app/views/dummies/index.html.erb") assert_file_changed("app/controllers/hello_world_controller.rb", "DummiesController", "HelloWorldController") routes_contents = File.read("config/routes.rb") assert routes_contents.include?("hello_world") assert !routes_contents.include?("dummies") helper_contents = File.read("app/helpers/hello_world_helper.rb") assert helper_contents.include?("HelloWorldHelper") assert !helper_contents.include?("DummiesHelper") assert File.exist?("spec/controllers/hello_world_controller_spec.rb") assert !File.exist?("spec/controllers/dummies_controller_spec.rb") assert_file_changed("spec/controllers/hello_world_controller_spec.rb", "DummiesController", "HelloWorldController") end
test_model_rename()
click to toggle source
# File bin/rails_refactor.rb, line 131 def test_model_rename rename("DummyModel", "NewModel") assert File.exist?("app/models/new_model.rb") assert !File.exist?("app/models/dummy_model.rb") assert_file_changed("app/models/new_model.rb", "DummyModel", "NewModel") assert File.exist?("spec/models/new_model_spec.rb") assert !File.exist?("spec/models/dummy_model_spec.rb") assert_file_changed("spec/models/new_model_spec.rb", "DummyModel", "NewModel") assert File.exist?("db/migrate/20170214234158_create_new_models.rb") assert !File.exist?("db/migrate/20170214234158_create_dummy_models.rb") assert_file_changed("db/migrate/20170214234158_create_new_models.rb", "CreateDummies", "CreateNewModels") assert_file_changed("db/migrate/20170214234158_create_new_models.rb", ":dummy_models", ":new_models") end