mirror of
https://github.com/thoughtbot/shoulda-matchers.git
synced 2022-11-09 12:01:38 -05:00
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
This commit is contained in:
parent
0f7eeafa3d
commit
c07bff350a
4 changed files with 31 additions and 1 deletions
|
@ -325,7 +325,33 @@ module ThoughtBot # :nodoc:
|
||||||
assert reflection, "#{klass.name} does not have any relationship to #{association}"
|
assert reflection, "#{klass.name} does not have any relationship to #{association}"
|
||||||
assert_equal :belongs_to, reflection.macro
|
assert_equal :belongs_to, reflection.macro
|
||||||
fk = reflection.options[:foreign_key] || "#{association}_id"
|
fk = reflection.options[:foreign_key] || "#{association}_id"
|
||||||
assert klass.column_names.include?(fk), "#{klass.name} does not have a #{fk} foreign key."
|
assert klass.column_names.include?(fk.to_s), "#{klass.name} does not have a #{fk} foreign key."
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# Ensure that the given class methods are defined on the model.
|
||||||
|
#
|
||||||
|
# should_have_class_methods :find, :destroy
|
||||||
|
def should_have_class_methods(*methods)
|
||||||
|
get_options!(methods)
|
||||||
|
klass = model_class
|
||||||
|
methods.each do |method|
|
||||||
|
should "respond to class method #{method}" do
|
||||||
|
assert_respond_to klass, method, "#{klass.name} does not have class method #{method}"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# Ensure that instance methods exist.
|
||||||
|
#
|
||||||
|
# should_have_instance_methods :instance_method
|
||||||
|
def should_have_instance_methods(*methods)
|
||||||
|
get_options!(methods)
|
||||||
|
klass = model_class
|
||||||
|
methods.each do |method|
|
||||||
|
should "respond to instance method #{method}" do
|
||||||
|
assert_respond_to klass.new, method, "#{klass.name} does not have instance method #{method}"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
class Post < ActiveRecord::Base
|
class Post < ActiveRecord::Base
|
||||||
belongs_to :user
|
belongs_to :user
|
||||||
|
belongs_to :owner, :foreign_key => :user_id, :class_name => 'User'
|
||||||
has_many :taggings
|
has_many :taggings
|
||||||
has_many :tags, :through => :taggings
|
has_many :tags, :through => :taggings
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,7 @@ class PostTest < Test::Unit::TestCase
|
||||||
load_all_fixtures
|
load_all_fixtures
|
||||||
|
|
||||||
should_belong_to :user
|
should_belong_to :user
|
||||||
|
should_belong_to :owner
|
||||||
should_have_many :tags, :through => :taggings
|
should_have_many :tags, :through => :taggings
|
||||||
|
|
||||||
should_require_unique_attributes :title
|
should_require_unique_attributes :title
|
||||||
|
|
|
@ -10,4 +10,6 @@ class UserTest < Test::Unit::TestCase
|
||||||
should_ensure_length_in_range :email, 1..100
|
should_ensure_length_in_range :email, 1..100
|
||||||
should_ensure_value_in_range :age, 1..100
|
should_ensure_value_in_range :age, 1..100
|
||||||
should_protect_attributes :password
|
should_protect_attributes :password
|
||||||
|
should_have_class_methods :find, :destroy
|
||||||
|
should_have_instance_methods :email, :age
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Reference in a new issue