Sha256: 88c4840e427ee22eb5065fd0a0bd68aaabaf2cdbd1ec55631cefd17988bc0a63

Contents?: true

Size: 808 Bytes

Versions: 25

Compression:

Stored size: 808 Bytes

Contents

class Topic < ActiveRecord::Base
  validates_presence_of :author_name
  validates :title, numericality: { only_integer: true }, on: :context_test
  validates :title, uniqueness: true
  validates :content, uniqueness: true
  validates :word_count, numericality: { greater_than: 0 }, if: :content?

  validate -> { errors.add(:title, :validate_failed) if title == 'validate_failed' }
  before_validation -> { errors.add(:title, :invalid) if title == 'invalid' }

  has_many :books, inverse_of: :topic
  belongs_to :parent, class_name: "Topic"

  composed_of :description, mapping: [%w(title title), %w(author_name author_name)], allow_nil: true, class_name: "TopicDescription"

  default_scope { where(approved: true) }

  private

  def word_count
    @word_count ||= content.to_s.scan(/\w+/).count
  end
end

Version data entries

25 entries across 25 versions & 2 rubygems

Version Path
activerecord-import-1.4.0 test/models/topic.rb
activerecord-import-1.3.0 test/models/topic.rb
rails_mini_profiler-0.2.0 vendor/bundle/ruby/3.0.0/gems/activerecord-import-1.2.0/test/models/topic.rb
activerecord-import-1.2.0 test/models/topic.rb
activerecord-import-1.1.0 test/models/topic.rb
activerecord-import-1.0.8 test/models/topic.rb
activerecord-import-1.0.7 test/models/topic.rb
activerecord-import-1.0.6 test/models/topic.rb
activerecord-import-1.0.5 test/models/topic.rb
activerecord-import-1.0.4 test/models/topic.rb
activerecord-import-1.0.3 test/models/topic.rb
activerecord-import-1.0.2 test/models/topic.rb
activerecord-import-1.0.1 test/models/topic.rb
activerecord-import-1.0.0 test/models/topic.rb
activerecord-import-0.28.2 test/models/topic.rb
activerecord-import-0.28.1 test/models/topic.rb
activerecord-import-0.28.0 test/models/topic.rb
activerecord-import-0.27.0 test/models/topic.rb
activerecord-import-0.26.0 test/models/topic.rb
activerecord-import-0.25.0 test/models/topic.rb