lib/matchers/associations/associations.rb in mongoid-minitest-1.1.0 vs lib/matchers/associations/associations.rb in mongoid-minitest-1.2.0
- old
+ new
@@ -1,15 +1,25 @@
module Mongoid
module Matchers
module Associations
- HAS_ONE = Mongoid::Relations::Referenced::One
- HAS_MANY = Mongoid::Relations::Referenced::Many
- HAS_AND_BELONGS_TO_MANY = Mongoid::Relations::Referenced::ManyToMany
- BELONGS_TO = Mongoid::Relations::Referenced::In
- EMBEDS_ONE = Mongoid::Relations::Embedded::One
- EMBEDS_MANY = Mongoid::Relations::Embedded::Many
- EMBEDDED_IN = Mongoid::Relations::Embedded::In
+ if Mongoid::Compatibility::Version.mongoid7_or_newer?
+ HAS_ONE = Mongoid::Association::Referenced::HasOne
+ HAS_MANY = Mongoid::Association::Referenced::HasMany
+ HAS_AND_BELONGS_TO_MANY = Mongoid::Association::Referenced::HasAndBelongsToMany
+ BELONGS_TO = Mongoid::Association::Referenced::BelongsTo
+ EMBEDS_ONE = Mongoid::Association::Embedded::EmbedsOne
+ EMBEDS_MANY = Mongoid::Association::Embedded::EmbedsMany
+ EMBEDDED_IN = Mongoid::Association::Embedded::EmbeddedIn
+ else
+ HAS_ONE = Mongoid::Relations::Referenced::One
+ HAS_MANY = Mongoid::Relations::Referenced::Many
+ HAS_AND_BELONGS_TO_MANY = Mongoid::Relations::Referenced::ManyToMany
+ BELONGS_TO = Mongoid::Relations::Referenced::In
+ EMBEDS_ONE = Mongoid::Relations::Embedded::One
+ EMBEDS_MANY = Mongoid::Relations::Embedded::Many
+ EMBEDDED_IN = Mongoid::Relations::Embedded::In
+ end
class HaveAssociationMatcher < Matcher
def initialize name, type
@association = {}
@association[:name] = name.to_s
@@ -60,10 +70,16 @@
@positive_message = "association named #{@association[:name].inspect}"
end
end
def check_association_type
- if !@metadata.nil? && @metadata.relation != @association[:type]
+ is_failure = if Mongoid::Compatibility::Version.mongoid7_or_newer?
+ !@metadata.nil? && @metadata.class != @association[:type]
+ else
+ !@metadata.nil? && @metadata.relation != @association[:type]
+ end
+
+ if is_failure
@negative_message = association_type_failure_message
@result = false
else
@positive_message = association_type_failure_message
end