forked from solidusio/solidus_auth_devise
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update specs and dependencies for RSpec 3.
- Loading branch information
Showing
35 changed files
with
194 additions
and
216 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
--color | ||
--color | ||
-r spec_helper | ||
-f documentation |
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 |
---|---|---|
@@ -1,35 +1,32 @@ | ||
require 'spec_helper' | ||
RSpec.describe Spree::CheckoutController, type: :controller do | ||
|
||
describe Spree::CheckoutController do | ||
let(:order) { create(:order_with_totals, email: nil, user: nil) } | ||
let(:user) { mock_model Spree::User, last_incomplete_spree_order: nil, has_spree_role?: true, spree_api_key: 'fake' } | ||
let(:user) { build(:user, spree_api_key: 'fake') } | ||
let(:token) { 'some_token' } | ||
|
||
before do | ||
controller.stub current_order: order | ||
order.stub confirmation_required?: true | ||
allow(controller).to receive(:current_order) { order } | ||
allow(order).to receive(:confirmation_required?) { true } | ||
end | ||
|
||
context '#edit' do | ||
context 'when registration step enabled' do | ||
before do | ||
controller.stub :check_authorization | ||
allow(controller).to receive(:check_authorization) | ||
Spree::Auth::Config.set(registration_step: true) | ||
end | ||
|
||
context 'when authenticated as registered user' do | ||
before { controller.stub spree_current_user: user } | ||
|
||
it 'proceed to the first checkout step' do | ||
user.should_receive(:ship_address) | ||
before { allow(controller).to receive(:spree_current_user) { user } } | ||
|
||
it 'proceeds to the first checkout step' do | ||
spree_get :edit, { state: 'address' } | ||
expect(response).to render_template :edit | ||
end | ||
end | ||
|
||
context 'when authenticated as guest' do | ||
it 'redirect to registration step' do | ||
it 'redirects to registration step' do | ||
spree_get :edit, { state: 'address' } | ||
expect(response).to redirect_to spree.checkout_registration_path | ||
end | ||
|
@@ -39,22 +36,20 @@ | |
context 'when registration step disabled' do | ||
before do | ||
Spree::Auth::Config.set(registration_step: false) | ||
controller.stub :check_authorization | ||
allow(controller).to receive(:check_authorization) | ||
end | ||
|
||
context 'when authenticated as registered' do | ||
before { controller.stub spree_current_user: user } | ||
|
||
it 'proceed to the first checkout step' do | ||
user.should_receive(:ship_address) | ||
before { allow(controller).to receive(:spree_current_user) { user } } | ||
|
||
it 'proceeds to the first checkout step' do | ||
spree_get :edit, { state: 'address' } | ||
expect(response).to render_template :edit | ||
end | ||
end | ||
|
||
context 'when authenticated as guest' do | ||
it 'proceed to the first checkout step' do | ||
it 'proceeds to the first checkout step' do | ||
spree_get :edit, { state: 'address' } | ||
expect(response).to render_template :edit | ||
end | ||
|
@@ -69,15 +64,13 @@ | |
order.update_column(:state, 'confirm') | ||
|
||
# So that the order can transition to complete successfully | ||
order.stub payment_required?: false | ||
allow(order).to receive(:payment_required?) { false } | ||
end | ||
|
||
context 'with a token' do | ||
before do | ||
order.stub guest_token: 'ABC' | ||
end | ||
before { allow(order).to receive(:guest_token) { 'ABC' } } | ||
|
||
it 'redirect to the tokenized order view' do | ||
it 'redirects to the tokenized order view' do | ||
request.cookie_jar.signed[:guest_token] = 'ABC' | ||
spree_post :update, { state: 'confirm' } | ||
expect(response).to redirect_to spree.token_order_path(order, 'ABC') | ||
|
@@ -87,13 +80,13 @@ | |
|
||
context 'with a registered user' do | ||
before do | ||
controller.stub spree_current_user: user | ||
order.stub user: user | ||
order.stub guest_token: nil | ||
allow(controller).to receive(:spree_current_user) { user } | ||
allow(order).to receive(:user) { user } | ||
allow(order).to receive(:guest_token) { nil } | ||
end | ||
|
||
it 'redirect to the standard order view' do | ||
spree_post :update, { :state => 'confirm' } | ||
it 'redirects to the standard order view' do | ||
spree_post :update, { state: 'confirm' } | ||
expect(response).to redirect_to spree.order_path(order) | ||
end | ||
end | ||
|
@@ -102,20 +95,20 @@ | |
|
||
context '#registration' do | ||
it 'does not check registration' do | ||
controller.stub :check_authorization | ||
controller.should_not_receive :check_registration | ||
allow(controller).to receive(:check_authorization) | ||
expect(controller).not_to receive(:check_registration) | ||
spree_get :registration | ||
end | ||
|
||
it 'check if the user is authorized for :edit' do | ||
controller.should_receive(:authorize!).with(:edit, order, token) | ||
it 'checks if the user is authorized for :edit' do | ||
expect(controller).to receive(:authorize!).with(:edit, order, token) | ||
request.cookie_jar.signed[:guest_token] = token | ||
spree_get :registration, {} | ||
end | ||
end | ||
|
||
context '#update_registration' do | ||
let(:user) { user = mock_model Spree::User } | ||
let(:user) { build(:user) } | ||
|
||
it 'does not check registration' do | ||
controller.stub :check_authorization | ||
|
@@ -124,24 +117,24 @@ | |
spree_put :update_registration, { order: { } } | ||
end | ||
|
||
it 'render the registration view if unable to save' do | ||
controller.stub :check_authorization | ||
it 'renders the registration view if unable to save' do | ||
allow(controller).to receive(:check_authorization) | ||
spree_put :update_registration, { order: { email: 'invalid' } } | ||
expect(flash[:registration_error]).to eq I18n.t(:email_is_invalid, scope: [:errors, :messages]) | ||
expect(response).to render_template :registration | ||
end | ||
|
||
it 'redirect to the checkout_path after saving' do | ||
order.stub update_attributes: true | ||
controller.stub :check_authorization | ||
it 'redirects to the checkout_path after saving' do | ||
allow(order).to receive(:update_attributes) { true } | ||
allow(controller).to receive(:check_authorization) | ||
spree_put :update_registration, { order: { email: '[email protected]' } } | ||
expect(response).to redirect_to spree.checkout_path | ||
end | ||
|
||
it 'check if the user is authorized for :edit' do | ||
it 'checks if the user is authorized for :edit' do | ||
request.cookie_jar.signed[:guest_token] = token | ||
order.stub update_attributes: true | ||
controller.should_receive(:authorize!).with(:edit, order, token) | ||
allow(order).to receive(:update_attributes) { true } | ||
expect(controller).to receive(:authorize!).with(:edit, order, token) | ||
spree_put :update_registration, { order: { email: '[email protected]' } } | ||
end | ||
end | ||
|
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
16 changes: 8 additions & 8 deletions
16
spec/controllers/spree/user_registrations_controller_spec.rb
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 |
---|---|---|
@@ -1,12 +1,12 @@ | ||
require 'spec_helper' | ||
describe Spree::UserRegistrationsController do | ||
before do | ||
@request.env["devise.mapping"] = Devise.mappings[:spree_user] | ||
end | ||
RSpec.describe Spree::UserRegistrationsController, type: :controller do | ||
|
||
before { @request.env['devise.mapping'] = Devise.mappings[:spree_user] } | ||
|
||
context '#create' do | ||
before { controller.stub(:after_sign_up_path_for).and_return(spree.root_path(thing: 7)) } | ||
it 'should redirect to after_sign_up_path_for' do | ||
spree_post :create, { :spree_user => { :email => '[email protected]', :password => 'foobar123', :password_confirmation => 'foobar123' } } | ||
before { allow(controller).to receive(:after_sign_up_path_for).and_return(spree.root_path(thing: 7)) } | ||
|
||
it 'redirects to after_sign_up_path_for' do | ||
spree_post :create, { spree_user: { email: '[email protected]', password: 'foobar123', password_confirmation: 'foobar123' } } | ||
expect(response).to redirect_to spree.root_path(thing: 7) | ||
end | ||
end | ||
|
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 |
---|---|---|
@@ -1,32 +1,29 @@ | ||
require 'spec_helper' | ||
RSpec.describe Spree::UsersController, type: :controller do | ||
|
||
describe Spree::UsersController do | ||
let(:admin_user) { create(:user) } | ||
let(:user) { create(:user) } | ||
let(:role) { create(:role) } | ||
|
||
before do | ||
controller.stub spree_current_user: user | ||
end | ||
before { allow(controller).to receive(:spree_current_user) { user } } | ||
|
||
context '#load_object' do | ||
it 'should redirect to signup path if user is not found' do | ||
controller.stub(:spree_current_user => nil) | ||
spree_put :update, { :user => { :email => '[email protected]' } } | ||
response.should redirect_to('/login') | ||
it 'redirects to signup path if user is not found' do | ||
allow(controller).to receive(:spree_current_user) { nil } | ||
spree_put :update, { user: { email: '[email protected]' } } | ||
expect(response).to redirect_to('/login') | ||
end | ||
end | ||
|
||
context '#create' do | ||
it 'create a new user' do | ||
it 'creates a new user' do | ||
spree_post :create, { user: { email: '[email protected]', password: 'foobar123', password_confirmation: 'foobar123' } } | ||
expect(assigns[:user].new_record?).to be false | ||
end | ||
end | ||
|
||
context '#update' do | ||
context 'when updating own account' do | ||
it 'perform update' do | ||
it 'performs update' do | ||
spree_put :update, { user: { email: '[email protected]' } } | ||
expect(assigns[:user].email).to eq '[email protected]' | ||
expect(response).to redirect_to spree.account_url(only_path: true) | ||
|
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 |
---|---|---|
@@ -1,6 +1,4 @@ | ||
require 'spec_helper' | ||
|
||
feature 'Accounts' do | ||
RSpec.feature 'Accounts', type: :feature do | ||
|
||
context 'editing' do | ||
scenario 'can edit an admin user' do | ||
|
@@ -21,7 +19,7 @@ | |
|
||
fill_in 'Email', with: '[email protected]' | ||
fill_in 'Password', with: 'password' | ||
fill_in 'Password Confirmation', :with => 'password' | ||
fill_in 'Password Confirmation', with: 'password' | ||
click_button 'Create' | ||
|
||
click_link 'My Account' | ||
|
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 |
---|---|---|
@@ -1,30 +1,28 @@ | ||
require 'spec_helper' | ||
RSpec.feature 'Admin orders', type: :feature do | ||
|
||
feature 'Admin orders' do | ||
background do | ||
sign_in_as! create(:admin_user) | ||
end | ||
|
||
# regression #203 | ||
# Regression #203 | ||
scenario 'can lists orders' do | ||
expect { visit spree.admin_orders_path }.not_to raise_error | ||
end | ||
|
||
# regression #203 | ||
# Regression #203 | ||
scenario 'can new orders' do | ||
expect { visit spree.new_admin_order_path }.not_to raise_error | ||
end | ||
|
||
# regression #203 | ||
# Regression #203 | ||
scenario 'can not edit orders' do | ||
expect { visit spree.edit_admin_order_path('nodata') }.to raise_error(ActiveRecord::RecordNotFound) | ||
end | ||
|
||
# regression #203 | ||
# Regression #203 | ||
scenario 'can edit orders' do | ||
create(:order, number: 'R123') | ||
visit spree.edit_admin_order_path('R123') | ||
expect(page).not_to have_text 'Authorization Failure' | ||
end | ||
|
||
end |
Oops, something went wrong.