public
Rubygem
Description: Makes tests easy on the fingers and the eyes
Homepage: http://www.thoughtbot.com/projects/shoulda
Clone URL: git://github.com/thoughtbot/shoulda.git
should_have_one macro now supports the :dependent option
infused (author)
Wed Sep 17 12:32:44 -0700 2008
commit  829ebafba0e07795eeea9098f7661263597a7eb5
tree    ba4549c0c05e4c702860ceec3a9f5621ddc246bb
parent  feed1087bd185fcef97624ab2328f94f59415a2a
...
447
448
449
 
 
 
450
451
452
453
454
 
455
456
457
...
473
474
475
 
 
 
 
 
 
476
477
478
...
447
448
449
450
451
452
453
454
455
456
 
457
458
459
460
...
476
477
478
479
480
481
482
483
484
485
486
487
0
@@ -447,11 +447,14 @@ module ThoughtBot # :nodoc:
0
         # associated table has the required columns. Works with polymorphic
0
         # associations.
0
         #
0
+ # Options:
0
+ # * <tt>:dependent</tt> - tests that the association makes use of the dependent option.
0
+ #
0
         # Example:
0
         # should_have_one :god # unless hindu
0
         #
0
         def should_have_one(*associations)
0
- get_options!(associations)
0
+ dependent = get_options!(associations, :dependent)
0
           klass = model_class
0
           associations.each do |association|
0
             should "have one #{association}" do
0
@@ -473,6 +476,12 @@ module ThoughtBot # :nodoc:
0
               end
0
               assert associated_klass.column_names.include?(fk.to_s),
0
                      "#{associated_klass.name} does not have a #{fk} foreign key."
0
+
0
+ if dependent
0
+ assert_equal dependent.to_s,
0
+ reflection.options[:dependent].to_s,
0
+ "#{association} should have #{dependent} dependency"
0
+ end
0
             end
0
           end
0
         end
...
5
6
7
8
 
9
10
11
...
5
6
7
 
8
9
10
11
0
@@ -5,7 +5,7 @@ class User < ActiveRecord::Base
0
   has_many :friendships
0
   has_many :friends, :through => :friendships
0
 
0
- has_one :address, :as => :addressable
0
+ has_one :address, :as => :addressable, :dependent => :destroy
0
 
0
   named_scope :old, :conditions => "age > 50"
0
   named_scope :eighteen, :conditions => { :age => 18 }
...
9
10
11
12
 
13
14
15
...
9
10
11
 
12
13
14
15
0
@@ -9,7 +9,7 @@ class UserTest < Test::Unit::TestCase
0
   should_have_many :friendships
0
   should_have_many :friends
0
 
0
- should_have_one :address
0
+ should_have_one :address, :dependent => :destroy
0
 
0
   should_have_indices :email, :name, [:email, :name]
0
   should_have_index :age

Comments

    No one has commented yet.