Skip to content

Commit

Permalink
[SDP-314] Fixing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
aplegatt committed Jul 6, 2020
1 parent 9668912 commit 7c0b97c
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ module Api
module V2
module Storefront
class PasswordsController < ::Spree::Api::V2::BaseController
include Spree::Core::ControllerHelpers::Store

def create
user = Spree.user_class.find_by(email: params[:user][:email])

if user&.send_reset_password_instructions
if user&.send_reset_password_instructions(current_store)
head :ok
else
head :not_found
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
RSpec.describe Spree::Api::V2::Storefront::PasswordsController, type: :controller do
let(:user) { create(:user) }
let(:password) { 'new_password' }
let(:store) { create(:store) }

describe 'POST create' do
before { post :create, params: params }
Expand Down Expand Up @@ -31,7 +32,7 @@
context 'when updating password with blank password' do
let(:params) {
{
id: user.send_reset_password_instructions,
id: user.send_reset_password_instructions(Spree::Store.current),
user: {
password: '',
password_confirmation: ''
Expand All @@ -48,7 +49,7 @@
context 'when updating password with specified password' do
let(:params) {
{
id: user.send_reset_password_instructions,
id: user.send_reset_password_instructions(Spree::Store.current),
user: {
password: password,
password_confirmation: password
Expand Down
2 changes: 1 addition & 1 deletion spec/features/admin/sign_in_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
fill_in 'Email', with: user.email
fill_in 'Password', with: 'secret'
click_button 'Log in'
within '.user-menu' do
within '.navbar .dropdown-menu' do
expect(page).to have_text '[email protected]'
end
expect(current_path).to eq '/admin/orders'
Expand Down
12 changes: 6 additions & 6 deletions spec/features/sign_in_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,17 @@
fill_in 'Password', with: user.password
click_button 'Log in'

within '.user-menu' do
within '.navbar .dropdown-menu' do
expect(page).to have_text '[email protected]'
end
expect(current_path).to eq '/admin/orders'
end

xit "should store the user previous location" do
it 'should store the user previous location' do
visit spree.account_path
fill_in "Email", with: @user.email
fill_in "Password", with: @user.password
click_button "Login"
expect(current_path).to eq "/account"
fill_in 'Email', with: @user.email
fill_in 'Password', with: @user.password
click_button 'Log in'
expect(current_path).to eq '/account'
end
end
4 changes: 2 additions & 2 deletions spec/mailers/user_mailer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
describe '#reset_password_instructions' do
describe 'message contents' do
before do
@message = described_class.reset_password_instructions(user, 'token goes here')
@message = described_class.reset_password_instructions(user, 'token goes here', { current_store_id: Spree::Store.current.id })
end

context 'subject includes' do
Expand All @@ -30,7 +30,7 @@
describe 'legacy support for User object' do
it 'sends an email' do
expect {
described_class.reset_password_instructions(user, 'token goes here').deliver_now
described_class.reset_password_instructions(user, 'token goes here', { current_store_id: Spree::Store.current.id }).deliver_now
}.to change(ActionMailer::Base.deliveries, :size).by(1)
end
end
Expand Down
6 changes: 4 additions & 2 deletions spec/models/user_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
RSpec.describe Spree::User, type: :model do
before(:all) { Spree::Role.create name: 'admin' }
let!(:store) { create(:store) }

it '#admin?' do
expect(create(:admin_user).admin?).to be true
Expand All @@ -8,8 +9,9 @@

it 'generates the reset password token' do
user = build(:user)
expect(Spree::UserMailer).to receive(:reset_password_instructions).with(user, anything, {}).and_return(double(deliver: true))
user.send_reset_password_instructions
current_store = Spree::Store.current
expect(Spree::UserMailer).to receive(:reset_password_instructions).with(user, anything, { current_store_id: current_store.id }).and_return(double(deliver: true))
user.send_reset_password_instructions(current_store)
expect(user.reset_password_token).not_to be_nil
end

Expand Down

0 comments on commit 7c0b97c

Please sign in to comment.