Sha256: b8cfffe6d602ce79bd5bc599bbe9f2db4e6ea401afbc1dd08139b3568c4ad2f0

Contents?: true

Size: 1.13 KB

Versions: 27

Compression:

Stored size: 1.13 KB

Contents

# frozen_string_literal: true
# encoding: utf-8

class Label
  include Mongoid::Document
  include Mongoid::Timestamps::Updated::Short

  field :name, type: String
  field :after_create_called, type: Mongoid::Boolean, default: false
  field :after_save_called, type: Mongoid::Boolean, default: false
  field :after_update_called, type: Mongoid::Boolean, default: false
  field :after_validation_called, type: Mongoid::Boolean, default: false

  field :before_save_count, type: Integer, default: 0

  embedded_in :artist
  embedded_in :band

  before_save :before_save_stub
  after_create :after_create_stub
  after_save :after_save_stub
  after_update :after_update_stub
  after_validation :after_validation_stub
  before_validation :cleanup

  def before_save_stub
    self.before_save_count += 1
  end

  def after_create_stub
    self.after_create_called = true
  end

  def after_save_stub
    self.after_save_called = true
  end

  def after_update_stub
    self.after_update_called = true
  end

  def after_validation_stub
    self.after_validation_called = true
  end

  private
  def cleanup
    self.name = self.name.downcase.capitalize
  end
end

Version data entries

27 entries across 27 versions & 2 rubygems

Version Path
mongoid-7.3.5 spec/support/models/label.rb
mongoid-7.3.4 spec/support/models/label.rb
mongoid-7.1.11 spec/app/models/label.rb
mongoid-7.2.6 spec/support/models/label.rb
mongoid-7.3.3 spec/support/models/label.rb
mongoid-7.3.2 spec/support/models/label.rb
mongoid-7.2.5 spec/support/models/label.rb
mongoid-7.1.10 spec/app/models/label.rb
mongoid-7.1.9 spec/app/models/label.rb
mongoid-7.2.4 spec/support/models/label.rb
mongoid-7.3.1 spec/support/models/label.rb
tdiary-5.1.6 vendor/bundle/ruby/2.7.0/gems/mongoid-7.1.7/spec/app/models/label.rb
mongoid-7.3.0 spec/support/models/label.rb
mongoid-7.2.3 spec/support/models/label.rb
mongoid-7.1.8 spec/app/models/label.rb
mongoid-7.2.2 spec/support/models/label.rb
mongoid-7.2.1 spec/support/models/label.rb
mongoid-7.1.7 spec/app/models/label.rb
mongoid-7.2.0 spec/support/models/label.rb
mongoid-7.1.6 spec/app/models/label.rb