Run transpec for spec/controllers

This commit is contained in:
luisramos0
2019-05-10 01:20:40 +01:00
parent df459a21a4
commit 6996353d05
25 changed files with 242 additions and 240 deletions

View File

@@ -17,7 +17,7 @@ describe Admin::BulkLineItemsController, type: :controller do
let!(:line_item4) { FactoryBot.create(:line_item_with_shipment, order: order3) }
context "as a normal user" do
before { controller.stub spree_current_user: create_enterprise_user }
before { allow(controller).to receive_messages spree_current_user: create_enterprise_user }
it "should deny me access to the index action" do
spree_get :index, :format => :json
@@ -27,7 +27,7 @@ describe Admin::BulkLineItemsController, type: :controller do
context "as an administrator" do
before do
controller.stub spree_current_user: quick_login_as_admin
allow(controller).to receive_messages spree_current_user: quick_login_as_admin
end
context "when no ransack params are passed in" do
@@ -37,7 +37,7 @@ describe Admin::BulkLineItemsController, type: :controller do
it "retrieves a list of line_items with appropriate attributes, including line items with appropriate attributes" do
keys = json_response.first.keys.map(&:to_sym)
line_item_attributes.all?{ |attr| keys.include? attr }.should == true
expect(line_item_attributes.all?{ |attr| keys.include? attr }).to eq(true)
end
it "sorts line_items in ascending id line_item" do
@@ -47,11 +47,11 @@ describe Admin::BulkLineItemsController, type: :controller do
end
it "formats final_weight_volume as a float" do
json_response.map{ |line_item| line_item['final_weight_volume'] }.all?{ |fwv| fwv.is_a?(Float) }.should == true
expect(json_response.map{ |line_item| line_item['final_weight_volume'] }.all?{ |fwv| fwv.is_a?(Float) }).to eq(true)
end
it "returns distributor object with id key" do
json_response.map{ |line_item| line_item['supplier'] }.all?{ |d| d.key?('id') }.should == true
expect(json_response.map{ |line_item| line_item['supplier'] }.all?{ |d| d.key?('id') }).to eq(true)
end
end
@@ -90,7 +90,7 @@ describe Admin::BulkLineItemsController, type: :controller do
context "producer enterprise" do
before do
controller.stub spree_current_user: supplier.owner
allow(controller).to receive_messages spree_current_user: supplier.owner
spree_get :index, :format => :json
end
@@ -101,25 +101,25 @@ describe Admin::BulkLineItemsController, type: :controller do
context "coordinator enterprise" do
before do
controller.stub spree_current_user: coordinator.owner
allow(controller).to receive_messages spree_current_user: coordinator.owner
spree_get :index, :format => :json
end
it "retrieves a list of line_items" do
keys = json_response.first.keys.map(&:to_sym)
line_item_attributes.all?{ |attr| keys.include? attr }.should == true
expect(line_item_attributes.all?{ |attr| keys.include? attr }).to eq(true)
end
end
context "hub enterprise" do
before do
controller.stub spree_current_user: distributor1.owner
allow(controller).to receive_messages spree_current_user: distributor1.owner
spree_get :index, :format => :json
end
it "retrieves a list of line_items" do
keys = json_response.first.keys.map(&:to_sym)
line_item_attributes.all?{ |attr| keys.include? attr }.should == true
expect(line_item_attributes.all?{ |attr| keys.include? attr }).to eq(true)
end
end
end
@@ -142,7 +142,7 @@ describe Admin::BulkLineItemsController, type: :controller do
context "as an enterprise user" do
context "producer enterprise" do
before do
controller.stub spree_current_user: supplier.owner
allow(controller).to receive_messages spree_current_user: supplier.owner
spree_put :update, params
end
@@ -155,7 +155,7 @@ describe Admin::BulkLineItemsController, type: :controller do
render_views
before do
controller.stub spree_current_user: coordinator.owner
allow(controller).to receive_messages spree_current_user: coordinator.owner
end
# Used in admin/orders/bulk_management
@@ -209,7 +209,7 @@ describe Admin::BulkLineItemsController, type: :controller do
context "hub enterprise" do
before do
controller.stub spree_current_user: distributor1.owner
allow(controller).to receive_messages spree_current_user: distributor1.owner
xhr :put, :update, params
end
@@ -235,7 +235,7 @@ describe Admin::BulkLineItemsController, type: :controller do
let(:params) { { id: line_item1.id, order_id: order1.number } }
before do
controller.stub spree_current_user: coordinator.owner
allow(controller).to receive_messages spree_current_user: coordinator.owner
end
# Used in admin/orders/bulk_management

View File

