lib/matchers/associations.rb in mongoid-rspec-1.4.2 vs lib/matchers/associations.rb in mongoid-rspec-1.4.3
- old
+ new
@@ -31,21 +31,27 @@
@expectation_message << " of type #{@association[:class].inspect}"
self
end
def as_inverse_of(association_inverse_name)
- raise "#{@association[:type].inspect} does not respond to :inverse_of" unless [BELONGS_TO, EMBEDDED_IN].include?(@association[:type])
+ raise "#{@association[:type].inspect} does not respond to :inverse_of" unless [HAS_MANY, HAS_AND_BELONGS_TO_MANY, BELONGS_TO, EMBEDDED_IN].include?(@association[:type])
@association[:inverse_of] = association_inverse_name.to_s
@expectation_message << " which is an inverse of #{@association[:inverse_of].inspect}"
self
end
def with_dependent(method_name)
@association[:dependent] = method_name
@expectation_message << " which specifies dependent as #{@association[:dependent].to_s}"
self
end
+
+ def with_autosave
+ @association[:autosave] = true
+ @expectation_message << " which specifies autosave as #{@association[:autosave].to_s}"
+ self
+ end
def stored_as(store_as)
raise NotImplementedError, "`references_many #{@association[:name]} :stored_as => :array` has been removed in Mongoid 2.0.0.rc, use `references_and_referenced_in_many #{@association[:name]}` instead"
end
@@ -94,9 +100,18 @@
if @association[:dependent].to_s != metadata.dependent.to_s
@negative_result_message = "#{@positive_result_message} which specified dependent as #{metadata.dependent}"
return false
else
@positive_result_message = "#{@positive_result_message} which specified dependent as #{metadata.dependent}"
+ end
+ end
+
+ if @association[:autosave]
+ if metadata.autosave != true
+ @negative_result_message = "#{@positive_result_message} which did not set autosave"
+ return false
+ else
+ @positive_result_message = "#{@positive_result_message} which set autosave"
end
end
if @association[:foreign_key]
if metadata.foreign_key != @association[:foreign_key]