lib/matchers/associations.rb in mongoid-rspec-1.2.0 vs lib/matchers/associations.rb in mongoid-rspec-1.2.1

- old
+ new

@@ -2,10 +2,11 @@ module Mongoid module Matchers module Associations HAS_MANY = defined?(Mongoid::Associations::HasManyRelated) ? Mongoid::Associations::HasManyRelated : Mongoid::Associations::ReferencesMany + HAS_MANY_AS_ARRAY = Mongoid::Associations::ReferencesManyAsArray HAS_ONE = defined?(Mongoid::Associations::HasOneRelated) ? Mongoid::Associations::HasOneRelated : Mongoid::Associations::ReferencesOne BELONGS_TO = defined?(Mongoid::Associations::BelongsToRelated) ? Mongoid::Associations::BelongsToRelated : Mongoid::Associations::ReferencedIn EMBEDS_MANY = Mongoid::Associations::EmbedsMany EMBEDS_ONE = Mongoid::Associations::EmbedsOne EMBEDDED_IN = Mongoid::Associations::EmbeddedIn @@ -35,10 +36,15 @@ @association[:inverse_of] = association_inverse_name.to_s @expectation_message << " which is an inverse of #{@association[:inverse_of].inspect}" self end + def stored_as(store_as) + @association[:type] = HAS_MANY_AS_ARRAY if store_as == :array + self + end + def matches?(actual) @actual = actual.is_a?(Class) ? actual : actual.class association = @actual.associations[@association[:name]] @@ -97,14 +103,16 @@ when EMBEDDED_IN.name (passive ? 'be' : 'is') << ' embedded in' when HAS_ONE.name (passive ? 'reference' : 'references') << ' one' when HAS_MANY.name - (passive ? 'reference' : 'references') << ' many' + (passive ? 'reference' : 'references') << ' many' + when HAS_MANY_AS_ARRAY.name + (passive ? 'reference' : 'references') << ' many as array' when BELONGS_TO.name (passive ? 'be referenced in' : 'referenced in') else - raise "Unknown association type" + raise "Unknown association type '%s'" % type end end end def embed_one(association_name) \ No newline at end of file