Froze rails gems
[depot.git] / vendor / rails / activerecord / test / models / topic.rb
1 class Topic < ActiveRecord::Base
2 named_scope :base
3 named_scope :written_before, lambda { |time|
4 { :conditions => ['written_on < ?', time] }
5 }
6 named_scope :approved, :conditions => {:approved => true}
7 named_scope :by_lifo, :conditions => {:author_name => 'lifo'}
8
9 named_scope :approved_as_hash_condition, :conditions => {:topics => {:approved => true}}
10 named_scope 'approved_as_string', :conditions => {:approved => true}
11 named_scope :replied, :conditions => ['replies_count > 0']
12 named_scope :anonymous_extension do
13 def one
14 1
15 end
16 end
17 module NamedExtension
18 def two
19 2
20 end
21 end
22 module MultipleExtensionOne
23 def extension_one
24 1
25 end
26 end
27 module MultipleExtensionTwo
28 def extension_two
29 2
30 end
31 end
32 named_scope :named_extension, :extend => NamedExtension
33 named_scope :multiple_extensions, :extend => [MultipleExtensionTwo, MultipleExtensionOne]
34
35 has_many :replies, :dependent => :destroy, :foreign_key => "parent_id"
36 serialize :content
37
38 before_create :default_written_on
39 before_destroy :destroy_children
40
41 def parent
42 Topic.find(parent_id)
43 end
44
45 # trivial method for testing Array#to_xml with :methods
46 def topic_id
47 id
48 end
49
50 protected
51 def approved=(val)
52 @custom_approved = val
53 write_attribute(:approved, val)
54 end
55
56 def default_written_on
57 self.written_on = Time.now unless attribute_present?("written_on")
58 end
59
60 def destroy_children
61 self.class.delete_all "parent_id = #{id}"
62 end
63
64 def after_initialize
65 if self.new_record?
66 self.author_email_address = 'test@test.com'
67 end
68 end
69 end