1
0
Fork 0
mirror of https://github.com/heartcombo/devise.git synced 2022-11-09 12:18:31 -05:00

Refactoring simulation inside engine to decide based on the api

This commit is contained in:
Rodrigo Flores 2012-05-02 14:51:01 -03:00
parent 34a64070ca
commit 525bcd4e2d

View file

@ -41,16 +41,28 @@ if DEVISE_ORM == :active_record
end end
end end
def simulate_inside_engine(engine, namespace)
if Rails::Generators.respond_to?(:namespace=)
swap Rails::Generators, :namespace => namespace do
yield
end
else
swap Rails, :application => engine.instance do
yield
end
end
end
class ActiveRecordEngineGeneratorTest < Rails::Generators::TestCase class ActiveRecordEngineGeneratorTest < Rails::Generators::TestCase
tests ActiveRecord::Generators::DeviseGenerator tests ActiveRecord::Generators::DeviseGenerator
destination File.expand_path("../../tmp", __FILE__) destination File.expand_path("../../tmp", __FILE__)
setup :prepare_destination setup :prepare_destination
test "all files are properly created" do test "all files are properly created" do
swap Rails, :application => RailsEngine::Engine.instance do simulate_inside_engine(RailsEngine::Engine, RailsEngine) do
run_generator ["monster"] run_generator ["monster"]
assert_file "app/models/rails_engine/monster.rb", /devise/, /attr_accessible (:[a-z_]+(, )?)+/ assert_file "app/models/rails_engine/monster.rb", /devise/,/attr_accessible (:[a-z_]+(, )?)+/
end end
end end
end end