Created
February 13, 2014 19:05
-
-
Save dpritchett/8981627 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
# encoding: utf-8 | |
require 'spec_helper' | |
describe "Gift Cards" do | |
include_context "custom products" | |
before(:all) { load "db/seeds/gift_cards.rb" } | |
before(:each) { visit spree.products_path } | |
context "purchasing a gift card" do | |
let(:gift_card_product) { Spree::Product.where("name ilike '%Gift Card%'").first } | |
before { click_link gift_card_product.name } | |
context "recipient form is filled out" do | |
let(:email) { Faker::Internet.email } | |
let(:name) { Faker::Name.name } | |
before do | |
fill_in "gift_card_email", with: email | |
fill_in "gift_card_name", with: name | |
end | |
it "should be possible to add to cart" do | |
click_on "Add To Cart" | |
page.status_code.should == 200 | |
page.current_path.should =~ /cart/ | |
end | |
end | |
end | |
context "Redeeming gift cards" do | |
let(:purchased_card) { FactoryGirl.create(:gift_card) } | |
context "a regular product is in the cart" do | |
before do | |
click_link "Ruby on Rails Ringer T-Shirt" | |
click_on "Add To Cart" | |
end | |
context "gift card code is eligible and applied" do | |
before do | |
Spree::GiftCard.any_instance.stub(:order_activatable?) { true } | |
fill_in "order_gift_code", with: purchased_card.code | |
click_on "Apply" | |
end | |
it "should flash a success note" do | |
first(".flash").text.should =~ /success/ | |
end | |
it "should apply a discount to the order" do | |
adjustments_texts = find("#cart_adjustments").all("td").map(&:text).join | |
adjustments_texts.include?("Gift Card").should be_true | |
end | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment