Sha256: e7ce421432d3d51c31f076efcec560d80d3908bd82d066630759047d6252d978

Contents?: true

Size: 928 Bytes

Versions: 1

Compression:

Stored size: 928 Bytes

Contents

class Article
  include Mongoid::Document
  include Mongoid::Timestamps

  field :title, localize: true
  field :content
  field :published, type: Boolean, default: false
  field :allow_comments, type: Boolean, default: true
  field :number_of_comments, type: Integer
  field :status, type: Symbol

  embeds_many :comments, cascade_callbacks: true, inverse_of: :article
  embeds_one :permalink, inverse_of: :linkable
  belongs_to :author, class_name: 'User', inverse_of: :articles, index: true

  validates :title, presence: true

  validates_inclusion_of :status, in: [:pending], on: :create
  validates_inclusion_of :status, in: %i[approved rejected], on: :update

  validates_length_of :title, within: 8..16
  validates_length_of :content, minimum: 200

  index({ title: 1 }, unique: true, background: true, drop_dups: true)
  index(published: 1)
  index('permalink._id' => 1)

  accepts_nested_attributes_for :permalink
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
mongoid-rspec-4.0.0 spec/models/article.rb