Skip to content

Instantly share code, notes, and snippets.

@steveburkett
Created September 25, 2013 21:01
Show Gist options
  • Save steveburkett/6705979 to your computer and use it in GitHub Desktop.
Save steveburkett/6705979 to your computer and use it in GitHub Desktop.
Given:
Organization
has_one :plan, dependent: :destroy, inverse_of: :organization
validates_presence_of :name, :plan
Plan
belongs_to :organization, inverse_of: :plan
validates :organization, :type, presence: true
class Plan < ActiveRecord::Base {
:id => :integer,
:organization_id => :integer,
:type => :string ...
class FreePlan < Plan
end
I need:
(1) that when i create a organization, it creates and associates itself w/ a default FreePlan. This is saved when an org is saved (& once a plan is set, dont accidentally override it). How to do this?
(2) need to make sure that the blueprint builds a org w/ the FreePlan
Organization.blueprint do
name { "Test Corp" }
end
#Organization.make.plan.class == "FreePlan"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment