test/generators/scaffold_override_test.rb in ember-appkit-rails-0.3.2 vs test/generators/scaffold_override_test.rb in ember-appkit-rails-0.4.0
- old
+ new
@@ -65,30 +65,43 @@
assert_equal 1, content.scan(/v1/).size
assert_equal 1, content.scan(/v2/).size
end
end
+ test 'destroy does not remove any non-matching resources or namespaces' do
+ copy_routes_with_api_version_namespaces_and_route
+ config_content = File.read(File.expand_path('config/routes.rb', destination_root))
+ run_generator ['post'], behavior: :revoke
+
+ assert_file 'config/routes.rb' do |content|
+ assert_equal config_content, content
+ end
+ end
+
+ test 'destroy removes matching resources and namespaces' do
+ copy_routes_with_api_version_namespaces_and_route
+ config_content = File.read(File.expand_path('config/routes.rb', destination_root))
+ run_generator ['dogs'], behavior: :revoke
+
+ assert_file 'config/routes.rb' do |content|
+ refute_match(/ namespace :api do\n namespace :v1 do\n resource :dogs, except: \[:new, :edit\]\n end\n end/, content)
+ end
+ end
+
private
def reset_api_version
::Rails.application.config.ember.api_version = 1
end
- def copy_routes
- copy_routes_file("../../dummy/config/routes.rb")
- end
-
def copy_routes_with_api_namespace
copy_routes_file("../../fixtures/routes_with_api_namespace.rb")
end
def copy_routes_with_api_and_version_namespaces
copy_routes_file("../../fixtures/routes_with_api_and_version_namespaces.rb")
end
- def copy_routes_file(routes_destination)
- routes = File.expand_path(routes_destination, __FILE__)
- destination = File.expand_path('../../dummy/tmp/config', __FILE__)
- FileUtils.mkdir_p(destination)
- FileUtils.cp routes, File.join(destination, 'routes.rb')
+ def copy_routes_with_api_version_namespaces_and_route
+ copy_routes_file("../../fixtures/routes_with_api_version_namespaces_and_route.rb")
end
end