Product.find(product_id) availability = backend.check_availability(product) if availability.any_available? reservation = backend.reserve_for_purchase(product) if points_program.eligible?(user) backend.pay_with_points(reservation, points_program.authorize(user, allocated_points)) else backend.pay_with_credit_card(reservation, credit_card_information) end else fail NoProductsAvailableError end end end
Product.find(product_id) availability = backend.check_availability(product) if availability.any_available? reservation = backend.reserve_for_purchase(product) if points_program.eligible?(user) backend.pay_with_points(reservation, points_program.authorize(user, allocated_points)) else backend.pay_with_credit_card(reservation, credit_card_information) end else fail NoProductsAvailableError end end end
Product.find(product_id) availability = backend.check_availability(product) if availability.any_available? reservation = backend.reserve_for_purchase(product) if points_program.eligible?(user) backend.pay_with_points(reservation, points_program.authorize(user, allocated_points)) else backend.pay_with_credit_card(reservation, credit_card_information) end else fail NoProductsAvailableError end end end
order.save fulfillment = Backend.new.fulfill_order(order) if fulfillment OrderMailer.order_confirmation(order.customer).deliver_n ow redirect_to confirmation_order_path(order), notice: 'Yes!' else OrderMailer.order_failed(order.customer).deliver_now redirect_to confirmation_order_path(order), alert: 'No!' end else flash[:alert] = 'Oh, oh! No order for you!' render :new end end end
class Square < Shape def rotate(deg) # !!... end end class Circle < Shape def rotate(deg) self end end class RotationTool def rotate(shape, deg) shape.rotate(deg) end end
class Square < Shape def rotate(deg) # !!... end end class Circle < Shape def rotate(deg) self end end class RotationTool def rotate(shape, deg) shape.rotate(deg) end end
params end attr_reader :product_id, :params def call product = Product.find(product_id) order = Backend.new.create_order(product, params) # !!... end end
} describe '#call' do context 'when the Backend cannot be reached' do before do expect(backend) .to receive(:create_order) .and_raise(Errno!::ENETUNREACH) end it 'wraps the error' do expect { subject.call(nil, nil) } .to raise_error(OrderCreationError) end end end end
context 'when the Backend cannot be reached' do let(:backend) do Class.new def create_order(*) fail Errno!::ENETUNREACH end end.new end it 'wraps the error' do expect { subject.call(nil, nil) } .to raise_error(OrderCreationError) end end end end