@@ -23,81 +23,81 @@ module Admin
let(:enterprise_params) { {enterprise: {name: 'zzz', permalink: 'zzz', is_primary_producer: '0', address_attributes: {address1: 'a', city: 'a', zipcode: 'a', country_id: country.id, state_id: state.id}}} }
it "grants management permission if the current user is an enterprise user" do
controller.stub spree_current_user: distributor_manager
allow(controller).to receive_messages spree_current_user: distributor_manager
enterprise_params[:enterprise][:owner_id] = distributor_manager
spree_put :create, enterprise_params
enterprise = Enterprise.find_by_name 'zzz'
response.should redirect_to edit_admin_enterprise_path enterprise
distributor_manager.enterprise_roles.where(enterprise_id: enterprise).first.should be
expect(response).to redirect_to edit_admin_enterprise_path enterprise
expect(distributor_manager.enterprise_roles.where(enterprise_id: enterprise).first).to be
end
it "overrides the owner_id submitted by the user (when not super admin)" do
controller.stub spree_current_user: distributor_manager
allow(controller).to receive_messages spree_current_user: distributor_manager
enterprise_params[:enterprise][:owner_id] = user
spree_put :create, enterprise_params
enterprise = Enterprise.find_by_name 'zzz'
response.should redirect_to edit_admin_enterprise_path enterprise
distributor_manager.enterprise_roles.where(enterprise_id: enterprise).first.should be
expect(response).to redirect_to edit_admin_enterprise_path enterprise
expect(distributor_manager.enterprise_roles.where(enterprise_id: enterprise).first).to be
end
context "when I already own a hub" do
before { distributor }
it "creates new non-producers as hubs" do
controller.stub spree_current_user: distributor_owner
allow(controller).to receive_messages spree_current_user: distributor_owner
enterprise_params[:enterprise][:owner_id] = distributor_owner
spree_put :create, enterprise_params
enterprise = Enterprise.find_by_name 'zzz'
response.should redirect_to edit_admin_enterprise_path enterprise
enterprise.sells.should == 'any'
expect(response).to redirect_to edit_admin_enterprise_path enterprise
expect(enterprise.sells).to eq('any')
end
it "creates new producers as sells none" do
controller.stub spree_current_user: distributor_owner
allow(controller).to receive_messages spree_current_user: distributor_owner
enterprise_params[:enterprise][:owner_id] = distributor_owner
enterprise_params[:enterprise][:is_primary_producer] = '1'
spree_put :create, enterprise_params
enterprise = Enterprise.find_by_name 'zzz'
response.should redirect_to edit_admin_enterprise_path enterprise
enterprise.sells.should == 'none'
expect(response).to redirect_to edit_admin_enterprise_path enterprise
expect(enterprise.sells).to eq('none')
end
it "doesn't affect the hub status for super admins" do
admin_user.enterprises << create(:distributor_enterprise)
controller.stub spree_current_user: admin_user
allow(controller).to receive_messages spree_current_user: admin_user
enterprise_params[:enterprise][:owner_id] = admin_user
enterprise_params[:enterprise][:sells] = 'none'
spree_put :create, enterprise_params
enterprise = Enterprise.find_by_name 'zzz'
response.should redirect_to edit_admin_enterprise_path enterprise
enterprise.sells.should == 'none'
expect(response).to redirect_to edit_admin_enterprise_path enterprise
expect(enterprise.sells).to eq('none')
end
end
context "when I do not have a hub" do
it "does not create the new enterprise as a hub" do
controller.stub spree_current_user: supplier_manager
allow(controller).to receive_messages spree_current_user: supplier_manager
enterprise_params[:enterprise][:owner_id] = supplier_manager
spree_put :create, enterprise_params
enterprise = Enterprise.find_by_name 'zzz'
enterprise.sells.should == 'none'
expect(enterprise.sells).to eq('none')
end
it "doesn't affect the hub status for super admins" do
controller.stub spree_current_user: admin_user
allow(controller).to receive_messages spree_current_user: admin_user
enterprise_params[:enterprise][:owner_id] = admin_user
enterprise_params[:enterprise][:sells] = 'any'
spree_put :create, enterprise_params
enterprise = Enterprise.find_by_name 'zzz'
enterprise.sells.should == 'any'
expect(enterprise.sells).to eq('any')
end
end
end
@@ -108,7 +108,7 @@ module Admin
context "as manager" do
it "does not allow 'sells' to be changed" do
profile_enterprise.enterprise_roles.build(user: distributor_manager).save
controller.stub spree_current_user: distributor_manager
allow(controller).to receive_messages spree_current_user: distributor_manager
enterprise_params = { id: profile_enterprise, enterprise: { sells: 'any' } }
spree_put :update, enterprise_params
@@ -117,7 +117,7 @@ module Admin
end
it "does not allow owner to be changed" do
controller.stub spree_current_user: distributor_manager
allow(controller).to receive_messages spree_current_user: distributor_manager
update_params = { id: distributor, enterprise: { owner_id: distributor_manager } }
spree_post :update, update_params
@@ -126,7 +126,7 @@ module Admin
end
it "does not allow managers to be changed" do
controller.stub spree_current_user: distributor_manager
allow(controller).to receive_messages spree_current_user: distributor_manager
update_params = { id: distributor, enterprise: { user_ids: [distributor_owner.id,distributor_manager.id,user.id] } }
spree_post :update, update_params
@@ -232,7 +232,7 @@ module Admin
context "as owner" do
it "allows 'sells' to be changed" do
controller.stub spree_current_user: profile_enterprise.owner
allow(controller).to receive_messages spree_current_user: profile_enterprise.owner
enterprise_params = { id: profile_enterprise, enterprise: { sells: 'any' } }
spree_put :update, enterprise_params
@@ -241,7 +241,7 @@ module Admin
end
it "allows owner to be changed" do
controller.stub spree_current_user: distributor_owner
allow(controller).to receive_messages spree_current_user: distributor_owner
update_params = { id: distributor, enterprise: { owner_id: distributor_manager } }
spree_post :update, update_params
@@ -250,7 +250,7 @@ module Admin
end
it "allows managers to be changed" do
controller.stub spree_current_user: distributor_owner
allow(controller).to receive_messages spree_current_user: distributor_owner
update_params = { id: distributor, enterprise: { user_ids: [distributor_owner.id,distributor_manager.id,user.id] } }
spree_post :update, update_params
@@ -261,7 +261,7 @@ module Admin
context "as super admin" do
it "allows 'sells' to be changed" do
controller.stub spree_current_user: admin_user
allow(controller).to receive_messages spree_current_user: admin_user
enterprise_params = { id: profile_enterprise, enterprise: { sells: 'any' } }
spree_put :update, enterprise_params
@@ -271,7 +271,7 @@ module Admin
it "allows owner to be changed" do
controller.stub spree_current_user: admin_user
allow(controller).to receive_messages spree_current_user: admin_user
update_params = { id: distributor, enterprise: { owner_id: distributor_manager } }
spree_post :update, update_params
@@ -280,7 +280,7 @@ module Admin
end
it "allows managers to be changed" do
controller.stub spree_current_user: admin_user
allow(controller).to receive_messages spree_current_user: admin_user
update_params = { id: distributor, enterprise: { user_ids: [distributor_owner.id,distributor_manager.id,user.id] } }
spree_post :update, update_params
@@ -295,7 +295,7 @@ module Admin
context "as a normal user" do
before do
controller.stub spree_current_user: distributor_manager
allow(controller).to receive_messages spree_current_user: distributor_manager
end
it "does not allow access" do
@@ -306,7 +306,7 @@ module Admin
context "as a manager" do
before do
controller.stub spree_current_user: distributor_manager
allow(controller).to receive_messages spree_current_user: distributor_manager
enterprise.enterprise_roles.build(user: distributor_manager).save
end
@@ -318,7 +318,7 @@ module Admin
context "as an owner" do
before do
controller.stub spree_current_user: enterprise.owner
allow(controller).to receive_messages spree_current_user: enterprise.owner
end
context "setting 'sells' to 'none'" do
@@ -391,7 +391,7 @@ module Admin
it "does not allow 'sells' or 'owner' to be changed" do
profile_enterprise1.enterprise_roles.build(user: new_owner).save
profile_enterprise2.enterprise_roles.build(user: new_owner).save
controller.stub spree_current_user: new_owner
allow(controller).to receive_messages spree_current_user: new_owner
bulk_enterprise_params = { enterprise_set: { collection_attributes: { '0' => { id: profile_enterprise1.id, sells: 'any', owner_id: new_owner.id }, '1' => { id: profile_enterprise2.id, sells: 'any', owner_id: new_owner.id } } } }
spree_put :bulk_update, bulk_enterprise_params
@@ -404,9 +404,9 @@ module Admin
end
it "cuts down the list of enterprises displayed when error received on bulk update" do
EnterpriseSet.any_instance.stub(:save) { false }
allow_any_instance_of(EnterpriseSet).to receive(:save) { false }
profile_enterprise1.enterprise_roles.build(user: new_owner).save
controller.stub spree_current_user: new_owner
allow(controller).to receive_messages spree_current_user: new_owner
bulk_enterprise_params = { enterprise_set: { collection_attributes: { '0' => { id: profile_enterprise1.id, visible: 'false' } } } }
spree_put :bulk_update, bulk_enterprise_params
expect(assigns(:enterprise_set).collection).to eq [profile_enterprise1]
@@ -415,7 +415,7 @@ module Admin
context "as the owner of an enterprise" do
it "allows 'sells' and 'owner' to be changed" do
controller.stub spree_current_user: original_owner
allow(controller).to receive_messages spree_current_user: original_owner
bulk_enterprise_params = { enterprise_set: { collection_attributes: { '0' => { id: profile_enterprise1.id, sells: 'any', owner_id: new_owner.id }, '1' => { id: profile_enterprise2.id, sells: 'any', owner_id: new_owner.id } } } }
spree_put :bulk_update, bulk_enterprise_params
@@ -432,7 +432,7 @@ module Admin
it "allows 'sells' and 'owner' to be changed" do
profile_enterprise1.enterprise_roles.build(user: new_owner).save
profile_enterprise2.enterprise_roles.build(user: new_owner).save
controller.stub spree_current_user: admin_user
allow(controller).to receive_messages spree_current_user: admin_user
bulk_enterprise_params = { enterprise_set: { collection_attributes: { '0' => { id: profile_enterprise1.id, sells: 'any', owner_id: new_owner.id }, '1' => { id: profile_enterprise2.id, sells: 'any', owner_id: new_owner.id } } } }
spree_put :bulk_update, bulk_enterprise_params
@@ -453,10 +453,10 @@ module Admin
before do
# As a user with permission
controller.stub spree_current_user: user
OrderCycle.stub find_by_id: "existing OrderCycle"
Enterprise.stub find_by_id: "existing Enterprise"
OrderCycle.stub new: "new OrderCycle"
allow(controller).to receive_messages spree_current_user: user
allow(OrderCycle).to receive_messages find_by_id: "existing OrderCycle"
allow(Enterprise).to receive_messages find_by_id: "existing Enterprise"
allow(OrderCycle).to receive_messages new: "new OrderCycle"
allow(OpenFoodNetwork::OrderCyclePermissions).to receive(:new) { permission_mock }
allow(permission_mock).to receive(:visible_enterprises) { [] }
@@ -499,7 +499,7 @@ module Admin
before do
# As a user with permission
controller.stub spree_current_user: user
allow(controller).to receive_messages spree_current_user: user
# :create_variant_overrides does not affect visiblity (at time of writing)
create(:enterprise_relationship, parent: not_visible_enterprise, child: visible_enterprise, permissions_list: [:create_variant_overrides])
@@ -520,7 +520,7 @@ module Admin
let!(:enterprise3) { create(:enterprise, sells: 'any', owner: create_enterprise_user ) }
before do
controller.stub spree_current_user: super_admin
allow(controller).to receive_messages spree_current_user: super_admin
end
context "html" do
@@ -545,7 +545,7 @@ module Admin
let!(:enterprise3) { create(:enterprise, sells: 'any', owner: create_enterprise_user ) }
before do
controller.stub spree_current_user: user
allow(controller).to receive_messages spree_current_user: user
end
context "html" do

