lib/matchers/associations.rb in mongoid-rspec-2.0.0 vs lib/matchers/associations.rb in mongoid-rspec-2.1.0

- old
+ new

@@ -99,10 +99,16 @@ @association[:foreign_key] = foreign_key.to_s @expectation_message << " using foreign key #{@association[:foreign_key].inspect}" self end + def with_counter_cache + @association[:counter_cache] = true + @expectation_message << " which specifies counter_cache as #{@association[:counter_cache].to_s}" + self + end + def matches?(actual) @actual = actual.is_a?(Class) ? actual : actual.class metadata = @actual.relations[@association[:name]] if metadata.nil? @@ -230,9 +236,18 @@ if metadata.foreign_key != @association[:foreign_key] @negative_result_message = "#{@positive_result_message} with foreign key #{metadata.foreign_key.inspect}" return false else @positive_result_message = "#{@positive_result_message} with foreign key #{metadata.foreign_key.inspect}" + end + end + + if @association[:counter_cache] + if metadata.counter_cached? != true + @negative_result_message = "#{@positive_result_message} which did not set counter_cache" + return false + else + @positive_result_message = "#{@positive_result_message} which set counter_cache" end end return true end