Skip to content
Browse files

Better named the should clause for should_have_one when the :dependen…

…t option is in use [#81]
  • Loading branch information...
1 parent 829ebaf commit a692f6d882c51679d6fb6292647a9e88a19da132 @rmm5t rmm5t committed
Showing with 5 additions and 2 deletions.
  1. +4 −2 lib/shoulda/active_record/macros.rb
  2. +1 −0 test/unit/user_test.rb
View
6 lib/shoulda/active_record/macros.rb
@@ -457,7 +457,9 @@ def should_have_one(*associations)
dependent = get_options!(associations, :dependent)
klass = model_class
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)
assert reflection, "#{klass.name} does not have any relationship to #{association}"
assert_equal :has_one, reflection.macro
@@ -476,7 +478,7 @@ def should_have_one(*associations)
end
assert associated_klass.column_names.include?(fk.to_s),
"#{associated_klass.name} does not have a #{fk} foreign key."
-
+
if dependent
assert_equal dependent.to_s,
reflection.options[:dependent].to_s,
View
1 test/unit/user_test.rb
@@ -9,6 +9,7 @@ class UserTest < Test::Unit::TestCase
should_have_many :friendships
should_have_many :friends
+ should_have_one :address
should_have_one :address, :dependent => :destroy
should_have_indices :email, :name, [:email, :name]

0 comments on commit a692f6d

Please sign in to comment.
Something went wrong with that request. Please try again.