View File

@@ -14,7 +14,7 @@ module Admin
describe "#create" do
context "when given email matches an existing user" do
before do
controller.stub spree_current_user: admin
allow(controller).to receive_messages spree_current_user: admin
end
it "returns an error" do
@@ -30,7 +30,7 @@ module Admin
before do
setup_email
controller.stub spree_current_user: admin
allow(controller).to receive_messages spree_current_user: admin
end
it 'enqueues an invitation email' do
@@ -55,7 +55,7 @@ module Admin
context "as user with proper enterprise permissions" do
before do
setup_email
controller.stub spree_current_user: enterprise_owner
allow(controller).to receive_messages spree_current_user: enterprise_owner
end
it "returns success code" do
@@ -71,7 +71,7 @@ module Admin
context "as another enterprise user without permissions for this enterprise" do
before do
controller.stub spree_current_user: other_enterprise_user
allow(controller).to receive_messages spree_current_user: other_enterprise_user
end
it "returns unauthorized response" do

View File

@@ -7,7 +7,7 @@ module Admin
let!(:distributor_owner) { create_enterprise_user enterprise_limit: 2 }
before do
controller.stub spree_current_user: distributor_owner
allow(controller).to receive_messages spree_current_user: distributor_owner
end
describe "#index" do
@@ -151,14 +151,14 @@ module Admin
it "sets flash message" do
spree_put :update, params
flash[:notice].should == 'Your order cycle has been updated.'
expect(flash[:notice]).to eq('Your order cycle has been updated.')
end
end
context "when the page is not reloading" do
it "does not set flash message" do
spree_put :update, params
flash[:notice].should be nil
expect(flash[:notice]).to be nil
end
end
end
@@ -288,7 +288,7 @@ module Admin
let(:order_cycle) { create(:simple_order_cycle) }
before do
controller.stub spree_current_user: admin_user
allow(controller).to receive_messages spree_current_user: admin_user
end
it "enqueues a job" do
@@ -300,7 +300,7 @@ module Admin
it "redirects back to the order cycles path with a success message" do
spree_post :notify_producers, {id: order_cycle.id}
expect(response).to redirect_to admin_order_cycles_path
flash[:notice].should == 'Emails to be sent to producers have been queued for sending.'
expect(flash[:notice]).to eq('Emails to be sent to producers have been queued for sending.')
end
end

View File

@@ -13,7 +13,7 @@ describe Admin::SchedulesController, type: :controller do
context "html" do
context "where I manage an order cycle coordinator" do
before do
controller.stub spree_current_user: managed_coordinator.owner
allow(controller).to receive_messages spree_current_user: managed_coordinator.owner
end
it "returns an empty @collection" do
@@ -26,7 +26,7 @@ describe Admin::SchedulesController, type: :controller do
context "json" do
context "where I manage an order cycle coordinator" do
before do
controller.stub spree_current_user: managed_coordinator.owner
allow(controller).to receive_messages spree_current_user: managed_coordinator.owner
end
let(:params) { { format: :json } }
@@ -68,7 +68,7 @@ describe Admin::SchedulesController, type: :controller do
render_views
before do
controller.stub spree_current_user: user
allow(controller).to receive_messages spree_current_user: user
end
it "allows me to update basic information" do
@@ -102,7 +102,7 @@ describe Admin::SchedulesController, type: :controller do
context "where I don't manage any of the schedule's coordinators" do
before do
controller.stub spree_current_user: uncoordinated_order_cycle2.coordinator.owner
allow(controller).to receive_messages spree_current_user: uncoordinated_order_cycle2.coordinator.owner
end
it "prevents me from updating the schedule" do

