mirror of
https://github.com/heartcombo/devise.git
synced 2022-11-09 12:18:31 -05:00
Do not generate attr_accessible for any Rails 4 app
This commit is contained in:
parent
7539d31a05
commit
cd1bc53947
2 changed files with 5 additions and 25 deletions
|
@ -19,11 +19,7 @@ CONTENT
|
|||
end
|
||||
|
||||
def needs_attr_accessible?
|
||||
if rails_3?
|
||||
!strong_parameters_enabled?
|
||||
else
|
||||
protected_attributes_enabled?
|
||||
end
|
||||
rails_3? && !strong_parameters_enabled?
|
||||
end
|
||||
|
||||
def rails_3?
|
||||
|
@ -34,18 +30,16 @@ CONTENT
|
|||
defined?(ActionController::StrongParameters)
|
||||
end
|
||||
|
||||
def protected_attributes_enabled?
|
||||
defined?(ActiveModel::MassAssignmentSecurity)
|
||||
end
|
||||
private
|
||||
|
||||
def model_exists?
|
||||
File.exists?(File.join(destination_root, model_path))
|
||||
end
|
||||
|
||||
|
||||
def migration_exists?(table_name)
|
||||
Dir.glob("#{File.join(destination_root, migration_path)}/[0-9]*_*.rb").grep(/\d+_add_devise_to_#{table_name}.rb$/).first
|
||||
end
|
||||
|
||||
|
||||
def migration_path
|
||||
@migration_path ||= File.join("db", "migrate")
|
||||
end
|
||||
|
|
|
@ -62,9 +62,8 @@ if DEVISE_ORM == :active_record
|
|||
destination File.expand_path("../../tmp", __FILE__)
|
||||
setup :prepare_destination
|
||||
|
||||
test "all files are properly created in rails 4.0 without the protected_attributes gem" do
|
||||
test "all files are properly created in rails 4.0" do
|
||||
ActiveRecord::Generators::DeviseGenerator.any_instance.stubs(:rails_3?).returns(false)
|
||||
ActiveRecord::Generators::DeviseGenerator.any_instance.stubs(:protected_attributes_enabled?).returns(false)
|
||||
simulate_inside_engine(RailsEngine::Engine, RailsEngine) do
|
||||
run_generator ["monster"]
|
||||
|
||||
|
@ -75,19 +74,6 @@ if DEVISE_ORM == :active_record
|
|||
end
|
||||
end
|
||||
|
||||
test "all files are properly created in rails 4.0 when the protected_attributes gem is installed" do
|
||||
ActiveRecord::Generators::DeviseGenerator.any_instance.stubs(:rails_3?).returns(false)
|
||||
ActiveRecord::Generators::DeviseGenerator.any_instance.stubs(:protected_attributes_enabled?).returns(true)
|
||||
simulate_inside_engine(RailsEngine::Engine, RailsEngine) do
|
||||
run_generator ["monster"]
|
||||
|
||||
assert_file "app/models/rails_engine/monster.rb", /devise/
|
||||
assert_file "app/models/rails_engine/monster.rb" do |content|
|
||||
assert_match /attr_accessible :email/, content
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
test "all files are properly created in rails 3.2 when strong_parameters gem is not installed" do
|
||||
ActiveRecord::Generators::DeviseGenerator.any_instance.stubs(:rails_3?).returns(true)
|
||||
ActiveRecord::Generators::DeviseGenerator.any_instance.stubs(:strong_parameters_enabled?).returns(false)
|
||||
|
|
Loading…
Reference in a new issue