Upgraded Rails and RSpec
[monkeycharger.git] / vendor / rails / activerecord / test / fixtures / author.rb
blobd41d8ac439f582e486e7bce3d9d90acac319fd77
1 class Author < ActiveRecord::Base
2   has_many :posts
3   has_many :posts_with_comments, :include => :comments, :class_name => "Post"
4   has_many :posts_with_categories, :include => :categories, :class_name => "Post"
5   has_many :posts_with_comments_and_categories, :include => [ :comments, :categories ], :order => "posts.id", :class_name => "Post"
6   has_many :posts_with_extension, :class_name => "Post" do #, :extend => ProxyTestExtension
7     def testing_proxy_owner
8       proxy_owner
9     end
10     def testing_proxy_reflection
11       proxy_reflection
12     end
13     def testing_proxy_target
14       proxy_target
15     end
16   end
17   has_many :comments, :through => :posts
18   has_many :comments_desc, :through => :posts, :source => :comments, :order => 'comments.id DESC'
19   has_many :limited_comments, :through => :posts, :source => :comments, :limit => 1
20   has_many :funky_comments, :through => :posts, :source => :comments
22   has_many :special_posts
23   has_many :special_post_comments, :through => :special_posts, :source => :comments
24   
25   has_many :special_nonexistant_posts, :class_name => "SpecialPost", :conditions => "posts.body = 'nonexistant'"
26   has_many :special_nonexistant_post_comments, :through => :special_nonexistant_posts, :source => :comments, :conditions => "comments.post_id = 0"
27   has_many :nonexistant_comments, :through => :posts
29   has_many :hello_posts, :class_name => "Post", :conditions => "posts.body = 'hello'"
30   has_many :hello_post_comments, :through => :hello_posts, :source => :comments
31   has_many :posts_with_no_comments, :class_name => 'Post', :conditions => 'comments.id is null', :include => :comments
33   has_many :other_posts,          :class_name => "Post"
34   has_many :posts_with_callbacks, :class_name => "Post", :before_add => :log_before_adding,
35            :after_add     => :log_after_adding, 
36            :before_remove => :log_before_removing,
37            :after_remove  => :log_after_removing
38   has_many :posts_with_proc_callbacks, :class_name => "Post",
39            :before_add    => Proc.new {|o, r| o.post_log << "before_adding#{r.id || '<new>'}"},
40            :after_add     => Proc.new {|o, r| o.post_log << "after_adding#{r.id || '<new>'}"},
41            :before_remove => Proc.new {|o, r| o.post_log << "before_removing#{r.id}"},
42            :after_remove  => Proc.new {|o, r| o.post_log << "after_removing#{r.id}"}
43   has_many :posts_with_multiple_callbacks, :class_name => "Post",
44            :before_add => [:log_before_adding, Proc.new {|o, r| o.post_log << "before_adding_proc#{r.id || '<new>'}"}],
45            :after_add  => [:log_after_adding,  Proc.new {|o, r| o.post_log << "after_adding_proc#{r.id || '<new>'}"}]
46   has_many :unchangable_posts, :class_name => "Post", :before_add => :raise_exception, :after_add => :log_after_adding
48   has_many :categorizations
49   has_many :categories, :through => :categorizations
51   has_many :categories_like_general, :through => :categorizations, :source => :category, :class_name => 'Category', :conditions => { :name => 'General' }
53   has_many :categorized_posts, :through => :categorizations, :source => :post
54   has_many :unique_categorized_posts, :through => :categorizations, :source => :post, :uniq => true
56   has_many :nothings, :through => :kateggorisatons, :class_name => 'Category'
58   has_many :author_favorites
59   has_many :favorite_authors, :through => :author_favorites, :order => 'name'
61   has_many :tagging,  :through => :posts # through polymorphic has_one
62   has_many :taggings, :through => :posts, :source => :taggings # through polymorphic has_many
63   has_many :tags,     :through => :posts # through has_many :through
64   has_many :post_categories, :through => :posts, :source => :categories
66   belongs_to :author_address
68   attr_accessor :post_log
70   def after_initialize
71     @post_log = []
72   end
74   def label
75     "#{id}-#{name}"
76   end
78   private
79     def log_before_adding(object)
80       @post_log << "before_adding#{object.id || '<new>'}"
81     end
83     def log_after_adding(object)
84       @post_log << "after_adding#{object.id}"
85     end
87     def log_before_removing(object)
88       @post_log << "before_removing#{object.id}"
89     end
91     def log_after_removing(object)
92       @post_log << "after_removing#{object.id}"
93     end
95     def raise_exception(object)
96       raise Exception.new("You can't add a post")
97     end
98 end
100 class AuthorAddress < ActiveRecord::Base
101   has_one :author
104 class AuthorFavorite < ActiveRecord::Base
105   belongs_to :author
106   belongs_to :favorite_author, :class_name => "Author", :foreign_key => 'favorite_author_id'