View File

@@ -33,10 +33,10 @@ module Api
it "creates as sells=any when it is not a producer" do
spree_post :create, new_enterprise_params
response.should be_success
expect(response).to be_success
enterprise = Enterprise.last
enterprise.sells.should == 'any'
expect(enterprise.sells).to eq('any')
end
end
end
@@ -53,12 +53,12 @@ module Api
before do
allow(Enterprise)
.to receive(:find_by_permalink).with(enterprise.id.to_s) { enterprise }
enterprise.stub(:update_attributes).and_return(true)
allow(enterprise).to receive(:update_attributes).and_return(true)
end
it "I can update enterprise image" do
spree_post :update_image, logo: 'a logo', id: enterprise.id
response.should be_success
expect(response).to be_success
end
end
end
@@ -73,7 +73,7 @@ module Api
end
describe "submitting a valid image" do
before { enterprise.stub(:update_attributes).and_return(true) }
before { allow(enterprise).to receive(:update_attributes).and_return(true) }
it "I can't update enterprise image" do
spree_post :update_image, logo: 'a logo', id: enterprise.id

View File

@@ -32,7 +32,7 @@ module Api
it "retrieves a list of variants with appropriate attributes" do
get :managed, { :format => :json }
keys = json_response.first.keys.map{ |key| key.to_sym }
attributes.all?{ |attr| keys.include? attr }.should == true
expect(attributes.all?{ |attr| keys.include? attr }).to eq(true)
end
end
@@ -42,7 +42,7 @@ module Api
it "retrieves a list of variants with appropriate attributes" do
get :managed, { :format => :json }
keys = json_response.first.keys.map{ |key| key.to_sym }
attributes.all?{ |attr| keys.include? attr }.should == true
expect(attributes.all?{ |attr| keys.include? attr }).to eq(true)
end
end
end
@@ -83,8 +83,8 @@ module Api
it "gives me access" do
spree_get :accessible, { :template => 'bulk_index', :format => :json }
json_response.length.should == 1
json_response[0]['id'].should == order_cycle.id
expect(json_response.length).to eq(1)
expect(json_response[0]['id']).to eq(order_cycle.id)
end
end
@@ -95,7 +95,7 @@ module Api
it "does not give me access" do
spree_get :accessible, { :template => 'bulk_index', :format => :json }
json_response.length.should == 0
expect(json_response.length).to eq(0)
end
end
@@ -107,8 +107,8 @@ module Api
it "gives me access" do
spree_get :accessible, { :template => 'bulk_index', :format => :json }
json_response.length.should == 1
json_response[0]['id'].should == order_cycle.id
expect(json_response.length).to eq(1)
expect(json_response[0]['id']).to eq(order_cycle.id)
end
end
end

View File

@@ -8,22 +8,22 @@ module Api
it "returns alive when up to date" do
Spree::Config.last_job_queue_heartbeat_at = Time.now
spree_get :job_queue
response.should be_success
response.body.should == {alive: true}.to_json
expect(response).to be_success
expect(response.body).to eq({alive: true}.to_json)
end
it "returns dead otherwise" do
Spree::Config.last_job_queue_heartbeat_at = 10.minutes.ago
spree_get :job_queue
response.should be_success
response.body.should == {alive: false}.to_json
expect(response).to be_success
expect(response.body).to eq({alive: false}.to_json)
end
it "returns dead when no heartbeat recorded" do
Spree::Config.last_job_queue_heartbeat_at = nil
spree_get :job_queue
response.should be_success
response.body.should == {alive: false}.to_json
expect(response).to be_success
expect(response.body).to eq({alive: false}.to_json)
end
end
end

View File

