Skip to content

Commit

Permalink
Better named the should clause for should_have_one when the :dependen…
Browse files Browse the repository at this point in the history
…t option is in use [thoughtbot#81]
  • Loading branch information
rmm5t committed Sep 17, 2008
1 parent 829ebaf commit a692f6d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/shoulda/active_record/macros.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand Down
1 change: 1 addition & 0 deletions test/unit/user_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down

0 comments on commit a692f6d

Please sign in to comment.