diff options
author | Jason Rush <diminish7@gmail.com> | 2012-04-05 13:21:48 -0600 |
---|---|---|
committer | Andrew White <andyw@pixeltrix.co.uk> | 2012-11-29 05:50:34 +0000 |
commit | 89b5b31cc4f8407f648a2447665ef23f9024e8a5 (patch) | |
tree | 721b47a8f33bf70851736164bf4a80cdd7c59e94 /activerecord/test/cases/forbidden_attributes_protection_test.rb | |
parent | eba430aecbce963f5b2d91ef6a9c36aec8c824bb (diff) | |
download | rails-89b5b31cc4f8407f648a2447665ef23f9024e8a5.tar.gz rails-89b5b31cc4f8407f648a2447665ef23f9024e8a5.tar.bz2 rails-89b5b31cc4f8407f648a2447665ef23f9024e8a5.zip |
Added STI support to init and building associations
Allows you to do BaseClass.new(:type => "SubClass") as well as
parent.children.build(:type => "SubClass") or parent.build_child
to initialize an STI subclass. Ensures that the class name is a
valid class and that it is in the ancestors of the super class
that the association is expecting.
Diffstat (limited to 'activerecord/test/cases/forbidden_attributes_protection_test.rb')
-rw-r--r-- | activerecord/test/cases/forbidden_attributes_protection_test.rb | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/activerecord/test/cases/forbidden_attributes_protection_test.rb b/activerecord/test/cases/forbidden_attributes_protection_test.rb index 9a2172f41e..490b599fb6 100644 --- a/activerecord/test/cases/forbidden_attributes_protection_test.rb +++ b/activerecord/test/cases/forbidden_attributes_protection_test.rb @@ -1,6 +1,7 @@ require 'cases/helper' require 'active_support/core_ext/hash/indifferent_access' require 'models/person' +require 'models/company' class ProtectedParams < ActiveSupport::HashWithIndifferentAccess attr_accessor :permitted @@ -40,6 +41,20 @@ class ForbiddenAttributesProtectionTest < ActiveRecord::TestCase assert_equal 'm', person.gender end + def test_forbidden_attributes_cannot_be_used_for_sti_inheritance_column + params = ProtectedParams.new(type: 'Client') + assert_raises(ActiveModel::ForbiddenAttributesError) do + Company.new(params) + end + end + + def test_permitted_attributes_can_be_used_for_sti_inheritance_column + params = ProtectedParams.new(type: 'Client') + params.permit! + person = Company.new(params) + assert_equal person.class, Client + end + def test_regular_hash_should_still_be_used_for_mass_assignment person = Person.new(first_name: 'Guille', gender: 'm') |