API v3: make polymorphic has_many work

This commit is contained in:
Konstantin Haase 2015-04-28 12:41:29 +02:00
parent d8f1075491
commit 99ca87b7c4
2 changed files with 6 additions and 0 deletions

View File

@ -27,6 +27,11 @@ module Travis::API::V3
polymorfic_foreign_types << (options[:foreign_type] || "#{field}_type") if options[:polymorphic]
super
end
def name
return super unless caller_locations.first.base_label == 'add_constraints'.freeze
@constraint_name ||= super.sub("#{parent}::", ''.freeze)
end
end
def self.included(base)

View File

@ -13,5 +13,6 @@ describe Travis::API::V3::Extensions::BelongsTo do
example { expect(repo.owner).to be_a(Travis::API::V3::Models::User) }
example { expect(::Repository.find(repo.id).owner).to be_a(::User) }
example { expect(user.repositories).to include(repo) }
end
end