Skip to content

Instantly share code, notes, and snippets.

@phildionne
Last active December 17, 2015 07:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save phildionne/5572909 to your computer and use it in GitHub Desktop.
Save phildionne/5572909 to your computer and use it in GitHub Desktop.
RSpec.configure do |config|
config.around do |example|
VCR.use_cassette('stripe-customer') do |cassette|
example.run
end
end
end
FactoryGirl.define do
factory :user do
username { Faker::Internet.user_name.sub(/_|\./, '') }
email { Faker::Internet.email }
password { Faker::Lorem.characters(8) }
end
end
class UserObserver < ActiveRecord::Observer
def after_create(user)
user.create_profile!
begin
customer = Stripe::Customer.create(
email: user.email,
plan: 'default'
)
user.stripe_customer_id = customer.id
user.save!
rescue Stripe::InvalidRequestError => e
raise e
end
end
end
describe :InstanceMethods do
let(:user) { FactoryGirl.create(:user) }
describe "#flexible_name" do
it "returns the name when name is specified" do
user.profile.first_name = "Foo"
user.profile.last_name = "Bar"
user.flexible_name.should eq("Foo Bar")
end
end
end
require 'vcr'
VCR.configure do |config|
config.default_cassette_options = { record: :once, re_record_interval: 1.day }
config.cassette_library_dir = 'spec/fixtures/cassettes'
config.hook_into :webmock
config.configure_rspec_metadata!
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment