zdennis / ar-extensions

ActiveRecord::Extension (aka ar-extensions) is a plugin to extend and enhance the functionality of ActiveRecord

This URL has Read+Write access

ar-extensions / ar-extensions / tests / test_activerecord_compatability.rb
100644 61 lines (54 sloc) 2.36 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
require File.expand_path( File.join( File.dirname( __FILE__ ), 'test_helper' ) )
 
class FindersTest < Test::Unit::TestCase
  include ActiveRecord::ConnectionAdapters
 
  def setup
    @connection = ActiveRecord::Base.connection
  end
  
  # def test_activerecord_model_can_be_used_with_reserved_words
  # group1 = Group.create!(:order => "x")
  # group2 = Group.create!(:order => "y")
  # x = nil
  # assert_nothing_raised { x = Group.new }
  # x.order = 'x'
  # assert_nothing_raised { x.save }
  # x.order = 'y'
  # assert_nothing_raised { x.save }
  # assert_nothing_raised { y = Group.find_by_order('y') }
  # assert_nothing_raised { y = Group.find(group2.id) }
  # x = Group.find(group1.id)
  # end
  #
  # def test_find_on_hash_conditions_with_explicit_table_name
  # group1 = Group.create!(:order => "x")
  # assert Group.find(group1.id, :conditions => { "group.order" => "x" })
  # assert_raises(ActiveRecord::RecordNotFound) {
  # Group.find(group1.id, :conditions => { 'group.order' => "y" })
  # }
  # end
  #
  # def test_exists_with_aggregate_having_three_mappings
  # topic = Topic.create! :title => "SomeBook", :author_name => "Joe Smith"
  # assert Topic.exists?(:description => topic.description)
  #
  # topic = Topic.new :title => "MayDay", :author_name => "Joe Smith the 2nd"
  # assert !Topic.exists?(:description => topic.description)
  # end
  #
  # def test_find_with_aggregate
  # topic = Topic.create! :title => "SomeBook", :author_name => "Joe Smith"
  # assert_equal topic, Topic.find(:first, :conditions => { :description => topic.description })
  #
  # topic = Topic.new :title => "MayDay", :author_name => "Joe Smith the 2nd"
  # assert !Topic.find(:first, :conditions => { :description => topic.description })
  # end
 
  def test_find_with_blank_conditions
    Topic.destroy_all
    Book.destroy_all
    topic = Topic.create! :author_name => "Zach Dennis", :title => "Books by Brooks"
    topic.books << Book.create!(:title => "Sword of Shannara", :author_name => "Terry Brooks", :publisher => "DelRey")
    topic.books << Book.create!(:title => "Gemstones of Shannara", :author_name => "Terry Brooks", :publisher => "DelRey")
    [[], {}, nil, ""].each do |blank|
      assert_equal 2, Topic.find(:first).books.find(:all, :conditions => blank).size
    end
  end
 
  
end