1
0
Fork 0
mirror of https://github.com/thoughtbot/shoulda-matchers.git synced 2022-11-09 12:01:38 -05:00

Better named the should clause for should_have_one when the :dependent option is in use [#81]

This commit is contained in:
Ryan McGeary 2008-09-17 16:16:41 -04:00
parent 829ebafba0
commit a692f6d882
2 changed files with 5 additions and 2 deletions

View file

@ -457,7 +457,9 @@ module ThoughtBot # :nodoc:
dependent = get_options!(associations, :dependent) dependent = get_options!(associations, :dependent)
klass = model_class klass = model_class
associations.each do |association| associations.each do |association|
should "have one #{association}" do name = "have one #{association}"
name += " dependent => #{dependent}" if dependent
should name do
reflection = klass.reflect_on_association(association) reflection = klass.reflect_on_association(association)
assert reflection, "#{klass.name} does not have any relationship to #{association}" assert reflection, "#{klass.name} does not have any relationship to #{association}"
assert_equal :has_one, reflection.macro assert_equal :has_one, reflection.macro
@ -476,7 +478,7 @@ module ThoughtBot # :nodoc:
end end
assert associated_klass.column_names.include?(fk.to_s), assert associated_klass.column_names.include?(fk.to_s),
"#{associated_klass.name} does not have a #{fk} foreign key." "#{associated_klass.name} does not have a #{fk} foreign key."
if dependent if dependent
assert_equal dependent.to_s, assert_equal dependent.to_s,
reflection.options[:dependent].to_s, reflection.options[:dependent].to_s,

View file

@ -9,6 +9,7 @@ class UserTest < Test::Unit::TestCase
should_have_many :friendships should_have_many :friendships
should_have_many :friends should_have_many :friends
should_have_one :address
should_have_one :address, :dependent => :destroy should_have_one :address, :dependent => :destroy
should_have_indices :email, :name, [:email, :name] should_have_indices :email, :name, [:email, :name]