Sha256: 50a71dbff7c87ba5552707506fe0138258a8bf41e74a002674e85e03792bfacb

Contents?: true

Size: 1.47 KB

Versions: 20

Compression:

Stored size: 1.47 KB

Contents

class Topic < ActiveRecord::Base
  named_scope :base
  named_scope :written_before, lambda { |time|
    { :conditions => ['written_on < ?', time] }
  }
  named_scope :approved, :conditions => {:approved => true}
  named_scope 'approved_as_string', :conditions => {:approved => true}
  named_scope :replied, :conditions => ['replies_count > 0']
  named_scope :anonymous_extension do
    def one
      1
    end
  end
  module NamedExtension
    def two
      2
    end
  end
  module MultipleExtensionOne
    def extension_one
      1
    end
  end
  module MultipleExtensionTwo
    def extension_two
      2
    end
  end
  named_scope :named_extension, :extend => NamedExtension
  named_scope :multiple_extensions, :extend => [MultipleExtensionTwo, MultipleExtensionOne]

  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

Version data entries

20 entries across 20 versions & 5 rubygems

Version Path
3mix-castronaut-0.5.0.2 vendor/activerecord/test/models/topic.rb
masover-castronaut-0.4.4.4 vendor/activerecord/test/models/topic.rb
masover-castronaut-0.4.4.5 vendor/activerecord/test/models/topic.rb
masover-castronaut-0.5.0.1 vendor/activerecord/test/models/topic.rb
relevance-castronaut-0.4.1 vendor/activerecord/test/models/topic.rb
relevance-castronaut-0.4.2 vendor/activerecord/test/models/topic.rb
relevance-castronaut-0.4.3 vendor/activerecord/test/models/topic.rb
relevance-castronaut-0.4.4 vendor/activerecord/test/models/topic.rb
relevance-castronaut-0.4.5 vendor/activerecord/test/models/topic.rb
relevance-castronaut-0.4.6 vendor/activerecord/test/models/topic.rb
relevance-castronaut-0.5.0 vendor/activerecord/test/models/topic.rb
relevance-castronaut-0.5.1 vendor/activerecord/test/models/topic.rb
relevance-castronaut-0.5.2 vendor/activerecord/test/models/topic.rb
relevance-castronaut-0.5.3 vendor/activerecord/test/models/topic.rb
relevance-castronaut-0.5.4 vendor/activerecord/test/models/topic.rb
radiant-0.7.2 vendor/rails/activerecord/test/models/topic.rb
activerecord-2.1.2 test/models/topic.rb
activerecord-2.1.1 test/models/topic.rb
radiant-0.7.0 vendor/rails/activerecord/test/models/topic.rb
radiant-0.7.1 vendor/rails/activerecord/test/models/topic.rb