Skip to content

Commit

Permalink
adding more tests surrounding where_values_hash
Browse files Browse the repository at this point in the history
  • Loading branch information
tenderlove committed Nov 30, 2010
1 parent 6c32290 commit 795dc3d
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions activerecord/test/cases/relation_test.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
require "cases/helper"
require 'models/post'
require 'models/comment'

module ActiveRecord
class RelationTest < ActiveRecord::TestCase
class FakeTable < Struct.new(:table_name)
fixtures :posts, :comments

class FakeKlass < Struct.new(:table_name)
end

def test_construction
Expand Down Expand Up @@ -56,16 +60,28 @@ def test_extensions
assert_equal [], relation.extensions
end

def test_where_values_hash
def test_empty_where_values_hash
relation = Relation.new :a, :b
assert_equal({}, relation.where_values_hash)

relation.where_values << :hello
assert_equal({}, relation.where_values_hash)
end

def test_has_values
relation = Relation.new Post, Post.arel_table
relation.where_values << relation.table[:id].eq(10)
assert_equal({:id => 10}, relation.where_values_hash)
end

def test_values_wrong_table
relation = Relation.new Post, Post.arel_table
relation.where_values << Comment.arel_table[:id].eq(10)
assert_equal({}, relation.where_values_hash)
end

def test_table_name_delegates_to_klass
relation = Relation.new FakeTable.new('foo'), :b
relation = Relation.new FakeKlass.new('foo'), :b
assert_equal 'foo', relation.table_name
end

Expand Down

0 comments on commit 795dc3d

Please sign in to comment.