Sha256: db31b09276a31478477d1c895faf0886088fe5f5e849f7c3b7b983180fd2c01b
Contents?: true
Size: 1.66 KB
Versions: 1
Compression:
Stored size: 1.66 KB
Contents
require File.dirname(__FILE__) + '/../test_helper' Comment.class_eval do public :find_polymorphic_association_name end class PolymorphicIdentityTest < Test::Unit::TestCase fixtures :authors, :articles, :pages, :users, :comments def test_find_polymorphic_association_name c = Comment.new c.commenter_type = 'Article' assert_equal :commenter, c.find_polymorphic_association_name(:article) assert_equal :commenter, c.find_polymorphic_association_name('article') assert_equal nil, c.find_polymorphic_association_name('page') end def test_no_value ([Comment.new] + Comment.find(:all)).each do |c| c.commentable = nil if c.commentable c.commenter = nil if c.commenter assert !c.respond_to?(:article) assert !c.respond_to?(:page) assert !c.respond_to?(:author) assert !c.respond_to?(:user) end end def test_existing_value c = comments(:article_test_author_john_doe) assert c.respond_to?(:article) assert c.respond_to?(:author) assert_equal articles(:test), c.article assert_equal authors(:john_doe), c.author c = comments(:page_about_user_anonymous) assert c.respond_to?(:page) assert c.respond_to?(:user) assert_equal pages(:about), c.page assert_equal users(:anonymous), c.user end def test_change_value c = comments(:article_test_author_john_doe) c.commentable = pages(:about) c.commenter = users(:anonymous) assert !c.respond_to?(:article) assert !c.respond_to?(:author) assert c.respond_to?(:page) assert c.respond_to?(:user) assert_equal pages(:about), c.page assert_equal users(:anonymous), c.user end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
polymorphic_identity-0.0.1 | test/unit/polymorphic_identity_test.rb |