-
-
Save joshuaclayton/ca891cd403d052486343 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
require 'test/shoulda_macros/braintree_macros' | |
class AnalyticsBuilder | |
include FactoryGirl::Syntax::Methods | |
include BraintreeMacros::Shoulda::Helpers | |
include WebMock::API | |
def initialize(campaign, &block) | |
@campaign = campaign | |
stub_braintree_customer_sale_success_with_transaction_ids('123456') | |
instance_exec &block | |
end | |
def customer(*args, &block) | |
options = args.extract_options! | |
name = args.first || Faker::Name.first_name | |
user = create :user, { :first_name => name }.merge(options) | |
create :credit_card, :user => user | |
OrderAndClaimBuilder.new(@campaign, user, &block) | |
end | |
def order(options) | |
OrderAndClaimBuilder.new(@campaign, options[:user]).order(options[:spend]) | |
end | |
class OrderAndClaimBuilder | |
include FactoryGirl::Syntax::Methods | |
def initialize(campaign, user, &block) | |
@campaign = campaign | |
@merchant = campaign.merchants.first | |
@user = user | |
instance_exec &block if block_given? | |
end | |
def claim | |
create :claim, :user => @user, :campaign => @campaign | |
end | |
def order(spend) | |
create(:order, :user => @user, :merchant => @merchant, :spend => spend).tap &:complete | |
end | |
end | |
end | |
Spec::Runner.configure do |config| | |
config.after do | |
WebMock.reset! | |
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
AnalyticsBuilder.new(campaign) do | |
customer do | |
claim | |
order 15.to_money | |
end | |
customer do | |
claim | |
order 25.to_money | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment