aboutsummaryrefslogtreecommitdiffstats
path: root/railties
diff options
context:
space:
mode:
authorRafael Mendonça França <rafaelmfranca@gmail.com>2012-03-04 20:53:59 -0300
committerRafael Mendonça França <rafaelmfranca@gmail.com>2012-03-04 21:02:28 -0300
commit5afb2f7b40d1712f2e9ec1a69062d6e9b175e639 (patch)
treeeca429afb9f067a72f22a4fa997d62894f36723d /railties
parent641a4f62405cc2765424320932902ed8076b5d38 (diff)
downloadrails-5afb2f7b40d1712f2e9ec1a69062d6e9b175e639.tar.gz
rails-5afb2f7b40d1712f2e9ec1a69062d6e9b175e639.tar.bz2
rails-5afb2f7b40d1712f2e9ec1a69062d6e9b175e639.zip
Only add the whitelist_attributes option if ActiveRecord is present
Diffstat (limited to 'railties')
-rw-r--r--railties/lib/rails/generators/rails/app/templates/config/application.rb2
-rw-r--r--railties/test/generators/app_generator_test.rb6
-rw-r--r--railties/test/isolation/abstract_unit.rb5
3 files changed, 11 insertions, 2 deletions
diff --git a/railties/lib/rails/generators/rails/app/templates/config/application.rb b/railties/lib/rails/generators/rails/app/templates/config/application.rb
index 03242a3bef..e47784994a 100644
--- a/railties/lib/rails/generators/rails/app/templates/config/application.rb
+++ b/railties/lib/rails/generators/rails/app/templates/config/application.rb
@@ -54,7 +54,7 @@ module <%= app_const_base %>
# 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
# 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
# an exception. If set to true, then an ActiveRecord::DeleteRestrictionError exception would be
diff --git a/railties/test/generators/app_generator_test.rb b/railties/test/generators/app_generator_test.rb
index a3c24c392b..cf6f9b90c9 100644
--- a/railties/test/generators/app_generator_test.rb
+++ b/railties/test/generators/app_generator_test.rb
@@ -202,6 +202,7 @@ class AppGeneratorTest < Rails::Generators::TestCase
run_generator [destination_root, "--skip-active-record"]
assert_no_file "config/database.yml"
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 "test/test_helper.rb" do |helper_content|
assert_no_match(/fixtures :all/, helper_content)
@@ -350,6 +351,11 @@ class AppGeneratorTest < Rails::Generators::TestCase
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
run_generator
assert_file "config/application.rb", /config\.active_record\.dependent_restrict_raises = false/
diff --git a/railties/test/isolation/abstract_unit.rb b/railties/test/isolation/abstract_unit.rb
index 4fb5e6a4eb..b0be555c4c 100644
--- a/railties/test/isolation/abstract_unit.rb
+++ b/railties/test/isolation/abstract_unit.rb
@@ -247,7 +247,10 @@ module TestHelpers
:activemodel,
:activerecord,
: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('|')})/' }
end