Merge pull request #3165 from coopdevs/fix-send-confirmation-instructions-specs

[Spree Upgrade] Fix send confirmation instructions specs
This commit is contained in:
Maikel
2018-12-06 16:24:40 +11:00
committed by GitHub
6 changed files with 54 additions and 56 deletions

View File

@@ -45,26 +45,3 @@
%td.text-center  
%td= t(:total).upcase
%td.text-right= invoice_total_for(invoice)
-# - if @enterprises.empty?
-# %h4 No enterprises to display
-#
-# - @enterprises.each do |enterprise|
-# %h2= enterprise.name
-# %table
-# %thead
-# %th Begins
-# %th Ends
-# %th Sells
-# %th Trial?
-# %th Turnover
-# %th Bill
-# - enterprise.billable_periods.each do |billable_period|
-# %tr
-# %td= billable_period.begins_at.in_time_zone.strftime("%F %T")
-# %td= billable_period.ends_at.in_time_zone.strftime("%F %T")
-# %td= billable_period.sells
-# %td= billable_period.trial?
-# %td= billable_period.display_turnover
-# %td= billable_period.display_bill

View File

@@ -26,20 +26,26 @@ module Admin
end
context "signing up a new user" do
let(:manager_invitation) { instance_double(ManagerInvitationJob) }
before do
setup_email
controller.stub spree_current_user: admin
end
it "creates a new user, sends an invitation email, and returns the user id" do
expect do
spree_post :create, {email: 'un.registered@email.com', enterprise_id: enterprise.id}
end.to send_confirmation_instructions
it 'enqueues an invitation email' do
allow(ManagerInvitationJob)
.to receive(:new).with(enterprise.id, kind_of(Integer)) { manager_invitation }
expect(Delayed::Job).to receive(:enqueue).with(manager_invitation)
spree_post :create, { email: 'un.registered@email.com', enterprise_id: enterprise.id }
end
it "returns the user id" do
spree_post :create, { email: 'un.registered@email.com', enterprise_id: enterprise.id }
new_user = Spree::User.find_by_email('un.registered@email.com')
expect(new_user.reset_password_token).to_not be_nil
expect(response.status).to eq 200
expect(json_response['user']).to eq new_user.id
end
end

View File

@@ -32,6 +32,10 @@ feature "Managing users" do
describe "resending confirmation email", js: true do
let(:user) { create :user, confirmed_at: nil }
around do |example|
performing_deliveries { example.run }
end
it "displays success" do
visit spree.edit_admin_user_path user

View File

@@ -21,21 +21,23 @@ feature "Account Settings", js: true do
end
it "allows the user to update their email address" do
fill_in 'user_email', with: 'new@email.com'
performing_deliveries do
fill_in 'user_email', with: 'new@email.com'
expect do
click_button I18n.t(:update)
end.to send_confirmation_instructions
expect do
click_button I18n.t(:update)
end.to send_confirmation_instructions
sent_mail = ActionMailer::Base.deliveries.last
expect(sent_mail.to).to eq ['new@email.com']
sent_mail = ActionMailer::Base.deliveries.last
expect(sent_mail.to).to eq ['new@email.com']
expect(find(".alert-box.success").text.strip).to eq "#{I18n.t('spree.account_updated')} ×"
user.reload
expect(user.email).to eq 'old@email.com'
expect(user.unconfirmed_email).to eq 'new@email.com'
click_link I18n.t('spree.users.show.tabs.settings')
expect(page).to have_content I18n.t('spree.users.show.unconfirmed_email', unconfirmed_email: 'new@email.com')
expect(find(".alert-box.success").text.strip).to eq "#{I18n.t('spree.account_updated')} ×"
user.reload
expect(user.email).to eq 'old@email.com'
expect(user.unconfirmed_email).to eq 'new@email.com'
click_link I18n.t('spree.users.show.tabs.settings')
expect(page).to have_content I18n.t('spree.users.show.unconfirmed_email', unconfirmed_email: 'new@email.com')
end
end
it "allows the user to change their password" do

View File

@@ -1,14 +1,9 @@
require 'spec_helper'
feature "Authentication", js: true, retry: 3 do
feature "Authentication", js: true do
include UIComponentHelper
include OpenFoodNetwork::EmailHelper
# Attempt to address intermittent failures in these specs
around do |example|
Capybara.using_wait_time(120) { example.run }
end
describe "login" do
let(:user) { create(:user, password: "password", password_confirmation: "password") }
@@ -76,15 +71,17 @@ feature "Authentication", js: true, retry: 3 do
end
scenario "Signing up successfully" do
setup_email
fill_in "Email", with: "test@foo.com"
fill_in "Choose a password", with: "test12345"
fill_in "Confirm password", with: "test12345"
performing_deliveries do
setup_email
fill_in "Email", with: "test@foo.com"
fill_in "Choose a password", with: "test12345"
fill_in "Confirm password", with: "test12345"
expect do
click_signup_button
expect(page).to have_content I18n.t('devise.user_registrations.spree_user.signed_up_but_unconfirmed')
end.to send_confirmation_instructions
expect do
click_signup_button
expect(page).to have_content I18n.t('devise.user_registrations.spree_user.signed_up_but_unconfirmed')
end.to send_confirmation_instructions
end
end
end

View File

@@ -7,5 +7,17 @@ module OpenFoodNetwork
def setup_email
Spree::Config[:mails_from] = "test@ofn.example.org"
end
# Ensures the value `perform_deliveries` had is restored. This saves us
# from messing up with the test suite's global state which is cause of
# trouble.
def performing_deliveries
old_value = ActionMailer::Base.perform_deliveries
ActionMailer::Base.perform_deliveries = true
yield
ActionMailer::Base.perform_deliveries = old_value
end
end
end