Skip to content

Commit

Permalink
Merge pull request #5275 from rafaelfranca/master
Browse files Browse the repository at this point in the history
Only add the whitelist_attributes option if ActiveRecord is present
  • Loading branch information
jonleighton committed Mar 5, 2012
2 parents 641a4f6 + 5afb2f7 commit db3d5f0
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
Expand Up @@ -54,7 +54,7 @@ class Application < Rails::Application
# This will create an empty whitelist of attributes available for mass-assignment for all models # This will create an empty whitelist of attributes available for mass-assignment for all models
# in your app. As such, your models will need to explicitly whitelist or blacklist accessible # in your app. As such, your models will need to explicitly whitelist or blacklist accessible
# parameters by using an attr_accessible or attr_protected declaration. # parameters by using an attr_accessible or attr_protected declaration.
config.active_record.whitelist_attributes = true <%= comment_if :skip_active_record %>config.active_record.whitelist_attributes = true


# Specifies wether or not has_many or has_one association option :dependent => :restrict raises # Specifies wether or not has_many or has_one association option :dependent => :restrict raises
# an exception. If set to true, then an ActiveRecord::DeleteRestrictionError exception would be # an exception. If set to true, then an ActiveRecord::DeleteRestrictionError exception would be
Expand Down
6 changes: 6 additions & 0 deletions railties/test/generators/app_generator_test.rb
Expand Up @@ -202,6 +202,7 @@ def test_generator_if_skip_active_record_is_given
run_generator [destination_root, "--skip-active-record"] run_generator [destination_root, "--skip-active-record"]
assert_no_file "config/database.yml" assert_no_file "config/database.yml"
assert_file "config/application.rb", /#\s+require\s+["']active_record\/railtie["']/ assert_file "config/application.rb", /#\s+require\s+["']active_record\/railtie["']/
assert_file "config/application.rb", /#\s+config\.active_record\.whitelist_attributes = true/
assert_file "config/application.rb", /#\s+config\.active_record\.dependent_restrict_raises = false/ assert_file "config/application.rb", /#\s+config\.active_record\.dependent_restrict_raises = false/
assert_file "test/test_helper.rb" do |helper_content| assert_file "test/test_helper.rb" do |helper_content|
assert_no_match(/fixtures :all/, helper_content) assert_no_match(/fixtures :all/, helper_content)
Expand Down Expand Up @@ -350,6 +351,11 @@ def test_generated_environments_file_for_auto_explain
end end
end end


def test_active_record_whitelist_attributes_is_present_application_config
run_generator
assert_file "config/application.rb", /config\.active_record\.whitelist_attributes = true/
end

def test_active_record_dependent_restrict_raises_is_present_application_config def test_active_record_dependent_restrict_raises_is_present_application_config
run_generator run_generator
assert_file "config/application.rb", /config\.active_record\.dependent_restrict_raises = false/ assert_file "config/application.rb", /config\.active_record\.dependent_restrict_raises = false/
Expand Down
5 changes: 4 additions & 1 deletion railties/test/isolation/abstract_unit.rb
Expand Up @@ -247,7 +247,10 @@ def use_frameworks(arr)
:activemodel, :activemodel,
:activerecord, :activerecord,
:activeresource] - arr :activeresource] - arr
remove_from_config "config.active_record.dependent_restrict_raises = false" if to_remove.include? :activerecord if to_remove.include? :activerecord
remove_from_config "config.active_record.whitelist_attributes = true"
remove_from_config "config.active_record.dependent_restrict_raises = false"
end
$:.reject! {|path| path =~ %r'/(#{to_remove.join('|')})/' } $:.reject! {|path| path =~ %r'/(#{to_remove.join('|')})/' }
end end


Expand Down

0 comments on commit db3d5f0

Please sign in to comment.