diff options
author | Michael Koziarski <michael@koziarski.com> | 2012-03-05 11:12:01 +1300 |
---|---|---|
committer | Michael Koziarski <michael@koziarski.com> | 2012-03-05 11:25:25 +1300 |
commit | 641a4f62405cc2765424320932902ed8076b5d38 (patch) | |
tree | c577b8d05d015f19a031a10bfce6ecb5dbccbadb /railties | |
parent | c8f6025fd37c7b5c8922b11eb5ceba22e4650b59 (diff) | |
download | rails-641a4f62405cc2765424320932902ed8076b5d38.tar.gz rails-641a4f62405cc2765424320932902ed8076b5d38.tar.bz2 rails-641a4f62405cc2765424320932902ed8076b5d38.zip |
Whitelist all attribute assignment by default.
Change the default for newly generated applications to whitelist all attribute assignment. Also update the generated model classes so users are reminded of the importance of attr_accessible.
Diffstat (limited to 'railties')
-rw-r--r-- | railties/lib/rails/generators/rails/app/templates/config/application.rb | 2 | ||||
-rw-r--r-- | railties/test/generators/model_generator_test.rb | 10 |
2 files changed, 11 insertions, 1 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 acf47a03e5..03242a3bef 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 + 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/model_generator_test.rb b/railties/test/generators/model_generator_test.rb index 156fa86eee..e8d933935d 100644 --- a/railties/test/generators/model_generator_test.rb +++ b/railties/test/generators/model_generator_test.rb @@ -317,4 +317,14 @@ class ModelGeneratorTest < Rails::Generators::TestCase end end end + + def test_attr_accessible_added_with_non_reference_attributes + run_generator + assert_file 'app/models/account.rb', /attr_accessible :age, :name/ + end + + def test_attr_accessible_added_with_comments_when_no_attributes_present + run_generator ["Account"] + assert_file 'app/models/account.rb', /# attr_accessible :title, :body/ + end end |