Skip to content

Commit

Permalink
add plan and subscription models
Browse files Browse the repository at this point in the history
  • Loading branch information
flyerhzm committed Dec 20, 2011
1 parent e9be81d commit 70cd349
Show file tree
Hide file tree
Showing 9 changed files with 74 additions and 1 deletion.
3 changes: 3 additions & 0 deletions app/models/plan.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class Plan < ActiveRecord::Base
has_many :subscriptions
end
5 changes: 5 additions & 0 deletions app/models/subscription.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class Subscription < ActiveRecord::Base
belongs_to :plan
validates_presence_of :plan_id
validates_presence_of :email
end
10 changes: 10 additions & 0 deletions db/migrate/20111220153227_create_plans.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class CreatePlans < ActiveRecord::Migration
def change
create_table :plans do |t|
t.string :name
t.decimal :price

t.timestamps
end
end
end
11 changes: 11 additions & 0 deletions db/migrate/20111220153314_create_subscriptions.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class CreateSubscriptions < ActiveRecord::Migration
def change
create_table :subscriptions do |t|
t.integer :plan_id
t.string :email
t.string :stripe_customer_token

t.timestamps
end
end
end
17 changes: 16 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.

ActiveRecord::Schema.define(:version => 20111217105744) do
ActiveRecord::Schema.define(:version => 20111220153314) do

create_table "builds", :force => true do |t|
t.integer "warning_count"
Expand Down Expand Up @@ -62,6 +62,13 @@
t.integer "configuration_id"
end

create_table "plans", :force => true do |t|
t.string "name"
t.decimal "price", :precision => 10, :scale => 0
t.datetime "created_at"
t.datetime "updated_at"
end

create_table "repositories", :force => true do |t|
t.string "git_url"
t.string "name"
Expand All @@ -80,6 +87,14 @@
t.integer "builds_count", :default => 0
end

create_table "subscriptions", :force => true do |t|
t.integer "plan_id"
t.string "email"
t.string "stripe_customer_token"
t.datetime "created_at"
t.datetime "updated_at"
end

create_table "user_repositories", :force => true do |t|
t.integer "user_id"
t.integer "repository_id"
Expand Down
8 changes: 8 additions & 0 deletions spec/factories/plans.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Read about factories at http://github.com/thoughtbot/factory_girl

FactoryGirl.define do
factory :plan do
name "MyString"
price "9.99"
end
end
9 changes: 9 additions & 0 deletions spec/factories/subscriptions.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Read about factories at http://github.com/thoughtbot/factory_girl

FactoryGirl.define do
factory :subscription do
plan_id 1
email "MyString"
stripe_customer_token "MyString"
end
end
5 changes: 5 additions & 0 deletions spec/models/plan_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
require 'spec_helper'

describe Plan do
it { should have_many(:subscriptions) }
end
7 changes: 7 additions & 0 deletions spec/models/subscription_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require 'spec_helper'

describe Subscription do
it { should belong_to(:plan) }
it { should validate_presence_of(:plan_id) }
it { should validate_presence_of(:email) }
end

0 comments on commit 70cd349

Please sign in to comment.