Permalink
Browse files

Add test case to has_many through association when mass_assignment_sa…

…nitizer is

:strict

Conflicts:

	activerecord/test/models/person.rb
  • Loading branch information...
1 parent 94b2c8c commit 7cd4063162e47e28715cafc021241f14cf8a278d @rafaelfranca rafaelfranca committed Mar 5, 2012
@@ -4,6 +4,7 @@
require 'models/reference'
require 'models/job'
require 'models/reader'
+require 'models/secure_reader'
require 'models/comment'
require 'models/tag'
require 'models/tagging'
@@ -44,17 +45,33 @@ def test_include?
end
def test_associate_existing
- posts(:thinking); people(:david) # Warm cache
+ post = posts(:thinking)
+ person = people(:david)
assert_queries(1) do
- posts(:thinking).people << people(:david)
+ post.people << person
end
assert_queries(1) do
- assert posts(:thinking).people.include?(people(:david))
+ assert post.people.include?(person)
end
- assert posts(:thinking).reload.people(true).include?(people(:david))
+ assert post.reload.people(true).include?(person)
+ end
+
+ def test_associate_existing_with_strict_mass_assignment_sanitizer
+ ActiveRecord::Base.mass_assignment_sanitizer = :strict
+
+ SecureReader.new
+
+ post = posts(:thinking)
+ person = people(:david)
+
+ assert_queries(1) do
+ post.secure_people << person
+ end
+ ensure
+ ActiveRecord::Base.mass_assignment_sanitizer = :logger
end
def test_associate_existing_record_twice_should_add_to_target_twice
@@ -1,8 +1,10 @@
class Person < ActiveRecord::Base
has_many :readers
+ has_many :secure_readers
has_one :reader
has_many :posts, :through => :readers
+ has_many :secure_posts, :through => :secure_readers
has_many :posts_with_no_comments, :through => :readers, :source => :post, :include => :comments, :conditions => 'comments.id is null'
has_many :references
@@ -115,8 +115,10 @@ def add_joins_and_select
has_many :named_categories, :through => :standard_categorizations
has_many :readers
+ has_many :secure_readers
has_many :readers_with_person, :include => :person, :class_name => "Reader"
has_many :people, :through => :readers
+ has_many :secure_people, :through => :secure_readers
has_many :single_people, :through => :readers
has_many :people_with_callbacks, :source=>:person, :through => :readers,
:before_add => lambda {|owner, reader| log(:added, :before, reader.first_name) },
@@ -0,0 +1,9 @@
+class SecureReader < ActiveRecord::Base
+ self.table_name = "readers"
+
+ belongs_to :secure_post, :class_name => "Post", :foreign_key => "post_id"
+ belongs_to :secure_person, :inverse_of => :secure_readers, :class_name => "Person", :foreign_key => "person_id"
+
+
+ attr_accessible nil
+end

0 comments on commit 7cd4063

Please sign in to comment.