@@ -7,33 +7,33 @@ describe CheckoutController, type: :controller do
let(:reset_order_service) { double(ResetOrderService) }
before do
order.stub(:checkout_allowed?).and_return true
controller.stub(:check_authorization).and_return true
allow(order).to receive(:checkout_allowed?).and_return true
allow(controller).to receive(:check_authorization).and_return true
end
it "redirects home when no distributor is selected" do
get :edit
response.should redirect_to root_path
expect(response).to redirect_to root_path
end
it "redirects to the shop when no order cycle is selected" do
controller.stub(:current_distributor).and_return(distributor)
allow(controller).to receive(:current_distributor).and_return(distributor)
get :edit
response.should redirect_to shop_path
expect(response).to redirect_to shop_path
end
it "redirects home with message if hub is not ready for checkout" do
distributor.stub(:ready_for_checkout?) { false }
order.stub(distributor: distributor, order_cycle: order_cycle)
controller.stub(:current_order).and_return(order)
allow(distributor).to receive(:ready_for_checkout?) { false }
allow(order).to receive_messages(distributor: distributor, order_cycle: order_cycle)
allow(controller).to receive(:current_order).and_return(order)
order.should_receive(:empty!)
order.should_receive(:set_distribution!).with(nil, nil)
expect(order).to receive(:empty!)
expect(order).to receive(:set_distribution!).with(nil, nil)
get :edit
response.should redirect_to root_url
flash[:info].should == "The hub you have selected is temporarily closed for orders. Please try again later."
expect(response).to redirect_to root_url
expect(flash[:info]).to eq("The hub you have selected is temporarily closed for orders. Please try again later.")
end
describe "redirection to the cart" do
@@ -73,32 +73,32 @@ describe CheckoutController, type: :controller do
describe "building the order" do
before do
controller.stub(:current_distributor).and_return(distributor)
controller.stub(:current_order_cycle).and_return(order_cycle)
controller.stub(:current_order).and_return(order)
allow(controller).to receive(:current_distributor).and_return(distributor)
allow(controller).to receive(:current_order_cycle).and_return(order_cycle)
allow(controller).to receive(:current_order).and_return(order)
end
it "does not clone the ship address from distributor when shipping method requires address" do
get :edit
assigns[:order].ship_address.address1.should be_nil
expect(assigns[:order].ship_address.address1).to be_nil
end
it "clears the ship address when re-rendering edit" do
controller.should_receive(:clear_ship_address).and_return true
order.stub(:update_attributes).and_return false
expect(controller).to receive(:clear_ship_address).and_return true
allow(order).to receive(:update_attributes).and_return false
spree_post :update, format: :json, order: {}
end
it "clears the ship address when the order state cannot be advanced" do
controller.should_receive(:clear_ship_address).and_return true
order.stub(:update_attributes).and_return true
order.stub(:next).and_return false
expect(controller).to receive(:clear_ship_address).and_return true
allow(order).to receive(:update_attributes).and_return true
allow(order).to receive(:next).and_return false
spree_post :update, format: :json, order: {}
end
it "only clears the ship address with a pickup shipping method" do
order.stub_chain(:shipping_method, :andand, :require_ship_address).and_return false
order.should_receive(:ship_address=)
allow(order).to receive_message_chain(:shipping_method, :andand, :require_ship_address).and_return false
expect(order).to receive(:ship_address=)
controller.send(:clear_ship_address)
end
@@ -179,35 +179,35 @@ describe CheckoutController, type: :controller do
context "via xhr" do
before do
controller.stub(:current_distributor).and_return(distributor)
allow(controller).to receive(:current_distributor).and_return(distributor)
controller.stub(:current_order_cycle).and_return(order_cycle)
controller.stub(:current_order).and_return(order)
allow(controller).to receive(:current_order_cycle).and_return(order_cycle)
allow(controller).to receive(:current_order).and_return(order)
end
it "returns errors" do
spree_post :update, format: :json, order: {}
response.status.should == 400
response.body.should == {errors: assigns[:order].errors, flash: {}}.to_json
expect(response.status).to eq(400)
expect(response.body).to eq({errors: assigns[:order].errors, flash: {}}.to_json)
end
it "returns flash" do
order.stub(:update_attributes).and_return true
order.stub(:next).and_return false
allow(order).to receive(:update_attributes).and_return true
allow(order).to receive(:next).and_return false
spree_post :update, format: :json, order: {}
response.body.should == {errors: assigns[:order].errors, flash: {error: "Payment could not be processed, please check the details you entered"}}.to_json
expect(response.body).to eq({errors: assigns[:order].errors, flash: {error: "Payment could not be processed, please check the details you entered"}}.to_json)
end
it "returns order confirmation url on success" do
allow(ResetOrderService).to receive(:new).with(controller, order) { reset_order_service }
expect(reset_order_service).to receive(:call)
order.stub(:update_attributes).and_return true
order.stub(:state).and_return "complete"
allow(order).to receive(:update_attributes).and_return true
allow(order).to receive(:state).and_return "complete"
spree_post :update, format: :json, order: {}
response.status.should == 200
response.body.should == {path: spree.order_path(order)}.to_json
expect(response.status).to eq(200)
expect(response.body).to eq({path: spree.order_path(order)}.to_json)
end
describe "stale object handling" do
@@ -215,27 +215,27 @@ describe CheckoutController, type: :controller do
allow(ResetOrderService).to receive(:new).with(controller, order) { reset_order_service }
expect(reset_order_service).to receive(:call)
order.stub(:update_attributes).and_return true
controller.stub(:state_callback)
allow(order).to receive(:update_attributes).and_return true
allow(controller).to receive(:state_callback)
# The first time, raise a StaleObjectError. The second time, succeed.
order.stub(:next).once.
allow(order).to receive(:next).once.
and_raise(ActiveRecord::StaleObjectError.new(Spree::Variant.new, 'update'))
order.stub(:next).once do
allow(order).to receive(:next).once do
order.update_column :state, 'complete'
true
end
spree_post :update, format: :json, order: {}
response.status.should == 200
expect(response.status).to eq(200)
end
it "tries a maximum of 3 times before giving up and returning an error" do
order.stub(:update_attributes).and_return true
order.stub(:next) { raise ActiveRecord::StaleObjectError.new(Spree::Variant.new, 'update') }
allow(order).to receive(:update_attributes).and_return true
allow(order).to receive(:next) { raise ActiveRecord::StaleObjectError.new(Spree::Variant.new, 'update') }
spree_post :update, format: :json, order: {}
response.status.should == 400
expect(response.status).to eq(400)
end
end
end

View File

@@ -17,18 +17,18 @@ describe EnterprisesController, type: :controller do
it "sets the shop as the distributor on the order when shopping for the distributor" do
spree_get :shop, {id: distributor}
controller.current_order.distributor.should == distributor
controller.current_order.order_cycle.should be_nil
expect(controller.current_order.distributor).to eq(distributor)
expect(controller.current_order.order_cycle).to be_nil
end
it "sorts order cycles by the distributor's preferred ordering attr" do
distributor.update_attribute(:preferred_shopfront_order_cycle_order, 'orders_close_at')
spree_get :shop, {id: distributor}
assigns(:order_cycles).should == [order_cycle1, order_cycle2].sort_by(&:orders_close_at)
expect(assigns(:order_cycles)).to eq([order_cycle1, order_cycle2].sort_by(&:orders_close_at))
distributor.update_attribute(:preferred_shopfront_order_cycle_order, 'orders_open_at')
spree_get :shop, {id: distributor}
assigns(:order_cycles).should == [order_cycle1, order_cycle2].sort_by(&:orders_open_at)
expect(assigns(:order_cycles)).to eq([order_cycle1, order_cycle2].sort_by(&:orders_open_at))
end
context "using FilterOrderCycles tag rules" do
@@ -76,9 +76,9 @@ describe EnterprisesController, type: :controller do
spree_get :shop, {id: distributor}
controller.current_order.distributor.should == distributor
controller.current_order.order_cycle.should be_nil
controller.current_order.line_items.size.should == 0
expect(controller.current_order.distributor).to eq(distributor)
expect(controller.current_order.order_cycle).to be_nil
expect(controller.current_order.line_items.size).to eq(0)
end
it "should not empty an order if returning to the same distributor" do
@@ -109,7 +109,7 @@ describe EnterprisesController, type: :controller do
it "redirects to the cart" do
spree_get :shop, {id: current_distributor}
response.should redirect_to spree.cart_path
expect(response).to redirect_to spree.cart_path
end
end
@@ -118,8 +118,8 @@ describe EnterprisesController, type: :controller do
spree_get :shop, {id: distributor}
controller.current_order.distributor.should == distributor
controller.current_order.order_cycle.should == order_cycle1
expect(controller.current_order.distributor).to eq(distributor)
expect(controller.current_order.order_cycle).to eq(order_cycle1)
end
end

View File

