Skip to content

Instantly share code, notes, and snippets.

Created January 9, 2013 21:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/4497186 to your computer and use it in GitHub Desktop.
Save anonymous/4497186 to your computer and use it in GitHub Desktop.
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 af91fb2..f3e4d10 100644
--- a/activerecord/test/cases/associations/has_many_through_associations_test.rb
+++ b/activerecord/test/cases/associations/has_many_through_associations_test.rb
@@ -894,4 +894,11 @@ class HasManyThroughAssociationsTest < ActiveRecord::TestCase
end
end
+ def test_validation_call_counter_on_join_records
+ author = Author.create(:name => "tenderlove")
+ Categorization.any_instance.expects(:check_validation_call_count).times(1)
+ category = Category.new(:name => "rails 4.0")
+ category.authors << author
+ category.save
+ end
end
diff --git a/activerecord/test/models/author.rb b/activerecord/test/models/author.rb
index 6935cfb..bd7fd86 100644
--- a/activerecord/test/models/author.rb
+++ b/activerecord/test/models/author.rb
@@ -181,6 +181,8 @@ class Author < ActiveRecord::Base
def raise_exception(object)
raise Exception.new("You can't add a post")
end
+
+
end
class AuthorAddress < ActiveRecord::Base
diff --git a/activerecord/test/models/categorization.rb b/activerecord/test/models/categorization.rb
index 6588531..cad9e15 100644
--- a/activerecord/test/models/categorization.rb
+++ b/activerecord/test/models/categorization.rb
@@ -8,6 +8,13 @@ class Categorization < ActiveRecord::Base
belongs_to :author_using_custom_pk, :class_name => 'Author', :foreign_key => :author_id, :primary_key => :author_address_extra_id
has_many :authors_using_custom_pk, :class_name => 'Author', :foreign_key => :id, :primary_key => :category_id
+ validate :check_validation_call_count
+
+ private
+ def check_validation_call_count
+ @count ||= 0
+ @count = @count + 1
+ end
end
class SpecialCategorization < ActiveRecord::Base
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment