aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/models
diff options
context:
space:
mode:
authorJeremy Kemper <jeremy@bitsweat.net>2008-01-18 07:27:03 +0000
committerJeremy Kemper <jeremy@bitsweat.net>2008-01-18 07:27:03 +0000
commit43b81d01d0a175c76fea1cdad2484ceb64ca659b (patch)
tree1afa41720e50b5dd605e77cb6048ad58bb4332e8 /activerecord/test/models
parent49794485b6629a04d7efe324d7c91c0845dbdc2f (diff)
downloadrails-43b81d01d0a175c76fea1cdad2484ceb64ca659b.tar.gz
rails-43b81d01d0a175c76fea1cdad2484ceb64ca659b.tar.bz2
rails-43b81d01d0a175c76fea1cdad2484ceb64ca659b.zip
move assets and models
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8657 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/test/models')
-rw-r--r--activerecord/test/models/author.rb109
-rw-r--r--activerecord/test/models/auto_id.rb4
-rw-r--r--activerecord/test/models/binary.rb2
-rw-r--r--activerecord/test/models/book.rb4
-rw-r--r--activerecord/test/models/categorization.rb5
-rw-r--r--activerecord/test/models/category.rb26
-rw-r--r--activerecord/test/models/citation.rb6
-rw-r--r--activerecord/test/models/column_name.rb3
-rw-r--r--activerecord/test/models/comment.rb23
-rwxr-xr-xactiverecord/test/models/company.rb114
-rw-r--r--activerecord/test/models/company_in_module.rb59
-rw-r--r--activerecord/test/models/computer.rb3
-rw-r--r--activerecord/test/models/contact.rb16
-rw-r--r--activerecord/test/models/course.rb3
-rw-r--r--activerecord/test/models/customer.rb55
-rw-r--r--activerecord/test/models/default.rb2
-rw-r--r--activerecord/test/models/developer.rb72
-rw-r--r--activerecord/test/models/edge.rb5
-rw-r--r--activerecord/test/models/entrant.rb3
-rw-r--r--activerecord/test/models/item.rb7
-rw-r--r--activerecord/test/models/joke.rb3
-rw-r--r--activerecord/test/models/keyboard.rb3
-rw-r--r--activerecord/test/models/legacy_thing.rb3
-rw-r--r--activerecord/test/models/matey.rb4
-rw-r--r--activerecord/test/models/minimalistic.rb2
-rw-r--r--activerecord/test/models/mixed_case_monkey.rb3
-rw-r--r--activerecord/test/models/movie.rb5
-rw-r--r--activerecord/test/models/order.rb4
-rw-r--r--activerecord/test/models/parrot.rb13
-rw-r--r--activerecord/test/models/person.rb4
-rw-r--r--activerecord/test/models/pirate.rb5
-rw-r--r--activerecord/test/models/post.rb59
-rw-r--r--activerecord/test/models/project.rb28
-rw-r--r--activerecord/test/models/reader.rb4
-rwxr-xr-xactiverecord/test/models/reply.rb37
-rw-r--r--activerecord/test/models/ship.rb3
-rw-r--r--activerecord/test/models/subject.rb4
-rw-r--r--activerecord/test/models/subscriber.rb6
-rw-r--r--activerecord/test/models/tag.rb7
-rw-r--r--activerecord/test/models/tagging.rb10
-rw-r--r--activerecord/test/models/task.rb3
-rwxr-xr-xactiverecord/test/models/topic.rb37
-rw-r--r--activerecord/test/models/treasure.rb4
-rw-r--r--activerecord/test/models/vertex.rb9
-rw-r--r--activerecord/test/models/warehouse_thing.rb5
45 files changed, 786 insertions, 0 deletions
diff --git a/activerecord/test/models/author.rb b/activerecord/test/models/author.rb
new file mode 100644
index 0000000000..bf0c993c50
--- /dev/null
+++ b/activerecord/test/models/author.rb
@@ -0,0 +1,109 @@
+class Author < ActiveRecord::Base
+ has_many :posts
+ has_many :posts_with_comments, :include => :comments, :class_name => "Post"
+ has_many :posts_with_categories, :include => :categories, :class_name => "Post"
+ has_many :posts_with_comments_and_categories, :include => [ :comments, :categories ], :order => "posts.id", :class_name => "Post"
+ has_many :posts_with_extension, :class_name => "Post" do #, :extend => ProxyTestExtension
+ def testing_proxy_owner
+ proxy_owner
+ end
+ def testing_proxy_reflection
+ proxy_reflection
+ end
+ def testing_proxy_target
+ proxy_target
+ end
+ end
+ has_many :comments, :through => :posts
+ has_many :comments_desc, :through => :posts, :source => :comments, :order => 'comments.id DESC'
+ has_many :limited_comments, :through => :posts, :source => :comments, :limit => 1
+ has_many :funky_comments, :through => :posts, :source => :comments
+ has_many :ordered_uniq_comments, :through => :posts, :source => :comments, :uniq => true, :order => 'comments.id'
+ has_many :ordered_uniq_comments_desc, :through => :posts, :source => :comments, :uniq => true, :order => 'comments.id DESC'
+
+ has_many :special_posts
+ has_many :special_post_comments, :through => :special_posts, :source => :comments
+
+ has_many :special_nonexistant_posts, :class_name => "SpecialPost", :conditions => "posts.body = 'nonexistant'"
+ has_many :special_nonexistant_post_comments, :through => :special_nonexistant_posts, :source => :comments, :conditions => "comments.post_id = 0"
+ has_many :nonexistant_comments, :through => :posts
+
+ has_many :hello_posts, :class_name => "Post", :conditions => "posts.body = 'hello'"
+ has_many :hello_post_comments, :through => :hello_posts, :source => :comments
+ has_many :posts_with_no_comments, :class_name => 'Post', :conditions => 'comments.id is null', :include => :comments
+
+ has_many :other_posts, :class_name => "Post"
+ has_many :posts_with_callbacks, :class_name => "Post", :before_add => :log_before_adding,
+ :after_add => :log_after_adding,
+ :before_remove => :log_before_removing,
+ :after_remove => :log_after_removing
+ has_many :posts_with_proc_callbacks, :class_name => "Post",
+ :before_add => Proc.new {|o, r| o.post_log << "before_adding#{r.id || '<new>'}"},
+ :after_add => Proc.new {|o, r| o.post_log << "after_adding#{r.id || '<new>'}"},
+ :before_remove => Proc.new {|o, r| o.post_log << "before_removing#{r.id}"},
+ :after_remove => Proc.new {|o, r| o.post_log << "after_removing#{r.id}"}
+ has_many :posts_with_multiple_callbacks, :class_name => "Post",
+ :before_add => [:log_before_adding, Proc.new {|o, r| o.post_log << "before_adding_proc#{r.id || '<new>'}"}],
+ :after_add => [:log_after_adding, Proc.new {|o, r| o.post_log << "after_adding_proc#{r.id || '<new>'}"}]
+ has_many :unchangable_posts, :class_name => "Post", :before_add => :raise_exception, :after_add => :log_after_adding
+
+ has_many :categorizations
+ has_many :categories, :through => :categorizations
+
+ has_many :categories_like_general, :through => :categorizations, :source => :category, :class_name => 'Category', :conditions => { :name => 'General' }
+
+ has_many :categorized_posts, :through => :categorizations, :source => :post
+ has_many :unique_categorized_posts, :through => :categorizations, :source => :post, :uniq => true
+
+ has_many :nothings, :through => :kateggorisatons, :class_name => 'Category'
+
+ has_many :author_favorites
+ has_many :favorite_authors, :through => :author_favorites, :order => 'name'
+
+ has_many :tagging, :through => :posts # through polymorphic has_one
+ has_many :taggings, :through => :posts, :source => :taggings # through polymorphic has_many
+ has_many :tags, :through => :posts # through has_many :through
+ has_many :post_categories, :through => :posts, :source => :categories
+
+ belongs_to :author_address
+
+ attr_accessor :post_log
+
+ def after_initialize
+ @post_log = []
+ end
+
+ def label
+ "#{id}-#{name}"
+ end
+
+ private
+ def log_before_adding(object)
+ @post_log << "before_adding#{object.id || '<new>'}"
+ end
+
+ def log_after_adding(object)
+ @post_log << "after_adding#{object.id}"
+ end
+
+ def log_before_removing(object)
+ @post_log << "before_removing#{object.id}"
+ end
+
+ def log_after_removing(object)
+ @post_log << "after_removing#{object.id}"
+ end
+
+ def raise_exception(object)
+ raise Exception.new("You can't add a post")
+ end
+end
+
+class AuthorAddress < ActiveRecord::Base
+ has_one :author
+end
+
+class AuthorFavorite < ActiveRecord::Base
+ belongs_to :author
+ belongs_to :favorite_author, :class_name => "Author"
+end
diff --git a/activerecord/test/models/auto_id.rb b/activerecord/test/models/auto_id.rb
new file mode 100644
index 0000000000..d720e2be5e
--- /dev/null
+++ b/activerecord/test/models/auto_id.rb
@@ -0,0 +1,4 @@
+class AutoId < ActiveRecord::Base
+ def self.table_name () "auto_id_tests" end
+ def self.primary_key () "auto_id" end
+end
diff --git a/activerecord/test/models/binary.rb b/activerecord/test/models/binary.rb
new file mode 100644
index 0000000000..950c459199
--- /dev/null
+++ b/activerecord/test/models/binary.rb
@@ -0,0 +1,2 @@
+class Binary < ActiveRecord::Base
+end \ No newline at end of file
diff --git a/activerecord/test/models/book.rb b/activerecord/test/models/book.rb
new file mode 100644
index 0000000000..cfd07abddc
--- /dev/null
+++ b/activerecord/test/models/book.rb
@@ -0,0 +1,4 @@
+class Book < ActiveRecord::Base
+ has_many :citations, :foreign_key => 'book1_id'
+ has_many :references, :through => :citations, :source => :reference_of, :uniq => true
+end
diff --git a/activerecord/test/models/categorization.rb b/activerecord/test/models/categorization.rb
new file mode 100644
index 0000000000..10594323ff
--- /dev/null
+++ b/activerecord/test/models/categorization.rb
@@ -0,0 +1,5 @@
+class Categorization < ActiveRecord::Base
+ belongs_to :post
+ belongs_to :category
+ belongs_to :author
+end \ No newline at end of file
diff --git a/activerecord/test/models/category.rb b/activerecord/test/models/category.rb
new file mode 100644
index 0000000000..89d61b7e4e
--- /dev/null
+++ b/activerecord/test/models/category.rb
@@ -0,0 +1,26 @@
+class Category < ActiveRecord::Base
+ has_and_belongs_to_many :posts
+ has_and_belongs_to_many :special_posts, :class_name => "Post"
+ has_and_belongs_to_many :other_posts, :class_name => "Post"
+
+ has_and_belongs_to_many(:select_testing_posts,
+ :class_name => 'Post',
+ :foreign_key => 'category_id',
+ :association_foreign_key => 'post_id',
+ :select => 'posts.*, 1 as correctness_marker')
+
+ def self.what_are_you
+ 'a category...'
+ end
+
+ has_many :categorizations
+ has_many :authors, :through => :categorizations, :select => 'authors.*, categorizations.post_id'
+end
+
+class SpecialCategory < Category
+
+ def self.what_are_you
+ 'a special category...'
+ end
+
+end
diff --git a/activerecord/test/models/citation.rb b/activerecord/test/models/citation.rb
new file mode 100644
index 0000000000..545aa8110d
--- /dev/null
+++ b/activerecord/test/models/citation.rb
@@ -0,0 +1,6 @@
+class Citation < ActiveRecord::Base
+ belongs_to :reference_of, :class_name => "Book", :foreign_key => :book2_id
+
+ belongs_to :book1, :class_name => "Book", :foreign_key => :book1_id
+ belongs_to :book2, :class_name => "Book", :foreign_key => :book2_id
+end
diff --git a/activerecord/test/models/column_name.rb b/activerecord/test/models/column_name.rb
new file mode 100644
index 0000000000..ec07205a3a
--- /dev/null
+++ b/activerecord/test/models/column_name.rb
@@ -0,0 +1,3 @@
+class ColumnName < ActiveRecord::Base
+ def self.table_name () "colnametests" end
+end \ No newline at end of file
diff --git a/activerecord/test/models/comment.rb b/activerecord/test/models/comment.rb
new file mode 100644
index 0000000000..60ca082c2e
--- /dev/null
+++ b/activerecord/test/models/comment.rb
@@ -0,0 +1,23 @@
+class Comment < ActiveRecord::Base
+ belongs_to :post
+
+ def self.what_are_you
+ 'a comment...'
+ end
+
+ def self.search_by_type(q)
+ self.find(:all, :conditions => ["#{QUOTED_TYPE} = ?", q])
+ end
+end
+
+class SpecialComment < Comment
+ def self.what_are_you
+ 'a special comment...'
+ end
+end
+
+class VerySpecialComment < Comment
+ def self.what_are_you
+ 'a very special comment...'
+ end
+end \ No newline at end of file
diff --git a/activerecord/test/models/company.rb b/activerecord/test/models/company.rb
new file mode 100755
index 0000000000..c33f188a02
--- /dev/null
+++ b/activerecord/test/models/company.rb
@@ -0,0 +1,114 @@
+class AbstractCompany < ActiveRecord::Base
+ self.abstract_class = true
+end
+
+class Company < AbstractCompany
+ attr_protected :rating
+ set_sequence_name :companies_nonstd_seq
+
+ validates_presence_of :name
+
+ has_one :dummy_account, :foreign_key => "firm_id", :class_name => "Account"
+
+ def arbitrary_method
+ "I am Jack's profound disappointment"
+ end
+end
+
+
+class Firm < Company
+ has_many :clients, :order => "id", :dependent => :destroy, :counter_sql =>
+ "SELECT COUNT(*) FROM companies WHERE firm_id = 1 " +
+ "AND (#{QUOTED_TYPE} = 'Client' OR #{QUOTED_TYPE} = 'SpecialClient' OR #{QUOTED_TYPE} = 'VerySpecialClient' )"
+ has_many :clients_sorted_desc, :class_name => "Client", :order => "id DESC"
+ has_many :clients_of_firm, :foreign_key => "client_of", :class_name => "Client", :order => "id"
+ has_many :dependent_clients_of_firm, :foreign_key => "client_of", :class_name => "Client", :order => "id", :dependent => :destroy
+ has_many :exclusively_dependent_clients_of_firm, :foreign_key => "client_of", :class_name => "Client", :order => "id", :dependent => :delete_all
+ has_many :limited_clients, :class_name => "Client", :order => "id", :limit => 1
+ has_many :clients_like_ms, :conditions => "name = 'Microsoft'", :class_name => "Client", :order => "id"
+ has_many :clients_with_interpolated_conditions, :class_name => "Client", :conditions => 'rating > #{rating}'
+ has_many :clients_like_ms_with_hash_conditions, :conditions => { :name => 'Microsoft' }, :class_name => "Client", :order => "id"
+ has_many :clients_using_sql, :class_name => "Client", :finder_sql => 'SELECT * FROM companies WHERE client_of = #{id}'
+ has_many :clients_using_counter_sql, :class_name => "Client",
+ :finder_sql => 'SELECT * FROM companies WHERE client_of = #{id}',
+ :counter_sql => 'SELECT COUNT(*) FROM companies WHERE client_of = #{id}'
+ has_many :clients_using_zero_counter_sql, :class_name => "Client",
+ :finder_sql => 'SELECT * FROM companies WHERE client_of = #{id}',
+ :counter_sql => 'SELECT 0 FROM companies WHERE client_of = #{id}'
+ has_many :no_clients_using_counter_sql, :class_name => "Client",
+ :finder_sql => 'SELECT * FROM companies WHERE client_of = 1000',
+ :counter_sql => 'SELECT COUNT(*) FROM companies WHERE client_of = 1000'
+ has_many :clients_using_finder_sql, :class_name => "Client", :finder_sql => 'SELECT * FROM companies WHERE 1=1'
+ has_many :plain_clients, :class_name => 'Client'
+
+ has_one :account, :foreign_key => "firm_id", :dependent => :destroy
+end
+
+class DependentFirm < Company
+ has_one :account, :foreign_key => "firm_id", :dependent => :nullify
+ has_many :companies, :foreign_key => 'client_of', :order => "id", :dependent => :nullify
+end
+
+class ExclusivelyDependentFirm < Company
+ has_one :account, :foreign_key => "firm_id", :dependent => :delete
+ has_many :dependent_sanitized_conditional_clients_of_firm, :foreign_key => "client_of", :class_name => "Client", :order => "id", :dependent => :delete_all, :conditions => "name = 'BigShot Inc.'"
+ has_many :dependent_conditional_clients_of_firm, :foreign_key => "client_of", :class_name => "Client", :order => "id", :dependent => :delete_all, :conditions => ["name = ?", 'BigShot Inc.']
+end
+
+class Client < Company
+ belongs_to :firm, :foreign_key => "client_of"
+ belongs_to :firm_with_basic_id, :class_name => "Firm", :foreign_key => "firm_id"
+ belongs_to :firm_with_other_name, :class_name => "Firm", :foreign_key => "client_of"
+ belongs_to :firm_with_condition, :class_name => "Firm", :foreign_key => "client_of", :conditions => ["1 = ?", 1]
+
+ # Record destruction so we can test whether firm.clients.clear has
+ # is calling client.destroy, deleting from the database, or setting
+ # foreign keys to NULL.
+ def self.destroyed_client_ids
+ @destroyed_client_ids ||= Hash.new { |h,k| h[k] = [] }
+ end
+
+ before_destroy do |client|
+ if client.firm
+ Client.destroyed_client_ids[client.firm.id] << client.id
+ end
+ true
+ end
+
+ # Used to test that read and question methods are not generated for these attributes
+ def ruby_type
+ read_attribute :ruby_type
+ end
+
+ def rating?
+ query_attribute :rating
+ end
+end
+
+
+class SpecialClient < Client
+end
+
+class VerySpecialClient < SpecialClient
+end
+
+class Account < ActiveRecord::Base
+ belongs_to :firm
+
+ def self.destroyed_account_ids
+ @destroyed_account_ids ||= Hash.new { |h,k| h[k] = [] }
+ end
+
+ before_destroy do |account|
+ if account.firm
+ Account.destroyed_account_ids[account.firm.id] << account.id
+ end
+ true
+ end
+
+
+ protected
+ def validate
+ errors.add_on_empty "credit_limit"
+ end
+end
diff --git a/activerecord/test/models/company_in_module.rb b/activerecord/test/models/company_in_module.rb
new file mode 100644
index 0000000000..2f269f9c3f
--- /dev/null
+++ b/activerecord/test/models/company_in_module.rb
@@ -0,0 +1,59 @@
+module MyApplication
+ module Business
+ class Company < ActiveRecord::Base
+ attr_protected :rating
+ end
+
+ class Firm < Company
+ has_many :clients, :order => "id", :dependent => :destroy
+ has_many :clients_sorted_desc, :class_name => "Client", :order => "id DESC"
+ has_many :clients_of_firm, :foreign_key => "client_of", :class_name => "Client", :order => "id"
+ has_many :clients_like_ms, :conditions => "name = 'Microsoft'", :class_name => "Client", :order => "id"
+ has_many :clients_using_sql, :class_name => "Client", :finder_sql => 'SELECT * FROM companies WHERE client_of = #{id}'
+
+ has_one :account, :dependent => :destroy
+ end
+
+ class Client < Company
+ belongs_to :firm, :foreign_key => "client_of"
+ belongs_to :firm_with_other_name, :class_name => "Firm", :foreign_key => "client_of"
+ end
+
+ class Developer < ActiveRecord::Base
+ has_and_belongs_to_many :projects
+ validates_length_of :name, :within => (3..20)
+ end
+
+ class Project < ActiveRecord::Base
+ has_and_belongs_to_many :developers
+ end
+
+ end
+
+ module Billing
+ class Firm < ActiveRecord::Base
+ self.table_name = 'companies'
+ end
+
+ module Nested
+ class Firm < ActiveRecord::Base
+ self.table_name = 'companies'
+ end
+ end
+
+ class Account < ActiveRecord::Base
+ with_options(:foreign_key => :firm_id) do |i|
+ i.belongs_to :firm, :class_name => 'MyApplication::Business::Firm'
+ i.belongs_to :qualified_billing_firm, :class_name => 'MyApplication::Billing::Firm'
+ i.belongs_to :unqualified_billing_firm, :class_name => 'Firm'
+ i.belongs_to :nested_qualified_billing_firm, :class_name => 'MyApplication::Billing::Nested::Firm'
+ i.belongs_to :nested_unqualified_billing_firm, :class_name => 'Nested::Firm'
+ end
+
+ protected
+ def validate
+ errors.add_on_empty "credit_limit"
+ end
+ end
+ end
+end
diff --git a/activerecord/test/models/computer.rb b/activerecord/test/models/computer.rb
new file mode 100644
index 0000000000..cc8deb1b2b
--- /dev/null
+++ b/activerecord/test/models/computer.rb
@@ -0,0 +1,3 @@
+class Computer < ActiveRecord::Base
+ belongs_to :developer, :foreign_key=>'developer'
+end
diff --git a/activerecord/test/models/contact.rb b/activerecord/test/models/contact.rb
new file mode 100644
index 0000000000..dbfa57bf49
--- /dev/null
+++ b/activerecord/test/models/contact.rb
@@ -0,0 +1,16 @@
+class Contact < ActiveRecord::Base
+ # mock out self.columns so no pesky db is needed for these tests
+ def self.column(name, sql_type = nil, options = {})
+ @columns ||= []
+ @columns << ActiveRecord::ConnectionAdapters::Column.new(name.to_s, options[:default], sql_type.to_s, options[:null])
+ end
+
+ column :name, :string
+ column :age, :integer
+ column :avatar, :binary
+ column :created_at, :datetime
+ column :awesome, :boolean
+ column :preferences, :string
+
+ serialize :preferences
+end \ No newline at end of file
diff --git a/activerecord/test/models/course.rb b/activerecord/test/models/course.rb
new file mode 100644
index 0000000000..8a40fa740d
--- /dev/null
+++ b/activerecord/test/models/course.rb
@@ -0,0 +1,3 @@
+class Course < ActiveRecord::Base
+ has_many :entrants
+end
diff --git a/activerecord/test/models/customer.rb b/activerecord/test/models/customer.rb
new file mode 100644
index 0000000000..030bbc6237
--- /dev/null
+++ b/activerecord/test/models/customer.rb
@@ -0,0 +1,55 @@
+class Customer < ActiveRecord::Base
+ composed_of :address, :mapping => [ %w(address_street street), %w(address_city city), %w(address_country country) ], :allow_nil => true
+ composed_of(:balance, :class_name => "Money", :mapping => %w(balance amount)) { |balance| balance.to_money }
+ composed_of :gps_location, :allow_nil => true
+end
+
+class Address
+ attr_reader :street, :city, :country
+
+ def initialize(street, city, country)
+ @street, @city, @country = street, city, country
+ end
+
+ def close_to?(other_address)
+ city == other_address.city && country == other_address.country
+ end
+
+ def ==(other)
+ other.is_a?(self.class) && other.street == street && other.city == city && other.country == country
+ end
+end
+
+class Money
+ attr_reader :amount, :currency
+
+ EXCHANGE_RATES = { "USD_TO_DKK" => 6, "DKK_TO_USD" => 0.6 }
+
+ def initialize(amount, currency = "USD")
+ @amount, @currency = amount, currency
+ end
+
+ def exchange_to(other_currency)
+ Money.new((amount * EXCHANGE_RATES["#{currency}_TO_#{other_currency}"]).floor, other_currency)
+ end
+end
+
+class GpsLocation
+ attr_reader :gps_location
+
+ def initialize(gps_location)
+ @gps_location = gps_location
+ end
+
+ def latitude
+ gps_location.split("x").first
+ end
+
+ def longitude
+ gps_location.split("x").last
+ end
+
+ def ==(other)
+ self.latitude == other.latitude && self.longitude == other.longitude
+ end
+end
diff --git a/activerecord/test/models/default.rb b/activerecord/test/models/default.rb
new file mode 100644
index 0000000000..887e9cc999
--- /dev/null
+++ b/activerecord/test/models/default.rb
@@ -0,0 +1,2 @@
+class Default < ActiveRecord::Base
+end
diff --git a/activerecord/test/models/developer.rb b/activerecord/test/models/developer.rb
new file mode 100644
index 0000000000..192c2cb5ab
--- /dev/null
+++ b/activerecord/test/models/developer.rb
@@ -0,0 +1,72 @@
+module DeveloperProjectsAssociationExtension
+ def find_most_recent
+ find(:first, :order => "id DESC")
+ end
+end
+
+module DeveloperProjectsAssociationExtension2
+ def find_least_recent
+ find(:first, :order => "id ASC")
+ end
+end
+
+class Developer < ActiveRecord::Base
+ has_and_belongs_to_many :projects do
+ def find_most_recent
+ find(:first, :order => "id DESC")
+ end
+ end
+
+ has_and_belongs_to_many :projects_extended_by_name,
+ :class_name => "Project",
+ :join_table => "developers_projects",
+ :association_foreign_key => "project_id",
+ :extend => DeveloperProjectsAssociationExtension
+
+ has_and_belongs_to_many :projects_extended_by_name_twice,
+ :class_name => "Project",
+ :join_table => "developers_projects",
+ :association_foreign_key => "project_id",
+ :extend => [DeveloperProjectsAssociationExtension, DeveloperProjectsAssociationExtension2]
+
+ has_and_belongs_to_many :projects_extended_by_name_and_block,
+ :class_name => "Project",
+ :join_table => "developers_projects",
+ :association_foreign_key => "project_id",
+ :extend => DeveloperProjectsAssociationExtension do
+ def find_least_recent
+ find(:first, :order => "id ASC")
+ end
+ end
+
+ has_and_belongs_to_many :special_projects, :join_table => 'developers_projects', :association_foreign_key => 'project_id'
+
+ has_many :audit_logs
+
+ validates_inclusion_of :salary, :in => 50000..200000
+ validates_length_of :name, :within => 3..20
+
+ before_create do |developer|
+ developer.audit_logs.build :message => "Computer created"
+ end
+end
+
+class AuditLog < ActiveRecord::Base
+ belongs_to :developer
+end
+
+DeveloperSalary = Struct.new(:amount)
+class DeveloperWithAggregate < ActiveRecord::Base
+ self.table_name = 'developers'
+ composed_of :salary, :class_name => 'DeveloperSalary', :mapping => [%w(salary amount)]
+end
+
+class DeveloperWithBeforeDestroyRaise < ActiveRecord::Base
+ self.table_name = 'developers'
+ has_and_belongs_to_many :projects, :join_table => 'developers_projects', :foreign_key => 'developer_id'
+ before_destroy :raise_if_projects_empty!
+
+ def raise_if_projects_empty!
+ raise if projects.empty?
+ end
+end
diff --git a/activerecord/test/models/edge.rb b/activerecord/test/models/edge.rb
new file mode 100644
index 0000000000..55e0c31fcb
--- /dev/null
+++ b/activerecord/test/models/edge.rb
@@ -0,0 +1,5 @@
+# This class models an edge in a directed graph.
+class Edge < ActiveRecord::Base
+ belongs_to :source, :class_name => 'Vertex', :foreign_key => 'source_id'
+ belongs_to :sink, :class_name => 'Vertex', :foreign_key => 'sink_id'
+end
diff --git a/activerecord/test/models/entrant.rb b/activerecord/test/models/entrant.rb
new file mode 100644
index 0000000000..4682ce48c8
--- /dev/null
+++ b/activerecord/test/models/entrant.rb
@@ -0,0 +1,3 @@
+class Entrant < ActiveRecord::Base
+ belongs_to :course
+end
diff --git a/activerecord/test/models/item.rb b/activerecord/test/models/item.rb
new file mode 100644
index 0000000000..c2571dd7fb
--- /dev/null
+++ b/activerecord/test/models/item.rb
@@ -0,0 +1,7 @@
+class AbstractItem < ActiveRecord::Base
+ self.abstract_class = true
+ has_one :tagging, :as => :taggable
+end
+
+class Item < AbstractItem
+end
diff --git a/activerecord/test/models/joke.rb b/activerecord/test/models/joke.rb
new file mode 100644
index 0000000000..3978abc2ba
--- /dev/null
+++ b/activerecord/test/models/joke.rb
@@ -0,0 +1,3 @@
+class Joke < ActiveRecord::Base
+ set_table_name 'funny_jokes'
+end
diff --git a/activerecord/test/models/keyboard.rb b/activerecord/test/models/keyboard.rb
new file mode 100644
index 0000000000..32a4a7fad0
--- /dev/null
+++ b/activerecord/test/models/keyboard.rb
@@ -0,0 +1,3 @@
+class Keyboard < ActiveRecord::Base
+ set_primary_key 'key_number'
+end
diff --git a/activerecord/test/models/legacy_thing.rb b/activerecord/test/models/legacy_thing.rb
new file mode 100644
index 0000000000..eaeb642d12
--- /dev/null
+++ b/activerecord/test/models/legacy_thing.rb
@@ -0,0 +1,3 @@
+class LegacyThing < ActiveRecord::Base
+ set_locking_column :version
+end
diff --git a/activerecord/test/models/matey.rb b/activerecord/test/models/matey.rb
new file mode 100644
index 0000000000..47b0baa974
--- /dev/null
+++ b/activerecord/test/models/matey.rb
@@ -0,0 +1,4 @@
+class Matey < ActiveRecord::Base
+ belongs_to :pirate
+ belongs_to :target, :class_name => 'Pirate'
+end
diff --git a/activerecord/test/models/minimalistic.rb b/activerecord/test/models/minimalistic.rb
new file mode 100644
index 0000000000..2e3f8e081a
--- /dev/null
+++ b/activerecord/test/models/minimalistic.rb
@@ -0,0 +1,2 @@
+class Minimalistic < ActiveRecord::Base
+end
diff --git a/activerecord/test/models/mixed_case_monkey.rb b/activerecord/test/models/mixed_case_monkey.rb
new file mode 100644
index 0000000000..853f2682b3
--- /dev/null
+++ b/activerecord/test/models/mixed_case_monkey.rb
@@ -0,0 +1,3 @@
+class MixedCaseMonkey < ActiveRecord::Base
+ set_primary_key 'monkeyID'
+end
diff --git a/activerecord/test/models/movie.rb b/activerecord/test/models/movie.rb
new file mode 100644
index 0000000000..6384b4c801
--- /dev/null
+++ b/activerecord/test/models/movie.rb
@@ -0,0 +1,5 @@
+class Movie < ActiveRecord::Base
+ def self.primary_key
+ "movieid"
+ end
+end
diff --git a/activerecord/test/models/order.rb b/activerecord/test/models/order.rb
new file mode 100644
index 0000000000..e838c0b70d
--- /dev/null
+++ b/activerecord/test/models/order.rb
@@ -0,0 +1,4 @@
+class Order < ActiveRecord::Base
+ belongs_to :billing, :class_name => 'Customer', :foreign_key => 'billing_customer_id'
+ belongs_to :shipping, :class_name => 'Customer', :foreign_key => 'shipping_customer_id'
+end
diff --git a/activerecord/test/models/parrot.rb b/activerecord/test/models/parrot.rb
new file mode 100644
index 0000000000..65191c1aa5
--- /dev/null
+++ b/activerecord/test/models/parrot.rb
@@ -0,0 +1,13 @@
+class Parrot < ActiveRecord::Base
+ set_inheritance_column :parrot_sti_class
+ has_and_belongs_to_many :pirates
+ has_and_belongs_to_many :treasures
+ has_many :loots, :as => :looter
+end
+
+class LiveParrot < Parrot
+end
+
+class DeadParrot < Parrot
+ belongs_to :killer, :class_name => 'Pirate'
+end
diff --git a/activerecord/test/models/person.rb b/activerecord/test/models/person.rb
new file mode 100644
index 0000000000..7a9666f4eb
--- /dev/null
+++ b/activerecord/test/models/person.rb
@@ -0,0 +1,4 @@
+class Person < ActiveRecord::Base
+ has_many :readers
+ has_many :posts, :through => :readers
+end
diff --git a/activerecord/test/models/pirate.rb b/activerecord/test/models/pirate.rb
new file mode 100644
index 0000000000..f7193dfbe0
--- /dev/null
+++ b/activerecord/test/models/pirate.rb
@@ -0,0 +1,5 @@
+class Pirate < ActiveRecord::Base
+ belongs_to :parrot
+ has_and_belongs_to_many :parrots
+ has_many :loots, :as => :looter
+end
diff --git a/activerecord/test/models/post.rb b/activerecord/test/models/post.rb
new file mode 100644
index 0000000000..53dcbb74f3
--- /dev/null
+++ b/activerecord/test/models/post.rb
@@ -0,0 +1,59 @@
+class Post < ActiveRecord::Base
+ belongs_to :author do
+ def greeting
+ "hello"
+ end
+ end
+
+ belongs_to :author_with_posts, :class_name => "Author", :foreign_key => :author_id, :include => :posts
+
+ has_many :comments, :order => "body" do
+ def find_most_recent
+ find(:first, :order => "id DESC")
+ end
+ end
+
+ has_one :very_special_comment
+ has_one :very_special_comment_with_post, :class_name => "VerySpecialComment", :include => :post
+ has_many :special_comments
+ has_many :nonexistant_comments, :class_name => 'Comment', :conditions => 'comments.id < 0'
+
+ has_and_belongs_to_many :categories
+ has_and_belongs_to_many :special_categories, :join_table => "categories_posts", :association_foreign_key => 'category_id'
+
+ has_many :taggings, :as => :taggable
+ has_many :tags, :through => :taggings, :include => :tagging do
+ def add_joins_and_select
+ find :all, :select => 'tags.*, authors.id as author_id', :include => false,
+ :joins => 'left outer join posts on taggings.taggable_id = posts.id left outer join authors on posts.author_id = authors.id'
+ end
+ end
+
+ has_many :funky_tags, :through => :taggings, :source => :tag
+ has_many :super_tags, :through => :taggings
+ has_one :tagging, :as => :taggable
+
+ has_many :invalid_taggings, :as => :taggable, :class_name => "Tagging", :conditions => 'taggings.id < 0'
+ has_many :invalid_tags, :through => :invalid_taggings, :source => :tag
+
+ has_many :categorizations, :foreign_key => :category_id
+ has_many :authors, :through => :categorizations
+
+ has_many :readers
+ has_many :people, :through => :readers
+
+ def self.what_are_you
+ 'a post...'
+ end
+end
+
+class SpecialPost < Post; end
+
+class StiPost < Post
+ self.abstract_class = true
+ has_one :special_comment, :class_name => "SpecialComment"
+end
+
+class SubStiPost < StiPost
+ self.table_name = Post.table_name
+end
diff --git a/activerecord/test/models/project.rb b/activerecord/test/models/project.rb
new file mode 100644
index 0000000000..b90d2c6fbc
--- /dev/null
+++ b/activerecord/test/models/project.rb
@@ -0,0 +1,28 @@
+class Project < ActiveRecord::Base
+ has_and_belongs_to_many :developers, :uniq => true, :order => 'developers.name desc, developers.id desc'
+ has_and_belongs_to_many :selected_developers, :class_name => "Developer", :select => "developers.*", :uniq => true
+ has_and_belongs_to_many :non_unique_developers, :order => 'developers.name desc, developers.id desc', :class_name => 'Developer'
+ has_and_belongs_to_many :limited_developers, :class_name => "Developer", :limit => 1
+ has_and_belongs_to_many :developers_named_david, :class_name => "Developer", :conditions => "name = 'David'", :uniq => true
+ has_and_belongs_to_many :developers_named_david_with_hash_conditions, :class_name => "Developer", :conditions => { :name => 'David' }, :uniq => true
+ has_and_belongs_to_many :salaried_developers, :class_name => "Developer", :conditions => "salary > 0"
+ has_and_belongs_to_many :developers_with_finder_sql, :class_name => "Developer", :finder_sql => 'SELECT t.*, j.* FROM developers_projects j, developers t WHERE t.id = j.developer_id AND j.project_id = #{id}'
+ has_and_belongs_to_many :developers_by_sql, :class_name => "Developer", :delete_sql => "DELETE FROM developers_projects WHERE project_id = \#{id} AND developer_id = \#{record.id}"
+ has_and_belongs_to_many :developers_with_callbacks, :class_name => "Developer", :before_add => Proc.new {|o, r| o.developers_log << "before_adding#{r.id || '<new>'}"},
+ :after_add => Proc.new {|o, r| o.developers_log << "after_adding#{r.id || '<new>'}"},
+ :before_remove => Proc.new {|o, r| o.developers_log << "before_removing#{r.id}"},
+ :after_remove => Proc.new {|o, r| o.developers_log << "after_removing#{r.id}"}
+
+ attr_accessor :developers_log
+
+ def after_initialize
+ @developers_log = []
+ end
+
+end
+
+class SpecialProject < Project
+ def hello_world
+ "hello there!"
+ end
+end
diff --git a/activerecord/test/models/reader.rb b/activerecord/test/models/reader.rb
new file mode 100644
index 0000000000..27527bf566
--- /dev/null
+++ b/activerecord/test/models/reader.rb
@@ -0,0 +1,4 @@
+class Reader < ActiveRecord::Base
+ belongs_to :post
+ belongs_to :person
+end
diff --git a/activerecord/test/models/reply.rb b/activerecord/test/models/reply.rb
new file mode 100755
index 0000000000..b719bc2e82
--- /dev/null
+++ b/activerecord/test/models/reply.rb
@@ -0,0 +1,37 @@
+require 'fixtures/topic'
+
+class Reply < Topic
+ belongs_to :topic, :foreign_key => "parent_id", :counter_cache => true
+ has_many :replies, :class_name => "SillyReply", :dependent => :destroy, :foreign_key => "parent_id"
+
+ validate :errors_on_empty_content
+ validate_on_create :title_is_wrong_create
+
+ attr_accessible :title, :author_name, :author_email_address, :written_on, :content, :last_read
+
+ def validate
+ errors.add("title", "Empty") unless attribute_present? "title"
+ end
+
+ def errors_on_empty_content
+ errors.add("content", "Empty") unless attribute_present? "content"
+ end
+
+ def validate_on_create
+ if attribute_present?("title") && attribute_present?("content") && content == "Mismatch"
+ errors.add("title", "is Content Mismatch")
+ end
+ end
+
+ def title_is_wrong_create
+ errors.add("title", "is Wrong Create") if attribute_present?("title") && title == "Wrong Create"
+ end
+
+ def validate_on_update
+ errors.add("title", "is Wrong Update") if attribute_present?("title") && title == "Wrong Update"
+ end
+end
+
+class SillyReply < Reply
+ belongs_to :reply, :foreign_key => "parent_id", :counter_cache => :replies_count
+end
diff --git a/activerecord/test/models/ship.rb b/activerecord/test/models/ship.rb
new file mode 100644
index 0000000000..05b09fc1b9
--- /dev/null
+++ b/activerecord/test/models/ship.rb
@@ -0,0 +1,3 @@
+class Ship < ActiveRecord::Base
+ self.record_timestamps = false
+end \ No newline at end of file
diff --git a/activerecord/test/models/subject.rb b/activerecord/test/models/subject.rb
new file mode 100644
index 0000000000..3502943f3a
--- /dev/null
+++ b/activerecord/test/models/subject.rb
@@ -0,0 +1,4 @@
+# used for OracleSynonymTest, see test/synonym_test_oci.rb
+#
+class Subject < ActiveRecord::Base
+end
diff --git a/activerecord/test/models/subscriber.rb b/activerecord/test/models/subscriber.rb
new file mode 100644
index 0000000000..51335a8f20
--- /dev/null
+++ b/activerecord/test/models/subscriber.rb
@@ -0,0 +1,6 @@
+class Subscriber < ActiveRecord::Base
+ set_primary_key 'nick'
+end
+
+class SpecialSubscriber < Subscriber
+end
diff --git a/activerecord/test/models/tag.rb b/activerecord/test/models/tag.rb
new file mode 100644
index 0000000000..a581b381e8
--- /dev/null
+++ b/activerecord/test/models/tag.rb
@@ -0,0 +1,7 @@
+class Tag < ActiveRecord::Base
+ has_many :taggings
+ has_many :taggables, :through => :taggings
+ has_one :tagging
+
+ has_many :tagged_posts, :through => :taggings, :source => :taggable, :source_type => 'Post'
+end \ No newline at end of file
diff --git a/activerecord/test/models/tagging.rb b/activerecord/test/models/tagging.rb
new file mode 100644
index 0000000000..a1fa1a9750
--- /dev/null
+++ b/activerecord/test/models/tagging.rb
@@ -0,0 +1,10 @@
+# test that attr_readonly isn't called on the :taggable polymorphic association
+module Taggable
+end
+
+class Tagging < ActiveRecord::Base
+ belongs_to :tag, :include => :tagging
+ belongs_to :super_tag, :class_name => 'Tag', :foreign_key => 'super_tag_id'
+ belongs_to :invalid_tag, :class_name => 'Tag', :foreign_key => 'tag_id'
+ belongs_to :taggable, :polymorphic => true, :counter_cache => true
+end \ No newline at end of file
diff --git a/activerecord/test/models/task.rb b/activerecord/test/models/task.rb
new file mode 100644
index 0000000000..ee0282c79b
--- /dev/null
+++ b/activerecord/test/models/task.rb
@@ -0,0 +1,3 @@
+class Task < ActiveRecord::Base
+
+end
diff --git a/activerecord/test/models/topic.rb b/activerecord/test/models/topic.rb
new file mode 100755
index 0000000000..17e91e4b13
--- /dev/null
+++ b/activerecord/test/models/topic.rb
@@ -0,0 +1,37 @@
+class Topic < ActiveRecord::Base
+ has_many :replies, :dependent => :destroy, :foreign_key => "parent_id"
+ serialize :content
+
+ before_create :default_written_on
+ before_destroy :destroy_children
+
+ def parent
+ Topic.find(parent_id)
+ end
+
+ # trivial method for testing Array#to_xml with :methods
+ def topic_id
+ id
+ end
+
+
+ protected
+ def approved=(val)
+ @custom_approved = val
+ write_attribute(:approved, val)
+ end
+
+ def default_written_on
+ self.written_on = Time.now unless attribute_present?("written_on")
+ end
+
+ def destroy_children
+ self.class.delete_all "parent_id = #{id}"
+ end
+
+ def after_initialize
+ if self.new_record?
+ self.author_email_address = 'test@test.com'
+ end
+ end
+end \ No newline at end of file
diff --git a/activerecord/test/models/treasure.rb b/activerecord/test/models/treasure.rb
new file mode 100644
index 0000000000..7a429e2a2f
--- /dev/null
+++ b/activerecord/test/models/treasure.rb
@@ -0,0 +1,4 @@
+class Treasure < ActiveRecord::Base
+ has_and_belongs_to_many :parrots
+ belongs_to :looter, :polymorphic => true
+end
diff --git a/activerecord/test/models/vertex.rb b/activerecord/test/models/vertex.rb
new file mode 100644
index 0000000000..48bb851e62
--- /dev/null
+++ b/activerecord/test/models/vertex.rb
@@ -0,0 +1,9 @@
+# This class models a vertex in a directed graph.
+class Vertex < ActiveRecord::Base
+ has_many :sink_edges, :class_name => 'Edge', :foreign_key => 'source_id'
+ has_many :sinks, :through => :sink_edges
+
+ has_and_belongs_to_many :sources,
+ :class_name => 'Vertex', :join_table => 'edges',
+ :foreign_key => 'sink_id', :association_foreign_key => 'source_id'
+end
diff --git a/activerecord/test/models/warehouse_thing.rb b/activerecord/test/models/warehouse_thing.rb
new file mode 100644
index 0000000000..6ace1183cc
--- /dev/null
+++ b/activerecord/test/models/warehouse_thing.rb
@@ -0,0 +1,5 @@
+class WarehouseThing < ActiveRecord::Base
+ set_table_name "warehouse-things"
+
+ validates_uniqueness_of :value
+end \ No newline at end of file