From 43b81d01d0a175c76fea1cdad2484ceb64ca659b Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Fri, 18 Jan 2008 07:27:03 +0000 Subject: move assets and models git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8657 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- activerecord/test/assets/example.log | 1 + activerecord/test/assets/flowers.jpg | Bin 0 -> 5834 bytes activerecord/test/fixtures/author.rb | 109 ---------------------- activerecord/test/fixtures/auto_id.rb | 4 - activerecord/test/fixtures/binary.rb | 2 - activerecord/test/fixtures/book.rb | 4 - activerecord/test/fixtures/categorization.rb | 5 -- activerecord/test/fixtures/category.rb | 26 ------ activerecord/test/fixtures/citation.rb | 6 -- activerecord/test/fixtures/column_name.rb | 3 - activerecord/test/fixtures/comment.rb | 23 ----- activerecord/test/fixtures/company.rb | 114 ------------------------ activerecord/test/fixtures/company_in_module.rb | 59 ------------ activerecord/test/fixtures/computer.rb | 4 - activerecord/test/fixtures/contact.rb | 16 ---- activerecord/test/fixtures/course.rb | 3 - activerecord/test/fixtures/customer.rb | 55 ------------ activerecord/test/fixtures/default.rb | 2 - activerecord/test/fixtures/developer.rb | 72 --------------- activerecord/test/fixtures/edge.rb | 5 -- activerecord/test/fixtures/entrant.rb | 3 - activerecord/test/fixtures/example.log | 1 - activerecord/test/fixtures/flowers.jpg | Bin 5834 -> 0 bytes activerecord/test/fixtures/item.rb | 7 -- activerecord/test/fixtures/joke.rb | 3 - activerecord/test/fixtures/keyboard.rb | 3 - activerecord/test/fixtures/legacy_thing.rb | 3 - activerecord/test/fixtures/matey.rb | 4 - activerecord/test/fixtures/minimalistic.rb | 2 - activerecord/test/fixtures/mixed_case_monkey.rb | 3 - activerecord/test/fixtures/movie.rb | 5 -- activerecord/test/fixtures/order.rb | 4 - activerecord/test/fixtures/parrot.rb | 13 --- activerecord/test/fixtures/person.rb | 4 - activerecord/test/fixtures/pirate.rb | 5 -- activerecord/test/fixtures/post.rb | 59 ------------ activerecord/test/fixtures/project.rb | 28 ------ activerecord/test/fixtures/reader.rb | 4 - activerecord/test/fixtures/reply.rb | 37 -------- activerecord/test/fixtures/ship.rb | 3 - activerecord/test/fixtures/subject.rb | 4 - activerecord/test/fixtures/subscriber.rb | 6 -- activerecord/test/fixtures/tag.rb | 7 -- activerecord/test/fixtures/tagging.rb | 10 --- activerecord/test/fixtures/task.rb | 3 - activerecord/test/fixtures/topic.rb | 37 -------- activerecord/test/fixtures/treasure.rb | 4 - activerecord/test/fixtures/vertex.rb | 9 -- activerecord/test/fixtures/warehouse_thing.rb | 5 -- activerecord/test/models/author.rb | 109 ++++++++++++++++++++++ activerecord/test/models/auto_id.rb | 4 + activerecord/test/models/binary.rb | 2 + activerecord/test/models/book.rb | 4 + activerecord/test/models/categorization.rb | 5 ++ activerecord/test/models/category.rb | 26 ++++++ activerecord/test/models/citation.rb | 6 ++ activerecord/test/models/column_name.rb | 3 + activerecord/test/models/comment.rb | 23 +++++ activerecord/test/models/company.rb | 114 ++++++++++++++++++++++++ activerecord/test/models/company_in_module.rb | 59 ++++++++++++ activerecord/test/models/computer.rb | 3 + activerecord/test/models/contact.rb | 16 ++++ activerecord/test/models/course.rb | 3 + activerecord/test/models/customer.rb | 55 ++++++++++++ activerecord/test/models/default.rb | 2 + activerecord/test/models/developer.rb | 72 +++++++++++++++ activerecord/test/models/edge.rb | 5 ++ activerecord/test/models/entrant.rb | 3 + activerecord/test/models/item.rb | 7 ++ activerecord/test/models/joke.rb | 3 + activerecord/test/models/keyboard.rb | 3 + activerecord/test/models/legacy_thing.rb | 3 + activerecord/test/models/matey.rb | 4 + activerecord/test/models/minimalistic.rb | 2 + activerecord/test/models/mixed_case_monkey.rb | 3 + activerecord/test/models/movie.rb | 5 ++ activerecord/test/models/order.rb | 4 + activerecord/test/models/parrot.rb | 13 +++ activerecord/test/models/person.rb | 4 + activerecord/test/models/pirate.rb | 5 ++ activerecord/test/models/post.rb | 59 ++++++++++++ activerecord/test/models/project.rb | 28 ++++++ activerecord/test/models/reader.rb | 4 + activerecord/test/models/reply.rb | 37 ++++++++ activerecord/test/models/ship.rb | 3 + activerecord/test/models/subject.rb | 4 + activerecord/test/models/subscriber.rb | 6 ++ activerecord/test/models/tag.rb | 7 ++ activerecord/test/models/tagging.rb | 10 +++ activerecord/test/models/task.rb | 3 + activerecord/test/models/topic.rb | 37 ++++++++ activerecord/test/models/treasure.rb | 4 + activerecord/test/models/vertex.rb | 9 ++ activerecord/test/models/warehouse_thing.rb | 5 ++ 94 files changed, 787 insertions(+), 788 deletions(-) create mode 100644 activerecord/test/assets/example.log create mode 100644 activerecord/test/assets/flowers.jpg delete mode 100644 activerecord/test/fixtures/author.rb delete mode 100644 activerecord/test/fixtures/auto_id.rb delete mode 100644 activerecord/test/fixtures/binary.rb delete mode 100644 activerecord/test/fixtures/book.rb delete mode 100644 activerecord/test/fixtures/categorization.rb delete mode 100644 activerecord/test/fixtures/category.rb delete mode 100644 activerecord/test/fixtures/citation.rb delete mode 100644 activerecord/test/fixtures/column_name.rb delete mode 100644 activerecord/test/fixtures/comment.rb delete mode 100755 activerecord/test/fixtures/company.rb delete mode 100644 activerecord/test/fixtures/company_in_module.rb delete mode 100644 activerecord/test/fixtures/computer.rb delete mode 100644 activerecord/test/fixtures/contact.rb delete mode 100644 activerecord/test/fixtures/course.rb delete mode 100644 activerecord/test/fixtures/customer.rb delete mode 100644 activerecord/test/fixtures/default.rb delete mode 100644 activerecord/test/fixtures/developer.rb delete mode 100644 activerecord/test/fixtures/edge.rb delete mode 100644 activerecord/test/fixtures/entrant.rb delete mode 100644 activerecord/test/fixtures/example.log delete mode 100644 activerecord/test/fixtures/flowers.jpg delete mode 100644 activerecord/test/fixtures/item.rb delete mode 100644 activerecord/test/fixtures/joke.rb delete mode 100644 activerecord/test/fixtures/keyboard.rb delete mode 100644 activerecord/test/fixtures/legacy_thing.rb delete mode 100644 activerecord/test/fixtures/matey.rb delete mode 100644 activerecord/test/fixtures/minimalistic.rb delete mode 100644 activerecord/test/fixtures/mixed_case_monkey.rb delete mode 100644 activerecord/test/fixtures/movie.rb delete mode 100644 activerecord/test/fixtures/order.rb delete mode 100644 activerecord/test/fixtures/parrot.rb delete mode 100644 activerecord/test/fixtures/person.rb delete mode 100644 activerecord/test/fixtures/pirate.rb delete mode 100644 activerecord/test/fixtures/post.rb delete mode 100644 activerecord/test/fixtures/project.rb delete mode 100644 activerecord/test/fixtures/reader.rb delete mode 100755 activerecord/test/fixtures/reply.rb delete mode 100644 activerecord/test/fixtures/ship.rb delete mode 100644 activerecord/test/fixtures/subject.rb delete mode 100644 activerecord/test/fixtures/subscriber.rb delete mode 100644 activerecord/test/fixtures/tag.rb delete mode 100644 activerecord/test/fixtures/tagging.rb delete mode 100644 activerecord/test/fixtures/task.rb delete mode 100755 activerecord/test/fixtures/topic.rb delete mode 100644 activerecord/test/fixtures/treasure.rb delete mode 100644 activerecord/test/fixtures/vertex.rb delete mode 100644 activerecord/test/fixtures/warehouse_thing.rb create mode 100644 activerecord/test/models/author.rb create mode 100644 activerecord/test/models/auto_id.rb create mode 100644 activerecord/test/models/binary.rb create mode 100644 activerecord/test/models/book.rb create mode 100644 activerecord/test/models/categorization.rb create mode 100644 activerecord/test/models/category.rb create mode 100644 activerecord/test/models/citation.rb create mode 100644 activerecord/test/models/column_name.rb create mode 100644 activerecord/test/models/comment.rb create mode 100755 activerecord/test/models/company.rb create mode 100644 activerecord/test/models/company_in_module.rb create mode 100644 activerecord/test/models/computer.rb create mode 100644 activerecord/test/models/contact.rb create mode 100644 activerecord/test/models/course.rb create mode 100644 activerecord/test/models/customer.rb create mode 100644 activerecord/test/models/default.rb create mode 100644 activerecord/test/models/developer.rb create mode 100644 activerecord/test/models/edge.rb create mode 100644 activerecord/test/models/entrant.rb create mode 100644 activerecord/test/models/item.rb create mode 100644 activerecord/test/models/joke.rb create mode 100644 activerecord/test/models/keyboard.rb create mode 100644 activerecord/test/models/legacy_thing.rb create mode 100644 activerecord/test/models/matey.rb create mode 100644 activerecord/test/models/minimalistic.rb create mode 100644 activerecord/test/models/mixed_case_monkey.rb create mode 100644 activerecord/test/models/movie.rb create mode 100644 activerecord/test/models/order.rb create mode 100644 activerecord/test/models/parrot.rb create mode 100644 activerecord/test/models/person.rb create mode 100644 activerecord/test/models/pirate.rb create mode 100644 activerecord/test/models/post.rb create mode 100644 activerecord/test/models/project.rb create mode 100644 activerecord/test/models/reader.rb create mode 100755 activerecord/test/models/reply.rb create mode 100644 activerecord/test/models/ship.rb create mode 100644 activerecord/test/models/subject.rb create mode 100644 activerecord/test/models/subscriber.rb create mode 100644 activerecord/test/models/tag.rb create mode 100644 activerecord/test/models/tagging.rb create mode 100644 activerecord/test/models/task.rb create mode 100755 activerecord/test/models/topic.rb create mode 100644 activerecord/test/models/treasure.rb create mode 100644 activerecord/test/models/vertex.rb create mode 100644 activerecord/test/models/warehouse_thing.rb (limited to 'activerecord/test') diff --git a/activerecord/test/assets/example.log b/activerecord/test/assets/example.log new file mode 100644 index 0000000000..f084369d8c --- /dev/null +++ b/activerecord/test/assets/example.log @@ -0,0 +1 @@ +# Logfile created on Wed Oct 31 16:05:13 +0000 2007 by logger.rb/1.5.2.9 diff --git a/activerecord/test/assets/flowers.jpg b/activerecord/test/assets/flowers.jpg new file mode 100644 index 0000000000..fe9df546df Binary files /dev/null and b/activerecord/test/assets/flowers.jpg differ diff --git a/activerecord/test/fixtures/author.rb b/activerecord/test/fixtures/author.rb deleted file mode 100644 index 538ed7ac7f..0000000000 --- a/activerecord/test/fixtures/author.rb +++ /dev/null @@ -1,109 +0,0 @@ -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 || ''}"}, - :after_add => Proc.new {|o, r| o.post_log << "after_adding#{r.id || ''}"}, - :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 || ''}"}], - :after_add => [:log_after_adding, Proc.new {|o, r| o.post_log << "after_adding_proc#{r.id || ''}"}] - 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 || ''}" - 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/fixtures/auto_id.rb b/activerecord/test/fixtures/auto_id.rb deleted file mode 100644 index d720e2be5e..0000000000 --- a/activerecord/test/fixtures/auto_id.rb +++ /dev/null @@ -1,4 +0,0 @@ -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/fixtures/binary.rb b/activerecord/test/fixtures/binary.rb deleted file mode 100644 index 950c459199..0000000000 --- a/activerecord/test/fixtures/binary.rb +++ /dev/null @@ -1,2 +0,0 @@ -class Binary < ActiveRecord::Base -end \ No newline at end of file diff --git a/activerecord/test/fixtures/book.rb b/activerecord/test/fixtures/book.rb deleted file mode 100644 index cfd07abddc..0000000000 --- a/activerecord/test/fixtures/book.rb +++ /dev/null @@ -1,4 +0,0 @@ -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/fixtures/categorization.rb b/activerecord/test/fixtures/categorization.rb deleted file mode 100644 index 10594323ff..0000000000 --- a/activerecord/test/fixtures/categorization.rb +++ /dev/null @@ -1,5 +0,0 @@ -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/fixtures/category.rb b/activerecord/test/fixtures/category.rb deleted file mode 100644 index 71685234e3..0000000000 --- a/activerecord/test/fixtures/category.rb +++ /dev/null @@ -1,26 +0,0 @@ -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/fixtures/citation.rb b/activerecord/test/fixtures/citation.rb deleted file mode 100644 index 545aa8110d..0000000000 --- a/activerecord/test/fixtures/citation.rb +++ /dev/null @@ -1,6 +0,0 @@ -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/fixtures/column_name.rb b/activerecord/test/fixtures/column_name.rb deleted file mode 100644 index ec07205a3a..0000000000 --- a/activerecord/test/fixtures/column_name.rb +++ /dev/null @@ -1,3 +0,0 @@ -class ColumnName < ActiveRecord::Base - def self.table_name () "colnametests" end -end \ No newline at end of file diff --git a/activerecord/test/fixtures/comment.rb b/activerecord/test/fixtures/comment.rb deleted file mode 100644 index 3eab263fa4..0000000000 --- a/activerecord/test/fixtures/comment.rb +++ /dev/null @@ -1,23 +0,0 @@ -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/fixtures/company.rb b/activerecord/test/fixtures/company.rb deleted file mode 100755 index 1048d5a652..0000000000 --- a/activerecord/test/fixtures/company.rb +++ /dev/null @@ -1,114 +0,0 @@ -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/fixtures/company_in_module.rb b/activerecord/test/fixtures/company_in_module.rb deleted file mode 100644 index feb3210c02..0000000000 --- a/activerecord/test/fixtures/company_in_module.rb +++ /dev/null @@ -1,59 +0,0 @@ -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/fixtures/computer.rb b/activerecord/test/fixtures/computer.rb deleted file mode 100644 index f26312f9a6..0000000000 --- a/activerecord/test/fixtures/computer.rb +++ /dev/null @@ -1,4 +0,0 @@ -class Computer < ActiveRecord::Base - belongs_to :developer, :foreign_key=>'developer' -end - diff --git a/activerecord/test/fixtures/contact.rb b/activerecord/test/fixtures/contact.rb deleted file mode 100644 index c574196d94..0000000000 --- a/activerecord/test/fixtures/contact.rb +++ /dev/null @@ -1,16 +0,0 @@ -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/fixtures/course.rb b/activerecord/test/fixtures/course.rb deleted file mode 100644 index 8a40fa740d..0000000000 --- a/activerecord/test/fixtures/course.rb +++ /dev/null @@ -1,3 +0,0 @@ -class Course < ActiveRecord::Base - has_many :entrants -end diff --git a/activerecord/test/fixtures/customer.rb b/activerecord/test/fixtures/customer.rb deleted file mode 100644 index 3d8d644f12..0000000000 --- a/activerecord/test/fixtures/customer.rb +++ /dev/null @@ -1,55 +0,0 @@ -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/fixtures/default.rb b/activerecord/test/fixtures/default.rb deleted file mode 100644 index 887e9cc999..0000000000 --- a/activerecord/test/fixtures/default.rb +++ /dev/null @@ -1,2 +0,0 @@ -class Default < ActiveRecord::Base -end diff --git a/activerecord/test/fixtures/developer.rb b/activerecord/test/fixtures/developer.rb deleted file mode 100644 index 20005ed04e..0000000000 --- a/activerecord/test/fixtures/developer.rb +++ /dev/null @@ -1,72 +0,0 @@ -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/fixtures/edge.rb b/activerecord/test/fixtures/edge.rb deleted file mode 100644 index 55e0c31fcb..0000000000 --- a/activerecord/test/fixtures/edge.rb +++ /dev/null @@ -1,5 +0,0 @@ -# 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/fixtures/entrant.rb b/activerecord/test/fixtures/entrant.rb deleted file mode 100644 index 4682ce48c8..0000000000 --- a/activerecord/test/fixtures/entrant.rb +++ /dev/null @@ -1,3 +0,0 @@ -class Entrant < ActiveRecord::Base - belongs_to :course -end diff --git a/activerecord/test/fixtures/example.log b/activerecord/test/fixtures/example.log deleted file mode 100644 index f084369d8c..0000000000 --- a/activerecord/test/fixtures/example.log +++ /dev/null @@ -1 +0,0 @@ -# Logfile created on Wed Oct 31 16:05:13 +0000 2007 by logger.rb/1.5.2.9 diff --git a/activerecord/test/fixtures/flowers.jpg b/activerecord/test/fixtures/flowers.jpg deleted file mode 100644 index fe9df546df..0000000000 Binary files a/activerecord/test/fixtures/flowers.jpg and /dev/null differ diff --git a/activerecord/test/fixtures/item.rb b/activerecord/test/fixtures/item.rb deleted file mode 100644 index c2571dd7fb..0000000000 --- a/activerecord/test/fixtures/item.rb +++ /dev/null @@ -1,7 +0,0 @@ -class AbstractItem < ActiveRecord::Base - self.abstract_class = true - has_one :tagging, :as => :taggable -end - -class Item < AbstractItem -end diff --git a/activerecord/test/fixtures/joke.rb b/activerecord/test/fixtures/joke.rb deleted file mode 100644 index 3978abc2ba..0000000000 --- a/activerecord/test/fixtures/joke.rb +++ /dev/null @@ -1,3 +0,0 @@ -class Joke < ActiveRecord::Base - set_table_name 'funny_jokes' -end diff --git a/activerecord/test/fixtures/keyboard.rb b/activerecord/test/fixtures/keyboard.rb deleted file mode 100644 index 32a4a7fad0..0000000000 --- a/activerecord/test/fixtures/keyboard.rb +++ /dev/null @@ -1,3 +0,0 @@ -class Keyboard < ActiveRecord::Base - set_primary_key 'key_number' -end diff --git a/activerecord/test/fixtures/legacy_thing.rb b/activerecord/test/fixtures/legacy_thing.rb deleted file mode 100644 index eaeb642d12..0000000000 --- a/activerecord/test/fixtures/legacy_thing.rb +++ /dev/null @@ -1,3 +0,0 @@ -class LegacyThing < ActiveRecord::Base - set_locking_column :version -end diff --git a/activerecord/test/fixtures/matey.rb b/activerecord/test/fixtures/matey.rb deleted file mode 100644 index 47b0baa974..0000000000 --- a/activerecord/test/fixtures/matey.rb +++ /dev/null @@ -1,4 +0,0 @@ -class Matey < ActiveRecord::Base - belongs_to :pirate - belongs_to :target, :class_name => 'Pirate' -end diff --git a/activerecord/test/fixtures/minimalistic.rb b/activerecord/test/fixtures/minimalistic.rb deleted file mode 100644 index 2e3f8e081a..0000000000 --- a/activerecord/test/fixtures/minimalistic.rb +++ /dev/null @@ -1,2 +0,0 @@ -class Minimalistic < ActiveRecord::Base -end diff --git a/activerecord/test/fixtures/mixed_case_monkey.rb b/activerecord/test/fixtures/mixed_case_monkey.rb deleted file mode 100644 index 853f2682b3..0000000000 --- a/activerecord/test/fixtures/mixed_case_monkey.rb +++ /dev/null @@ -1,3 +0,0 @@ -class MixedCaseMonkey < ActiveRecord::Base - set_primary_key 'monkeyID' -end diff --git a/activerecord/test/fixtures/movie.rb b/activerecord/test/fixtures/movie.rb deleted file mode 100644 index 6384b4c801..0000000000 --- a/activerecord/test/fixtures/movie.rb +++ /dev/null @@ -1,5 +0,0 @@ -class Movie < ActiveRecord::Base - def self.primary_key - "movieid" - end -end diff --git a/activerecord/test/fixtures/order.rb b/activerecord/test/fixtures/order.rb deleted file mode 100644 index ba114f22c6..0000000000 --- a/activerecord/test/fixtures/order.rb +++ /dev/null @@ -1,4 +0,0 @@ -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/fixtures/parrot.rb b/activerecord/test/fixtures/parrot.rb deleted file mode 100644 index 65191c1aa5..0000000000 --- a/activerecord/test/fixtures/parrot.rb +++ /dev/null @@ -1,13 +0,0 @@ -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/fixtures/person.rb b/activerecord/test/fixtures/person.rb deleted file mode 100644 index 7a9666f4eb..0000000000 --- a/activerecord/test/fixtures/person.rb +++ /dev/null @@ -1,4 +0,0 @@ -class Person < ActiveRecord::Base - has_many :readers - has_many :posts, :through => :readers -end diff --git a/activerecord/test/fixtures/pirate.rb b/activerecord/test/fixtures/pirate.rb deleted file mode 100644 index f7193dfbe0..0000000000 --- a/activerecord/test/fixtures/pirate.rb +++ /dev/null @@ -1,5 +0,0 @@ -class Pirate < ActiveRecord::Base - belongs_to :parrot - has_and_belongs_to_many :parrots - has_many :loots, :as => :looter -end diff --git a/activerecord/test/fixtures/post.rb b/activerecord/test/fixtures/post.rb deleted file mode 100644 index 4627da5206..0000000000 --- a/activerecord/test/fixtures/post.rb +++ /dev/null @@ -1,59 +0,0 @@ -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/fixtures/project.rb b/activerecord/test/fixtures/project.rb deleted file mode 100644 index b90d2c6fbc..0000000000 --- a/activerecord/test/fixtures/project.rb +++ /dev/null @@ -1,28 +0,0 @@ -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 || ''}"}, - :after_add => Proc.new {|o, r| o.developers_log << "after_adding#{r.id || ''}"}, - :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/fixtures/reader.rb b/activerecord/test/fixtures/reader.rb deleted file mode 100644 index 27527bf566..0000000000 --- a/activerecord/test/fixtures/reader.rb +++ /dev/null @@ -1,4 +0,0 @@ -class Reader < ActiveRecord::Base - belongs_to :post - belongs_to :person -end diff --git a/activerecord/test/fixtures/reply.rb b/activerecord/test/fixtures/reply.rb deleted file mode 100755 index bf7781e814..0000000000 --- a/activerecord/test/fixtures/reply.rb +++ /dev/null @@ -1,37 +0,0 @@ -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/fixtures/ship.rb b/activerecord/test/fixtures/ship.rb deleted file mode 100644 index 05b09fc1b9..0000000000 --- a/activerecord/test/fixtures/ship.rb +++ /dev/null @@ -1,3 +0,0 @@ -class Ship < ActiveRecord::Base - self.record_timestamps = false -end \ No newline at end of file diff --git a/activerecord/test/fixtures/subject.rb b/activerecord/test/fixtures/subject.rb deleted file mode 100644 index 3502943f3a..0000000000 --- a/activerecord/test/fixtures/subject.rb +++ /dev/null @@ -1,4 +0,0 @@ -# used for OracleSynonymTest, see test/synonym_test_oci.rb -# -class Subject < ActiveRecord::Base -end diff --git a/activerecord/test/fixtures/subscriber.rb b/activerecord/test/fixtures/subscriber.rb deleted file mode 100644 index 51335a8f20..0000000000 --- a/activerecord/test/fixtures/subscriber.rb +++ /dev/null @@ -1,6 +0,0 @@ -class Subscriber < ActiveRecord::Base - set_primary_key 'nick' -end - -class SpecialSubscriber < Subscriber -end diff --git a/activerecord/test/fixtures/tag.rb b/activerecord/test/fixtures/tag.rb deleted file mode 100644 index a581b381e8..0000000000 --- a/activerecord/test/fixtures/tag.rb +++ /dev/null @@ -1,7 +0,0 @@ -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/fixtures/tagging.rb b/activerecord/test/fixtures/tagging.rb deleted file mode 100644 index a1fa1a9750..0000000000 --- a/activerecord/test/fixtures/tagging.rb +++ /dev/null @@ -1,10 +0,0 @@ -# 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/fixtures/task.rb b/activerecord/test/fixtures/task.rb deleted file mode 100644 index ee0282c79b..0000000000 --- a/activerecord/test/fixtures/task.rb +++ /dev/null @@ -1,3 +0,0 @@ -class Task < ActiveRecord::Base - -end diff --git a/activerecord/test/fixtures/topic.rb b/activerecord/test/fixtures/topic.rb deleted file mode 100755 index b2541c8640..0000000000 --- a/activerecord/test/fixtures/topic.rb +++ /dev/null @@ -1,37 +0,0 @@ -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/fixtures/treasure.rb b/activerecord/test/fixtures/treasure.rb deleted file mode 100644 index 7a429e2a2f..0000000000 --- a/activerecord/test/fixtures/treasure.rb +++ /dev/null @@ -1,4 +0,0 @@ -class Treasure < ActiveRecord::Base - has_and_belongs_to_many :parrots - belongs_to :looter, :polymorphic => true -end diff --git a/activerecord/test/fixtures/vertex.rb b/activerecord/test/fixtures/vertex.rb deleted file mode 100644 index 48bb851e62..0000000000 --- a/activerecord/test/fixtures/vertex.rb +++ /dev/null @@ -1,9 +0,0 @@ -# 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/fixtures/warehouse_thing.rb b/activerecord/test/fixtures/warehouse_thing.rb deleted file mode 100644 index 6ace1183cc..0000000000 --- a/activerecord/test/fixtures/warehouse_thing.rb +++ /dev/null @@ -1,5 +0,0 @@ -class WarehouseThing < ActiveRecord::Base - set_table_name "warehouse-things" - - validates_uniqueness_of :value -end \ No newline at end of file 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 || ''}"}, + :after_add => Proc.new {|o, r| o.post_log << "after_adding#{r.id || ''}"}, + :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 || ''}"}], + :after_add => [:log_after_adding, Proc.new {|o, r| o.post_log << "after_adding_proc#{r.id || ''}"}] + 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 || ''}" + 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 || ''}"}, + :after_add => Proc.new {|o, r| o.developers_log << "after_adding#{r.id || ''}"}, + :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 -- cgit v1.2.3