Permalink
Browse files

Merge branch 'master' of https://github.com/yairgo/mongoid-rspec into…

… yairgo-master
  • Loading branch information...
evansagge committed Apr 22, 2011
2 parents 9a7320a + b5d676e commit 130b5db6133882baeb08a50b4fa55dd4dabb6e9d
Showing with 21 additions and 3 deletions.
  1. +3 −0 README.markdown
  2. +15 −0 lib/matchers/associations.rb
  3. +1 −1 spec/models/user.rb
  4. +2 −2 spec/unit/associations_spec.rb
View
@@ -14,6 +14,9 @@ Association Matchers
it { should reference_many :comments }
it { should have_many :comments }
+
+ #can also specify with_dependent to test if :dependent => :destroy/:destroy_all/:delete is set
+ it { should have_many(:comments).with_dependent(:destroy) }
it { should embed_one :profile }
@@ -39,6 +39,12 @@ def as_inverse_of(association_inverse_name)
self
end
+ def with_dependent(method_name)
+ @association[:dependent] = method_name
+ @expectation_message << " which specifies dependent as #{@association[:dependent].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
@@ -84,6 +90,15 @@ def matches?(actual)
end
end
+ if @association[:dependent]
+ 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[:foreign_key]
if metadata.foreign_key != @association[:foreign_key]
@negative_result_message = "#{@positive_result_message} with foreign key #{metadata.foreign_key.inspect}"
View
@@ -7,7 +7,7 @@ class User
referenced_in :site, :inverse_of => :users
references_many :articles, :foreign_key => :author_id
- references_many :comments
+ references_many :comments, :dependent => :destroy
references_and_referenced_in_many :children, :class_name => "User"
references_one :record
@@ -8,8 +8,8 @@
it { should reference_one(:record) }
it { should have_one(:record) }
- it { should reference_many :comments }
- it { should have_many :comments }
+ it { should reference_many(:comments).with_dependent(:destroy) }
+ it { should have_many(:comments).with_dependent(:destroy) }
it { should embed_one :profile }

0 comments on commit 130b5db

Please sign in to comment.