@@ -5,13 +5,13 @@ describe GroupsController, type: :controller do
let(:enterprise) { create(:distributor_enterprise) }
let!(:group) { create(:enterprise_group, enterprises: [enterprise], on_front_page: true) }
it "gets all visible groups" do
EnterpriseGroup.stub_chain :on_front_page, :by_position
EnterpriseGroup.should_receive :on_front_page
allow(EnterpriseGroup).to receive_message_chain :on_front_page, :by_position
expect(EnterpriseGroup).to receive :on_front_page
get :index
end
it "loads all enterprises for group" do
get :index
response.body.should have_text enterprise.id
expect(response.body).to have_text enterprise.id
end
end

View File

@@ -13,9 +13,9 @@ describe LineItemsController, type: :controller do
end
before do
controller.stub spree_current_user: user
controller.stub current_order_cycle: order_cycle
controller.stub current_distributor: distributor
allow(controller).to receive_messages spree_current_user: user
allow(controller).to receive_messages current_order_cycle: order_cycle
allow(controller).to receive_messages current_distributor: distributor
end
it "lists items bought by the user from the same shop in the same order_cycle" do
@@ -39,7 +39,7 @@ describe LineItemsController, type: :controller do
let(:order) { item.order }
let(:order_cycle) { create(:simple_order_cycle, distributors: [distributor], variants: [order.line_item_variants]) }
before { controller.stub spree_current_user: item.order.user }
before { allow(controller).to receive_messages spree_current_user: item.order.user }
context "without a line item id" do
it "fails and raises an error" do
@@ -112,7 +112,7 @@ describe LineItemsController, type: :controller do
# Delete the item
item = order.line_items.first
controller.stub spree_current_user: order.user
allow(controller).to receive_messages spree_current_user: order.user
request = { format: :json, id: item }
delete :destroy, request
expect(response.status).to eq 204
@@ -146,7 +146,7 @@ describe LineItemsController, type: :controller do
it "updates the fees" do
expect(order.reload.adjustment_total).to eq enterprise_fee.calculator.preferred_amount
controller.stub spree_current_user: user
allow(controller).to receive_messages spree_current_user: user
delete :destroy, params
expect(response.status).to eq 204

View File

@@ -5,7 +5,7 @@ describe RegistrationController, type: :controller do
describe "redirecting when user not logged in" do
it "index" do
get :index
response.should redirect_to registration_auth_path(anchor: "signup?after_login=/register")
expect(response).to redirect_to registration_auth_path(anchor: "signup?after_login=/register")
end
end
@@ -14,12 +14,12 @@ describe RegistrationController, type: :controller do
let!(:enterprise) { create(:distributor_enterprise, owner: user) }
before do
controller.stub spree_current_user: user
allow(controller).to receive_messages spree_current_user: user
end
it "index" do
get :index
response.should render_template :limit_reached
expect(response).to render_template :limit_reached
end
end
@@ -27,7 +27,7 @@ describe RegistrationController, type: :controller do
let!(:user) { create_enterprise_user }
before do
controller.stub spree_current_user: user
allow(controller).to receive_messages spree_current_user: user
end
describe "index" do

View File

@@ -7,26 +7,26 @@ describe ShopController, type: :controller do
it "redirects to the home page if no distributor is selected" do
spree_get :show
response.should redirect_to root_path
expect(response).to redirect_to root_path
end
describe "with a distributor in place" do
before do
controller.stub(:current_distributor).and_return distributor
allow(controller).to receive(:current_distributor).and_return distributor
end
describe "selecting an order cycle" do
it "should select an order cycle when only one order cycle is open" do
oc1 = create(:simple_order_cycle, distributors: [distributor])
spree_get :show
controller.current_order_cycle.should == oc1
expect(controller.current_order_cycle).to eq(oc1)
end
it "should not set an order cycle when multiple order cycles are open" do
oc1 = create(:simple_order_cycle, distributors: [distributor])
oc2 = create(:simple_order_cycle, distributors: [distributor])
spree_get :show
controller.current_order_cycle.should be_nil
expect(controller.current_order_cycle).to be_nil
end
it "should allow the user to post to select the current order cycle" do
@@ -34,8 +34,8 @@ describe ShopController, type: :controller do
oc2 = create(:simple_order_cycle, distributors: [distributor])
spree_post :order_cycle, order_cycle_id: oc2.id
response.should be_success
controller.current_order_cycle.should == oc2
expect(response).to be_success
expect(controller.current_order_cycle).to eq(oc2)
end
context "JSON tests" do
@@ -46,15 +46,15 @@ describe ShopController, type: :controller do
oc2 = create(:simple_order_cycle, distributors: [distributor])
spree_post :order_cycle, order_cycle_id: oc2.id
response.should be_success
response.body.should have_content oc2.id
expect(response).to be_success
expect(response.body).to have_content oc2.id
end
it "should return the current order cycle when hit with GET" do
oc1 = create(:simple_order_cycle, distributors: [distributor])
controller.stub(:current_order_cycle).and_return oc1
allow(controller).to receive(:current_order_cycle).and_return oc1
spree_get :order_cycle
response.body.should have_content oc1.id
expect(response.body).to have_content oc1.id
end
context "when the order cycle has already been set" do
@@ -78,8 +78,8 @@ describe ShopController, type: :controller do
oc3 = create(:simple_order_cycle, distributors: [create(:distributor_enterprise)])
spree_post :order_cycle, order_cycle_id: oc3.id
response.status.should == 404
controller.current_order_cycle.should be_nil
expect(response.status).to eq(404)
expect(controller.current_order_cycle).to be_nil
end
end
@@ -96,16 +96,16 @@ describe ShopController, type: :controller do
end
it "returns products via JSON" do
controller.stub(:current_order_cycle).and_return order_cycle
allow(controller).to receive(:current_order_cycle).and_return order_cycle
xhr :get, :products
response.should be_success
expect(response).to be_success
end
it "does not return products if no order cycle is selected" do
controller.stub(:current_order_cycle).and_return nil
allow(controller).to receive(:current_order_cycle).and_return nil
xhr :get, :products
response.status.should == 404
response.body.should be_empty
expect(response.status).to eq(404)
expect(response.body).to be_empty
end
end
end

View File

