Skip to content

Commit

Permalink
getting some tests to run
Browse files Browse the repository at this point in the history
  • Loading branch information
bborn committed Oct 3, 2012
1 parent 0af3e80 commit 6bf0e92
Show file tree
Hide file tree
Showing 81 changed files with 7,197 additions and 1,438 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -0,0 +1 @@
Gemfile.lock
23 changes: 12 additions & 11 deletions Guardfile
Expand Up @@ -16,19 +16,20 @@ end

guard 'rspec', :version => 2, :cli => '--drb' do
watch(%r{^spec/.+_spec\.rb$})
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
watch('spec/spec_helper.rb') { "spec" }
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
watch('spec/spec_helper.rb') { "spec" }

# Rails example
watch(%r{^spec/.+_spec\.rb$})
watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
watch(%r{^app/(.*)(\.erb|\.haml)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/requests/#{m[1]}_spec.rb"] }
watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
watch('spec/spec_helper.rb') { "spec" }
watch('config/routes.rb') { "spec/requests" }
watch('app/controllers/application_controller.rb') { "spec/requests" }
watch(%r{^spec/dummy/app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
watch(%r{^spec/dummy/app/(.*)(\.erb|\.haml)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
watch(%r{^spec/dummy/app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/requests/#{m[1]}_spec.rb"] }
watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
watch('spec/spec_helper.rb') { "spec" }
watch('config/routes.rb') { "spec/requests" }
watch('spec/dummy/app/controllers/application_controller.rb') { "spec/requests" }

# Capybara request specs
watch(%r{^app/views/(.+)/.*\.(erb|haml)$}) { |m| "spec/requests/#{m[1]}_spec.rb" }
watch(%r{^spec/dummy/app/views/(.+)/.*\.(erb|haml)$}) { |m| "spec/requests/#{m[1]}_spec.rb" }
end
2 changes: 1 addition & 1 deletion Procfile
@@ -1,4 +1,4 @@
redis: redis-server
redis: redis-server
web: bundle exec unicorn -p $PORT -c ./config/unicorn.rb
worker: ./start_resque
guard: bundle exec guard
Expand Down
15 changes: 6 additions & 9 deletions README.markdown
Expand Up @@ -31,15 +31,12 @@ Getting Started
3. Create a .env file based on the sample.env.
4. bundle install
5. Add the following fields to your User model:
t.string :vault_token
t.references :subscription_plan
t.references :coupon

add_index :striped_rails_users, :email, :unique => true
add_index :striped_rails_users, :subscription_plan_id
add_index :striped_rails_users, :coupon_id
add_index :striped_rails_users, :vault_token
add_index :striped_rails_users, :created_at

t.string :full_name
t.string :vault_token
t.references :subscription_plan
t.references :coupon
t.boolean :admin, default: false

6. Make your User model (or Person, or whatever you call it, include StripedRails::User)
7. bundle exec rake db:migrate
Expand Down
2 changes: 1 addition & 1 deletion app/decorators/striped_rails/user_decorator.rb
@@ -1,6 +1,6 @@
module StripedRails
class UserDecorator < BaseDecorator
decorates :user
decorates :user, :class_name => StripedRails::Engine.config.user_class

def signed_in?
!model.new_record?
Expand Down
24 changes: 13 additions & 11 deletions app/mailers/striped_rails/user_mailer.rb
@@ -1,14 +1,16 @@
class UserMailer < ActionMailer::Base
default from: "from@example.com"
module StripedRails
class UserMailer < ActionMailer::Base
default from: "from@example.com"

def invoice(user, invoice)
@user = UserDecorator.decorate(user)
@invoice = InvoiceDecorator.new(invoice)
mail(to: user.email, subject: "Brand Invoice")
end
def invoice(user, invoice)
@user = UserDecorator.decorate(user)
@invoice = InvoiceDecorator.new(invoice)
mail(to: user.email, subject: "Brand Invoice")
end

def password_reset(user, token)
@password_token = token
mail to: user.email, subject: 'Password Reset'
def password_reset(user, token)
@password_token = token
mail to: user.email, subject: 'Password Reset'
end
end
end
end
2 changes: 1 addition & 1 deletion app/models/striped_rails/coupon.rb
Expand Up @@ -13,7 +13,7 @@ class Coupon < ActiveRecord::Base
validates_numericality_of :duration_in_months, allow_nil: true, only_integer: true, greater_than_or_equal_to: 0
validates_numericality_of :max_redemptions, allow_nil: true, only_integer: true, greater_than_or_equal_to: 0
validates_numericality_of :times_redeemed, allow_nil: true, only_integer: true, greater_than_or_equal_to: 0
has_many :users
has_many :users, :class_name => StripedRails::Engine.config.user_class
has_many :coupon_subscription_plans, dependent: :destroy
has_many :subscription_plans, through: :coupon_subscription_plans
after_destroy :scrub_users
Expand Down
2 changes: 1 addition & 1 deletion app/workers/invoice_mailer.rb
Expand Up @@ -2,7 +2,7 @@ class InvoiceMailer
@queue = :invoice_mailer
def self.perform(id,invoice)
user = User.find(id)
invoice = Stripe::StripeObject.construct_from(JSON.parse(invoice), ENV['STRIPE_API_KEY'])
invoice = Stripe::StripeObject.construct_from(JSON.parse(invoice), Stripe.api_key)
UserMailer.invoice(user, invoice).deliver
end
end
4 changes: 2 additions & 2 deletions config/routes.rb
@@ -1,6 +1,5 @@
StripedRails::Engine.routes.draw do
mount Resque::Server, at: '/resque'


root to: 'pages#index'

resources :users
Expand All @@ -19,6 +18,7 @@
get :available
end
end

resources :coupons, only: [:index,:edit,:update]
resources :coupon_subscription_plans, only: [:create,:destroy]
resources :webhooks, only: :create
Expand Down
4 changes: 0 additions & 4 deletions sample.env

This file was deleted.

4 changes: 0 additions & 4 deletions spec/decorators/application_decorator_spec.rb

This file was deleted.

6 changes: 6 additions & 0 deletions spec/decorators/base_decorator_spec.rb
@@ -0,0 +1,6 @@
require 'spec_helper'

module StripedRails
describe BaseDecorator do
end
end
8 changes: 5 additions & 3 deletions spec/decorators/coupon_decorator_spec.rb
@@ -1,5 +1,7 @@
require 'spec_helper'

describe CouponDecorator do
before { ApplicationController.new.set_current_view_context }
end
module StripedRails
describe CouponDecorator do
before { BaseController.new.set_current_view_context }
end
end
32 changes: 18 additions & 14 deletions spec/decorators/page_decorator_spec.rb
@@ -1,23 +1,27 @@
require 'spec_helper'

describe PageDecorator, :draper_with_helpers do
include Rails.application.routes.url_helpers
module StripedRails

describe PageDecorator, :draper_with_helpers do
include Rails.application.routes.url_helpers

describe "#menu" do
context "when we have 5 pages" do
before :each do
@pages = (1..5).map { PageDecorator.new(Factory(:page)) }
end
describe "#menu" do
context "when we have 5 pages" do
before :each do
@pages = (1..5).map { PageDecorator.new(Factory(:page)) }
end

it "should produce a menu with a top level title element" do
@pages.first.menu(@pages).should include "<a href=\"#\" class=\"dropdown-toggle\""
end
it "should produce a menu with a top level title element" do
@pages.first.menu(@pages).should include "<a href=\"#\" class=\"dropdown-toggle\""
end

it "should produce menu items for each page" do
@pages.first.menu(@pages).should include @pages[0].title
@pages.first.menu(@pages).should include @pages[1].title
it "should produce menu items for each page" do
@pages.first.menu(@pages).should include @pages[0].title
@pages.first.menu(@pages).should include @pages[1].title
end
end
end

end

end
end
79 changes: 41 additions & 38 deletions spec/decorators/subscription_plan_decorator_spec.rb
@@ -1,51 +1,54 @@
require 'spec_helper'

describe SubscriptionPlanDecorator, :draper_with_helpers do
include Rails.application.routes.url_helpers

describe "#price" do
it "should provide the price in currency format" do
subscription_plan = SubscriptionPlanDecorator.decorate(Factory(:subscription_plan, amount: 999))
subscription_plan.price.should == "$9.99 per month"
module StripedRails
describe SubscriptionPlanDecorator, :draper_with_helpers do
include Rails.application.routes.url_helpers

describe "#price" do
it "should provide the price in currency format" do
subscription_plan = SubscriptionPlanDecorator.decorate(Factory(:subscription_plan, amount: 999))
subscription_plan.price.should == "$9.99 per month"
end
end
end

describe "#monthly_revenue" do
it "should format the monthly_revenue" do
subscription_plan = SubscriptionPlanDecorator.decorate(Factory(:subscription_plan, amount: 1000))
subscription_plan.monthly_revenue.should == "$0.00"
describe "#monthly_revenue" do
it "should format the monthly_revenue" do
subscription_plan = SubscriptionPlanDecorator.decorate(Factory(:subscription_plan, amount: 1000))
subscription_plan.monthly_revenue.should == "$0.00"
end
end
end

describe "#users_count" do
it "should format the users_count" do
subscription_plan = SubscriptionPlanDecorator.decorate(Factory(:subscription_plan))
subscription_plan.users_count.should == "0 Users"
describe "#users_count" do
it "should format the users_count" do
subscription_plan = SubscriptionPlanDecorator.decorate(Factory(:subscription_plan))
subscription_plan.users_count.should == "0 Users"
end
end
end

describe "#trial_information" do
it "should provide human readable trial information" do
subscription_plan = SubscriptionPlanDecorator.decorate(Factory(:subscription_plan, trial_period_days: 30))
subscription_plan.trial_information.should == '<p><span class="label label-success">30 day free trial!</span></p>'
end
describe "#trial_information" do
it "should provide human readable trial information" do
subscription_plan = SubscriptionPlanDecorator.decorate(Factory(:subscription_plan, trial_period_days: 30))
subscription_plan.trial_information.should == '<p><span class="label label-success">30 day free trial!</span></p>'
end

it "should return an empty string when no trial" do
subscription_plan = SubscriptionPlanDecorator.decorate(Factory(:subscription_plan, trial_period_days: 0))
subscription_plan.trial_information.should == ""
end
end

describe "#unit_information" do
it "should provide human readable unit information" do
subscription_plan = SubscriptionPlanDecorator.decorate(Factory(:subscription_plan, unit_name: 'Button Push', included_units: '10', overage_price: '10'))
subscription_plan.unit_information.should include 'Button Push'
subscription_plan.unit_information.should include '$0.10'
it "should return an empty string when no trial" do
subscription_plan = SubscriptionPlanDecorator.decorate(Factory(:subscription_plan, trial_period_days: 0))
subscription_plan.trial_information.should == ""
end
end

it "should return an empty string when unit usage is not being used" do
subscription_plan = SubscriptionPlanDecorator.decorate(Factory(:subscription_plan))
subscription_plan.unit_information.should == ''
describe "#unit_information" do
it "should provide human readable unit information" do
subscription_plan = SubscriptionPlanDecorator.decorate(Factory(:subscription_plan, unit_name: 'Button Push', included_units: '10', overage_price: '10'))
subscription_plan.unit_information.should include 'Button Push'
subscription_plan.unit_information.should include '$0.10'
end

it "should return an empty string when unit usage is not being used" do
subscription_plan = SubscriptionPlanDecorator.decorate(Factory(:subscription_plan))
subscription_plan.unit_information.should == ''
end
end
end
end

end

0 comments on commit 6bf0e92

Please sign in to comment.