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
tsaleh (author)
Thu Feb 28 13:40:42 -0800 2008
commit  c397d016f8352e794e725e6cd6005e1e063d1aa8
tree    c825c4200a91e91c46a3f6ef2729243a0f03a169
parent  6b91e8b325ef8a1105f250dfa9ee363b3e4d482f
...
355
356
357
 
 
358
359
360
361
 
 
 
362
363
364
365
366
 
 
367
368
369
...
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
 
 
370
371
372
373
374
0
@@ -355,15 +355,20 @@ module ThoughtBot # :nodoc:
0
             assert reflection, "#{klass.name} does not have any relationship to #{association}"
0
             assert_equal :has_one, reflection.macro
0
             
0
+ associated_klass = (reflection.options[:class_name] || association.to_s.camelize).constantize
0
+
0
             if reflection.options[:foreign_key]
0
               fk = reflection.options[:foreign_key]
0
             elsif reflection.options[:as]
0
               fk = reflection.options[:as].to_s.foreign_key
0
+ fk_type = fk.gsub(/_id$/, '_type')
0
+ assert associated_klass.column_names.include?(fk_type),
0
+ "#{associated_klass.name} does not have a #{fk_type} column."
0
             else
0
               fk = klass.name.foreign_key
0
             end
0
- associated_klass = (reflection.options[:class_name] || association.to_s.classify).constantize
0
- assert associated_klass.column_names.include?(fk.to_s), "#{associated_klass.name} does not have a #{fk} foreign key."
0
+ assert associated_klass.column_names.include?(fk.to_s),
0
+ "#{associated_klass.name} does not have a #{fk} foreign key."
0
           end
0
         end
0
       end
...
1
2
3
 
 
4
5
6
...
1
2
3
4
5
6
7
8
0
@@ -1,6 +1,8 @@
0
 class User < ActiveRecord::Base
0
   has_many :posts
0
   has_many :dogs, :foreign_key => :owner_id
0
+
0
+ has_one :address, :as => :addressable
0
   
0
   attr_protected :password
0
 
...
6
7
8
 
 
9
10
11
...
6
7
8
9
10
11
12
13
0
@@ -6,6 +6,8 @@ class UserTest < Test::Unit::TestCase
0
   should_have_many :posts
0
   should_have_many :dogs
0
 
0
+ should_have_one :address
0
+
0
   should_not_allow_values_for :email, "blah", "b lah"
0
   should_allow_values_for :email, "a@b.com", "asdf@asdf.com"
0
   should_ensure_length_in_range :email, 1..100

Comments

    No one has commented yet.