Skip to content

Instantly share code, notes, and snippets.

@ka8725
Created November 28, 2013 08:31
Show Gist options
  • Select an option

  • Save ka8725/7688818 to your computer and use it in GitHub Desktop.

Select an option

Save ka8725/7688818 to your computer and use it in GitHub Desktop.
$ rails g model switchable_plan origin:references replacement:references 'switch_plan_fee:decimal{15,2}'
# app/models/switchable_plan.rb
class SwitchablePlan < ActiveRecord::Base
belongs_to :origin
belongs_to :replacement
end
# db/migrate/20131128082637_create_switchable_plans.rb
class CreateSwitchablePlans < ActiveRecord::Migration
def change
create_table :switchable_plans do |t|
t.references :origin, index: true
t.references :replacement, index: true
t.decimal :switch_plan_fee, precision: 15, scale: 2
t.timestamps
end
end
end
# spec/factories/switchable_plans.rb
# Read about factories at https://github.com/thoughtbot/factory_girl
FactoryGirl.define do
factory :switchable_plan do
origin nil
replacement nil
switch_plan_fee "9.99"
end
end
# spec/models/switchable_plan_spec.rb
require 'spec_helper'
describe SwitchablePlan do
pending "add some examples to (or delete) #{__FILE__}"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment