Skip to content

Instantly share code, notes, and snippets.

@fahim
Created September 30, 2011 19:07
Show Gist options
  • Save fahim/1254682 to your computer and use it in GitHub Desktop.
Save fahim/1254682 to your computer and use it in GitHub Desktop.
What's the best way to test this method?
# Employee Discount model
class Discount::Employee < Discount
def compute?(order)
raise "look at MerchandiserStandard.compute?"
order.front_end? &&
order.credit_adjustments.empty? &&
order.discount_adjustments.empty? &&
order.promotion_credits.empty? &&
order.has_only_customer_products? &&
can_use?(self.user)
end
end
# Employee Discount spec
describe Discount::Employee do
subject { Discount::Employee.new }
describe "compute?" do
let(:order) { mock_model(Order, :credit_adjustments => [], :discount_adjustments => [], :promotion_credits => []) }
before { subject.stubs(:user) }
it "should call the right methods" do
order.discount_adjustments.should_receive(:empty?)
order.should_receive(:front_end?)
order.promotion_credits.should_receive(:empty?)
order.should_receive(:has_only_customer_products?)
subject.should_receive(:can_use?)
subject.compute?(order)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment