aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorRafael Mendonça França <rafaelmfranca@gmail.com>2012-03-05 00:45:17 -0300
committerRafael Mendonça França <rafaelmfranca@gmail.com>2012-03-05 16:58:19 -0300
commite9bf0e3157fcc15f3520559a34bbfdd894dd8112 (patch)
tree28fd3bc8841a69e0e78d3e3abbe11484fb7a79f5 /activerecord
parentc97a1666910aa82b9c4348402cc8f52492b58692 (diff)
downloadrails-e9bf0e3157fcc15f3520559a34bbfdd894dd8112.tar.gz
rails-e9bf0e3157fcc15f3520559a34bbfdd894dd8112.tar.bz2
rails-e9bf0e3157fcc15f3520559a34bbfdd894dd8112.zip
Add test case to has_many through association when mass_assignment_sanitizer is
:strict
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/test/cases/associations/has_many_through_associations_test.rb25
-rw-r--r--activerecord/test/models/person.rb2
-rw-r--r--activerecord/test/models/post.rb2
-rw-r--r--activerecord/test/models/secure_reader.rb9
4 files changed, 34 insertions, 4 deletions
diff --git a/activerecord/test/cases/associations/has_many_through_associations_test.rb b/activerecord/test/cases/associations/has_many_through_associations_test.rb
index 9cc09194dc..8e64fd7c70 100644
--- a/activerecord/test/cases/associations/has_many_through_associations_test.rb
+++ b/activerecord/test/cases/associations/has_many_through_associations_test.rb
@@ -4,6 +4,7 @@ require 'models/person'
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 @@ class HasManyThroughAssociationsTest < ActiveRecord::TestCase
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
diff --git a/activerecord/test/models/person.rb b/activerecord/test/models/person.rb
index d2a0c6b40c..84bc901b5e 100644
--- a/activerecord/test/models/person.rb
+++ b/activerecord/test/models/person.rb
@@ -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', :references => :comments
diff --git a/activerecord/test/models/post.rb b/activerecord/test/models/post.rb
index 1cab78d8c7..0fc22ac6a3 100644
--- a/activerecord/test/models/post.rb
+++ b/activerecord/test/models/post.rb
@@ -115,8 +115,10 @@ class Post < ActiveRecord::Base
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) },
diff --git a/activerecord/test/models/secure_reader.rb b/activerecord/test/models/secure_reader.rb
new file mode 100644
index 0000000000..3a2a8496fd
--- /dev/null
+++ b/activerecord/test/models/secure_reader.rb
@@ -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