This commit is contained in:
Gabe Berke-Williams 2012-03-23 19:50:08 -04:00
parent c10cf343ae
commit 41bccc8cbf
3 changed files with 20 additions and 18 deletions

View File

@ -166,7 +166,7 @@ module Shoulda # :nodoc:
if @through == reflection.options[:through]
true
else
@missing = "Expected #{model_class.name} to have #{@name} through #{@through}, " <<
@missing = "Expected #{model_class.name} to have #{@name} through #{@through}, " +
"but got it through #{reflection.options[:through]}"
false
end
@ -210,7 +210,7 @@ module Shoulda # :nodoc:
def join_table_exists?
if @macro != :has_and_belongs_to_many ||
::ActiveRecord::Base.connection.tables.include?(join_table.to_s)
::ActiveRecord::Base.connection.tables.include?(join_table)
true
else
@missing = "join table #{join_table} doesn't exist"
@ -219,7 +219,7 @@ module Shoulda # :nodoc:
end
def class_has_foreign_key?(klass)
if klass.column_names.include?(foreign_key.to_s)
if klass.column_names.include?(foreign_key)
true
else
@missing = "#{klass} does not have a #{foreign_key} foreign key."
@ -232,7 +232,7 @@ module Shoulda # :nodoc:
end
def join_table
reflection.options[:join_table]
reflection.options[:join_table].to_s
end
def associated_class
@ -240,18 +240,12 @@ module Shoulda # :nodoc:
end
def foreign_key
fk_reflection = reflection
if [:has_one, :has_many].include?(@macro) && reflection.options.include?(:inverse_of)
fk_reflection = associated_class.reflect_on_association(
reflection.options[:inverse_of]
)
end
if fk_reflection
fk_reflection.respond_to?(:foreign_key) ?
fk_reflection.foreign_key :
fk_reflection.primary_key_name
else
nil
if foreign_key_reflection
if foreign_key_reflection.respond_to?(:foreign_key)
foreign_key_reflection.foreign_key.to_s
else
foreign_key_reflection.primary_key_name.to_s
end
end
end
@ -263,6 +257,14 @@ module Shoulda # :nodoc:
@reflection ||= model_class.reflect_on_association(@name)
end
def foreign_key_reflection
if [:has_one, :has_many].include?(@macro) && reflection.options.include?(:inverse_of)
associated_class.reflect_on_association(reflection.options[:inverse_of])
else
reflection
end
end
def through_reflection
@through_reflection ||= model_class.reflect_on_association(@through)
end

View File

@ -17,7 +17,7 @@ Gem::Specification.new do |s|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
s.require_paths = ["lib"]
s.add_development_dependency('mocha', '~> 0.10.5')
s.add_development_dependency('bourne', '~> 1.1.2')
s.add_development_dependency('rspec-rails', '~> 2.6.1')
s.add_development_dependency('cucumber', '~> 1.1.9')
s.add_development_dependency('aruba')

View File

@ -40,8 +40,8 @@ describe Shoulda::Matchers::ActiveRecord::QueryTheDatabaseMatcher do
it "passes arguments to the method to examine" do
model = stub("Model", :count => nil)
model.expects(:count).with("arguments")
model.should_not query_the_database.when_calling(:count).with("arguments")
model.should have_received(:count).with("arguments")
end
else
it "should raise an exception on Rails < 3.1" do