Last active
December 17, 2015 07:29
-
-
Save phildionne/5572909 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
RSpec.configure do |config| | |
config.around do |example| | |
VCR.use_cassette('stripe-customer') do |cassette| | |
example.run | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FactoryGirl.define do | |
factory :user do | |
username { Faker::Internet.user_name.sub(/_|\./, '') } | |
email { Faker::Internet.email } | |
password { Faker::Lorem.characters(8) } | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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