Sha256: f5c7298b748640dd0fb7dad2be69f02a5d5d813571c64b51e2b8a81fb5e5b509

Contents?: true

Size: 1.24 KB

Versions: 4

Compression:

Stored size: 1.24 KB

Contents

require 'database_helper'
require 'active_record/acts_as'

class Product < ActiveRecord::Base
  actable
  belongs_to :store
  validates_presence_of :name, :price

  def present
    "#{name} - $#{price}"
  end

  def raise_error
    specific.non_existant_method
  end
end

class Pen < ActiveRecord::Base
  acts_as :product

  validates_presence_of :color
end

class Store < ActiveRecord::Base
  has_many :products
end

module Inventory
  class ProductFeature < ActiveRecord::Base
    self.table_name = 'inventory_product_features'
    actable
    validates_presence_of :name, :price

    def present
      "#{name} - $#{price}"
    end
  end

  class PenLid < ActiveRecord::Base
    self.table_name = 'inventory_pen_lids'
    acts_as :product_feature, class_name: 'Inventory::ProductFeature'

    validates_presence_of :color
  end
end

initialize_database do
  create_table :pens do |t|
    t.string :color
  end

  create_table :products do |t|
    t.string :name
    t.float :price
    t.integer :store_id
    t.actable
  end

  create_table :stores do |t|
    t.string :name
  end

  create_table :inventory_pen_lids do |t|
    t.string :color
  end

  create_table :inventory_product_features do |t|
    t.string :name
    t.float :price
    t.actable
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
active_record-acts_as-1.0.3 spec/models.rb
active_record-acts_as-1.0.2 spec/models.rb
active_record-acts_as-1.0.1 spec/models.rb
active_record-acts_as-1.0.0 spec/models.rb