From ccc1f3df40f46eb60ec1635cec77fb5f3b11d0b9 Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Fri, 10 Apr 2015 17:06:18 +1000 Subject: [PATCH] Feature specs test email sending through delayed jobs --- spec/features/consumer/authentication_spec.rb | 10 ++++---- .../consumer/shopping/checkout_spec.rb | 23 ++++++++----------- .../shopping/variant_overrides_spec.rb | 8 +------ 3 files changed, 15 insertions(+), 26 deletions(-) diff --git a/spec/features/consumer/authentication_spec.rb b/spec/features/consumer/authentication_spec.rb index 2aefb42db5..e3fa340909 100644 --- a/spec/features/consumer/authentication_spec.rb +++ b/spec/features/consumer/authentication_spec.rb @@ -45,9 +45,9 @@ feature "Authentication", js: true do describe "signing up" do before do - ActionMailer::Base.deliveries.clear select_login_tab "Sign up" end + scenario "Failing to sign up because password is too short" do fill_in "Email", with: "test@foo.com" fill_in "Choose a password", with: "short" @@ -59,10 +59,11 @@ feature "Authentication", js: true do fill_in "Email", with: "test@foo.com" fill_in "Choose a password", with: "test12345" fill_in "Confirm password", with: "test12345" - click_signup_button - page.should have_content "Welcome! You have signed up successfully" + expect do + click_signup_button + page.should have_content "Welcome! You have signed up successfully" + end.to enqueue_job ConfirmSignupJob page.should be_logged_in_as "test@foo.com" - ActionMailer::Base.deliveries.last.subject.should =~ /Welcome to/ end end @@ -105,4 +106,3 @@ feature "Authentication", js: true do end end end - diff --git a/spec/features/consumer/shopping/checkout_spec.rb b/spec/features/consumer/shopping/checkout_spec.rb index ac7fac09c5..12eca09339 100644 --- a/spec/features/consumer/shopping/checkout_spec.rb +++ b/spec/features/consumer/shopping/checkout_spec.rb @@ -16,7 +16,6 @@ feature "As a consumer I want to check out my cart", js: true do let(:order) { create(:order, order_cycle: order_cycle, distributor: distributor) } before do - ActionMailer::Base.deliveries.clear add_enterprise_fee enterprise_fee set_order order add_product_to_cart @@ -80,7 +79,6 @@ feature "As a consumer I want to check out my cart", js: true do context "on the checkout page with payments open" do before do - ActionMailer::Base.deliveries.clear visit checkout_path checkout_as_guest toggle_payment @@ -120,13 +118,11 @@ feature "As a consumer I want to check out my cart", js: true do end - ActionMailer::Base.deliveries.length.should == 0 - place_order - page.should have_content "Your order has been processed successfully" - ActionMailer::Base.deliveries.length.should == 2 - email = ActionMailer::Base.deliveries.last - site_name = Spree::Config[:site_name] - email.subject.should include "#{site_name} Order Confirmation" + expect do + place_order + page.should have_content "Your order has been processed successfully" + end.to enqueue_job ConfirmOrderJob + o = Spree::Order.complete.first expect(o.special_instructions).to eq "SpEcIaL NoTeS" end @@ -214,7 +210,6 @@ feature "As a consumer I want to check out my cart", js: true do context "when the customer has a pre-set shipping and billing address" do before do - ActionMailer::Base.deliveries.clear # Load up the customer's order and give them a shipping and billing address # This is equivalent to when the customer has ordered before and their addresses # are pre-populated. @@ -231,10 +226,10 @@ feature "As a consumer I want to check out my cart", js: true do toggle_payment choose pm1.name - expect(ActionMailer::Base.deliveries.length).to be 0 - place_order - page.should have_content "Your order has been processed successfully" - expect(ActionMailer::Base.deliveries.length).to be 2 + expect do + place_order + page.should have_content "Your order has been processed successfully" + end.to enqueue_job ConfirmOrderJob end end end diff --git a/spec/features/consumer/shopping/variant_overrides_spec.rb b/spec/features/consumer/shopping/variant_overrides_spec.rb index 4178aeb2cc..98d58e174f 100644 --- a/spec/features/consumer/shopping/variant_overrides_spec.rb +++ b/spec/features/consumer/shopping/variant_overrides_spec.rb @@ -26,9 +26,9 @@ feature "shopping with variant overrides defined", js: true do let(:ef) { create(:enterprise_fee, enterprise: hub, fee_type: 'packing', calculator: Spree::Calculator::FlatPercentItemTotal.new(preferred_flat_percent: 10)) } before do - ActionMailer::Base.deliveries.clear outgoing_exchange.variants = [v1, v2, v3, v4] outgoing_exchange.enterprise_fees << ef + sm.calculator.preferred_amount = 0 visit shop_path click_link hub.name end @@ -109,15 +109,9 @@ feature "shopping with variant overrides defined", js: true do complete_checkout - ActionMailer::Base.deliveries.length.should == 2 - email = ActionMailer::Base.deliveries.last - o = Spree::Order.complete.last - o.line_items.first.price.should == 55.55 o.total.should == 122.21 - - email.body.should include "$122.21" end it "subtracts stock from the override" do