-
-
Notifications
You must be signed in to change notification settings - Fork 122
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #131 from yono/improve_edit_user
Fix to not reuse spree_current_user as `@user`
- Loading branch information
Showing
2 changed files
with
28 additions
and
8 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,11 +4,8 @@ | |
let(:user) { create(:user) } | ||
let(:role) { create(:role) } | ||
|
||
before { allow(controller).to receive(:spree_current_user) { user } } | ||
|
||
context '#load_object' do | ||
it 'redirects to signup path if user is not found' do | ||
allow(controller).to receive(:spree_current_user) { nil } | ||
put :update, params: { user: { email: '[email protected]' } } | ||
expect(response).to redirect_to spree.login_path | ||
end | ||
|
@@ -22,11 +19,32 @@ | |
end | ||
|
||
context '#update' do | ||
before { sign_in(user) } | ||
|
||
context 'when updating own account' do | ||
it 'performs update' do | ||
put :update, params: { user: { email: '[email protected]' } } | ||
expect(assigns[:user].email).to eq '[email protected]' | ||
expect(response).to redirect_to spree.account_url(only_path: true) | ||
|
||
context 'when user updated successfuly' do | ||
before { put :update, params: { user: { email: '[email protected]' } } } | ||
|
||
it 'saves user' do | ||
expect(assigns[:user].email).to eq '[email protected]' | ||
end | ||
|
||
it 'updates spree_current_user' do | ||
expect(subject.spree_current_user.email).to eq '[email protected]' | ||
end | ||
|
||
it 'redirects to account url' do | ||
expect(response).to redirect_to spree.account_url(only_path: true) | ||
end | ||
end | ||
|
||
context 'when user not valid' do | ||
before { put :update, params: { user: { email: '' } } } | ||
|
||
it 'does not affect spree_current_user' do | ||
expect(subject.spree_current_user.email).to eq user.email | ||
end | ||
end | ||
end | ||
|
||
|