Sha256: 2d54f4da235594e676c3f35a5ae5dc919a76e3a82534296012284789970194e9

Contents?: true

Size: 992 Bytes

Versions: 22

Compression:

Stored size: 992 Bytes

Contents

class Artist
  include Mongoid::Document
  field :name
  embeds_many :songs
  embeds_many :labels

  before_create :before_create_stub
  after_create :create_songs
  before_save :before_save_stub
  before_destroy :before_destroy_stub

  protected
  def before_create_stub
    true
  end

  def before_save_stub
    true
  end

  def before_destroy_stub
    true
  end

  def create_songs
    2.times { |n| songs.create!(:title => "#{n}") }
  end
end

class Song
  include Mongoid::Document
  field :title
  embedded_in :artist
end

class Label
  include Mongoid::Document
  field :name
  embedded_in :artist
  before_validation :cleanup

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

class ValidationCallback
  include Mongoid::Document
  field :history, :type => Array, :default => []
  validate do
    self.history << :validate
  end

  before_validation { self.history << :before_validation }
  after_validation { self.history << :after_validation }
end

Version data entries

22 entries across 22 versions & 4 rubygems

Version Path
mongoid_spacial-0.2.17 spec/models/callbacks.rb
sig_mongoid_spacial-0.2.17 spec/models/callbacks.rb
cb_mongoid_spacial-0.2.16 spec/models/callbacks.rb
mongoid_geospatial-1.0.0 spec/models/callbacks.rb
mongoid_geospatial-1.0.0rc1 spec/models/callbacks.rb
mongoid_geospatial-1.0.0rc0 spec/models/callbacks.rb
mongoid_spacial-0.2.16 spec/models/callbacks.rb
mongoid_spacial-0.2.13 spec/models/callbacks.rb
mongoid_spacial-0.2.12 spec/models/callbacks.rb
mongoid_spacial-0.2.11 spec/models/callbacks.rb
mongoid_spacial-0.2.10 spec/models/callbacks.rb
mongoid_spacial-0.2.8 spec/models/callbacks.rb
mongoid_spacial-0.2.7 spec/models/callbacks.rb
mongoid_spacial-0.2.6 spec/models/callbacks.rb
mongoid_spacial-0.2.5 spec/models/callbacks.rb
mongoid_spacial-0.2.4 spec/models/callbacks.rb
mongoid_spacial-0.2.3 spec/models/callbacks.rb
mongoid_spacial-0.2.2 spec/models/callbacks.rb
mongoid_spacial-0.2.0 spec/models/callbacks.rb
mongoid_spacial-0.1.1 spec/models/callbacks.rb