@@ -13,22 +13,22 @@ module Spree
describe "creating an adjustment" do
it "sets included tax to zero when no tax rate is specified" do
spree_post :create, {order_id: order.number, adjustment: {label: 'Testing included tax', amount: '110'}, tax_rate_id: ''}
response.should redirect_to spree.admin_order_adjustments_path(order)
expect(response).to redirect_to spree.admin_order_adjustments_path(order)
a = Adjustment.last
a.label.should == 'Testing included tax'
a.amount.should == 110
a.included_tax.should == 0
expect(a.label).to eq('Testing included tax')
expect(a.amount).to eq(110)
expect(a.included_tax).to eq(0)
end
it "calculates included tax when a tax rate is provided" do
spree_post :create, {order_id: order.number, adjustment: {label: 'Testing included tax', amount: '110'}, tax_rate_id: tax_rate.id.to_s}
response.should redirect_to spree.admin_order_adjustments_path(order)
expect(response).to redirect_to spree.admin_order_adjustments_path(order)
a = Adjustment.last
a.label.should == 'Testing included tax'
a.amount.should == 110
a.included_tax.should == 10
expect(a.label).to eq('Testing included tax')
expect(a.amount).to eq(110)
expect(a.included_tax).to eq(10)
end
end
@@ -37,22 +37,22 @@ module Spree
it "sets included tax to zero when no tax rate is specified" do
spree_put :update, {order_id: order.number, id: adjustment.id, adjustment: {label: 'Testing included tax', amount: '110'}, tax_rate_id: ''}
response.should redirect_to spree.admin_order_adjustments_path(order)
expect(response).to redirect_to spree.admin_order_adjustments_path(order)
a = Adjustment.last
a.label.should == 'Testing included tax'
a.amount.should == 110
a.included_tax.should == 0
expect(a.label).to eq('Testing included tax')
expect(a.amount).to eq(110)
expect(a.included_tax).to eq(0)
end
it "calculates included tax when a tax rate is provided" do
spree_put :update, {order_id: order.number, id: adjustment.id, adjustment: {label: 'Testing included tax', amount: '110'}, tax_rate_id: tax_rate.id.to_s}
response.should redirect_to spree.admin_order_adjustments_path(order)
expect(response).to redirect_to spree.admin_order_adjustments_path(order)
a = Adjustment.last
a.label.should == 'Testing included tax'
a.amount.should == 110
a.included_tax.should == 10
expect(a.label).to eq('Testing included tax')
expect(a.amount).to eq(110)
expect(a.included_tax).to eq(10)
end
end
end

View File

@@ -10,29 +10,31 @@ describe Spree::Admin::BaseController, type: :controller do
it "redirects to Angular login" do
spree_get :index
response.should redirect_to root_path(anchor: "login?after_login=/spree/admin/base")
expect(response).to redirect_to root_path(anchor: "login?after_login=/spree/admin/base")
end
describe "displaying error messages for active distributors not ready for checkout" do
it "generates an error message when there is one distributor" do
distributor = double(:distributor, name: 'My Hub')
controller.
send(:active_distributors_not_ready_for_checkout_message, [distributor]).
should ==
expect(controller.
send(:active_distributors_not_ready_for_checkout_message, [distributor])).
to eq(
"The hub My Hub is listed in an active order cycle, " +
"but does not have valid shipping and payment methods. " +
"Until you set these up, customers will not be able to shop at this hub."
)
end
it "generates an error message when there are several distributors" do
d1 = double(:distributor, name: 'Hub One')
d2 = double(:distributor, name: 'Hub Two')
controller.
send(:active_distributors_not_ready_for_checkout_message, [d1, d2]).
should ==
expect(controller.
send(:active_distributors_not_ready_for_checkout_message, [d1, d2])).
to eq(
"The hubs Hub One, Hub Two are listed in an active order cycle, " +
"but do not have valid shipping and payment methods. " +
"Until you set these up, customers will not be able to shop at these hubs."
)
end
end

View File

@@ -47,7 +47,7 @@ describe Spree::Admin::OrdersController, type: :controller do
let(:order) { create :completed_order_with_totals }
it "updates distribution charges and redirects to order details page" do
Spree::Order.any_instance.should_receive(:update_distribution_charge!)
expect_any_instance_of(Spree::Order).to receive(:update_distribution_charge!)
spree_put :update, params
@@ -77,7 +77,7 @@ describe Spree::Admin::OrdersController, type: :controller do
context "and no errors" do
it "updates distribution charges and redirects to customer details page" do
Spree::Order.any_instance.should_receive(:update_distribution_charge!)
expect_any_instance_of(Spree::Order).to receive(:update_distribution_charge!)
spree_put :update, params

View File

@@ -67,7 +67,7 @@ describe Spree::Admin::PaymentMethodsController, type: :controller do
end
before do
controller.stub spree_current_user: user
allow(controller).to receive_messages spree_current_user: user
end
context "on an existing payment method" do

View File

@@ -17,11 +17,11 @@ describe Spree::Admin::ProductsController, type: :controller do
end
it "denies access" do
response.should redirect_to spree.unauthorized_url
expect(response).to redirect_to spree.unauthorized_url
end
it "does not update any product" do
product.reload.name.should_not == "Pine nuts"
expect(product.reload.name).not_to eq("Pine nuts")
end
end
@@ -144,12 +144,12 @@ describe Spree::Admin::ProductsController, type: :controller do
it "redirects to products when the user hits 'create'" do
spree_post :create, { product: product_attrs, button: 'create' }
response.should redirect_to spree.admin_products_path
expect(response).to redirect_to spree.admin_products_path
end
it "redirects to new when the user hits 'add_another'" do
spree_post :create, { product: product_attrs, button: 'add_another' }
response.should redirect_to spree.new_admin_product_path
expect(response).to redirect_to spree.new_admin_product_path
end
end

View File

@@ -16,23 +16,23 @@ module Spree
it "filters by distributor" do
spree_get :search, q: 'Prod', distributor_id: d.id.to_s
assigns(:variants).should == [v1]
expect(assigns(:variants)).to eq([v1])
end
it "applies variant overrides" do
spree_get :search, q: 'Prod', distributor_id: d.id.to_s
assigns(:variants).should == [v1]
assigns(:variants).first.on_hand.should == 44
expect(assigns(:variants)).to eq([v1])
expect(assigns(:variants).first.on_hand).to eq(44)
end
it "filters by order cycle" do
spree_get :search, q: 'Prod', order_cycle_id: oc.id.to_s
assigns(:variants).should == [v1]
expect(assigns(:variants)).to eq([v1])
end
it "does not filter when no distributor or order cycle is specified" do
spree_get :search, q: 'Prod'
assigns(:variants).should match_array [v1, v2]
expect(assigns(:variants)).to match_array [v1, v2]
end
end

View File

