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
Applied patches from Tim Case (tim@powerupdev.com):
- should_have_instance_methods
- should_have_class_methods
- should_belong_to foreign key bugfix



git-svn-id: https://svn.thoughtbot.com/plugins/shoulda/trunk@233 
7bbfaf0e-4d1d-0410-9690-a8bb5f8ef2aa
tsaleh (author)
Wed Oct 31 06:47:37 -0700 2007
commit  c07bff350ac626f5d8ad39bef007ebbf4cbbdb50
tree    6ad74cbea80c082b540a21b950014832cc11e329
parent  0f7eeafa3dcd5d28aace326d940614e245c814ce
...
325
326
327
328
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
329
330
331
...
325
326
327
 
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
0
@@ -325,7 +325,33 @@ module ThoughtBot # :nodoc:
0
             assert reflection, "#{klass.name} does not have any relationship to #{association}"
0
             assert_equal :belongs_to, reflection.macro
0
             fk = reflection.options[:foreign_key] || "#{association}_id"
0
- assert klass.column_names.include?(fk), "#{klass.name} does not have a #{fk} foreign key."
0
+ assert klass.column_names.include?(fk.to_s), "#{klass.name} does not have a #{fk} foreign key."
0
+ end
0
+ end
0
+ end
0
+
0
+ # Ensure that the given class methods are defined on the model.
0
+ #
0
+ # should_have_class_methods :find, :destroy
0
+ def should_have_class_methods(*methods)
0
+ get_options!(methods)
0
+ klass = model_class
0
+ methods.each do |method|
0
+ should "respond to class method #{method}" do
0
+ assert_respond_to klass, method, "#{klass.name} does not have class method #{method}"
0
+ end
0
+ end
0
+ end
0
+
0
+ # Ensure that instance methods exist.
0
+ #
0
+ # should_have_instance_methods :instance_method
0
+ def should_have_instance_methods(*methods)
0
+ get_options!(methods)
0
+ klass = model_class
0
+ methods.each do |method|
0
+ should "respond to instance method #{method}" do
0
+ assert_respond_to klass.new, method, "#{klass.name} does not have instance method #{method}"
0
           end
0
         end
0
       end
...
1
2
 
3
4
5
...
1
2
3
4
5
6
0
@@ -1,5 +1,6 @@
0
 class Post < ActiveRecord::Base
0
   belongs_to :user
0
+ belongs_to :owner, :foreign_key => :user_id, :class_name => 'User'
0
   has_many :taggings
0
   has_many :tags, :through => :taggings
0
   
...
4
5
6
 
7
8
9
...
4
5
6
7
8
9
10
0
@@ -4,6 +4,7 @@ class PostTest < Test::Unit::TestCase
0
   load_all_fixtures
0
 
0
   should_belong_to :user
0
+ should_belong_to :owner
0
   should_have_many :tags, :through => :taggings
0
   
0
   should_require_unique_attributes :title
...
10
11
12
 
 
13
...
10
11
12
13
14
15
0
@@ -10,4 +10,6 @@ class UserTest < Test::Unit::TestCase
0
   should_ensure_length_in_range :email, 1..100
0
   should_ensure_value_in_range :age, 1..100
0
   should_protect_attributes :password
0
+ should_have_class_methods :find, :destroy
0
+ should_have_instance_methods :email, :age
0
 end

Comments

    No one has commented yet.