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
fixed should_have_and_belong_to to test for the join table


git-svn-id: https://svn.thoughtbot.com/plugins/shoulda/trunk@488 
7bbfaf0e-4d1d-0410-9690-a8bb5f8ef2aa
tsaleh (author)
Thu May 01 06:49:38 -0700 2008
commit  fa37ef07af6c1a36da12c26f7ec2afc6b0e2499e
tree    f2dd24073247c9ccd8572e4d778c39247bcdad55
parent  0cd585928ff9e189a42ce58b8bf2c6cac8bbd201
...
415
416
417
418
 
 
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
 
 
 
 
 
435
436
437
...
415
416
417
 
418
419
420
421
422
 
 
 
423
424
425
426
427
428
 
 
 
 
429
430
431
432
433
434
435
436
0
@@ -415,23 +415,22 @@ module ThoughtBot # :nodoc:
0
         end
0
       end
0
   
0
- # Ensures that the has_and_belongs_to_many relationship exists.
0
+ # Ensures that the has_and_belongs_to_many relationship exists, and that the join
0
+ # table is in place.
0
       #
0
       # should_have_and_belong_to_many :posts, :cars
0
       #
0
- # NOTE: One thing this macro should test, but doesn't is that the join
0
- # table exists in the DB. Please contact the author if you know of a DB
0
- # agnostic way of introspecting on the current schema.
0
       def should_have_and_belong_to_many(*associations)
0
         get_options!(associations)
0
         klass = model_class
0
 
0
         associations.each do |association|
0
           should "should have and belong to many #{association}" do
0
- assert klass.reflect_on_association(association),
0
- "#{klass.name} does not have any relationship to #{association}"
0
- assert_equal :has_and_belongs_to_many,
0
- klass.reflect_on_association(association).macro
0
+ reflection = klass.reflect_on_association(association)
0
+ assert reflection, "#{klass.name} does not have any relationship to #{association}"
0
+ assert_equal :has_and_belongs_to_many, reflection.macro
0
+ table = reflection.options[:join_table]
0
+ assert ::ActiveRecord::Base.connection.tables.include?(table), "table #{table} doesn't exist"
0
           end
0
         end
0
       end

Comments

    No one has commented yet.