@@ -39,21 +39,21 @@ module Spree
it "retrieves a list of managed products" do
spree_get :managed, { :template => 'bulk_index', :format => :json }
keys = json_response.first.keys.map{ |key| key.to_sym }
attributes.all?{ |attr| keys.include? attr }.should == true
expect(attributes.all?{ |attr| keys.include? attr }).to eq(true)
end
it "soft deletes my products" do
spree_delete :soft_delete, {product_id: product1.to_param, format: :json}
response.status.should == 204
lambda { product1.reload }.should_not raise_error
product1.deleted_at.should_not be_nil
expect(response.status).to eq(204)
expect { product1.reload }.not_to raise_error
expect(product1.deleted_at).not_to be_nil
end
it "is denied access to soft deleting another enterprises' product" do
spree_delete :soft_delete, {product_id: product_other_supplier.to_param, format: :json}
assert_unauthorized!
lambda { product_other_supplier.reload }.should_not raise_error
product_other_supplier.deleted_at.should be_nil
expect { product_other_supplier.reload }.not_to raise_error
expect(product_other_supplier.deleted_at).to be_nil
end
end
@@ -66,13 +66,13 @@ module Spree
it "retrieves a list of managed products" do
spree_get :managed, { :template => 'bulk_index', :format => :json }
keys = json_response.first.keys.map{ |key| key.to_sym }
attributes.all?{ |attr| keys.include? attr }.should == true
expect(attributes.all?{ |attr| keys.include? attr }).to eq(true)
end
it "retrieves a list of products with appropriate attributes" do
spree_get :index, { :template => 'bulk_index', :format => :json }
keys = json_response.first.keys.map{ |key| key.to_sym }
attributes.all?{ |attr| keys.include? attr }.should == true
expect(attributes.all?{ |attr| keys.include? attr }).to eq(true)
end
it "sorts products in ascending id order" do
@@ -82,37 +82,37 @@ module Spree
spree_get :index, { :template => 'bulk_index', :format => :json }
ids = json_response.map{ |product| product['id'] }
ids[0].should < ids[1]
ids[1].should < ids[2]
expect(ids[0]).to be < ids[1]
expect(ids[1]).to be < ids[2]
end
it "formats available_on to 'yyyy-mm-dd hh:mm'" do
spree_get :index, { :template => 'bulk_index', :format => :json }
json_response.map{ |product| product['available_on'] }.all?{ |a| a.match("^\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}$") }.should == true
expect(json_response.map{ |product| product['available_on'] }.all?{ |a| a.match("^\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}$") }).to eq(true)
end
it "returns permalink as permalink_live" do
spree_get :index, { :template => 'bulk_index', :format => :json }
json_response.detect{ |product| product['id'] == product1.id }['permalink_live'].should == product1.permalink
expect(json_response.detect{ |product| product['id'] == product1.id }['permalink_live']).to eq(product1.permalink)
end
it "should allow available_on to be nil" do
spree_get :index, { :template => 'bulk_index', :format => :json }
json_response.size.should == 1
expect(json_response.size).to eq(1)
product5 = FactoryBot.create(:product)
product5.available_on = nil
product5.save!
spree_get :index, { :template => 'bulk_index', :format => :json }
json_response.size.should == 2
expect(json_response.size).to eq(2)
end
it "soft deletes a product" do
spree_delete :soft_delete, {product_id: product1.to_param, format: :json}
response.status.should == 204
lambda { product1.reload }.should_not raise_error
product1.deleted_at.should_not be_nil
expect(response.status).to eq(204)
expect { product1.reload }.not_to raise_error
expect(product1.deleted_at).not_to be_nil
end
end

View File

@@ -20,7 +20,7 @@ module Spree
it "retrieves a list of variants with appropriate attributes" do
spree_get :index, { :template => 'bulk_index', :format => :json }
keys = json_response.first.keys.map{ |key| key.to_sym }
attributes.all?{ |attr| keys.include? attr }.should == true
expect(attributes.all?{ |attr| keys.include? attr }).to eq(true)
end
it "is denied access when trying to delete a variant" do
@@ -29,8 +29,8 @@ module Spree
spree_delete :soft_delete, {variant_id: variant.to_param, product_id: product.to_param, format: :json}
assert_unauthorized!
lambda { variant.reload }.should_not raise_error
variant.deleted_at.should be_nil
expect { variant.reload }.not_to raise_error
expect(variant.deleted_at).to be_nil
end
end
@@ -44,16 +44,16 @@ module Spree
it "soft deletes a variant" do
spree_delete :soft_delete, {variant_id: variant.to_param, product_id: product.to_param, format: :json}
response.status.should == 204
lambda { variant.reload }.should_not raise_error
variant.deleted_at.should be_present
expect(response.status).to eq(204)
expect { variant.reload }.not_to raise_error
expect(variant.deleted_at).to be_present
end
it "is denied access to soft deleting another enterprises' variant" do
spree_delete :soft_delete, {variant_id: variant_other.to_param, product_id: product_other.to_param, format: :json}
assert_unauthorized!
lambda { variant.reload }.should_not raise_error
variant.deleted_at.should be_nil
expect { variant.reload }.not_to raise_error
expect(variant.deleted_at).to be_nil
end
context 'when the variant is not the master' do
@@ -74,9 +74,9 @@ module Spree
it "soft deletes a variant" do
spree_delete :soft_delete, {variant_id: variant.to_param, product_id: product.to_param, format: :json}
response.status.should == 204
lambda { variant.reload }.should_not raise_error
variant.deleted_at.should_not be_nil
expect(response.status).to eq(204)
expect { variant.reload }.not_to raise_error
expect(variant.deleted_at).not_to be_nil
end
it "doesn't delete the only variant of the product" do

View File

@@ -9,6 +9,6 @@ describe Spree::StoreController, type: :controller do
end
it "redirects to home when unauthorized" do
get :index
response.should render_template("shared/unauthorized", layout: 'darkswarm')
expect(response).to render_template("shared/unauthorized", layout: 'darkswarm')
end
end

View File

@@ -14,7 +14,7 @@ describe Spree::UserSessionsController, type: :controller do
context "when referer is not '/checkout'" do
it "redirects to root" do
spree_post :create, spree_user: {email: user.email, password: user.password }, :use_route => :spree
response.should redirect_to root_path
expect(response).to redirect_to root_path
end
end
@@ -23,7 +23,7 @@ describe Spree::UserSessionsController, type: :controller do
it "redirects to checkout" do
spree_post :create, spree_user: { email: user.email, password: user.password }, :use_route => :spree
response.should redirect_to checkout_path
expect(response).to redirect_to checkout_path
end
end
end

View File

@@ -14,13 +14,13 @@ describe UserPasswordsController, type: :controller do
describe "create" do
it "returns errors" do
spree_post :create, spree_user: {}
response.should be_success
response.should render_template "spree/user_passwords/new"
expect(response).to be_success
expect(response).to render_template "spree/user_passwords/new"
end
it "redirects to login when data is valid" do
spree_post :create, spree_user: { email: user.email}
response.should be_redirect
expect(response).to be_redirect
end
end