mirror of
https://github.com/thoughtbot/shoulda-matchers.git
synced 2022-11-09 12:01:38 -05:00
added dependent option to should_belong_to [#108]
This commit is contained in:
parent
ef10377582
commit
fb11e5a896
3 changed files with 9 additions and 3 deletions
|
@ -537,7 +537,7 @@ module Shoulda # :nodoc:
|
|||
# should_belong_to :parent
|
||||
#
|
||||
def should_belong_to(*associations)
|
||||
get_options!(associations)
|
||||
dependent = get_options!(associations, :dependent)
|
||||
klass = model_class
|
||||
associations.each do |association|
|
||||
should "belong_to #{association}" do
|
||||
|
@ -550,6 +550,12 @@ module Shoulda # :nodoc:
|
|||
fk = reflection.options[:foreign_key] || reflection.primary_key_name
|
||||
assert klass.column_names.include?(fk.to_s), "#{klass.name} does not have a #{fk} foreign key."
|
||||
end
|
||||
|
||||
if dependent
|
||||
assert_equal dependent.to_s,
|
||||
reflection.options[:dependent].to_s,
|
||||
"#{association} should have #{dependent} dependency"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
module Pets
|
||||
class Dog < ActiveRecord::Base
|
||||
belongs_to :user, :foreign_key => :owner_id
|
||||
belongs_to :address
|
||||
belongs_to :address, :dependent => :destroy
|
||||
has_many :treats
|
||||
has_and_belongs_to_many :fleas, :join_table => :fleas
|
||||
validates_presence_of :treats, :fleas
|
||||
|
|
|
@ -2,7 +2,7 @@ require File.dirname(__FILE__) + '/../test_helper'
|
|||
|
||||
class Pets::DogTest < Test::Unit::TestCase
|
||||
should_belong_to :user
|
||||
should_belong_to :address
|
||||
should_belong_to :address, :dependent => :destroy
|
||||
should_have_many :treats
|
||||
should_have_and_belong_to_many :fleas
|
||||
should_require_attributes :treats, :fleas
|
||||
|
|
Loading…
Add table
Reference in a new issue