diff --git a/spec/controllers/admin/bulk_line_items_controller_spec.rb b/spec/controllers/admin/bulk_line_items_controller_spec.rb index d6463d5c52..da67920e8e 100644 --- a/spec/controllers/admin/bulk_line_items_controller_spec.rb +++ b/spec/controllers/admin/bulk_line_items_controller_spec.rb @@ -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 diff --git a/spec/controllers/admin/enterprises_controller_spec.rb b/spec/controllers/admin/enterprises_controller_spec.rb index 5c9fbea31a..b244047eb4 100644 --- a/spec/controllers/admin/enterprises_controller_spec.rb +++ b/spec/controllers/admin/enterprises_controller_spec.rb @@ -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 diff --git a/spec/controllers/admin/manager_invitations_controller_spec.rb b/spec/controllers/admin/manager_invitations_controller_spec.rb index 071566e3a4..e8e4d733cf 100644 --- a/spec/controllers/admin/manager_invitations_controller_spec.rb +++ b/spec/controllers/admin/manager_invitations_controller_spec.rb @@ -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 diff --git a/spec/controllers/admin/order_cycles_controller_spec.rb b/spec/controllers/admin/order_cycles_controller_spec.rb index 9ec07d2630..aaa2356bb3 100644 --- a/spec/controllers/admin/order_cycles_controller_spec.rb +++ b/spec/controllers/admin/order_cycles_controller_spec.rb @@ -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 diff --git a/spec/controllers/admin/schedules_controller_spec.rb b/spec/controllers/admin/schedules_controller_spec.rb index 4758847499..1f320125b1 100644 --- a/spec/controllers/admin/schedules_controller_spec.rb +++ b/spec/controllers/admin/schedules_controller_spec.rb @@ -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 diff --git a/spec/controllers/api/enterprises_controller_spec.rb b/spec/controllers/api/enterprises_controller_spec.rb index 7cedd8f526..df8ba4fc38 100644 --- a/spec/controllers/api/enterprises_controller_spec.rb +++ b/spec/controllers/api/enterprises_controller_spec.rb @@ -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 diff --git a/spec/controllers/api/order_cycles_controller_spec.rb b/spec/controllers/api/order_cycles_controller_spec.rb index 48b47fcb9c..f24170de10 100644 --- a/spec/controllers/api/order_cycles_controller_spec.rb +++ b/spec/controllers/api/order_cycles_controller_spec.rb @@ -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 diff --git a/spec/controllers/api/statuses_controller_spec.rb b/spec/controllers/api/statuses_controller_spec.rb index 5456b44722..48d30d6db7 100644 --- a/spec/controllers/api/statuses_controller_spec.rb +++ b/spec/controllers/api/statuses_controller_spec.rb @@ -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 diff --git a/spec/controllers/checkout_controller_spec.rb b/spec/controllers/checkout_controller_spec.rb index b59898b278..09fce7e779 100644 --- a/spec/controllers/checkout_controller_spec.rb +++ b/spec/controllers/checkout_controller_spec.rb @@ -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 diff --git a/spec/controllers/enterprises_controller_spec.rb b/spec/controllers/enterprises_controller_spec.rb index 852eb707de..e2140db927 100644 --- a/spec/controllers/enterprises_controller_spec.rb +++ b/spec/controllers/enterprises_controller_spec.rb @@ -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 diff --git a/spec/controllers/groups_controller_spec.rb b/spec/controllers/groups_controller_spec.rb index 5fe6bcd065..f134e6f4ca 100644 --- a/spec/controllers/groups_controller_spec.rb +++ b/spec/controllers/groups_controller_spec.rb @@ -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 diff --git a/spec/controllers/line_items_controller_spec.rb b/spec/controllers/line_items_controller_spec.rb index 1c9b237fed..a7c9fc5225 100644 --- a/spec/controllers/line_items_controller_spec.rb +++ b/spec/controllers/line_items_controller_spec.rb @@ -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 diff --git a/spec/controllers/registration_controller_spec.rb b/spec/controllers/registration_controller_spec.rb index 50c814d10a..31a1a91116 100644 --- a/spec/controllers/registration_controller_spec.rb +++ b/spec/controllers/registration_controller_spec.rb @@ -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 diff --git a/spec/controllers/shop_controller_spec.rb b/spec/controllers/shop_controller_spec.rb index 12b63d2ff8..a0a9587447 100644 --- a/spec/controllers/shop_controller_spec.rb +++ b/spec/controllers/shop_controller_spec.rb @@ -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 diff --git a/spec/controllers/spree/admin/adjustments_controller_spec.rb b/spec/controllers/spree/admin/adjustments_controller_spec.rb index 0547aaa855..c161fcd5ed 100644 --- a/spec/controllers/spree/admin/adjustments_controller_spec.rb +++ b/spec/controllers/spree/admin/adjustments_controller_spec.rb @@ -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 diff --git a/spec/controllers/spree/admin/base_controller_spec.rb b/spec/controllers/spree/admin/base_controller_spec.rb index 014809da00..e9e2edb6ec 100644 --- a/spec/controllers/spree/admin/base_controller_spec.rb +++ b/spec/controllers/spree/admin/base_controller_spec.rb @@ -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 diff --git a/spec/controllers/spree/admin/orders_controller_spec.rb b/spec/controllers/spree/admin/orders_controller_spec.rb index 59db9fc05f..061112e0cb 100644 --- a/spec/controllers/spree/admin/orders_controller_spec.rb +++ b/spec/controllers/spree/admin/orders_controller_spec.rb @@ -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 diff --git a/spec/controllers/spree/admin/payment_methods_controller_spec.rb b/spec/controllers/spree/admin/payment_methods_controller_spec.rb index 0ef2cd14ec..102ce719a3 100644 --- a/spec/controllers/spree/admin/payment_methods_controller_spec.rb +++ b/spec/controllers/spree/admin/payment_methods_controller_spec.rb @@ -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 diff --git a/spec/controllers/spree/admin/products_controller_spec.rb b/spec/controllers/spree/admin/products_controller_spec.rb index 7853ddebf3..ba680bf050 100644 --- a/spec/controllers/spree/admin/products_controller_spec.rb +++ b/spec/controllers/spree/admin/products_controller_spec.rb @@ -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 diff --git a/spec/controllers/spree/admin/variants_controller_spec.rb b/spec/controllers/spree/admin/variants_controller_spec.rb index 0e290014dc..4d4d1049cd 100644 --- a/spec/controllers/spree/admin/variants_controller_spec.rb +++ b/spec/controllers/spree/admin/variants_controller_spec.rb @@ -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 diff --git a/spec/controllers/spree/api/products_controller_spec.rb b/spec/controllers/spree/api/products_controller_spec.rb index 401604b8bf..821af72cff 100644 --- a/spec/controllers/spree/api/products_controller_spec.rb +++ b/spec/controllers/spree/api/products_controller_spec.rb @@ -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 diff --git a/spec/controllers/spree/api/variants_controller_spec.rb b/spec/controllers/spree/api/variants_controller_spec.rb index 4f5be2dbf2..11bdff7ad0 100644 --- a/spec/controllers/spree/api/variants_controller_spec.rb +++ b/spec/controllers/spree/api/variants_controller_spec.rb @@ -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 diff --git a/spec/controllers/spree/store_controller_spec.rb b/spec/controllers/spree/store_controller_spec.rb index de921f657d..b04ac0167e 100644 --- a/spec/controllers/spree/store_controller_spec.rb +++ b/spec/controllers/spree/store_controller_spec.rb @@ -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 diff --git a/spec/controllers/spree/user_sessions_controller_spec.rb b/spec/controllers/spree/user_sessions_controller_spec.rb index 3b97e2aab0..a6109e4011 100644 --- a/spec/controllers/spree/user_sessions_controller_spec.rb +++ b/spec/controllers/spree/user_sessions_controller_spec.rb @@ -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 diff --git a/spec/controllers/user_passwords_controller_spec.rb b/spec/controllers/user_passwords_controller_spec.rb index 1fa79519e9..189b1983f6 100644 --- a/spec/controllers/user_passwords_controller_spec.rb +++ b/spec/controllers/user_passwords_controller_spec.rb @@ -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 diff --git a/spec/helpers/checkout_helper_spec.rb b/spec/helpers/checkout_helper_spec.rb index 69e077eeb2..5dc45a3399 100644 --- a/spec/helpers/checkout_helper_spec.rb +++ b/spec/helpers/checkout_helper_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' describe CheckoutHelper, type: :helper do it "generates html for validated inputs" do - helper.should_receive(:render).with( + expect(helper).to receive(:render).with( "shared/validated_input", name: "test", path: "foo", @@ -17,14 +17,14 @@ describe CheckoutHelper, type: :helper do let(:order) { double(:order, total_tax: 123.45, currency: 'AUD') } it "retrieves the total tax on the order" do - helper.display_checkout_tax_total(order).should == Spree::Money.new(123.45, currency: 'AUD') + expect(helper.display_checkout_tax_total(order)).to eq(Spree::Money.new(123.45, currency: 'AUD')) end end it "knows if guests can checkout" do distributor = create(:distributor_enterprise) order = create(:order, distributor: distributor) - helper.stub(:current_order) { order } + allow(helper).to receive(:current_order) { order } expect(helper.guest_checkout_allowed?).to be true order.distributor.allow_guest_orders = false diff --git a/spec/helpers/html_helper_spec.rb b/spec/helpers/html_helper_spec.rb index c7549dd602..3b08d16dd3 100644 --- a/spec/helpers/html_helper_spec.rb +++ b/spec/helpers/html_helper_spec.rb @@ -3,39 +3,39 @@ require 'spec_helper' describe HtmlHelper, type: :helper do describe "stripping html from a string" do it "strips tags" do - helper.strip_html('

Hello world!

').should == "Hello world!" + expect(helper.strip_html('

Hello world!

')).to eq("Hello world!") end it "removes nbsp and amp entities" do - helper.strip_html('Hello world&&').should == 'Hello world&&' + expect(helper.strip_html('Hello world&&')).to eq('Hello world&&') end it "returns nil for nil input" do - helper.strip_html(nil).should be_nil + expect(helper.strip_html(nil)).to be_nil end describe "line breaks" do it "adds two line breaks after heading tags" do - helper.strip_html("

foo

bar").should == "foo\n\nbar"; - helper.strip_html("

foo

bar").should == "foo\n\nbar"; + expect(helper.strip_html("

foo

bar")).to eq("foo\n\nbar"); + expect(helper.strip_html("

foo

bar")).to eq("foo\n\nbar"); end it "adds two line breaks after p tags" do - helper.strip_html("

foo

bar").should == "foo\n\nbar"; + expect(helper.strip_html("

foo

bar")).to eq("foo\n\nbar"); end it "adds two line breaks after div tags" do - helper.strip_html("
foo
bar").should == "foo\n\nbar"; + expect(helper.strip_html("
foo
bar")).to eq("foo\n\nbar"); end it "adds a line break after br tags" do - helper.strip_html("foo
bar").should == "foo\nbar"; - helper.strip_html("foo
bar").should == "foo\nbar"; - helper.strip_html("foo
bar").should == "foo\nbar"; + expect(helper.strip_html("foo
bar")).to eq("foo\nbar"); + expect(helper.strip_html("foo
bar")).to eq("foo\nbar"); + expect(helper.strip_html("foo
bar")).to eq("foo\nbar"); end it "strips line breaks at the end of the string" do - helper.strip_html("
foo

").should == "foo"; + expect(helper.strip_html("
foo

")).to eq("foo"); end end end diff --git a/spec/helpers/injection_helper_spec.rb b/spec/helpers/injection_helper_spec.rb index 3f566905f3..0e23bc6473 100644 --- a/spec/helpers/injection_helper_spec.rb +++ b/spec/helpers/injection_helper_spec.rb @@ -11,17 +11,17 @@ describe InjectionHelper, type: :helper do let!(:d2o1) { create(:completed_order_with_totals, distributor: distributor2, user_id: user.id)} it "will inject via AMS" do - helper.inject_json_ams("test", [enterprise], Api::IdSerializer).should match /#{enterprise.id}/ + expect(helper.inject_json_ams("test", [enterprise], Api::IdSerializer)).to match /#{enterprise.id}/ end it "injects enterprises" do - helper.inject_enterprises.should match enterprise.name - helper.inject_enterprises.should match enterprise.facebook + expect(helper.inject_enterprises).to match enterprise.name + expect(helper.inject_enterprises).to match enterprise.facebook end it "only injects activated enterprises" do inactive_enterprise = create(:enterprise, sells: 'unspecified') - helper.inject_enterprises.should_not match inactive_enterprise.name + expect(helper.inject_enterprises).not_to match inactive_enterprise.name end it "injects shipping_methods" do @@ -30,8 +30,8 @@ describe InjectionHelper, type: :helper do order = create(:order, distributor: current_distributor) allow(helper).to receive(:current_order) { order } allow(helper).to receive(:spree_current_user) { nil } - helper.inject_available_shipping_methods.should match sm.id.to_s - helper.inject_available_shipping_methods.should match sm.compute_amount(order).to_s + expect(helper.inject_available_shipping_methods).to match sm.id.to_s + expect(helper.inject_available_shipping_methods).to match sm.compute_amount(order).to_s end it "injects payment methods" do @@ -40,18 +40,18 @@ describe InjectionHelper, type: :helper do order = create(:order, distributor: current_distributor) allow(helper).to receive(:current_order) { order } allow(helper).to receive(:spree_current_user) { nil } - helper.inject_available_payment_methods.should match pm.id.to_s - helper.inject_available_payment_methods.should match pm.name + expect(helper.inject_available_payment_methods).to match pm.id.to_s + expect(helper.inject_available_payment_methods).to match pm.name end it "injects current order" do - helper.stub(:current_order).and_return order = create(:order) - helper.inject_current_order.should match order.id.to_s + allow(helper).to receive(:current_order).and_return order = create(:order) + expect(helper.inject_current_order).to match order.id.to_s end it "injects taxons" do taxon = create(:taxon) - helper.inject_taxons.should match taxon.name + expect(helper.inject_taxons).to match taxon.name end it "only injects credit cards with a payment profile" do diff --git a/spec/helpers/navigation_helper_spec.rb b/spec/helpers/navigation_helper_spec.rb index a173dc48bf..4997211727 100644 --- a/spec/helpers/navigation_helper_spec.rb +++ b/spec/helpers/navigation_helper_spec.rb @@ -5,31 +5,31 @@ module Spree describe NavigationHelper, type: :helper do describe "klass_for" do it "returns the class when present" do - helper.klass_for('products').should == Spree::Product + expect(helper.klass_for('products')).to eq(Spree::Product) end it "returns a symbol when there's no available class" do - helper.klass_for('lions').should == :lion + expect(helper.klass_for('lions')).to eq(:lion) end it "returns Spree::Admin::ReportsController for reports" do - helper.klass_for('reports').should == Spree::Admin::ReportsController + expect(helper.klass_for('reports')).to eq(Spree::Admin::ReportsController) end it "returns :overview for the dashboard" do - helper.klass_for('dashboard').should == :overview + expect(helper.klass_for('dashboard')).to eq(:overview) end it "returns Spree::Order for bulk_order_management" do - helper.klass_for('bulk_order_management').should == Spree::Order + expect(helper.klass_for('bulk_order_management')).to eq(Spree::Order) end it "returns EnterpriseGroup for group" do - helper.klass_for('group').should == EnterpriseGroup + expect(helper.klass_for('group')).to eq(EnterpriseGroup) end it "returns VariantOverride for Inventory" do - helper.klass_for('Inventory').should == VariantOverride + expect(helper.klass_for('Inventory')).to eq(VariantOverride) end end end diff --git a/spec/helpers/order_cycles_helper_spec.rb b/spec/helpers/order_cycles_helper_spec.rb index 1b4398e8d7..079198cc8d 100644 --- a/spec/helpers/order_cycles_helper_spec.rb +++ b/spec/helpers/order_cycles_helper_spec.rb @@ -5,7 +5,7 @@ describe OrderCyclesHelper, type: :helper do describe "finding producer enterprise options" do before do - helper.stub(:permitted_producer_enterprises_for) { "enterprise list" } + allow(helper).to receive(:permitted_producer_enterprises_for) { "enterprise list" } end it "asks for a validation option list" do @@ -16,7 +16,7 @@ describe OrderCyclesHelper, type: :helper do describe "finding coodinator enterprise options" do before do - helper.stub(:permitted_coordinating_enterprises_for) { "enterprise list" } + allow(helper).to receive(:permitted_coordinating_enterprises_for) { "enterprise list" } end it "asks for a validation option list" do @@ -27,7 +27,7 @@ describe OrderCyclesHelper, type: :helper do describe "finding hub enterprise options" do before do - helper.stub(:permitted_hub_enterprises_for) { "enterprise list" } + allow(helper).to receive(:permitted_hub_enterprises_for) { "enterprise list" } end it "asks for a validation option list" do @@ -71,9 +71,9 @@ describe OrderCyclesHelper, type: :helper do exchange = Exchange.find(oc1.exchanges.to_enterprises(d).outgoing.first.id) exchange.update_attribute :pickup_time, "turtles" - helper.stub(:current_order_cycle).and_return oc1 - helper.stub(:current_distributor).and_return d - helper.pickup_time.should == "turtles" + allow(helper).to receive(:current_order_cycle).and_return oc1 + allow(helper).to receive(:current_distributor).and_return d + expect(helper.pickup_time).to eq("turtles") end it "gives me the pickup time for any order cycle" do @@ -84,9 +84,9 @@ describe OrderCyclesHelper, type: :helper do exchange = Exchange.find(oc2.exchanges.to_enterprises(d).outgoing.first.id) exchange.update_attribute :pickup_time, "turtles" - helper.stub(:current_order_cycle).and_return oc1 - helper.stub(:current_distributor).and_return d - helper.pickup_time(oc2).should == "turtles" + allow(helper).to receive(:current_order_cycle).and_return oc1 + allow(helper).to receive(:current_distributor).and_return d + expect(helper.pickup_time(oc2)).to eq("turtles") end end end diff --git a/spec/helpers/products_helper_spec.rb b/spec/helpers/products_helper_spec.rb index 812b053fb1..876c263eed 100644 --- a/spec/helpers/products_helper_spec.rb +++ b/spec/helpers/products_helper_spec.rb @@ -4,13 +4,13 @@ module Spree describe ProductsHelper, type: :helper do it "displays variant price differences as absolute, not relative values" do variant = make_variant_stub(10.00, 10.00) - helper.variant_price_diff(variant).should == "(#{with_currency(10.00)})" + expect(helper.variant_price_diff(variant)).to eq("(#{with_currency(10.00)})") variant = make_variant_stub(10.00, 15.55) - helper.variant_price_diff(variant).should == "(#{with_currency(15.55)})" + expect(helper.variant_price_diff(variant)).to eq("(#{with_currency(15.55)})") variant = make_variant_stub(10.00, 5.55) - helper.variant_price_diff(variant).should == "(#{with_currency(5.55)})" + expect(helper.variant_price_diff(variant)).to eq("(#{with_currency(5.55)})") end private diff --git a/spec/helpers/shared_helper_spec.rb b/spec/helpers/shared_helper_spec.rb index b632079c96..5c763f4238 100644 --- a/spec/helpers/shared_helper_spec.rb +++ b/spec/helpers/shared_helper_spec.rb @@ -5,22 +5,22 @@ describe SharedHelper, type: :helper do it "does not require emptying the cart when it is empty" do d = double(:distributor) order = double(:order, line_items: []) - helper.stub(:current_order) { order } - helper.distributor_link_class(d).should_not =~ /empties-cart/ + allow(helper).to receive(:current_order) { order } + expect(helper.distributor_link_class(d)).not_to match(/empties-cart/) end it "does not require emptying the cart when we are on the same distributor" do d = double(:distributor) order = double(:order, line_items: [double(:line_item)], distributor: d) - helper.stub(:current_order) { order } - helper.distributor_link_class(d).should_not =~ /empties-cart/ + allow(helper).to receive(:current_order) { order } + expect(helper.distributor_link_class(d)).not_to match(/empties-cart/) end it "requires emptying the cart otherwise" do d1 = double(:distributor) d2 = double(:distributor) order = double(:order, line_items: [double(:line_item)], distributor: d2) - helper.stub(:current_order) { order } - helper.distributor_link_class(d1).should =~ /empties-cart/ + allow(helper).to receive(:current_order) { order } + expect(helper.distributor_link_class(d1)).to match(/empties-cart/) end end diff --git a/spec/helpers/shop_helper_spec.rb b/spec/helpers/shop_helper_spec.rb index eb38f0730f..5ee1585526 100644 --- a/spec/helpers/shop_helper_spec.rb +++ b/spec/helpers/shop_helper_spec.rb @@ -4,8 +4,8 @@ describe ShopHelper, type: :helper do it "should build order cycle select options" do d = create(:distributor_enterprise) o1 = create(:simple_order_cycle, distributors: [d]) - helper.stub(:current_distributor).and_return d + allow(helper).to receive(:current_distributor).and_return d - helper.order_cycles_name_and_pickup_times([o1]).should == [[helper.pickup_time(o1), o1.id]] + expect(helper.order_cycles_name_and_pickup_times([o1])).to eq([[helper.pickup_time(o1), o1.id]]) end end diff --git a/spec/jobs/confirm_signup_job_spec.rb b/spec/jobs/confirm_signup_job_spec.rb index 4d7b97bcc0..59624b9a87 100644 --- a/spec/jobs/confirm_signup_job_spec.rb +++ b/spec/jobs/confirm_signup_job_spec.rb @@ -5,8 +5,8 @@ describe ConfirmSignupJob do it "sends a confirmation email to the user" do mail = double(:mail) - Spree::UserMailer.should_receive(:signup_confirmation).with(user).and_return(mail) - mail.should_receive(:deliver) + expect(Spree::UserMailer).to receive(:signup_confirmation).with(user).and_return(mail) + expect(mail).to receive(:deliver) run_job ConfirmSignupJob.new user.id end diff --git a/spec/jobs/heartbeat_job_spec.rb b/spec/jobs/heartbeat_job_spec.rb index 3bafecd572..7e9a61babe 100644 --- a/spec/jobs/heartbeat_job_spec.rb +++ b/spec/jobs/heartbeat_job_spec.rb @@ -12,7 +12,7 @@ describe HeartbeatJob do it "updates the last_job_queue_heartbeat_at config var" do run_job - Time.parse(Spree::Config.last_job_queue_heartbeat_at).should == run_time + expect(Time.parse(Spree::Config.last_job_queue_heartbeat_at)).to eq(run_time) end end diff --git a/spec/jobs/products_cache_integrity_checker_job_spec.rb b/spec/jobs/products_cache_integrity_checker_job_spec.rb index b77baf8018..19d5a79953 100644 --- a/spec/jobs/products_cache_integrity_checker_job_spec.rb +++ b/spec/jobs/products_cache_integrity_checker_job_spec.rb @@ -10,7 +10,7 @@ describe ProductsCacheIntegrityCheckerJob do before do Rails.cache.write(cache_key, "[1, 2, 3]\n") - OpenFoodNetwork::ProductsRenderer.stub(:new) { double(:pr, products_json: "[1, 3]\n") } + allow(OpenFoodNetwork::ProductsRenderer).to receive(:new) { double(:pr, products_json: "[1, 3]\n") } end it "reports errors" do diff --git a/spec/jobs/refresh_products_cache_job_spec.rb b/spec/jobs/refresh_products_cache_job_spec.rb index da62861717..c2dd66ff06 100644 --- a/spec/jobs/refresh_products_cache_job_spec.rb +++ b/spec/jobs/refresh_products_cache_job_spec.rb @@ -28,7 +28,7 @@ describe RefreshProductsCacheJob do it 'does not raise' do expect { run_job RefreshProductsCacheJob.new(distributor.id, order_cycle.id) - }.not_to raise_error(/ActiveRecord::RecordNotFound/) + }.not_to raise_error end it 'returns true' do diff --git a/spec/jobs/welcome_enterprise_job_spec.rb b/spec/jobs/welcome_enterprise_job_spec.rb index 051f4a31d1..a41322d185 100644 --- a/spec/jobs/welcome_enterprise_job_spec.rb +++ b/spec/jobs/welcome_enterprise_job_spec.rb @@ -5,8 +5,8 @@ describe WelcomeEnterpriseJob do it "sends a welcome email to the enterprise" do mail = double(:mail) - EnterpriseMailer.should_receive(:welcome).with(enterprise).and_return(mail) - mail.should_receive(:deliver) + expect(EnterpriseMailer).to receive(:welcome).with(enterprise).and_return(mail) + expect(mail).to receive(:deliver) run_job WelcomeEnterpriseJob.new(enterprise.id) end diff --git a/spec/lib/open_food_network/bulk_coop_report_spec.rb b/spec/lib/open_food_network/bulk_coop_report_spec.rb index 81ea742d07..4eeeae09dd 100644 --- a/spec/lib/open_food_network/bulk_coop_report_spec.rb +++ b/spec/lib/open_food_network/bulk_coop_report_spec.rb @@ -19,13 +19,13 @@ module OpenFoodNetwork it "fetches completed orders" do o2 = create(:order) o2.line_items << build(:line_item) - subject.table_items.should == [li1] + expect(subject.table_items).to eq([li1]) end it "does not show cancelled orders" do o2 = create(:order, state: "canceled", completed_at: 1.day.ago) o2.line_items << build(:line_item_with_shipment) - subject.table_items.should == [li1] + expect(subject.table_items).to eq([li1]) end end @@ -49,8 +49,8 @@ module OpenFoodNetwork end it "shows line items supplied by my producers, with names hidden" do - subject.table_items.should == [li2] - subject.table_items.first.order.bill_address.firstname.should == "HIDDEN" + expect(subject.table_items).to eq([li2]) + expect(subject.table_items.first.order.bill_address.firstname).to eq("HIDDEN") end end @@ -63,7 +63,7 @@ module OpenFoodNetwork end it "shows line items supplied by my producers, with names hidden" do - subject.table_items.should == [] + expect(subject.table_items).to eq([]) end end end @@ -81,15 +81,15 @@ module OpenFoodNetwork d2.enterprise_roles.create!(user: create(:user)) o2 = create(:order, distributor: d2, completed_at: 1.day.ago) o2.line_items << build(:line_item_with_shipment) - subject.table_items.should == [li1] + expect(subject.table_items).to eq([li1]) end it "only shows the selected order cycle" do oc2 = create(:simple_order_cycle) o2 = create(:order, distributor: d1, order_cycle: oc2) o2.line_items << build(:line_item) - subject.stub(:params).and_return(order_cycle_id_in: oc1.id) - subject.table_items.should == [li1] + allow(subject).to receive(:params).and_return(order_cycle_id_in: oc1.id) + expect(subject.table_items).to eq([li1]) end end end diff --git a/spec/lib/open_food_network/customers_report_spec.rb b/spec/lib/open_food_network/customers_report_spec.rb index b5ee26291b..686686f662 100644 --- a/spec/lib/open_food_network/customers_report_spec.rb +++ b/spec/lib/open_food_network/customers_report_spec.rb @@ -12,33 +12,33 @@ module OpenFoodNetwork describe "mailing list report" do before do - subject.stub(:params).and_return(report_type: "mailing_list") + allow(subject).to receive(:params).and_return(report_type: "mailing_list") end it "returns headers for mailing_list" do - subject.header.should == ["Email", "First Name", "Last Name", "Suburb"] + expect(subject.header).to eq(["Email", "First Name", "Last Name", "Suburb"]) end it "builds a table from a list of variants" do order = double(:order, email: "test@test.com") address = double(:billing_address, firstname: "Firsty", lastname: "Lasty", city: "Suburbia") - order.stub(:billing_address).and_return address - subject.stub(:orders).and_return [order] + allow(order).to receive(:billing_address).and_return address + allow(subject).to receive(:orders).and_return [order] - subject.table.should == [[ + expect(subject.table).to eq([[ "test@test.com", "Firsty", "Lasty", "Suburbia" - ]] + ]]) end end describe "addresses report" do before do - subject.stub(:params).and_return(report_type: "addresses") + allow(subject).to receive(:params).and_return(report_type: "addresses") end it "returns headers for addresses" do - subject.header.should == ["First Name", "Last Name", "Billing Address", "Email", "Phone", "Hub", "Hub Address", "Shipping Method"] + expect(subject.header).to eq(["First Name", "Last Name", "Billing Address", "Email", "Phone", "Hub", "Hub Address", "Shipping Method"]) end it "builds a table from a list of variants" do @@ -47,14 +47,14 @@ module OpenFoodNetwork o = create(:order, distributor: d, bill_address: a) o.shipments << create(:shipment) - subject.stub(:orders).and_return [o] - subject.table.should == [[ + allow(subject).to receive(:orders).and_return [o] + expect(subject.table).to eq([[ a.firstname, a.lastname, [a.address1, a.address2, a.city].join(" "), o.email, a.phone, d.name, [d.address.address1, d.address.address2, d.address.city].join(" "), o.shipping_method.name - ]] + ]]) end end @@ -62,13 +62,13 @@ module OpenFoodNetwork it "fetches completed orders" do o1 = create(:order) o2 = create(:order, completed_at: 1.day.ago) - subject.orders.should == [o2] + expect(subject.orders).to eq([o2]) end it "does not show cancelled orders" do o1 = create(:order, state: "canceled", completed_at: 1.day.ago) o2 = create(:order, completed_at: 1.day.ago) - subject.orders.should == [o2] + expect(subject.orders).to eq([o2]) end end end @@ -97,8 +97,8 @@ module OpenFoodNetwork o1 = create(:order, distributor: d1, completed_at: 1.day.ago) o2 = create(:order, distributor: d2, completed_at: 1.day.ago) - subject.should_receive(:filter).with([o1]).and_return([o1]) - subject.orders.should == [o1] + expect(subject).to receive(:filter).with([o1]).and_return([o1]) + expect(subject.orders).to eq([o1]) end it "does not show orders through a hub that the current user does not manage" do @@ -107,8 +107,8 @@ module OpenFoodNetwork order.line_items << create(:line_item_with_shipment, product: product) # When I fetch orders, I should see no orders - subject.should_receive(:filter).with([]).and_return([]) - subject.orders.should == [] + expect(subject).to receive(:filter).with([]).and_return([]) + expect(subject.orders).to eq([]) end end @@ -117,7 +117,7 @@ module OpenFoodNetwork let(:supplier) { create(:supplier_enterprise) } it "returns all orders sans-params" do - subject.filter(orders).should == orders + expect(subject.filter(orders)).to eq(orders) end it "returns orders with a specific supplier" do @@ -130,8 +130,8 @@ module OpenFoodNetwork order1.line_items << create(:line_item, product: product1) order2.line_items << create(:line_item, product: product2) - subject.stub(:params).and_return(supplier_id: supplier.id) - subject.filter(orders).should == [order1] + allow(subject).to receive(:params).and_return(supplier_id: supplier.id) + expect(subject.filter(orders)).to eq([order1]) end it "filters to a specific distributor" do @@ -140,8 +140,8 @@ module OpenFoodNetwork order1 = create(:order, distributor: d1) order2 = create(:order, distributor: d2) - subject.stub(:params).and_return(distributor_id: d1.id) - subject.filter(orders).should == [order1] + allow(subject).to receive(:params).and_return(distributor_id: d1.id) + expect(subject.filter(orders)).to eq([order1]) end it "filters to a specific cycle" do @@ -150,8 +150,8 @@ module OpenFoodNetwork order1 = create(:order, order_cycle: oc1) order2 = create(:order, order_cycle: oc2) - subject.stub(:params).and_return(order_cycle_id: oc1.id) - subject.filter(orders).should == [order1] + allow(subject).to receive(:params).and_return(order_cycle_id: oc1.id) + expect(subject.filter(orders)).to eq([order1]) end end end diff --git a/spec/lib/open_food_network/enterprise_fee_applicator_spec.rb b/spec/lib/open_food_network/enterprise_fee_applicator_spec.rb index b1a9074efb..8421b0616d 100644 --- a/spec/lib/open_food_network/enterprise_fee_applicator_spec.rb +++ b/spec/lib/open_food_network/enterprise_fee_applicator_spec.rb @@ -9,21 +9,21 @@ module OpenFoodNetwork product = create(:simple_product) efa = EnterpriseFeeApplicator.new enterprise_fee, product.master, 'role' - efa.stub(:line_item_adjustment_label) { 'label' } + allow(efa).to receive(:line_item_adjustment_label) { 'label' } efa.create_line_item_adjustment line_item adjustment = Spree::Adjustment.last - adjustment.label.should == 'label' - adjustment.adjustable.should == line_item.order - adjustment.source.should == line_item - adjustment.originator.should == enterprise_fee - adjustment.should be_mandatory + expect(adjustment.label).to eq('label') + expect(adjustment.adjustable).to eq(line_item.order) + expect(adjustment.source).to eq(line_item) + expect(adjustment.originator).to eq(enterprise_fee) + expect(adjustment).to be_mandatory md = adjustment.metadata - md.enterprise.should == enterprise_fee.enterprise - md.fee_name.should == enterprise_fee.name - md.fee_type.should == enterprise_fee.fee_type - md.enterprise_role.should == 'role' + expect(md.enterprise).to eq(enterprise_fee.enterprise) + expect(md.fee_name).to eq(enterprise_fee.name) + expect(md.fee_type).to eq(enterprise_fee.fee_type) + expect(md.enterprise_role).to eq('role') end it "creates an adjustment for an order" do @@ -32,21 +32,21 @@ module OpenFoodNetwork product = create(:simple_product) efa = EnterpriseFeeApplicator.new enterprise_fee, nil, 'role' - efa.stub(:order_adjustment_label) { 'label' } + allow(efa).to receive(:order_adjustment_label) { 'label' } efa.create_order_adjustment order adjustment = Spree::Adjustment.last - adjustment.label.should == 'label' - adjustment.adjustable.should == order - adjustment.source.should == order - adjustment.originator.should == enterprise_fee - adjustment.should be_mandatory + expect(adjustment.label).to eq('label') + expect(adjustment.adjustable).to eq(order) + expect(adjustment.source).to eq(order) + expect(adjustment.originator).to eq(enterprise_fee) + expect(adjustment).to be_mandatory md = adjustment.metadata - md.enterprise.should == enterprise_fee.enterprise - md.fee_name.should == enterprise_fee.name - md.fee_type.should == enterprise_fee.fee_type - md.enterprise_role.should == 'role' + expect(md.enterprise).to eq(enterprise_fee.enterprise) + expect(md.fee_name).to eq(enterprise_fee.name) + expect(md.fee_type).to eq(enterprise_fee.fee_type) + expect(md.enterprise_role).to eq('role') end it "makes an adjustment label for a line item" do @@ -55,7 +55,7 @@ module OpenFoodNetwork efa = EnterpriseFeeApplicator.new enterprise_fee, variant, 'distributor' - efa.send(:line_item_adjustment_label).should == "Bananas - packing fee by distributor Ballantyne" + expect(efa.send(:line_item_adjustment_label)).to eq("Bananas - packing fee by distributor Ballantyne") end it "makes an adjustment label for an order" do @@ -63,7 +63,7 @@ module OpenFoodNetwork efa = EnterpriseFeeApplicator.new enterprise_fee, nil, 'distributor' - efa.send(:order_adjustment_label).should == "Whole order - packing fee by distributor Ballantyne" + expect(efa.send(:order_adjustment_label)).to eq("Whole order - packing fee by distributor Ballantyne") end end end diff --git a/spec/lib/open_food_network/enterprise_fee_calculator_spec.rb b/spec/lib/open_food_network/enterprise_fee_calculator_spec.rb index ae79303b8d..5f6ef36ed6 100644 --- a/spec/lib/open_food_network/enterprise_fee_calculator_spec.rb +++ b/spec/lib/open_food_network/enterprise_fee_calculator_spec.rb @@ -27,13 +27,13 @@ module OpenFoodNetwork } it "calculates via regular computation" do - EnterpriseFeeCalculator.new(distributor, order_cycle).fees_for(product1.master).should == 20 - EnterpriseFeeCalculator.new(distributor, order_cycle).fees_for(product2.master).should == 3 + expect(EnterpriseFeeCalculator.new(distributor, order_cycle).fees_for(product1.master)).to eq(20) + expect(EnterpriseFeeCalculator.new(distributor, order_cycle).fees_for(product2.master)).to eq(3) end it "calculates via indexed computation" do - EnterpriseFeeCalculator.new(distributor, order_cycle).indexed_fees_for(product1.master).should == 20 - EnterpriseFeeCalculator.new(distributor, order_cycle).indexed_fees_for(product2.master).should == 3 + expect(EnterpriseFeeCalculator.new(distributor, order_cycle).indexed_fees_for(product1.master)).to eq(20) + expect(EnterpriseFeeCalculator.new(distributor, order_cycle).indexed_fees_for(product2.master)).to eq(3) end end @@ -47,11 +47,11 @@ module OpenFoodNetwork end it "sums via regular computation" do - EnterpriseFeeCalculator.new(distributor, order_cycle).fees_for(product1.master).should == 23 + expect(EnterpriseFeeCalculator.new(distributor, order_cycle).fees_for(product1.master)).to eq(23) end it "sums via indexed computation" do - EnterpriseFeeCalculator.new(distributor, order_cycle).indexed_fees_for(product1.master).should == 23 + expect(EnterpriseFeeCalculator.new(distributor, order_cycle).indexed_fees_for(product1.master)).to eq(23) end end @@ -61,11 +61,11 @@ module OpenFoodNetwork } it "sums via regular computation" do - EnterpriseFeeCalculator.new(distributor, order_cycle).fees_for(product1.master).should == 23 + expect(EnterpriseFeeCalculator.new(distributor, order_cycle).fees_for(product1.master)).to eq(23) end it "sums via indexed computation" do - EnterpriseFeeCalculator.new(distributor, order_cycle).indexed_fees_for(product1.master).should == 23 + expect(EnterpriseFeeCalculator.new(distributor, order_cycle).indexed_fees_for(product1.master)).to eq(23) end end end @@ -77,11 +77,11 @@ module OpenFoodNetwork } it "sums via regular computation" do - EnterpriseFeeCalculator.new(distributor, order_cycle).fees_for(product1.master).should == 2.00 + expect(EnterpriseFeeCalculator.new(distributor, order_cycle).fees_for(product1.master)).to eq(2.00) end it "sums via indexed computation" do - EnterpriseFeeCalculator.new(distributor, order_cycle).indexed_fees_for(product1.master).should == 2.00 + expect(EnterpriseFeeCalculator.new(distributor, order_cycle).indexed_fees_for(product1.master)).to eq(2.00) end end end @@ -100,23 +100,23 @@ module OpenFoodNetwork describe "regular computation" do it "returns a breakdown of fees" do - EnterpriseFeeCalculator.new(distributor, order_cycle).fees_by_type_for(product1.master).should == {admin: 1.23, sales: 4.56, packing: 7.89, transport: 0.12, fundraising: 3.45} + expect(EnterpriseFeeCalculator.new(distributor, order_cycle).fees_by_type_for(product1.master)).to eq({admin: 1.23, sales: 4.56, packing: 7.89, transport: 0.12, fundraising: 3.45}) end it "filters out zero fees" do ef_admin.calculator.update_attribute :preferred_amount, 0 - EnterpriseFeeCalculator.new(distributor, order_cycle).fees_by_type_for(product1.master).should == {sales: 4.56, packing: 7.89, transport: 0.12, fundraising: 3.45} + expect(EnterpriseFeeCalculator.new(distributor, order_cycle).fees_by_type_for(product1.master)).to eq({sales: 4.56, packing: 7.89, transport: 0.12, fundraising: 3.45}) end end describe "indexed computation" do it "returns a breakdown of fees" do - EnterpriseFeeCalculator.new(distributor, order_cycle).indexed_fees_by_type_for(product1.master).should == {admin: 1.23, sales: 4.56, packing: 7.89, transport: 0.12, fundraising: 3.45} + expect(EnterpriseFeeCalculator.new(distributor, order_cycle).indexed_fees_by_type_for(product1.master)).to eq({admin: 1.23, sales: 4.56, packing: 7.89, transport: 0.12, fundraising: 3.45}) end it "filters out zero fees" do ef_admin.calculator.update_attribute :preferred_amount, 0 - EnterpriseFeeCalculator.new(distributor, order_cycle).indexed_fees_by_type_for(product1.master).should == {sales: 4.56, packing: 7.89, transport: 0.12, fundraising: 3.45} + expect(EnterpriseFeeCalculator.new(distributor, order_cycle).indexed_fees_by_type_for(product1.master)).to eq({sales: 4.56, packing: 7.89, transport: 0.12, fundraising: 3.45}) end end end @@ -136,7 +136,7 @@ module OpenFoodNetwork EnterpriseFeeCalculator.new.create_line_item_adjustments_for line_item a = Spree::Adjustment.last - a.metadata.fee_name.should == enterprise_fee_line_item.name + expect(a.metadata.fee_name).to eq(enterprise_fee_line_item.name) end it "creates adjustments for an order" do @@ -145,7 +145,7 @@ module OpenFoodNetwork EnterpriseFeeCalculator.new.create_order_adjustments_for order a = Spree::Adjustment.last - a.metadata.fee_name.should == enterprise_fee_order.name + expect(a.metadata.fee_name).to eq(enterprise_fee_order.name) end end end @@ -169,18 +169,19 @@ module OpenFoodNetwork describe "fetching enterprise fees with pre-loaded exchange details" do it "scopes enterprise fees to those on exchanges for the current order cycle" do - subject.send(:per_item_enterprise_fees_with_exchange_details).should == [ef_exchange] + expect(subject.send(:per_item_enterprise_fees_with_exchange_details)).to eq([ef_exchange]) end it "includes the exchange variant id" do - subject.send(:per_item_enterprise_fees_with_exchange_details).first.variant_id.to_i.should == + expect(subject.send(:per_item_enterprise_fees_with_exchange_details).first.variant_id.to_i).to eq( v.id + ) end it "does not include outgoing exchanges to other distributors" do create(:exchange, order_cycle: order_cycle, sender: order_cycle.coordinator, receiver: distributor_other, enterprise_fees: [ef_other_distributor], variants: [v]) - subject.send(:per_item_enterprise_fees_with_exchange_details).should == [ef_exchange] + expect(subject.send(:per_item_enterprise_fees_with_exchange_details)).to eq([ef_exchange]) end end @@ -189,14 +190,14 @@ module OpenFoodNetwork it "loads exchange fees" do subject.send(:load_exchange_fees, exchange_fees) - indexed_enterprise_fees.should == {v.id => [ef_exchange]} + expect(indexed_enterprise_fees).to eq({v.id => [ef_exchange]}) end end describe "loading coordinator fees" do it "loads coordinator fees" do subject.send(:load_coordinator_fees) - indexed_enterprise_fees.should == {v.id => [ef_coordinator]} + expect(indexed_enterprise_fees).to eq({v.id => [ef_coordinator]}) end end end diff --git a/spec/lib/open_food_network/enterprise_injection_data_spec.rb b/spec/lib/open_food_network/enterprise_injection_data_spec.rb index d1e76221be..6cf917a002 100644 --- a/spec/lib/open_food_network/enterprise_injection_data_spec.rb +++ b/spec/lib/open_food_network/enterprise_injection_data_spec.rb @@ -10,12 +10,12 @@ module OpenFoodNetwork let!(:er_pi) { create(:enterprise_relationship, parent: producer_inactive, child: enterprise) } it "only loads activated relatives" do - subject.relatives[enterprise.id][:producers].should_not include producer_inactive.id + expect(subject.relatives[enterprise.id][:producers]).not_to include producer_inactive.id end it "loads self where appropiate" do - subject.relatives[producer.id][:producers].should include producer.id - subject.relatives[enterprise.id][:distributors].should include enterprise.id + expect(subject.relatives[producer.id][:producers]).to include producer.id + expect(subject.relatives[enterprise.id][:distributors]).to include enterprise.id end end end diff --git a/spec/lib/open_food_network/enterprise_issue_validator_spec.rb b/spec/lib/open_food_network/enterprise_issue_validator_spec.rb index ddae3e0b53..8503da23bb 100644 --- a/spec/lib/open_food_network/enterprise_issue_validator_spec.rb +++ b/spec/lib/open_food_network/enterprise_issue_validator_spec.rb @@ -7,8 +7,8 @@ module OpenFoodNetwork let(:warnings) { EnterpriseIssueValidator.new(enterprise_invisible).warnings } it "reports invisible enterprises" do - warnings.count.should == 1 - warnings.first[:description].should include "is not visible" + expect(warnings.count).to eq(1) + expect(warnings.first[:description]).to include "is not visible" end end end diff --git a/spec/lib/open_food_network/feature_toggle_spec.rb b/spec/lib/open_food_network/feature_toggle_spec.rb index 937cfba4bf..857a46a04f 100644 --- a/spec/lib/open_food_network/feature_toggle_spec.rb +++ b/spec/lib/open_food_network/feature_toggle_spec.rb @@ -3,18 +3,18 @@ require 'open_food_network/feature_toggle' module OpenFoodNetwork describe FeatureToggle do it "returns true when feature is on" do - FeatureToggle.stub(:features).and_return({foo: true}) - FeatureToggle.enabled?(:foo).should be true + allow(FeatureToggle).to receive(:features).and_return({foo: true}) + expect(FeatureToggle.enabled?(:foo)).to be true end it "returns false when feature is off" do - FeatureToggle.stub(:features).and_return({foo: false}) - FeatureToggle.enabled?(:foo).should be false + allow(FeatureToggle).to receive(:features).and_return({foo: false}) + expect(FeatureToggle.enabled?(:foo)).to be false end it "returns false when feature is undefined" do - FeatureToggle.stub(:features).and_return({}) - FeatureToggle.enabled?(:foo).should be false + allow(FeatureToggle).to receive(:features).and_return({}) + expect(FeatureToggle.enabled?(:foo)).to be false end end end diff --git a/spec/lib/open_food_network/group_buy_report_spec.rb b/spec/lib/open_food_network/group_buy_report_spec.rb index 91b7f15e0a..94735e0886 100644 --- a/spec/lib/open_food_network/group_buy_report_spec.rb +++ b/spec/lib/open_food_network/group_buy_report_spec.rb @@ -46,7 +46,7 @@ module OpenFoodNetwork it "should return a header row describing the report" do subject = GroupBuyReport.new [@order1] header = subject.header - header.should == ["Supplier", "Product", "Unit Size", "Variant", "Weight", "Total Ordered", "Total Max"] + expect(header).to eq(["Supplier", "Product", "Unit Size", "Variant", "Weight", "Total Ordered", "Total Max"]) end it "should provide the required variant and quantity information in a table" do @@ -59,7 +59,7 @@ module OpenFoodNetwork sum_quantities = line_items.map { |li| li.quantity }.sum sum_max_quantities = line_items.map { |li| li.max_quantity || 0 }.sum - table[0].should == [@variant1.product.supplier.name,@variant1.product.name,"UNITSIZE",@variant1.options_text,@variant1.weight,sum_quantities,sum_max_quantities] + expect(table[0]).to eq([@variant1.product.supplier.name,@variant1.product.name,"UNITSIZE",@variant1.options_text,@variant1.weight,sum_quantities,sum_max_quantities]) end it "should return a table wherein each rows contains the same number of columns as the heading" do @@ -69,7 +69,7 @@ module OpenFoodNetwork columns = subject.header.length table.each do |r| - r.length.should == columns + expect(r.length).to eq(columns) end end @@ -85,9 +85,9 @@ module OpenFoodNetwork variant_groups = variant_rows.group_by { |r| r.variant } product_groups = product_rows.group_by { |r| r.product } - supplier_groups.length.should == 2 - variant_groups.length.should == 3 - product_groups.length.should == 3 + expect(supplier_groups.length).to eq(2) + expect(variant_groups.length).to eq(3) + expect(product_groups.length).to eq(3) end end end diff --git a/spec/lib/open_food_network/lettuce_share_report_spec.rb b/spec/lib/open_food_network/lettuce_share_report_spec.rb index fac9ea118d..69032c7898 100644 --- a/spec/lib/open_food_network/lettuce_share_report_spec.rb +++ b/spec/lib/open_food_network/lettuce_share_report_spec.rb @@ -10,29 +10,29 @@ module OpenFoodNetwork describe "grower and method" do it "shows just the producer when there is no certification" do - report.stub(:producer_name) { "Producer" } - report.stub(:certification) { "" } + allow(report).to receive(:producer_name) { "Producer" } + allow(report).to receive(:certification) { "" } - report.send(:grower_and_method, variant).should == "Producer" + expect(report.send(:grower_and_method, variant)).to eq("Producer") end it "shows producer and certification when a certification is present" do - report.stub(:producer_name) { "Producer" } - report.stub(:certification) { "Method" } + allow(report).to receive(:producer_name) { "Producer" } + allow(report).to receive(:certification) { "Method" } - report.send(:grower_and_method, variant).should == "Producer (Method)" + expect(report.send(:grower_and_method, variant)).to eq("Producer (Method)") end end describe "gst" do it "handles tax category without rates" do - report.send(:gst, variant).should == 0 + expect(report.send(:gst, variant)).to eq(0) end end describe "table" do it "handles no items" do - report.table.should eq [] + expect(report.table).to eq [] end describe "lists" do @@ -45,14 +45,14 @@ module OpenFoodNetwork let(:variant3_override) { create(:variant_override, hub: hub, variant: variant3, count_on_hand: 0) } it "all items" do - report.stub(:child_variants) { Spree::Variant.where(id: [variant, variant2, variant3]) } - report.table.count.should eq 3 + allow(report).to receive(:child_variants) { Spree::Variant.where(id: [variant, variant2, variant3]) } + expect(report.table.count).to eq 3 end it "only available items" do variant.on_hand = 0 - report.stub(:child_variants) { Spree::Variant.where(id: [variant, variant2, variant3, variant4]) } - report.table.count.should eq 3 + allow(report).to receive(:child_variants) { Spree::Variant.where(id: [variant, variant2, variant3, variant4]) } + expect(report.table.count).to eq 3 end it "only available items considering overrides" do @@ -60,11 +60,11 @@ module OpenFoodNetwork # create the overrides variant2_override variant3_override - report.stub(:child_variants) { Spree::Variant.where(id: [variant, variant2, variant3]) } - report.stub(:params) { {distributor_id: hub.id} } + allow(report).to receive(:child_variants) { Spree::Variant.where(id: [variant, variant2, variant3]) } + allow(report).to receive(:params) { {distributor_id: hub.id} } rows = report.table - rows.count.should eq 2 - rows.map{ |row| row[0] }.should include variant.product.name, variant2.product.name + expect(rows.count).to eq 2 + expect(rows.map{ |row| row[0] }).to include variant.product.name, variant2.product.name end end diff --git a/spec/lib/open_food_network/option_value_namer_spec.rb b/spec/lib/open_food_network/option_value_namer_spec.rb index c5dbd0f557..fbef09a8e0 100644 --- a/spec/lib/open_food_network/option_value_namer_spec.rb +++ b/spec/lib/open_food_network/option_value_namer_spec.rb @@ -7,31 +7,31 @@ module OpenFoodNetwork let(:subject) { OptionValueNamer.new } it "when description is blank" do - v.stub(:unit_description) { nil } - subject.stub(:value_scaled?) { true } - subject.stub(:option_value_value_unit) { %w(value unit) } - subject.name(v).should == "valueunit" + allow(v).to receive(:unit_description) { nil } + allow(subject).to receive(:value_scaled?) { true } + allow(subject).to receive(:option_value_value_unit) { %w(value unit) } + expect(subject.name(v)).to eq("valueunit") end it "when description is present" do - v.stub(:unit_description) { 'desc' } - subject.stub(:option_value_value_unit) { %w(value unit) } - subject.stub(:value_scaled?) { true } - subject.name(v).should == "valueunit desc" + allow(v).to receive(:unit_description) { 'desc' } + allow(subject).to receive(:option_value_value_unit) { %w(value unit) } + allow(subject).to receive(:value_scaled?) { true } + expect(subject.name(v)).to eq("valueunit desc") end it "when value is blank and description is present" do - v.stub(:unit_description) { 'desc' } - subject.stub(:option_value_value_unit) { [nil, nil] } - subject.stub(:value_scaled?) { true } - subject.name(v).should == "desc" + allow(v).to receive(:unit_description) { 'desc' } + allow(subject).to receive(:option_value_value_unit) { [nil, nil] } + allow(subject).to receive(:value_scaled?) { true } + expect(subject.name(v)).to eq("desc") end it "spaces value and unit when value is unscaled" do - v.stub(:unit_description) { nil } - subject.stub(:option_value_value_unit) { %w(value unit) } - subject.stub(:value_scaled?) { false } - subject.name(v).should == "value unit" + allow(v).to receive(:unit_description) { nil } + allow(subject).to receive(:option_value_value_unit) { %w(value unit) } + allow(subject).to receive(:value_scaled?) { false } + expect(subject.name(v)).to eq("value unit") end end @@ -39,7 +39,7 @@ module OpenFoodNetwork it "returns true when the product has a scale" do p = Spree::Product.new variant_unit_scale: 1000 v = Spree::Variant.new - v.stub(:product) { p } + allow(v).to receive(:product) { p } subject = OptionValueNamer.new v expect(subject.send(:value_scaled?)).to be true @@ -48,7 +48,7 @@ module OpenFoodNetwork it "returns false otherwise" do p = Spree::Product.new v = Spree::Variant.new - v.stub(:product) { p } + allow(v).to receive(:product) { p } subject = OptionValueNamer.new v expect(subject.send(:value_scaled?)).to be false @@ -61,8 +61,8 @@ module OpenFoodNetwork it "generates simple values" do p = double(:product, variant_unit: 'weight', variant_unit_scale: 1.0) - v.stub(:product) { p } - v.stub(:unit_value) { 100 } + allow(v).to receive(:product) { p } + allow(v).to receive(:unit_value) { 100 } expect(subject.send(:option_value_value_unit)).to eq [100, 'g'] @@ -70,16 +70,16 @@ module OpenFoodNetwork it "generates values when unit value is non-integer" do p = double(:product, variant_unit: 'weight', variant_unit_scale: 1.0) - v.stub(:product) { p } - v.stub(:unit_value) { 123.45 } + allow(v).to receive(:product) { p } + allow(v).to receive(:unit_value) { 123.45 } expect(subject.send(:option_value_value_unit)).to eq [123.45, 'g'] end it "returns a value of 1 when unit value equals the scale" do p = double(:product, variant_unit: 'weight', variant_unit_scale: 1000.0) - v.stub(:product) { p } - v.stub(:unit_value) { 1000.0 } + allow(v).to receive(:product) { p } + allow(v).to receive(:unit_value) { 1000.0 } expect(subject.send(:option_value_value_unit)).to eq [1, 'kg'] end @@ -87,8 +87,8 @@ module OpenFoodNetwork it "generates values for all weight scales" do [[1.0, 'g'], [1000.0, 'kg'], [1000000.0, 'T']].each do |scale, unit| p = double(:product, variant_unit: 'weight', variant_unit_scale: scale) - v.stub(:product) { p } - v.stub(:unit_value) { 100 * scale } + allow(v).to receive(:product) { p } + allow(v).to receive(:unit_value) { 100 * scale } expect(subject.send(:option_value_value_unit)).to eq [100, unit] end end @@ -96,39 +96,39 @@ module OpenFoodNetwork it "generates values for all volume scales" do [[0.001, 'mL'], [1.0, 'L'], [1000.0, 'kL']].each do |scale, unit| p = double(:product, variant_unit: 'volume', variant_unit_scale: scale) - v.stub(:product) { p } - v.stub(:unit_value) { 100 * scale } + allow(v).to receive(:product) { p } + allow(v).to receive(:unit_value) { 100 * scale } expect(subject.send(:option_value_value_unit)).to eq [100, unit] end end it "chooses the correct scale when value is very small" do p = double(:product, variant_unit: 'volume', variant_unit_scale: 0.001) - v.stub(:product) { p } - v.stub(:unit_value) { 0.0001 } + allow(v).to receive(:product) { p } + allow(v).to receive(:unit_value) { 0.0001 } expect(subject.send(:option_value_value_unit)).to eq [0.1, 'mL'] end it "generates values for item units" do %w(packet box).each do |unit| p = double(:product, variant_unit: 'items', variant_unit_scale: nil, variant_unit_name: unit) - v.stub(:product) { p } - v.stub(:unit_value) { 100 } + allow(v).to receive(:product) { p } + allow(v).to receive(:unit_value) { 100 } expect(subject.send(:option_value_value_unit)).to eq [100, unit.pluralize] end end it "generates singular values for item units when value is 1" do p = double(:product, variant_unit: 'items', variant_unit_scale: nil, variant_unit_name: 'packet') - v.stub(:product) { p } - v.stub(:unit_value) { 1 } + allow(v).to receive(:product) { p } + allow(v).to receive(:unit_value) { 1 } expect(subject.send(:option_value_value_unit)).to eq [1, 'packet'] end it "returns [nil, nil] when unit value is not set" do p = double(:product, variant_unit: 'items', variant_unit_scale: nil, variant_unit_name: 'foo') - v.stub(:product) { p } - v.stub(:unit_value) { nil } + allow(v).to receive(:product) { p } + allow(v).to receive(:unit_value) { nil } expect(subject.send(:option_value_value_unit)).to eq [nil, nil] end end diff --git a/spec/lib/open_food_network/order_cycle_form_applicator_spec.rb b/spec/lib/open_food_network/order_cycle_form_applicator_spec.rb index db02f1656d..2ba8775657 100644 --- a/spec/lib/open_food_network/order_cycle_form_applicator_spec.rb +++ b/spec/lib/open_food_network/order_cycle_form_applicator_spec.rb @@ -17,10 +17,10 @@ module OpenFoodNetwork applicator = OrderCycleFormApplicator.new(oc, user) - applicator.should_receive(:incoming_exchange_variant_ids).with(incoming_exchange).and_return([1, 3]) - applicator.should_receive(:exchange_exists?).with(supplier_id, coordinator_id, true).and_return(false) - applicator.should_receive(:add_exchange).with(supplier_id, coordinator_id, true, {:variant_ids => [1, 3], :enterprise_fee_ids => [1, 2], :receival_instructions => 'receival instructions'}) - applicator.should_receive(:destroy_untouched_exchanges) + expect(applicator).to receive(:incoming_exchange_variant_ids).with(incoming_exchange).and_return([1, 3]) + expect(applicator).to receive(:exchange_exists?).with(supplier_id, coordinator_id, true).and_return(false) + expect(applicator).to receive(:add_exchange).with(supplier_id, coordinator_id, true, {:variant_ids => [1, 3], :enterprise_fee_ids => [1, 2], :receival_instructions => 'receival instructions'}) + expect(applicator).to receive(:destroy_untouched_exchanges) applicator.go! end @@ -35,10 +35,10 @@ module OpenFoodNetwork applicator = OrderCycleFormApplicator.new(oc, user) - applicator.should_receive(:outgoing_exchange_variant_ids).with(outgoing_exchange).and_return([1, 3]) - applicator.should_receive(:exchange_exists?).with(coordinator_id, distributor_id, false).and_return(false) - applicator.should_receive(:add_exchange).with(coordinator_id, distributor_id, false, {:variant_ids => [1, 3], :enterprise_fee_ids => [1, 2], :pickup_time => 'pickup time', :pickup_instructions => 'pickup instructions', tag_list: 'wholesale'}) - applicator.should_receive(:destroy_untouched_exchanges) + expect(applicator).to receive(:outgoing_exchange_variant_ids).with(outgoing_exchange).and_return([1, 3]) + expect(applicator).to receive(:exchange_exists?).with(coordinator_id, distributor_id, false).and_return(false) + expect(applicator).to receive(:add_exchange).with(coordinator_id, distributor_id, false, {:variant_ids => [1, 3], :enterprise_fee_ids => [1, 2], :pickup_time => 'pickup time', :pickup_instructions => 'pickup instructions', tag_list: 'wholesale'}) + expect(applicator).to receive(:destroy_untouched_exchanges) applicator.go! end @@ -57,10 +57,10 @@ module OpenFoodNetwork applicator = OrderCycleFormApplicator.new(oc, user) - applicator.should_receive(:incoming_exchange_variant_ids).with(incoming_exchange).and_return([1, 3]) - applicator.should_receive(:exchange_exists?).with(supplier_id, coordinator_id, true).and_return(true) - applicator.should_receive(:update_exchange).with(supplier_id, coordinator_id, true, {:variant_ids => [1, 3], :enterprise_fee_ids => [1, 2], :receival_instructions => 'receival instructions'}) - applicator.should_receive(:destroy_untouched_exchanges) + expect(applicator).to receive(:incoming_exchange_variant_ids).with(incoming_exchange).and_return([1, 3]) + expect(applicator).to receive(:exchange_exists?).with(supplier_id, coordinator_id, true).and_return(true) + expect(applicator).to receive(:update_exchange).with(supplier_id, coordinator_id, true, {:variant_ids => [1, 3], :enterprise_fee_ids => [1, 2], :receival_instructions => 'receival instructions'}) + expect(applicator).to receive(:destroy_untouched_exchanges) applicator.go! end @@ -79,10 +79,10 @@ module OpenFoodNetwork applicator = OrderCycleFormApplicator.new(oc, user) - applicator.should_receive(:outgoing_exchange_variant_ids).with(outgoing_exchange).and_return([1, 3]) - applicator.should_receive(:exchange_exists?).with(coordinator_id, distributor_id, false).and_return(true) - applicator.should_receive(:update_exchange).with(coordinator_id, distributor_id, false, {:variant_ids => [1, 3], :enterprise_fee_ids => [1, 2], :pickup_time => 'pickup time', :pickup_instructions => 'pickup instructions', tag_list: 'wholesale'}) - applicator.should_receive(:destroy_untouched_exchanges) + expect(applicator).to receive(:outgoing_exchange_variant_ids).with(outgoing_exchange).and_return([1, 3]) + expect(applicator).to receive(:exchange_exists?).with(coordinator_id, distributor_id, false).and_return(true) + expect(applicator).to receive(:update_exchange).with(coordinator_id, distributor_id, false, {:variant_ids => [1, 3], :enterprise_fee_ids => [1, 2], :pickup_time => 'pickup time', :pickup_instructions => 'pickup instructions', tag_list: 'wholesale'}) + expect(applicator).to receive(:destroy_untouched_exchanges) applicator.go! end @@ -101,10 +101,10 @@ module OpenFoodNetwork applicator = OrderCycleFormApplicator.new(oc, user) - applicator.should_receive(:destroy_untouched_exchanges) + expect(applicator).to receive(:destroy_untouched_exchanges) applicator.go! - applicator.send(:untouched_exchanges).should == [exchange] + expect(applicator.send(:untouched_exchanges)).to eq([exchange]) end it "compares exchanges by id only" do @@ -117,12 +117,12 @@ module OpenFoodNetwork @touched_exchanges = [e2] end - applicator.send(:untouched_exchanges).should == [] + expect(applicator.send(:untouched_exchanges)).to eq([]) end context "as a manager of the coordinator" do let(:applicator) { OrderCycleFormApplicator.new(nil, user) } - before { applicator.stub(:manages_coordinator?) { true } } + before { allow(applicator).to receive(:manages_coordinator?) { true } } it "destroys exchanges" do exchanges = [double(:exchange), double(:exchange)] @@ -135,7 +135,7 @@ module OpenFoodNetwork context "as a non-manager of the coordinator" do let(:applicator) { OrderCycleFormApplicator.new(nil, user) } - before { applicator.stub(:manages_coordinator?) { false } } + before { allow(applicator).to receive(:manages_coordinator?) { false } } it "does not destroy any exchanges" do expect(applicator).to_not receive(:with_permission) @@ -270,9 +270,9 @@ module OpenFoodNetwork ex = double(:exchange, participant: e) applicator = OrderCycleFormApplicator.new(nil, user) - applicator.stub(:permitted_enterprises) { [e] } + allow(applicator).to receive(:permitted_enterprises) { [e] } - applicator.send(:permission_for, ex).should be true + expect(applicator.send(:permission_for, ex)).to be true end it "returns false otherwise" do @@ -280,9 +280,9 @@ module OpenFoodNetwork ex = double(:exchange, participant: e) applicator = OrderCycleFormApplicator.new(nil, user) - applicator.stub(:permitted_enterprises) { [] } + allow(applicator).to receive(:permitted_enterprises) { [] } - applicator.send(:permission_for, ex).should be false + expect(applicator.send(:permission_for, ex)).to be false end end end @@ -298,12 +298,12 @@ module OpenFoodNetwork exchange = FactoryBot.create(:exchange, order_cycle: oc) applicator = OrderCycleFormApplicator.new(oc, user) - applicator.send(:exchange_exists?, exchange.sender_id, exchange.receiver_id, exchange.incoming).should be true - applicator.send(:exchange_exists?, exchange.sender_id, exchange.receiver_id, !exchange.incoming).should be false - applicator.send(:exchange_exists?, exchange.receiver_id, exchange.sender_id, exchange.incoming).should be false - applicator.send(:exchange_exists?, exchange.sender_id, 999999, exchange.incoming).should be false - applicator.send(:exchange_exists?, 999999, exchange.receiver_id, exchange.incoming).should be false - applicator.send(:exchange_exists?, 999999, 888888, exchange.incoming).should be false + expect(applicator.send(:exchange_exists?, exchange.sender_id, exchange.receiver_id, exchange.incoming)).to be true + expect(applicator.send(:exchange_exists?, exchange.sender_id, exchange.receiver_id, !exchange.incoming)).to be false + expect(applicator.send(:exchange_exists?, exchange.receiver_id, exchange.sender_id, exchange.incoming)).to be false + expect(applicator.send(:exchange_exists?, exchange.sender_id, 999999, exchange.incoming)).to be false + expect(applicator.send(:exchange_exists?, 999999, exchange.receiver_id, exchange.incoming)).to be false + expect(applicator.send(:exchange_exists?, 999999, 888888, exchange.incoming)).to be false end describe "adding exchanges" do @@ -332,7 +332,7 @@ module OpenFoodNetwork expect(exchange.variants).to match_array [variant1, variant2] expect(exchange.enterprise_fees).to match_array [enterprise_fee1, enterprise_fee2] - applicator.send(:touched_exchanges).should == [exchange] + expect(applicator.send(:touched_exchanges)).to eq([exchange]) end end @@ -449,7 +449,7 @@ module OpenFoodNetwork applicator.send(:touched_exchanges=, []) applicator.send(:update_exchange, sender.id, receiver.id, incoming, {:variant_ids => [variant1.id]}) - exchange.variants.should_not == [variant1] + expect(exchange.variants).not_to eq([variant1]) end end end diff --git a/spec/lib/open_food_network/order_cycle_management_report_spec.rb b/spec/lib/open_food_network/order_cycle_management_report_spec.rb index 4fed3daadf..44e4ca7c01 100644 --- a/spec/lib/open_food_network/order_cycle_management_report_spec.rb +++ b/spec/lib/open_food_network/order_cycle_management_report_spec.rb @@ -16,13 +16,13 @@ module OpenFoodNetwork it "fetches completed orders" do o1 = create(:order) o2 = create(:order, completed_at: 1.day.ago) - subject.orders.should == [o2] + expect(subject.orders).to eq([o2]) end it "does not show cancelled orders" do o1 = create(:order, state: "canceled", completed_at: 1.day.ago) o2 = create(:order, completed_at: 1.day.ago) - subject.orders.should == [o2] + expect(subject.orders).to eq([o2]) end end end @@ -46,8 +46,8 @@ module OpenFoodNetwork o1 = create(:order, distributor: d1, completed_at: 1.day.ago) o2 = create(:order, distributor: d2, completed_at: 1.day.ago) - subject.should_receive(:filter).with([o1]).and_return([o1]) - subject.orders.should == [o1] + expect(subject).to receive(:filter).with([o1]).and_return([o1]) + expect(subject.orders).to eq([o1]) end @@ -57,8 +57,8 @@ module OpenFoodNetwork order.line_items << create(:line_item_with_shipment, product: product) # When I fetch orders, I should see no orders - subject.should_receive(:filter).with([]).and_return([]) - subject.orders.should == [] + expect(subject).to receive(:filter).with([]).and_return([]) + expect(subject.orders).to eq([]) end end @@ -74,15 +74,15 @@ module OpenFoodNetwork let!(:payment1) { create(:payment, order: order1, payment_method: pm1) } it "returns all orders sans-params" do - subject.filter(orders).should == orders + expect(subject.filter(orders)).to eq(orders) end it "filters to a specific order cycle" do oc2 = create(:simple_order_cycle) order2 = create(:order, order_cycle: oc2) - subject.stub(:params).and_return(order_cycle_id: oc1.id) - subject.filter(orders).should == [order1] + allow(subject).to receive(:params).and_return(order_cycle_id: oc1.id) + expect(subject.filter(orders)).to eq([order1]) end it "filters to a payment method" do @@ -91,8 +91,8 @@ module OpenFoodNetwork order2 = create(:order, payments: [create(:payment, payment_method: pm2)]) order3 = create(:order, payments: [create(:payment, payment_method: pm3)]) - subject.stub(:params).and_return(payment_method_in: [pm1.id, pm3.id] ) - subject.filter(orders).should match_array [order1, order3] + allow(subject).to receive(:params).and_return(payment_method_in: [pm1.id, pm3.id] ) + expect(subject.filter(orders)).to match_array [order1, order3] end it "filters to a shipping method" do @@ -103,15 +103,15 @@ module OpenFoodNetwork order2 = create(:order, shipments: [s2]) order3 = create(:order, shipments: [s3]) - subject.stub(:params).and_return(shipping_method_in: [sm1.id, sm3.id]) + allow(subject).to receive(:params).and_return(shipping_method_in: [sm1.id, sm3.id]) expect(subject.filter(orders)).to match_array [order1, order3] end it "should do all the filters at once" do - subject.stub(:params).and_return(order_cycle_id: oc1.id, + allow(subject).to receive(:params).and_return(order_cycle_id: oc1.id, shipping_method_name: sm1.name, payment_method_name: pm1.name) - subject.filter(orders).should == [order1] + expect(subject.filter(orders)).to eq([order1]) end end end diff --git a/spec/lib/open_food_network/order_cycle_permissions_spec.rb b/spec/lib/open_food_network/order_cycle_permissions_spec.rb index 275d91d13d..016599e7a2 100644 --- a/spec/lib/open_food_network/order_cycle_permissions_spec.rb +++ b/spec/lib/open_food_network/order_cycle_permissions_spec.rb @@ -14,7 +14,7 @@ module OpenFoodNetwork let(:permissions) { OrderCyclePermissions.new(user, nil) } before do - permissions.stub(:managed_enterprises) { Enterprise.where(id: [coordinator]) } + allow(permissions).to receive(:managed_enterprises) { Enterprise.where(id: [coordinator]) } end it "returns an empty scope" do @@ -24,7 +24,7 @@ module OpenFoodNetwork context "as a manager of the coordinator" do before do - permissions.stub(:managed_enterprises) { Enterprise.where(id: [coordinator]) } + allow(permissions).to receive(:managed_enterprises) { Enterprise.where(id: [coordinator]) } end it "returns the coordinator itself" do @@ -45,7 +45,7 @@ module OpenFoodNetwork end context "where the coordinator sells 'own'" do - before { coordinator.stub(:sells) { 'own' } } + before { allow(coordinator).to receive(:sells) { 'own' } } it "returns just the coordinator" do enterprises = permissions.visible_enterprises expect(enterprises).to_not include hub, producer @@ -66,7 +66,7 @@ module OpenFoodNetwork end context "where the coordinator sells 'own'" do - before { coordinator.stub(:sells) { 'own' } } + before { allow(coordinator).to receive(:sells) { 'own' } } it "returns just the coordinator" do enterprises = permissions.visible_enterprises expect(enterprises).to_not include hub, producer @@ -85,7 +85,7 @@ module OpenFoodNetwork context "as a manager of a hub" do before do - permissions.stub(:managed_enterprises) { Enterprise.where(id: [hub]) } + allow(permissions).to receive(:managed_enterprises) { Enterprise.where(id: [hub]) } end context "that has granted P-OC to the coordinator" do @@ -192,7 +192,7 @@ module OpenFoodNetwork context "as a manager of a producer" do before do - permissions.stub(:managed_enterprises) { Enterprise.where(id: [producer]) } + allow(permissions).to receive(:managed_enterprises) { Enterprise.where(id: [producer]) } end context "which has granted P-OC to the coordinator" do @@ -308,11 +308,11 @@ module OpenFoodNetwork let!(:ex_out) { create(:exchange, order_cycle: oc, sender: coordinator, receiver: hub, incoming: false) } before do - permissions.stub(:managed_enterprises) { Enterprise.where(id: [coordinator]) } + allow(permissions).to receive(:managed_enterprises) { Enterprise.where(id: [coordinator]) } end it "returns all exchanges in the order cycle, regardless of hubE permissions" do - permissions.visible_exchanges.should include ex_in, ex_out + expect(permissions.visible_exchanges).to include ex_in, ex_out end end @@ -321,14 +321,14 @@ module OpenFoodNetwork let!(:ex_in) { create(:exchange, order_cycle: oc, sender: producer, receiver: coordinator, incoming: true) } before do - permissions.stub(:managed_enterprises) { Enterprise.where(id: [hub]) } + allow(permissions).to receive(:managed_enterprises) { Enterprise.where(id: [hub]) } end context "where my hub is in the order cycle" do let!(:ex_out) { create(:exchange, order_cycle: oc, sender: coordinator, receiver: hub, incoming: false) } it "returns my hub's outgoing exchange" do - permissions.visible_exchanges.should == [ex_out] + expect(permissions.visible_exchanges).to eq([ex_out]) end context "where my hub has been granted P-OC by an incoming producer" do @@ -337,20 +337,20 @@ module OpenFoodNetwork end it "returns the producer's incoming exchange" do - permissions.visible_exchanges.should include ex_in + expect(permissions.visible_exchanges).to include ex_in end end context "where my hub has not been granted P-OC by an incoming producer" do it "returns the producers's incoming exchange, and my own outhoing exchange" do - permissions.visible_exchanges.should_not include ex_in + expect(permissions.visible_exchanges).not_to include ex_in end end end context "where my hub isn't in the order cycle" do it "does not return the producer's incoming exchanges" do - permissions.visible_exchanges.should == [] + expect(permissions.visible_exchanges).to eq([]) end end @@ -363,7 +363,7 @@ module OpenFoodNetwork before { ex_out.variants << variant } it "returns incoming exchanges supplying the variants in my outgoing exchange" do - permissions.visible_exchanges.should include ex_out + expect(permissions.visible_exchanges).to include ex_out end end end @@ -373,14 +373,14 @@ module OpenFoodNetwork let!(:ex_out) { create(:exchange, order_cycle: oc, sender: coordinator, receiver: hub, incoming: false) } before do - permissions.stub(:managed_enterprises) { Enterprise.where(id: [producer]) } + allow(permissions).to receive(:managed_enterprises) { Enterprise.where(id: [producer]) } end context "where my producer supplies to the order cycle" do let!(:ex_in) { create(:exchange, order_cycle: oc, sender: producer, receiver: coordinator, incoming: true) } it "returns my producer's incoming exchange" do - permissions.visible_exchanges.should == [ex_in] + expect(permissions.visible_exchanges).to eq([ex_in]) end context "my producer has granted P-OC to an outgoing hub" do @@ -389,20 +389,20 @@ module OpenFoodNetwork end it "returns the hub's outgoing exchange" do - permissions.visible_exchanges.should include ex_out + expect(permissions.visible_exchanges).to include ex_out end end context "my producer has not granted P-OC to an outgoing hub" do it "does not return the hub's outgoing exchange" do - permissions.visible_exchanges.should_not include ex_out + expect(permissions.visible_exchanges).not_to include ex_out end end end context "where my producer doesn't supply the order cycle" do it "does not return the hub's outgoing exchanges" do - permissions.visible_exchanges.should == [] + expect(permissions.visible_exchanges).to eq([]) end end @@ -417,13 +417,13 @@ module OpenFoodNetwork let!(:ex_in) { create(:exchange, order_cycle: oc, sender: producer, receiver: coordinator, incoming: true) } it "returns the outgoing exchange" do - permissions.visible_exchanges.should include ex_out + expect(permissions.visible_exchanges).to include ex_out end end context "where my producer doesn't supply to the order cycle" do it "does not return the outgoing exchange" do - permissions.visible_exchanges.should_not include ex_out + expect(permissions.visible_exchanges).not_to include ex_out end end end @@ -441,7 +441,7 @@ module OpenFoodNetwork describe "incoming exchanges" do context "as a manager of the coordinator" do before do - permissions.stub(:managed_enterprises) { Enterprise.where(id: [coordinator]) } + allow(permissions).to receive(:managed_enterprises) { Enterprise.where(id: [coordinator]) } end it "returns all variants belonging to the sending producer" do @@ -453,7 +453,7 @@ module OpenFoodNetwork context "as a manager of the producer" do before do - permissions.stub(:managed_enterprises) { Enterprise.where(id: [producer1]) } + allow(permissions).to receive(:managed_enterprises) { Enterprise.where(id: [producer1]) } end it "returns all variants belonging to the sending producer" do @@ -465,7 +465,7 @@ module OpenFoodNetwork context "as a manager of a hub which has been granted P-OC by the producer" do before do - permissions.stub(:managed_enterprises) { Enterprise.where(id: [hub]) } + allow(permissions).to receive(:managed_enterprises) { Enterprise.where(id: [hub]) } create(:enterprise_relationship, parent: producer1, child: hub, permissions_list: [:add_to_order_cycle]) end @@ -493,7 +493,7 @@ module OpenFoodNetwork describe "outgoing exchanges" do context "as a manager of the coordinator" do before do - permissions.stub(:managed_enterprises) { Enterprise.where(id: [coordinator]) } + allow(permissions).to receive(:managed_enterprises) { Enterprise.where(id: [coordinator]) } create(:enterprise_relationship, parent: producer1, child: hub, permissions_list: [:add_to_order_cycle]) end @@ -535,7 +535,7 @@ module OpenFoodNetwork context "as manager of an outgoing hub" do before do - permissions.stub(:managed_enterprises) { Enterprise.where(id: [hub]) } + allow(permissions).to receive(:managed_enterprises) { Enterprise.where(id: [hub]) } create(:enterprise_relationship, parent: producer1, child: hub, permissions_list: [:add_to_order_cycle]) end @@ -571,7 +571,7 @@ module OpenFoodNetwork context "as the manager of a producer which has granted P-OC to an outgoing hub" do before do - permissions.stub(:managed_enterprises) { Enterprise.where(id: [producer1]) } + allow(permissions).to receive(:managed_enterprises) { Enterprise.where(id: [producer1]) } create(:enterprise_relationship, parent: producer1, child: hub, permissions_list: [:add_to_order_cycle]) end @@ -597,7 +597,7 @@ module OpenFoodNetwork context "as the manager of a producer which has not granted P-OC to an outgoing hub" do before do - permissions.stub(:managed_enterprises) { Enterprise.where(id: [producer2]) } + allow(permissions).to receive(:managed_enterprises) { Enterprise.where(id: [producer2]) } create(:enterprise_relationship, parent: producer1, child: hub, permissions_list: [:add_to_order_cycle]) end @@ -632,7 +632,7 @@ module OpenFoodNetwork describe "incoming exchanges" do context "as a manager of the coordinator" do before do - permissions.stub(:managed_enterprises) { Enterprise.where(id: [coordinator]) } + allow(permissions).to receive(:managed_enterprises) { Enterprise.where(id: [coordinator]) } end it "returns all variants belonging to the sending producer" do @@ -644,7 +644,7 @@ module OpenFoodNetwork context "as a manager of the producer" do before do - permissions.stub(:managed_enterprises) { Enterprise.where(id: [producer1]) } + allow(permissions).to receive(:managed_enterprises) { Enterprise.where(id: [producer1]) } end it "returns all variants belonging to the sending producer" do @@ -656,7 +656,7 @@ module OpenFoodNetwork context "as a manager of a hub which has been granted P-OC by the producer" do before do - permissions.stub(:managed_enterprises) { Enterprise.where(id: [hub]) } + allow(permissions).to receive(:managed_enterprises) { Enterprise.where(id: [hub]) } create(:enterprise_relationship, parent: producer1, child: hub, permissions_list: [:add_to_order_cycle]) end @@ -670,7 +670,7 @@ module OpenFoodNetwork describe "outgoing exchanges" do context "as a manager of the coordinator" do before do - permissions.stub(:managed_enterprises) { Enterprise.where(id: [coordinator]) } + allow(permissions).to receive(:managed_enterprises) { Enterprise.where(id: [coordinator]) } create(:enterprise_relationship, parent: producer1, child: hub, permissions_list: [:add_to_order_cycle]) end @@ -712,7 +712,7 @@ module OpenFoodNetwork context "as manager of an outgoing hub" do before do - permissions.stub(:managed_enterprises) { Enterprise.where(id: [hub]) } + allow(permissions).to receive(:managed_enterprises) { Enterprise.where(id: [hub]) } create(:enterprise_relationship, parent: producer1, child: hub, permissions_list: [:add_to_order_cycle]) end @@ -748,7 +748,7 @@ module OpenFoodNetwork context "as the manager of a producer which has granted P-OC to an outgoing hub" do before do - permissions.stub(:managed_enterprises) { Enterprise.where(id: [producer1]) } + allow(permissions).to receive(:managed_enterprises) { Enterprise.where(id: [producer1]) } create(:enterprise_relationship, parent: producer1, child: hub, permissions_list: [:add_to_order_cycle]) end @@ -789,7 +789,7 @@ module OpenFoodNetwork context "as the manager of a producer which has not granted P-OC to an outgoing hub" do before do - permissions.stub(:managed_enterprises) { Enterprise.where(id: [producer2]) } + allow(permissions).to receive(:managed_enterprises) { Enterprise.where(id: [producer2]) } create(:enterprise_relationship, parent: producer1, child: hub, permissions_list: [:add_to_order_cycle]) end diff --git a/spec/lib/open_food_network/order_grouper_spec.rb b/spec/lib/open_food_network/order_grouper_spec.rb index 56112a0a00..7579200381 100644 --- a/spec/lib/open_food_network/order_grouper_spec.rb +++ b/spec/lib/open_food_network/order_grouper_spec.rb @@ -16,8 +16,8 @@ module OpenFoodNetwork subject = OrderGrouper.new rules, columns tree = double(:tree) - subject.should_receive(:build_tree).with(@items, rules).and_return(tree) - subject.should_receive(:build_table).with(tree) + expect(subject).to receive(:build_tree).with(@items, rules).and_return(tree) + expect(subject).to receive(:build_table).with(tree) subject.table(@items) end @@ -32,8 +32,8 @@ module OpenFoodNetwork columns = [column1, column2] subject = OrderGrouper.new rules, columns - rules.should_receive(:clone).and_return(rules) - subject.build_tree(@items, rules).should == @items + expect(rules).to receive(:clone).and_return(rules) + expect(subject.build_tree(@items, rules)).to eq(@items) end end @@ -52,42 +52,42 @@ module OpenFoodNetwork it "builds branches by removing a rule from 'rules' and running group_and_sort" do subject = OrderGrouper.new @rules, @columns - @rules.should_receive(:clone).and_return(@rules) - @rules.should_receive(:delete_at).with(0) + expect(@rules).to receive(:clone).and_return(@rules) + expect(@rules).to receive(:delete_at).with(0) grouped_tree = double(:grouped_tree) - subject.should_receive(:group_and_sort).and_return(grouped_tree) + expect(subject).to receive(:group_and_sort).and_return(grouped_tree) - subject.build_tree(@items, @rules).should == grouped_tree + expect(subject.build_tree(@items, @rules)).to eq(grouped_tree) end it "separates the first rule from rules before sending to group_and_sort" do subject = OrderGrouper.new @rules, @columns grouped_tree = double(:grouped_tree) - subject.should_receive(:group_and_sort).with(@rule1, @rules[1..-1], @items).and_return(grouped_tree) + expect(subject).to receive(:group_and_sort).with(@rule1, @rules[1..-1], @items).and_return(grouped_tree) - subject.build_tree(@items, @rules).should == grouped_tree + expect(subject.build_tree(@items, @rules)).to eq(grouped_tree) end it "should group, then sort, send each group to build_tree, and return a branch" do summary_columns_object = double(:summary_columns) - @rule1.stub(:[]).with(:summary_columns) { summary_columns_object } + allow(@rule1).to receive(:[]).with(:summary_columns) { summary_columns_object } subject = OrderGrouper.new @rules, @columns number_of_categories = 3 groups = double(:groups) - @items.should_receive(:group_by).and_return(groups) + expect(@items).to receive(:group_by).and_return(groups) sorted_groups = {} 1.upto(number_of_categories) { |i| sorted_groups[i] = double(:group, name: "Group "+ i.to_s ) } - groups.should_receive(:sort_by).and_return(sorted_groups) + expect(groups).to receive(:sort_by).and_return(sorted_groups) group = { group1: 1, group2: 2, group3: 3 } - subject.should_receive(:build_tree).exactly(number_of_categories).times.and_return(group) + expect(subject).to receive(:build_tree).exactly(number_of_categories).times.and_return(group) group_tree = {} 1.upto(number_of_categories) { |i| group_tree[i] = group } 1.upto(number_of_categories) { |i| group_tree[i][:summary_row] = summary_columns_object } - subject.group_and_sort(@rule1, @remaining_rules, @items).should == group_tree + expect(subject.group_and_sort(@rule1, @remaining_rules, @items)).to eq(group_tree) end end @@ -114,10 +114,10 @@ module OpenFoodNetwork it "should return columns when given an Array" do subject = OrderGrouper.new @rules, @columns - @column1.should_receive(:call) - @column2.should_receive(:call) + expect(@column1).to receive(:call) + expect(@column2).to receive(:call) - subject.build_table(@items1).should == [["Column1", "Column2"]] + expect(subject.build_table(@items1)).to eq([["Column1", "Column2"]]) end it "should return a row for each key-value pair when given a Hash" do @@ -129,7 +129,7 @@ module OpenFoodNetwork expected_return = [] groups.length.times { expected_return << ["Column1", "Column2"] } - subject.build_table(groups).should == expected_return + expect(subject.build_table(groups)).to eq(expected_return) end it "should return an extra row when a :summary_row key appears in a given Hash" do @@ -145,7 +145,7 @@ module OpenFoodNetwork expected_return << ["Column1", "Column2"] end end - subject.build_table(groups).should == expected_return + expect(subject.build_table(groups)).to eq(expected_return) end end end diff --git a/spec/lib/open_food_network/packing_report_spec.rb b/spec/lib/open_food_network/packing_report_spec.rb index ba6c0a1e6c..6bbb1b2687 100644 --- a/spec/lib/open_food_network/packing_report_spec.rb +++ b/spec/lib/open_food_network/packing_report_spec.rb @@ -19,13 +19,13 @@ module OpenFoodNetwork it "fetches completed orders" do o2 = create(:order) o2.line_items << build(:line_item) - subject.table_items.should == [li1] + expect(subject.table_items).to eq([li1]) end it "does not show cancelled orders" do o2 = create(:order, state: "canceled", completed_at: 1.day.ago) o2.line_items << build(:line_item_with_shipment) - subject.table_items.should == [li1] + expect(subject.table_items).to eq([li1]) end end @@ -49,8 +49,8 @@ module OpenFoodNetwork end it "shows line items supplied by my producers, with names hidden" do - subject.table_items.should == [li2] - subject.table_items.first.order.bill_address.firstname.should == "HIDDEN" + expect(subject.table_items).to eq([li2]) + expect(subject.table_items.first.order.bill_address.firstname).to eq("HIDDEN") end end @@ -63,7 +63,7 @@ module OpenFoodNetwork end it "shows line items supplied by my producers, with names hidden" do - subject.table_items.should == [] + expect(subject.table_items).to eq([]) end end end @@ -81,15 +81,15 @@ module OpenFoodNetwork d2.enterprise_roles.create!(user: create(:user)) o2 = create(:order, distributor: d2, completed_at: 1.day.ago) o2.line_items << build(:line_item_with_shipment) - subject.table_items.should == [li1] + expect(subject.table_items).to eq([li1]) end it "only shows the selected order cycle" do oc2 = create(:simple_order_cycle) o2 = create(:order, distributor: d1, order_cycle: oc2) o2.line_items << build(:line_item) - subject.stub(:params).and_return(order_cycle_id_in: oc1.id) - subject.table_items.should == [li1] + allow(subject).to receive(:params).and_return(order_cycle_id_in: oc1.id) + expect(subject.table_items).to eq([li1]) end end end diff --git a/spec/lib/open_food_network/permissions_spec.rb b/spec/lib/open_food_network/permissions_spec.rb index 90480acf44..0c8e9ee018 100644 --- a/spec/lib/open_food_network/permissions_spec.rb +++ b/spec/lib/open_food_network/permissions_spec.rb @@ -81,12 +81,12 @@ module OpenFoodNetwork let(:e) { double(:enterprise) } it "returns managed and related enterprises with edit_profile permission" do - permissions. - should_receive(:managed_and_related_enterprises_granting). + expect(permissions). + to receive(:managed_and_related_enterprises_granting). with(:edit_profile). and_return([e]) - permissions.editable_enterprises.should == [e] + expect(permissions.editable_enterprises).to eq([e]) end end @@ -95,11 +95,11 @@ module OpenFoodNetwork let(:e2) { create(:supplier_enterprise) } it "compiles the list from variant_override_enterprises_per_hub" do - permissions.stub(:variant_override_enterprises_per_hub) do + allow(permissions).to receive(:variant_override_enterprises_per_hub) do {1 => [e1.id], 2 => [e1.id, e2.id]} end - permissions.variant_override_producers.should match_array [e1, e2] + expect(permissions.variant_override_producers).to match_array [e1, e2] end end @@ -111,30 +111,33 @@ module OpenFoodNetwork } before do - permissions.stub(:managed_enterprises) { Enterprise.where(id: hub.id) } - permissions.stub(:admin?) { false } + allow(permissions).to receive(:managed_enterprises) { Enterprise.where(id: hub.id) } + allow(permissions).to receive(:admin?) { false } end it "returns enterprises as hub_id => [producer, ...]" do - permissions.variant_override_enterprises_per_hub.should == + expect(permissions.variant_override_enterprises_per_hub).to eq( {hub.id => [producer.id]} + ) end it "returns only permissions relating to managed hubs" do create(:enterprise_relationship, parent: e1, child: e2, permissions_list: [:create_variant_overrides]) - permissions.variant_override_enterprises_per_hub.should == + expect(permissions.variant_override_enterprises_per_hub).to eq( {hub.id => [producer.id]} + ) end it "returns only create_variant_overrides permissions" do - permissions.stub(:managed_enterprises) { Enterprise.where(id: [hub, e2]) } + allow(permissions).to receive(:managed_enterprises) { Enterprise.where(id: [hub, e2]) } create(:enterprise_relationship, parent: e1, child: e2, permissions_list: [:manage_products]) - permissions.variant_override_enterprises_per_hub.should == + expect(permissions.variant_override_enterprises_per_hub).to eq( {hub.id => [producer.id]} + ) end describe "hubs connected to the user by relationships only" do @@ -144,17 +147,17 @@ module OpenFoodNetwork } before do - permissions.stub(:managed_enterprises) { Enterprise.where(id: producer_managed.id) } + allow(permissions).to receive(:managed_enterprises) { Enterprise.where(id: producer_managed.id) } end it "does not allow the user to create variant overrides for the hub" do - permissions.variant_override_enterprises_per_hub.should == {} + expect(permissions.variant_override_enterprises_per_hub).to eq({}) end end it "does not return managed producers (ie. only uses explicitly granted VO permissions)" do producer2 = create(:supplier_enterprise) - permissions.stub(:managed_enterprises) { Enterprise.where(id: [hub, producer2]) } + allow(permissions).to receive(:managed_enterprises) { Enterprise.where(id: [hub, producer2]) } expect(permissions.variant_override_enterprises_per_hub[hub.id]).to_not include producer2.id end @@ -171,19 +174,19 @@ module OpenFoodNetwork let!(:p2) { create(:simple_product, supplier: create(:supplier_enterprise) ) } before do - permissions.stub(:managed_enterprise_products) { Spree::Product.where('1=0') } + allow(permissions).to receive(:managed_enterprise_products) { Spree::Product.where('1=0') } allow(permissions).to receive(:related_enterprises_granting).with(:manage_products) { Enterprise.where("1=0") } end it "returns products produced by managed enterprises" do - permissions.stub(:managed_enterprise_products) { Spree::Product.where(id: p1) } - permissions.editable_products.should == [p1] + allow(permissions).to receive(:managed_enterprise_products) { Spree::Product.where(id: p1) } + expect(permissions.editable_products).to eq([p1]) end it "returns products produced by permitted enterprises" do allow(permissions).to receive(:related_enterprises_granting). with(:manage_products) { Enterprise.where(id: p2.supplier) } - permissions.editable_products.should == [p2] + expect(permissions.editable_products).to eq([p2]) end end @@ -193,26 +196,26 @@ module OpenFoodNetwork let!(:p3) { create(:simple_product, supplier: create(:supplier_enterprise) ) } before do - permissions.stub(:managed_enterprise_products) { Spree::Product.where("1=0") } + allow(permissions).to receive(:managed_enterprise_products) { Spree::Product.where("1=0") } allow(permissions).to receive(:related_enterprises_granting).with(:manage_products) { Enterprise.where("1=0") } allow(permissions).to receive(:related_enterprises_granting).with(:add_to_order_cycle) { Enterprise.where("1=0") } end it "returns products produced by managed enterprises" do - permissions.stub(:managed_enterprise_products) { Spree::Product.where(id: p1) } - permissions.visible_products.should == [p1] + allow(permissions).to receive(:managed_enterprise_products) { Spree::Product.where(id: p1) } + expect(permissions.visible_products).to eq([p1]) end it "returns products produced by enterprises that have granted manage products" do allow(permissions).to receive(:related_enterprises_granting). with(:manage_products) { Enterprise.where(id: p2.supplier) } - permissions.visible_products.should == [p2] + expect(permissions.visible_products).to eq([p2]) end it "returns products produced by enterprises that have granted P-OC" do allow(permissions).to receive(:related_enterprises_granting). with(:add_to_order_cycle) { Enterprise.where(id: p3.supplier) } - permissions.visible_products.should == [p3] + expect(permissions.visible_products).to eq([p3]) end end @@ -220,12 +223,12 @@ module OpenFoodNetwork let(:e) { double(:enterprise) } it "returns managed and related enterprises with manage_products permission" do - permissions. - should_receive(:managed_and_related_enterprises_granting). + expect(permissions). + to receive(:managed_and_related_enterprises_granting). with(:manage_products). and_return([e]) - permissions.managed_product_enterprises.should == [e] + expect(permissions.managed_product_enterprises).to eq([e]) end end @@ -235,32 +238,32 @@ module OpenFoodNetwork let!(:er) { create(:enterprise_relationship, parent: e1, child: e2, permissions_list: [permission]) } it "returns the enterprises" do - permissions.stub(:managed_enterprises) { e2 } - permissions.send(:related_enterprises_granting, permission).should == [e1] + allow(permissions).to receive(:managed_enterprises) { e2 } + expect(permissions.send(:related_enterprises_granting, permission)).to eq([e1]) end it "returns an empty array when there are none" do - permissions.stub(:managed_enterprises) { e1 } - permissions.send(:related_enterprises_granting, permission).should == [] + allow(permissions).to receive(:managed_enterprises) { e1 } + expect(permissions.send(:related_enterprises_granting, permission)).to eq([]) end end describe "finding enterprises that are managed or with a particular permission" do before do - permissions.stub(:managed_enterprises) { Enterprise.where('1=0') } - permissions.stub(:related_enterprises_granting) { Enterprise.where('1=0') } - permissions.stub(:admin?) { false } + allow(permissions).to receive(:managed_enterprises) { Enterprise.where('1=0') } + allow(permissions).to receive(:related_enterprises_granting) { Enterprise.where('1=0') } + allow(permissions).to receive(:admin?) { false } end it "returns managed enterprises" do - permissions.should_receive(:managed_enterprises) { Enterprise.where(id: e1) } - permissions.send(:managed_and_related_enterprises_granting, permission).should == [e1] + expect(permissions).to receive(:managed_enterprises) { Enterprise.where(id: e1) } + expect(permissions.send(:managed_and_related_enterprises_granting, permission)).to eq([e1]) end it "returns permitted enterprises" do - permissions.should_receive(:related_enterprises_granting).with(permission). + expect(permissions).to receive(:related_enterprises_granting).with(permission). and_return(Enterprise.where(id: e2)) - permissions.send(:managed_and_related_enterprises_granting, permission).should == [e2] + expect(permissions.send(:managed_and_related_enterprises_granting, permission)).to eq([e2]) end end @@ -274,12 +277,12 @@ module OpenFoodNetwork let!(:producer) { create(:supplier_enterprise) } before do - permissions.stub(:coordinated_order_cycles) { Enterprise.where("1=0") } + allow(permissions).to receive(:coordinated_order_cycles) { Enterprise.where("1=0") } end context "as the hub through which the order was placed" do before do - permissions.stub(:managed_enterprises) { Enterprise.where(id: distributor) } + allow(permissions).to receive(:managed_enterprises) { Enterprise.where(id: distributor) } end it "should let me see the order" do @@ -289,8 +292,8 @@ module OpenFoodNetwork context "as the coordinator of the order cycle through which the order was placed" do before do - permissions.stub(:managed_enterprises) { Enterprise.where(id: coordinator) } - permissions.stub(:coordinated_order_cycles) { OrderCycle.where(id: order_cycle) } + allow(permissions).to receive(:managed_enterprises) { Enterprise.where(id: coordinator) } + allow(permissions).to receive(:coordinated_order_cycles) { OrderCycle.where(id: order_cycle) } end it "should let me see the order" do @@ -300,7 +303,7 @@ module OpenFoodNetwork context "as a producer which has granted P-OC to the distributor of an order" do before do - permissions.stub(:managed_enterprises) { Enterprise.where(id: producer) } + allow(permissions).to receive(:managed_enterprises) { Enterprise.where(id: producer) } create(:enterprise_relationship, parent: producer, child: distributor, permissions_list: [:add_to_order_cycle]) end @@ -324,7 +327,7 @@ module OpenFoodNetwork context "as an enterprise that is a distributor in the order cycle, but not the distributor of the order" do before do - permissions.stub(:managed_enterprises) { Enterprise.where(id: random_enterprise) } + allow(permissions).to receive(:managed_enterprises) { Enterprise.where(id: random_enterprise) } end it "should not let me see the order" do @@ -344,12 +347,12 @@ module OpenFoodNetwork let!(:producer) { create(:supplier_enterprise) } before do - permissions.stub(:coordinated_order_cycles) { Enterprise.where("1=0") } + allow(permissions).to receive(:coordinated_order_cycles) { Enterprise.where("1=0") } end context "as the hub through which the parent order was placed" do before do - permissions.stub(:managed_enterprises) { Enterprise.where(id: distributor) } + allow(permissions).to receive(:managed_enterprises) { Enterprise.where(id: distributor) } end it "should let me see the line_items" do @@ -359,8 +362,8 @@ module OpenFoodNetwork context "as the coordinator of the order cycle through which the parent order was placed" do before do - permissions.stub(:managed_enterprises) { Enterprise.where(id: coordinator) } - permissions.stub(:coordinated_order_cycles) { OrderCycle.where(id: order_cycle) } + allow(permissions).to receive(:managed_enterprises) { Enterprise.where(id: coordinator) } + allow(permissions).to receive(:coordinated_order_cycles) { OrderCycle.where(id: order_cycle) } end it "should let me see the line_items" do @@ -370,7 +373,7 @@ module OpenFoodNetwork context "as the manager producer which has granted P-OC to the distributor of the parent order" do before do - permissions.stub(:managed_enterprises) { Enterprise.where(id: producer) } + allow(permissions).to receive(:managed_enterprises) { Enterprise.where(id: producer) } create(:enterprise_relationship, parent: producer, child: distributor, permissions_list: [:add_to_order_cycle]) line_item1.product.supplier = producer @@ -386,7 +389,7 @@ module OpenFoodNetwork context "as an enterprise that is a distributor in the order cycle, but not the distributor of the parent order" do before do - permissions.stub(:managed_enterprises) { Enterprise.where(id: random_enterprise) } + allow(permissions).to receive(:managed_enterprises) { Enterprise.where(id: random_enterprise) } end it "should not let me see the line_items" do diff --git a/spec/lib/open_food_network/products_and_inventory_report_spec.rb b/spec/lib/open_food_network/products_and_inventory_report_spec.rb index b70d542d15..a0efbdddd8 100644 --- a/spec/lib/open_food_network/products_and_inventory_report_spec.rb +++ b/spec/lib/open_food_network/products_and_inventory_report_spec.rb @@ -13,7 +13,7 @@ module OpenFoodNetwork end it "Should return headers" do - subject.header.should == [ + expect(subject.header).to eq([ "Supplier", "Producer Suburb", "Product", @@ -24,7 +24,7 @@ module OpenFoodNetwork "Group Buy Unit Quantity", "Amount", "SKU" - ] + ]) end it "should build a table from a list of variants" do @@ -32,15 +32,15 @@ module OpenFoodNetwork full_name: "Variant Name", count_on_hand: 10, price: 100) - variant.stub_chain(:product, :supplier, :name).and_return("Supplier") - variant.stub_chain(:product, :supplier, :address, :city).and_return("A city") - variant.stub_chain(:product, :name).and_return("Product Name") - variant.stub_chain(:product, :properties).and_return [double(name: "property1"), double(name: "property2")] - variant.stub_chain(:product, :taxons).and_return [double(name: "taxon1"), double(name: "taxon2")] - variant.stub_chain(:product, :group_buy_unit_size).and_return(21) - subject.stub(:variants).and_return [variant] + allow(variant).to receive_message_chain(:product, :supplier, :name).and_return("Supplier") + allow(variant).to receive_message_chain(:product, :supplier, :address, :city).and_return("A city") + allow(variant).to receive_message_chain(:product, :name).and_return("Product Name") + allow(variant).to receive_message_chain(:product, :properties).and_return [double(name: "property1"), double(name: "property2")] + allow(variant).to receive_message_chain(:product, :taxons).and_return [double(name: "taxon1"), double(name: "taxon2")] + allow(variant).to receive_message_chain(:product, :group_buy_unit_size).and_return(21) + allow(subject).to receive(:variants).and_return [variant] - subject.table.should == [[ + expect(subject.table).to eq([[ "Supplier", "A city", "Product Name", @@ -51,13 +51,13 @@ module OpenFoodNetwork 21, "", "sku" - ]] + ]]) end it "fetches variants for some params" do - subject.should_receive(:child_variants).and_return ["children"] - subject.should_receive(:filter).with(['children']).and_return ["filter_children"] - subject.variants.should == ["filter_children"] + expect(subject).to receive(:child_variants).and_return ["children"] + expect(subject).to receive(:filter).with(['children']).and_return ["filter_children"] + expect(subject.variants).to eq(["filter_children"]) end end @@ -81,7 +81,7 @@ module OpenFoodNetwork variant_1 = product1.variants.first variant_2 = create(:variant, product: product1) - subject.child_variants.should match_array [variant_1, variant_2] + expect(subject.child_variants).to match_array [variant_1, variant_2] end it "should only return variants managed by the user" do @@ -90,7 +90,7 @@ module OpenFoodNetwork variant_1 = product1.variants.first variant_2 = product2.variants.first - subject.child_variants.should == [variant_2] + expect(subject.child_variants).to eq([variant_2]) end end @@ -100,21 +100,21 @@ module OpenFoodNetwork product1 = create(:simple_product, supplier: supplier) product2 = create(:simple_product, supplier: supplier) - subject.filter(Spree::Variant.scoped).should match_array [product1.master, product1.variants.first, product2.master, product2.variants.first] + expect(subject.filter(Spree::Variant.scoped)).to match_array [product1.master, product1.variants.first, product2.master, product2.variants.first] end it "should filter deleted products" do product1 = create(:simple_product, supplier: supplier) product2 = create(:simple_product, supplier: supplier) product2.destroy - subject.filter(Spree::Variant.scoped).should match_array [product1.master, product1.variants.first] + expect(subject.filter(Spree::Variant.scoped)).to match_array [product1.master, product1.variants.first] end describe "based on report type" do it "returns only variants on hand" do product1 = create(:simple_product, supplier: supplier, on_hand: 99) product2 = create(:simple_product, supplier: supplier, on_hand: 0) - subject.stub(:params).and_return(report_type: 'inventory') - subject.filter(variants).should == [product1.variants.first] + allow(subject).to receive(:params).and_return(report_type: 'inventory') + expect(subject.filter(variants)).to eq([product1.variants.first]) end end it "filters to a specific supplier" do @@ -122,8 +122,8 @@ module OpenFoodNetwork product1 = create(:simple_product, supplier: supplier) product2 = create(:simple_product, supplier: supplier2) - subject.stub(:params).and_return(supplier_id: supplier.id) - subject.filter(variants).should == [product1.variants.first] + allow(subject).to receive(:params).and_return(supplier_id: supplier.id) + expect(subject.filter(variants)).to eq([product1.variants.first]) end it "filters to a specific distributor" do distributor = create(:distributor_enterprise) @@ -131,8 +131,8 @@ module OpenFoodNetwork product2 = create(:simple_product, supplier: supplier) order_cycle = create(:simple_order_cycle, suppliers: [supplier], distributors: [distributor], variants: [product2.variants.first]) - subject.stub(:params).and_return(distributor_id: distributor.id) - subject.filter(variants).should == [product2.variants.first] + allow(subject).to receive(:params).and_return(distributor_id: distributor.id) + expect(subject.filter(variants)).to eq([product2.variants.first]) end it "ignores variant overrides without filter" do @@ -166,8 +166,8 @@ module OpenFoodNetwork product2 = create(:simple_product, supplier: supplier) order_cycle = create(:simple_order_cycle, suppliers: [supplier], distributors: [distributor], variants: [product1.variants.first]) - subject.stub(:params).and_return(order_cycle_id: order_cycle.id) - subject.filter(variants).should == [product1.variants.first] + allow(subject).to receive(:params).and_return(order_cycle_id: order_cycle.id) + expect(subject.filter(variants)).to eq([product1.variants.first]) end it "should do all the filters at once" do @@ -176,7 +176,7 @@ module OpenFoodNetwork product2 = create(:simple_product, supplier: supplier) order_cycle = create(:simple_order_cycle, suppliers: [supplier], distributors: [distributor], variants: [product1.variants.first]) - subject.stub(:params).and_return( + allow(subject).to receive(:params).and_return( order_cycle_id: order_cycle.id, supplier_id: supplier.id, distributor_id: distributor.id, diff --git a/spec/lib/open_food_network/products_renderer_spec.rb b/spec/lib/open_food_network/products_renderer_spec.rb index 330ad57062..47564f3aec 100644 --- a/spec/lib/open_food_network/products_renderer_spec.rb +++ b/spec/lib/open_food_network/products_renderer_spec.rb @@ -24,15 +24,15 @@ module OpenFoodNetwork end it "sorts products by the distributor's preferred taxon list" do - distributor.stub(:preferred_shopfront_taxon_order) {"#{t1.id},#{t2.id}"} + allow(distributor).to receive(:preferred_shopfront_taxon_order) {"#{t1.id},#{t2.id}"} products = pr.send(:load_products) - products.should == [p2, p4, p1, p3] + expect(products).to eq([p2, p4, p1, p3]) end it "alphabetizes products by name when taxon list is not set" do - distributor.stub(:preferred_shopfront_taxon_order) {""} + allow(distributor).to receive(:preferred_shopfront_taxon_order) {""} products = pr.send(:load_products) - products.should == [p1, p2, p3, p4] + expect(products).to eq([p1, p2, p3, p4]) end end @@ -45,34 +45,34 @@ module OpenFoodNetwork end it "only returns products for the current order cycle" do - pr.products_json.should include product.name + expect(pr.products_json).to include product.name end it "doesn't return products not in stock" do variant.update_attribute(:on_demand, false) variant.update_attribute(:on_hand, 0) - pr.products_json.should_not include product.name + expect(pr.products_json).not_to include product.name end it "strips html from description" do product.update_attribute(:description, "turtles frogs") json = pr.products_json - json.should include "frogs" - json.should_not include " {distributors: Set.new([e2.id]), producers: Set.new([e1.id, e2.id])}, e2.id => {distributors: Set.new([e2.id]), producers: Set.new([e2.id, e1.id])}} + ) end it "finds inactive enterprises by default" do e1.update_attribute :sells, 'unspecified' - EnterpriseRelationship.relatives[e2.id][:producers].should == Set.new([e1.id]) + expect(EnterpriseRelationship.relatives[e2.id][:producers]).to eq(Set.new([e1.id])) end it "does not find inactive enterprises when requested" do e1.update_attribute :sells, 'unspecified' - EnterpriseRelationship.relatives(true)[e2.id][:producers].should be_empty + expect(EnterpriseRelationship.relatives(true)[e2.id][:producers]).to be_empty end it "does not show duplicates" do er_reverse - EnterpriseRelationship.relatives[e2.id][:producers].should == Set.new([e1.id]) + expect(EnterpriseRelationship.relatives[e2.id][:producers]).to eq(Set.new([e1.id])) end end diff --git a/spec/models/enterprise_spec.rb b/spec/models/enterprise_spec.rb index 7a46867b38..1a31a4d5cb 100644 --- a/spec/models/enterprise_spec.rb +++ b/spec/models/enterprise_spec.rb @@ -17,10 +17,10 @@ describe Enterprise do end describe "associations" do - it { should belong_to(:owner) } - it { should have_many(:supplied_products) } - it { should have_many(:distributed_orders) } - it { should belong_to(:address) } + it { is_expected.to belong_to(:owner) } + it { is_expected.to have_many(:supplied_products) } + it { is_expected.to have_many(:distributed_orders) } + it { is_expected.to belong_to(:address) } it "destroys enterprise roles upon its own demise" do e = create(:enterprise) @@ -29,7 +29,7 @@ describe Enterprise do role = e.enterprise_roles.first e.destroy - EnterpriseRole.where(id: role.id).should be_empty + expect(EnterpriseRole.where(id: role.id)).to be_empty end xit "destroys supplied products upon destroy" do @@ -38,7 +38,7 @@ describe Enterprise do s.destroy - Spree::Product.where(id: p.id).should be_empty + expect(Spree::Product.where(id: p.id)).to be_empty end it "destroys relationships upon destroy" do @@ -49,7 +49,7 @@ describe Enterprise do e.destroy - EnterpriseRelationship.where(id: [er1, er2]).should be_empty + expect(EnterpriseRelationship.where(id: [er1, er2])).to be_empty end describe "relationships to other enterprises" do @@ -61,7 +61,7 @@ describe Enterprise do let!(:er2) { create(:enterprise_relationship, parent_id: e.id, child_id: c.id) } it "finds relatives" do - e.relatives.should match_array [p, c] + expect(e.relatives).to match_array [p, c] end it "finds relatives_including_self" do @@ -69,14 +69,14 @@ describe Enterprise do end it "scopes relatives to visible distributors" do - e.should_receive(:relatives_including_self).and_return(relatives = []) - relatives.should_receive(:is_distributor).and_return relatives + expect(e).to receive(:relatives_including_self).and_return(relatives = []) + expect(relatives).to receive(:is_distributor).and_return relatives e.distributors end it "scopes relatives to visible producers" do - e.should_receive(:relatives_including_self).and_return(relatives = []) - relatives.should_receive(:is_primary_producer).and_return relatives + expect(e).to receive(:relatives_including_self).and_return(relatives = []) + expect(relatives).to receive(:is_primary_producer).and_return relatives e.suppliers end end @@ -112,9 +112,9 @@ describe Enterprise do describe "validations" do subject { FactoryBot.create(:distributor_enterprise) } - it { should validate_presence_of(:name) } - it { should validate_uniqueness_of(:permalink) } - it { should ensure_length_of(:description).is_at_most(255) } + it { is_expected.to validate_presence_of(:name) } + it { is_expected.to validate_uniqueness_of(:permalink) } + it { is_expected.to ensure_length_of(:description).is_at_most(255) } it "requires an owner" do expect{ @@ -140,11 +140,11 @@ describe Enterprise do end it "does not prohibit the saving of an enterprise with no name clash" do - enterprise.should be_valid + expect(enterprise).to be_valid end it "sets the enterprise contact to the owner by default" do - enterprise.contact.should eq enterprise.owner + expect(enterprise.contact).to eq enterprise.owner end end @@ -187,10 +187,10 @@ describe Enterprise do describe "delegations" do #subject { FactoryBot.create(:distributor_enterprise, :address => FactoryBot.create(:address)) } - it { should delegate(:latitude).to(:address) } - it { should delegate(:longitude).to(:address) } - it { should delegate(:city).to(:address) } - it { should delegate(:state_name).to(:address) } + it { is_expected.to delegate(:latitude).to(:address) } + it { is_expected.to delegate(:longitude).to(:address) } + it { is_expected.to delegate(:city).to(:address) } + it { is_expected.to delegate(:state_name).to(:address) } end describe "callbacks" do @@ -208,7 +208,7 @@ describe Enterprise do it 'find visible enterprises' do d1 = create(:distributor_enterprise, visible: false) s1 = create(:supplier_enterprise) - Enterprise.visible.should == [s1] + expect(Enterprise.visible).to eq([s1]) end end @@ -229,24 +229,24 @@ describe Enterprise do it "does not show enterprises with no payment methods" do create(:shipping_method, distributors: [e]) - Enterprise.ready_for_checkout.should_not include e + expect(Enterprise.ready_for_checkout).not_to include e end it "does not show enterprises with no shipping methods" do create(:payment_method, distributors: [e]) - Enterprise.ready_for_checkout.should_not include e + expect(Enterprise.ready_for_checkout).not_to include e end it "does not show enterprises with unavailable payment methods" do create(:shipping_method, distributors: [e]) create(:payment_method, distributors: [e], active: false) - Enterprise.ready_for_checkout.should_not include e + expect(Enterprise.ready_for_checkout).not_to include e end it "shows enterprises with available payment and shipping methods" do create(:shipping_method, distributors: [e]) create(:payment_method, distributors: [e]) - Enterprise.ready_for_checkout.should include e + expect(Enterprise.ready_for_checkout).to include e end end @@ -255,24 +255,24 @@ describe Enterprise do it "shows enterprises with no payment methods" do create(:shipping_method, distributors: [e]) - Enterprise.not_ready_for_checkout.should include e + expect(Enterprise.not_ready_for_checkout).to include e end it "shows enterprises with no shipping methods" do create(:payment_method, distributors: [e]) - Enterprise.not_ready_for_checkout.should include e + expect(Enterprise.not_ready_for_checkout).to include e end it "shows enterprises with unavailable payment methods" do create(:shipping_method, distributors: [e]) create(:payment_method, distributors: [e], active: false) - Enterprise.not_ready_for_checkout.should include e + expect(Enterprise.not_ready_for_checkout).to include e end it "does not show enterprises with available payment and shipping methods" do create(:shipping_method, distributors: [e]) create(:payment_method, distributors: [e]) - Enterprise.not_ready_for_checkout.should_not include e + expect(Enterprise.not_ready_for_checkout).not_to include e end end @@ -281,24 +281,24 @@ describe Enterprise do it "returns false for enterprises with no payment methods" do create(:shipping_method, distributors: [e]) - e.reload.should_not be_ready_for_checkout + expect(e.reload).not_to be_ready_for_checkout end it "returns false for enterprises with no shipping methods" do create(:payment_method, distributors: [e]) - e.reload.should_not be_ready_for_checkout + expect(e.reload).not_to be_ready_for_checkout end it "returns false for enterprises with unavailable payment methods" do create(:shipping_method, distributors: [e]) create(:payment_method, distributors: [e], active: false) - e.reload.should_not be_ready_for_checkout + expect(e.reload).not_to be_ready_for_checkout end it "returns true for enterprises with available payment and shipping methods" do create(:shipping_method, distributors: [e]) create(:payment_method, distributors: [e]) - e.reload.should be_ready_for_checkout + expect(e.reload).to be_ready_for_checkout end end @@ -308,7 +308,7 @@ describe Enterprise do d = create(:distributor_enterprise) p = create(:product) create(:simple_order_cycle, suppliers: [s], distributors: [d], variants: [p.master]) - Enterprise.distributors_with_active_order_cycles.should == [d] + expect(Enterprise.distributors_with_active_order_cycles).to eq([d]) end it "should not find inactive distributors by order cycles" do @@ -316,7 +316,7 @@ describe Enterprise do d = create(:distributor_enterprise) p = create(:product) create(:simple_order_cycle, :orders_open_at => 10.days.from_now, orders_close_at: 17.days.from_now, suppliers: [s], distributors: [d], variants: [p.master]) - Enterprise.distributors_with_active_order_cycles.should_not include d + expect(Enterprise.distributors_with_active_order_cycles).not_to include d end end @@ -325,7 +325,7 @@ describe Enterprise do s = create(:supplier_enterprise) p = create(:simple_product, supplier: s) - Enterprise.supplying_variant_in([p.master]).should == [s] + expect(Enterprise.supplying_variant_in([p.master])).to eq([s]) end it "finds producers by supply of variant" do @@ -333,7 +333,7 @@ describe Enterprise do p = create(:simple_product, supplier: s) v = create(:variant, product: p) - Enterprise.supplying_variant_in([v]).should == [s] + expect(Enterprise.supplying_variant_in([v])).to eq([s]) end it "returns multiple enterprises when given multiple variants" do @@ -342,7 +342,7 @@ describe Enterprise do p1 = create(:simple_product, supplier: s1) p2 = create(:simple_product, supplier: s2) - Enterprise.supplying_variant_in([p1.master, p2.master]).should match_array [s1, s2] + expect(Enterprise.supplying_variant_in([p1.master, p2.master])).to match_array [s1, s2] end it "does not return duplicates" do @@ -350,7 +350,7 @@ describe Enterprise do p1 = create(:simple_product, supplier: s) p2 = create(:simple_product, supplier: s) - Enterprise.supplying_variant_in([p1.master, p2.master]).should == [s] + expect(Enterprise.supplying_variant_in([p1.master, p2.master])).to eq([s]) end end @@ -360,13 +360,13 @@ describe Enterprise do it "returns enterprises distributing via an order cycle" do order_cycle = create(:simple_order_cycle, distributors: [distributor], variants: [product.master]) - Enterprise.distributing_products(product).should == [distributor] + expect(Enterprise.distributing_products(product)).to eq([distributor]) end it "does not return duplicate enterprises" do another_product = create(:product) order_cycle = create(:simple_order_cycle, distributors: [distributor], variants: [product.master, another_product.master]) - Enterprise.distributing_products([product, another_product]).should == [distributor] + expect(Enterprise.distributing_products([product, another_product])).to eq([distributor]) end end @@ -379,8 +379,8 @@ describe Enterprise do e1.enterprise_roles.build(user: user).save enterprises = Enterprise.managed_by user - enterprises.count.should == 1 - enterprises.should include e1 + expect(enterprises.count).to eq(1) + expect(enterprises).to include e1 end it "shows all enterprises for admin user" do @@ -389,9 +389,9 @@ describe Enterprise do e2 = create(:enterprise) enterprises = Enterprise.managed_by user - enterprises.count.should == 2 - enterprises.should include e1 - enterprises.should include e2 + expect(enterprises.count).to eq(2) + expect(enterprises).to include e1 + expect(enterprises).to include e2 end end end @@ -459,11 +459,11 @@ describe Enterprise do def should_have_enterprise_relationship(opts={}) er = EnterpriseRelationship.where(parent_id: opts[:from], child_id: opts[:to]).last - er.should_not be_nil + expect(er).not_to be_nil if opts[:with] == :all_permissions - er.permissions.map(&:name).should match_array ['add_to_order_cycle', 'manage_products', 'edit_profile', 'create_variant_overrides'] + expect(er.permissions.map(&:name)).to match_array ['add_to_order_cycle', 'manage_products', 'edit_profile', 'create_variant_overrides'] elsif opts.key? :with - er.permissions.map(&:name).should match_array opts[:with].map(&:to_s) + expect(er.permissions.map(&:name)).to match_array opts[:with].map(&:to_s) end end end @@ -476,7 +476,7 @@ describe Enterprise do variant = product.variants.first create(:simple_order_cycle, distributors: [distributor], variants: [variant]) - distributor.distributed_variants.should match_array [product.master, variant] + expect(distributor.distributed_variants).to match_array [product.master, variant] end end @@ -489,13 +489,13 @@ describe Enterprise do let(:product2) { create(:simple_product, primary_taxon: taxon1, taxons: [taxon1, taxon2]) } it "gets all taxons of all distributed products" do - Spree::Product.stub(:in_distributor).and_return [product1, product2] - distributor.distributed_taxons.should match_array [taxon1, taxon2] + allow(Spree::Product).to receive(:in_distributor).and_return [product1, product2] + expect(distributor.distributed_taxons).to match_array [taxon1, taxon2] end it "gets all taxons of all supplied products" do - Spree::Product.stub(:in_supplier).and_return [product1, product2] - supplier.supplied_taxons.should match_array [taxon1, taxon2] + allow(Spree::Product).to receive(:in_supplier).and_return [product1, product2] + expect(supplier.supplied_taxons).to match_array [taxon1, taxon2] end end @@ -508,9 +508,9 @@ describe Enterprise do } it "strips http from url fields" do - distributor.website.should == "www.google.com" - distributor.facebook.should == "www.facebook.com/roger" - distributor.linkedin.should == "linkedin.com" + expect(distributor.website).to eq("www.google.com") + expect(distributor.facebook).to eq("www.facebook.com/roger") + expect(distributor.linkedin).to eq("linkedin.com") end end @@ -520,9 +520,9 @@ describe Enterprise do it "sets producer properties" do supplier.set_producer_property 'Organic Certified', 'NASAA 12345' - supplier.producer_properties.count.should == 1 - supplier.producer_properties.first.value.should == 'NASAA 12345' - supplier.producer_properties.first.property.presentation.should == 'Organic Certified' + expect(supplier.producer_properties.count).to eq(1) + expect(supplier.producer_properties.first.value).to eq('NASAA 12345') + expect(supplier.producer_properties.first.property.presentation).to eq('Organic Certified') end end @@ -535,15 +535,15 @@ describe Enterprise do let(:non_producer_sell_none) { build(:enterprise, is_primary_producer: false, sells: "none") } it "should output enterprise categories" do - producer_sell_all.is_primary_producer.should == true - producer_sell_all.sells.should == "any" + expect(producer_sell_all.is_primary_producer).to eq(true) + expect(producer_sell_all.sells).to eq("any") - producer_sell_all.category.should == :producer_hub - producer_sell_own.category.should == :producer_shop - producer_sell_none.category.should == :producer - non_producer_sell_all.category.should == :hub - non_producer_sell_own.category.should == :hub - non_producer_sell_none.category.should == :hub_profile + expect(producer_sell_all.category).to eq(:producer_hub) + expect(producer_sell_own.category).to eq(:producer_shop) + expect(producer_sell_none.category).to eq(:producer) + expect(non_producer_sell_all.category).to eq(:hub) + expect(non_producer_sell_own.category).to eq(:hub) + expect(non_producer_sell_none.category).to eq(:hub_profile) end end @@ -551,7 +551,7 @@ describe Enterprise do let(:enterprise) { build(:enterprise, name: "Name To Turn Into A Permalink") } it "assigns permalink when initialized" do allow(Enterprise).to receive(:find_available_permalink).and_return("available_permalink") - Enterprise.should_receive(:find_available_permalink).with("Name To Turn Into A Permalink") + expect(Enterprise).to receive(:find_available_permalink).with("Name To Turn Into A Permalink") expect( lambda { enterprise.send(:initialize_permalink) } ).to change{ diff --git a/spec/models/exchange_spec.rb b/spec/models/exchange_spec.rb index f8123f1a0e..2a55ee5991 100644 --- a/spec/models/exchange_spec.rb +++ b/spec/models/exchange_spec.rb @@ -2,14 +2,14 @@ require 'spec_helper' describe Exchange do it "should be valid when built from factory" do - build(:exchange).should be_valid + expect(build(:exchange)).to be_valid end [:order_cycle, :sender, :receiver].each do |attr| it "should not be valid without #{attr}" do e = build(:exchange) e.send("#{attr}=", nil) - e.should_not be_valid + expect(e).not_to be_valid end end @@ -18,18 +18,18 @@ describe Exchange do e2 = build(:exchange, :order_cycle => e1.order_cycle, :sender => e1.sender, :receiver => e1.receiver, :incoming => e1.incoming) - e2.should_not be_valid + expect(e2).not_to be_valid e2.incoming = !e2.incoming - e2.should be_valid + expect(e2).to be_valid e2.incoming = !e2.incoming e2.receiver = create(:enterprise) - e2.should be_valid + expect(e2).to be_valid e2.sender = e2.receiver e2.receiver = e1.receiver - e2.should be_valid + expect(e2).to be_valid end it "has exchange variants" do @@ -37,7 +37,7 @@ describe Exchange do p = create(:product) e.exchange_variants.create(:variant => p.master) - e.variants.count.should == 1 + expect(e.variants.count).to eq(1) end it "has exchange fees" do @@ -45,7 +45,7 @@ describe Exchange do f = create(:enterprise_fee) e.exchange_fees.create(:enterprise_fee => f) - e.enterprise_fees.count.should == 1 + expect(e.enterprise_fees.count).to eq(1) end describe "exchange directionality" do @@ -58,21 +58,21 @@ describe Exchange do describe "reporting whether it is an incoming exchange" do it "returns true for incoming exchanges" do - incoming_exchange.should be_incoming + expect(incoming_exchange).to be_incoming end it "returns false for outgoing exchanges" do - outgoing_exchange.should_not be_incoming + expect(outgoing_exchange).not_to be_incoming end end describe "finding the exchange participant (the enterprise other than the coordinator)" do it "returns the sender for incoming exchanges" do - incoming_exchange.participant.should == supplier + expect(incoming_exchange.participant).to eq(supplier) end it "returns the receiver for outgoing exchanges" do - outgoing_exchange.participant.should == distributor + expect(outgoing_exchange.participant).to eq(distributor) end end end @@ -80,14 +80,14 @@ describe Exchange do describe "reporting its role" do it "returns 'supplier' when it is an incoming exchange" do e = Exchange.new - e.stub(:incoming?) { true } - e.role.should == 'supplier' + allow(e).to receive(:incoming?) { true } + expect(e.role).to eq('supplier') end it "returns 'distributor' when it is an outgoing exchange" do e = Exchange.new - e.stub(:incoming?) { false } - e.role.should == 'distributor' + allow(e).to receive(:incoming?) { false } + expect(e.role).to eq('distributor') end end @@ -126,32 +126,32 @@ describe Exchange do exchange.sender.users << user exchange.receiver.users << user - Exchange.managed_by(user).should == [exchange] + expect(Exchange.managed_by(user)).to eq([exchange]) end it "does not return exchanges where the user manages only the sender" do exchange = create(:exchange, order_cycle: oc) exchange.sender.users << user - Exchange.managed_by(user).should be_empty + expect(Exchange.managed_by(user)).to be_empty end it "does not return exchanges where the user manages only the receiver" do exchange = create(:exchange, order_cycle: oc) exchange.receiver.users << user - Exchange.managed_by(user).should be_empty + expect(Exchange.managed_by(user)).to be_empty end it "does not return exchanges where the user manages neither enterprise" do exchange = create(:exchange, order_cycle: oc) - Exchange.managed_by(user).should be_empty + expect(Exchange.managed_by(user)).to be_empty end end it "finds exchanges in a particular order cycle" do ex = create(:exchange, order_cycle: oc) - Exchange.in_order_cycle(oc).should == [ex] + expect(Exchange.in_order_cycle(oc)).to eq([ex]) end describe "finding exchanges by direction" do @@ -159,44 +159,44 @@ describe Exchange do let!(:outgoing_exchange) { oc.exchanges.create! sender: coordinator, receiver: distributor, incoming: false } it "finds incoming exchanges" do - Exchange.incoming.should == [incoming_exchange] + expect(Exchange.incoming).to eq([incoming_exchange]) end it "finds outgoing exchanges" do - Exchange.outgoing.should == [outgoing_exchange] + expect(Exchange.outgoing).to eq([outgoing_exchange]) end it "correctly determines direction of exchanges between the same enterprise" do incoming_exchange.update_attributes sender: coordinator, incoming: true outgoing_exchange.update_attributes receiver: coordinator, incoming: false - Exchange.incoming.should == [incoming_exchange] - Exchange.outgoing.should == [outgoing_exchange] + expect(Exchange.incoming).to eq([incoming_exchange]) + expect(Exchange.outgoing).to eq([outgoing_exchange]) end it "finds exchanges coming from an enterprise" do - Exchange.from_enterprise(supplier).should == [incoming_exchange] - Exchange.from_enterprise(coordinator).should == [outgoing_exchange] + expect(Exchange.from_enterprise(supplier)).to eq([incoming_exchange]) + expect(Exchange.from_enterprise(coordinator)).to eq([outgoing_exchange]) end it "finds exchanges going to an enterprise" do - Exchange.to_enterprise(coordinator).should == [incoming_exchange] - Exchange.to_enterprise(distributor).should == [outgoing_exchange] + expect(Exchange.to_enterprise(coordinator)).to eq([incoming_exchange]) + expect(Exchange.to_enterprise(distributor)).to eq([outgoing_exchange]) end it "finds exchanges coming from any of a number of enterprises" do - Exchange.from_enterprises([coordinator]).should == [outgoing_exchange] - Exchange.from_enterprises([supplier, coordinator]).should match_array [incoming_exchange, outgoing_exchange] + expect(Exchange.from_enterprises([coordinator])).to eq([outgoing_exchange]) + expect(Exchange.from_enterprises([supplier, coordinator])).to match_array [incoming_exchange, outgoing_exchange] end it "finds exchanges going to any of a number of enterprises" do - Exchange.to_enterprises([coordinator]).should == [incoming_exchange] - Exchange.to_enterprises([coordinator, distributor]).should match_array [incoming_exchange, outgoing_exchange] + expect(Exchange.to_enterprises([coordinator])).to eq([incoming_exchange]) + expect(Exchange.to_enterprises([coordinator, distributor])).to match_array [incoming_exchange, outgoing_exchange] end it "finds exchanges involving any of a number of enterprises" do - Exchange.involving([supplier]).should == [incoming_exchange] - Exchange.involving([coordinator]).should match_array [incoming_exchange, outgoing_exchange] - Exchange.involving([distributor]).should == [outgoing_exchange] + expect(Exchange.involving([supplier])).to eq([incoming_exchange]) + expect(Exchange.involving([coordinator])).to match_array [incoming_exchange, outgoing_exchange] + expect(Exchange.involving([distributor])).to eq([outgoing_exchange]) end end @@ -205,14 +205,14 @@ describe Exchange do d = create(:distributor_enterprise) ex = create(:exchange, order_cycle: oc, incoming: true) - oc.exchanges.supplying_to(d).should == [ex] + expect(oc.exchanges.supplying_to(d)).to eq([ex]) end it "returns outgoing exchanges to the distributor" do d = create(:distributor_enterprise) ex = create(:exchange, order_cycle: oc, receiver: d, incoming: false) - oc.exchanges.supplying_to(d).should == [ex] + expect(oc.exchanges.supplying_to(d)).to eq([ex]) end it "does not return outgoing exchanges to a different distributor" do @@ -220,7 +220,7 @@ describe Exchange do d2 = create(:distributor_enterprise) ex = create(:exchange, order_cycle: oc, receiver: d1, incoming: false) - oc.exchanges.supplying_to(d2).should be_empty + expect(oc.exchanges.supplying_to(d2)).to be_empty end end @@ -229,7 +229,7 @@ describe Exchange do ex = create(:exchange) ex.variants << v - Exchange.with_variant(v).should == [ex] + expect(Exchange.with_variant(v)).to eq([ex]) end it "finds exchanges with any of a number of variants, without returning duplicates" do @@ -240,7 +240,7 @@ describe Exchange do ex.variants << v1 ex.variants << v2 - Exchange.with_any_variant([v1, v2, v3]).should == [ex] + expect(Exchange.with_any_variant([v1, v2, v3])).to eq([ex]) end it "finds exchanges with a particular product's master variant" do @@ -249,7 +249,7 @@ describe Exchange do ex.variants << p.master p.reload - Exchange.with_product(p).should == [ex] + expect(Exchange.with_product(p)).to eq([ex]) end it "finds exchanges with a particular product's non-master variant" do @@ -259,7 +259,7 @@ describe Exchange do ex.variants << v p.reload - Exchange.with_product(p).should == [ex] + expect(Exchange.with_product(p)).to eq([ex]) end describe "sorting exchanges by primary enterprise name" do @@ -272,7 +272,7 @@ describe Exchange do let!(:ex3) { create(:exchange, sender: e3, incoming: true) } it "sorts" do - Exchange.by_enterprise_name.should == [ex2, ex3, ex1] + expect(Exchange.by_enterprise_name).to eq([ex2, ex3, ex1]) end end end @@ -285,7 +285,7 @@ describe Exchange do ex1.update_attribute(:tag_list, "wholesale") ex2 = ex1.clone! new_oc - ex1.eql?(ex2).should be true + expect(ex1.eql?(ex2)).to be true expect(ex2.reload.tag_list).to eq ["wholesale"] end @@ -294,13 +294,13 @@ describe Exchange do let(:exchange) do exchange = oc.exchanges.last exchange.save! - exchange.stub(:variant_ids) { [1835, 1834] } # Test id ordering - exchange.stub(:enterprise_fee_ids) { [1493, 1492] } # Test id ordering + allow(exchange).to receive(:variant_ids) { [1835, 1834] } # Test id ordering + allow(exchange).to receive(:enterprise_fee_ids) { [1493, 1492] } # Test id ordering exchange end it "converts to a hash" do - exchange.to_h.should == + expect(exchange.to_h).to eq( {'id' => exchange.id, 'order_cycle_id' => oc.id, 'sender_id' => exchange.sender_id, 'receiver_id' => exchange.receiver_id, 'incoming' => exchange.incoming, @@ -309,16 +309,18 @@ describe Exchange do 'pickup_time' => exchange.pickup_time, 'pickup_instructions' => exchange.pickup_instructions, 'receival_instructions' => exchange.receival_instructions, 'created_at' => exchange.created_at, 'updated_at' => exchange.updated_at} + ) end it "converts to a hash of core attributes only" do - exchange.to_h(true).should == + expect(exchange.to_h(true)).to eq( {'sender_id' => exchange.sender_id, 'receiver_id' => exchange.receiver_id, 'incoming' => exchange.incoming, 'variant_ids' => exchange.variant_ids.sort, 'enterprise_fee_ids' => exchange.enterprise_fee_ids.sort, 'pickup_time' => exchange.pickup_time, 'pickup_instructions' => exchange.pickup_instructions, 'receival_instructions' => exchange.receival_instructions} + ) end end @@ -327,17 +329,17 @@ describe Exchange do e1 = Exchange.new e2 = Exchange.new - e1.stub(:to_h) { {'sender_id' => 456} } - e2.stub(:to_h) { {'sender_id' => 456} } + allow(e1).to receive(:to_h) { {'sender_id' => 456} } + allow(e2).to receive(:to_h) { {'sender_id' => 456} } - e1.eql?(e2).should be true + expect(e1.eql?(e2)).to be true end it "compares other objects using super" do exchange = Exchange.new exchange_fee = ExchangeFee.new - exchange.eql?(exchange_fee).should be false + expect(exchange.eql?(exchange_fee)).to be false end end end diff --git a/spec/models/model_set_spec.rb b/spec/models/model_set_spec.rb index 0533285cec..bac8047fa4 100644 --- a/spec/models/model_set_spec.rb +++ b/spec/models/model_set_spec.rb @@ -10,7 +10,7 @@ describe ModelSet do expect { ms.save }.to change(EnterpriseRelationshipPermission, :count).by(2) - EnterpriseRelationshipPermission.where(name: ['s1', 's2']).count.should == 2 + expect(EnterpriseRelationshipPermission.where(name: ['s1', 's2']).count).to eq(2) end @@ -25,7 +25,7 @@ describe ModelSet do expect { ms.save }.to change(EnterpriseGroup, :count).by(0) - EnterpriseGroup.where(name: ['e1zz', 'e2yy']).count.should == 2 + expect(EnterpriseGroup.where(name: ['e1zz', 'e2yy']).count).to eq(2) end @@ -41,8 +41,8 @@ describe ModelSet do expect { ms.save }.to change(Enterprise, :count).by(-1) - Enterprise.where(id: e1.id).should be_empty - Enterprise.where(id: e2.id).should be_present + expect(Enterprise.where(id: e1.id)).to be_empty + expect(Enterprise.where(id: e2.id)).to be_present end diff --git a/spec/models/order_cycle_spec.rb b/spec/models/order_cycle_spec.rb index 98596196ca..619f022c5d 100644 --- a/spec/models/order_cycle_spec.rb +++ b/spec/models/order_cycle_spec.rb @@ -4,13 +4,13 @@ describe OrderCycle do include OpenFoodNetwork::EmailHelper it "should be valid when built from factory" do - build(:simple_order_cycle).should be_valid + expect(build(:simple_order_cycle)).to be_valid end it "should not be valid without a name" do oc = build(:simple_order_cycle) oc.name = '' - oc.should_not be_valid + expect(oc).not_to be_valid end it 'should not be valid when open date is after close date' do @@ -46,7 +46,7 @@ describe OrderCycle do create(:exchange, order_cycle: oc) create(:exchange, order_cycle: oc) - oc.exchanges.count.should == 3 + expect(oc.exchanges.count).to eq(3) end it "finds order cycles in various stages of their lifecycle" do @@ -57,13 +57,13 @@ describe OrderCycle do oc_undated_open = create(:simple_order_cycle, orders_open_at: 1.week.ago, orders_close_at: nil) oc_undated_close = create(:simple_order_cycle, orders_open_at: nil, orders_close_at: 1.week.from_now) - OrderCycle.active.should == [oc_active] - OrderCycle.inactive.should match_array [oc_not_yet_open, oc_already_closed] - OrderCycle.upcoming.should == [oc_not_yet_open] - OrderCycle.closed.should == [oc_already_closed] - OrderCycle.undated.should == [oc_undated, oc_undated_open, oc_undated_close] - OrderCycle.not_closed.should == [oc_active, oc_not_yet_open, oc_undated, oc_undated_open, oc_undated_close] - OrderCycle.dated.should == [oc_active, oc_not_yet_open, oc_already_closed] + expect(OrderCycle.active).to eq([oc_active]) + expect(OrderCycle.inactive).to match_array [oc_not_yet_open, oc_already_closed] + expect(OrderCycle.upcoming).to eq([oc_not_yet_open]) + expect(OrderCycle.closed).to eq([oc_already_closed]) + expect(OrderCycle.undated).to eq([oc_undated, oc_undated_open, oc_undated_close]) + expect(OrderCycle.not_closed).to eq([oc_active, oc_not_yet_open, oc_undated, oc_undated_open, oc_undated_close]) + expect(OrderCycle.dated).to eq([oc_active, oc_not_yet_open, oc_already_closed]) end it "finds order cycles accessible by a user" do @@ -77,8 +77,8 @@ describe OrderCycle do oc_received = create(:simple_order_cycle, distributors: [e2]) oc_not_accessible = create(:simple_order_cycle, coordinator: e1) - OrderCycle.accessible_by(user).should include(oc_coordinated, oc_sent, oc_received) - OrderCycle.accessible_by(user).should_not include(oc_not_accessible) + expect(OrderCycle.accessible_by(user)).to include(oc_coordinated, oc_sent, oc_received) + expect(OrderCycle.accessible_by(user)).not_to include(oc_not_accessible) end it "finds the most recently closed order cycles" do @@ -86,7 +86,7 @@ describe OrderCycle do oc2 = create(:simple_order_cycle, orders_close_at: 1.hour.ago) oc3 = create(:simple_order_cycle, orders_close_at: 1.hour.from_now) - OrderCycle.most_recently_closed.should == [oc2, oc1] + expect(OrderCycle.most_recently_closed).to eq([oc2, oc1]) end it "finds the soonest opening order cycles" do @@ -94,7 +94,7 @@ describe OrderCycle do oc2 = create(:simple_order_cycle, orders_open_at: 2.hours.from_now) oc3 = create(:simple_order_cycle, orders_open_at: 1.hour.ago) - OrderCycle.soonest_opening.should == [oc2, oc1] + expect(OrderCycle.soonest_opening).to eq([oc2, oc1]) end it "finds the soonest closing order cycles" do @@ -102,7 +102,7 @@ describe OrderCycle do oc2 = create(:simple_order_cycle, orders_close_at: 2.hour.from_now) oc3 = create(:simple_order_cycle, orders_close_at: 1.hour.from_now) - OrderCycle.soonest_closing.should == [oc3, oc2] + expect(OrderCycle.soonest_closing).to eq([oc3, oc2]) end describe "finding order cycles with a particular distributor" do @@ -111,17 +111,17 @@ describe OrderCycle do it "returns order cycles with that distributor" do oc = create(:simple_order_cycle, coordinator: c, distributors: [d]) - OrderCycle.with_distributor(d).should == [oc] + expect(OrderCycle.with_distributor(d)).to eq([oc]) end it "does not return order cycles with that enterprise as supplier" do oc = create(:simple_order_cycle, coordinator: c, suppliers: [d]) - OrderCycle.with_distributor(d).should == [] + expect(OrderCycle.with_distributor(d)).to eq([]) end it "does not return order cycles without that distributor" do oc = create(:simple_order_cycle, coordinator: c) - OrderCycle.with_distributor(d).should == [] + expect(OrderCycle.with_distributor(d)).to eq([]) end end @@ -133,7 +133,7 @@ describe OrderCycle do e2 = create(:exchange, incoming: true, order_cycle: oc, receiver: oc.coordinator, sender: create(:enterprise)) - oc.suppliers.should match_array [e1.sender, e2.sender] + expect(oc.suppliers).to match_array [e1.sender, e2.sender] end it "reports its distributors" do @@ -144,7 +144,7 @@ describe OrderCycle do e2 = create(:exchange, incoming: false, order_cycle: oc, sender: oc.coordinator, receiver: create(:enterprise)) - oc.distributors.should match_array [e1.receiver, e2.receiver] + expect(oc.distributors).to match_array [e1.receiver, e2.receiver] end it "checks for existance of distributors" do @@ -153,8 +153,8 @@ describe OrderCycle do d2 = create(:distributor_enterprise) create(:exchange, order_cycle: oc, sender: oc.coordinator, receiver: d1, incoming: false) - oc.should have_distributor(d1) - oc.should_not have_distributor(d2) + expect(oc).to have_distributor(d1) + expect(oc).not_to have_distributor(d2) end it "checks for variants" do @@ -162,8 +162,8 @@ describe OrderCycle do p2 = create(:simple_product) oc = create(:simple_order_cycle, suppliers: [p1.supplier], variants: [p1.master]) - oc.should have_variant(p1.master) - oc.should_not have_variant(p2.master) + expect(oc).to have_variant(p1.master) + expect(oc).not_to have_variant(p2.master) end describe "product exchanges" do @@ -202,39 +202,39 @@ describe OrderCycle do end it "reports on the variants exchanged" do - oc.variants.should match_array [p0.master, p1.master, p2.master, p2_v, p1_v_visible, p1_v_hidden] + expect(oc.variants).to match_array [p0.master, p1.master, p2.master, p2_v, p1_v_visible, p1_v_hidden] end it "returns the correct count of variants" do - oc.variants.count.should == 6 + expect(oc.variants.count).to eq(6) end it "reports on the variants supplied" do - oc.supplied_variants.should match_array [p0.master] + expect(oc.supplied_variants).to match_array [p0.master] end it "reports on the variants distributed" do - oc.distributed_variants.should match_array [p1.master, p2.master, p2_v, p1_v_visible, p1_v_hidden] + expect(oc.distributed_variants).to match_array [p1.master, p2.master, p2_v, p1_v_visible, p1_v_hidden] end it "reports on the products distributed by a particular distributor" do - oc.products_distributed_by(d2).should == [p1] + expect(oc.products_distributed_by(d2)).to eq([p1]) end it "reports on the products exchanged" do - oc.products.should match_array [p0, p1, p2] + expect(oc.products).to match_array [p0, p1, p2] end context "listing variant distributed by a particular distributor" do context "when default settings are in play" do it "returns an empty list when no distributor is given" do - oc.variants_distributed_by(nil).should == [] + expect(oc.variants_distributed_by(nil)).to eq([]) end it "returns all variants in the outgoing exchange for the distributor provided" do - oc.variants_distributed_by(d2).should include p1.master, p1_v_visible - oc.variants_distributed_by(d2).should_not include p1_v_hidden, p1_v_deleted - oc.variants_distributed_by(d1).should include p2_v + expect(oc.variants_distributed_by(d2)).to include p1.master, p1_v_visible + expect(oc.variants_distributed_by(d2)).not_to include p1_v_hidden, p1_v_deleted + expect(oc.variants_distributed_by(d1)).to include p2_v end end @@ -244,11 +244,11 @@ describe OrderCycle do end it "returns an empty list when no distributor is given" do - oc.variants_distributed_by(nil).should == [] + expect(oc.variants_distributed_by(nil)).to eq([]) end it "returns only variants in the exchange that are also in the distributor's inventory" do - oc.variants_distributed_by(d1).should_not include p2_v + expect(oc.variants_distributed_by(d1)).not_to include p2_v end end end @@ -267,23 +267,23 @@ describe OrderCycle do end it "finds the exchange for a distributor" do - @oc.exchange_for_distributor(@d1).should == @e1 - @oc.exchange_for_distributor(@d2).should == @e2 + expect(@oc.exchange_for_distributor(@d1)).to eq(@e1) + expect(@oc.exchange_for_distributor(@d2)).to eq(@e2) end describe "finding pickup time for a distributor" do it "looks up the pickup time on the exchange when present" do - @oc.pickup_time_for(@d1).should == '5pm Tuesday' + expect(@oc.pickup_time_for(@d1)).to eq('5pm Tuesday') end it "returns the distributor's default collection time otherwise" do - @oc.pickup_time_for(@d2).should == '2-8pm Friday' + expect(@oc.pickup_time_for(@d2)).to eq('2-8pm Friday') end end describe "finding pickup instructions for a distributor" do it "returns the pickup instructions" do - @oc.pickup_instructions_for(@d1).should == "Come get it!" + expect(@oc.pickup_instructions_for(@d1)).to eq("Come get it!") end end end @@ -293,60 +293,60 @@ describe OrderCycle do it "reports status when an order cycle is upcoming" do Timecop.freeze(oc.orders_open_at - 1.second) do - oc.should_not be_undated - oc.should be_dated - oc.should be_upcoming - oc.should_not be_open - oc.should_not be_closed + expect(oc).not_to be_undated + expect(oc).to be_dated + expect(oc).to be_upcoming + expect(oc).not_to be_open + expect(oc).not_to be_closed end end it "reports status when an order cycle is open" do - oc.should_not be_undated - oc.should be_dated - oc.should_not be_upcoming - oc.should be_open - oc.should_not be_closed + expect(oc).not_to be_undated + expect(oc).to be_dated + expect(oc).not_to be_upcoming + expect(oc).to be_open + expect(oc).not_to be_closed end it "reports status when an order cycle has closed" do Timecop.freeze(oc.orders_close_at + 1.second) do - oc.should_not be_undated - oc.should be_dated - oc.should_not be_upcoming - oc.should_not be_open - oc.should be_closed + expect(oc).not_to be_undated + expect(oc).to be_dated + expect(oc).not_to be_upcoming + expect(oc).not_to be_open + expect(oc).to be_closed end end it "reports status when an order cycle is undated" do oc.update_attributes!(orders_open_at: nil, orders_close_at: nil) - oc.should be_undated - oc.should_not be_dated - oc.should_not be_upcoming - oc.should_not be_open - oc.should_not be_closed + expect(oc).to be_undated + expect(oc).not_to be_dated + expect(oc).not_to be_upcoming + expect(oc).not_to be_open + expect(oc).not_to be_closed end it "reports status when an order cycle is partially dated - opening time only" do oc.update_attributes!(orders_close_at: nil) - oc.should be_undated - oc.should_not be_dated - oc.should_not be_upcoming - oc.should_not be_open - oc.should_not be_closed + expect(oc).to be_undated + expect(oc).not_to be_dated + expect(oc).not_to be_upcoming + expect(oc).not_to be_open + expect(oc).not_to be_closed end it "reports status when an order cycle is partially dated - closing time only" do oc.update_attributes!(orders_open_at: nil) - oc.should be_undated - oc.should_not be_dated - oc.should_not be_upcoming - oc.should_not be_open - oc.should_not be_closed + expect(oc).to be_undated + expect(oc).not_to be_dated + expect(oc).not_to be_upcoming + expect(oc).not_to be_open + expect(oc).not_to be_closed end end @@ -358,16 +358,16 @@ describe OrderCycle do oc.clone! occ = OrderCycle.last - occ.name.should == "COPY OF #{oc.name}" - occ.orders_open_at.should be_nil - occ.orders_close_at.should be_nil - occ.coordinator.should_not be_nil - occ.preferred_product_selection_from_coordinator_inventory_only.should be true - occ.coordinator.should == oc.coordinator + expect(occ.name).to eq("COPY OF #{oc.name}") + expect(occ.orders_open_at).to be_nil + expect(occ.orders_close_at).to be_nil + expect(occ.coordinator).not_to be_nil + expect(occ.preferred_product_selection_from_coordinator_inventory_only).to be true + expect(occ.coordinator).to eq(oc.coordinator) - occ.coordinator_fee_ids.should_not be_empty - occ.coordinator_fee_ids.should == oc.coordinator_fee_ids - occ.preferred_product_selection_from_coordinator_inventory_only.should == oc.preferred_product_selection_from_coordinator_inventory_only + expect(occ.coordinator_fee_ids).not_to be_empty + expect(occ.coordinator_fee_ids).to eq(oc.coordinator_fee_ids) + expect(occ.preferred_product_selection_from_coordinator_inventory_only).to eq(oc.preferred_product_selection_from_coordinator_inventory_only) # to_h gives us a unique hash for each exchange # check that the clone has no additional exchanges @@ -383,12 +383,12 @@ describe OrderCycle do it "should give the most recently closed order cycle for a distributor" do distributor = create(:distributor_enterprise) oc = create(:simple_order_cycle, name: 'oc 1', distributors: [distributor], orders_open_at: 10.days.ago, orders_close_at: 9.days.ago) - OrderCycle.most_recently_closed_for(distributor).should == oc + expect(OrderCycle.most_recently_closed_for(distributor)).to eq(oc) end it "should return nil when there have been none" do distributor = create(:distributor_enterprise) - OrderCycle.most_recently_closed_for(distributor).should == nil + expect(OrderCycle.most_recently_closed_for(distributor)).to eq(nil) end end @@ -396,12 +396,12 @@ describe OrderCycle do it "should give the soonest opening order cycle for a distributor" do distributor = create(:distributor_enterprise) oc = create(:simple_order_cycle, name: 'oc 1', distributors: [distributor], orders_open_at: 10.days.from_now, orders_close_at: 11.days.from_now) - OrderCycle.first_opening_for(distributor).should == oc + expect(OrderCycle.first_opening_for(distributor)).to eq(oc) end it "should return no order cycle when none are impending" do distributor = create(:distributor_enterprise) - OrderCycle.first_opening_for(distributor).should == nil + expect(OrderCycle.first_opening_for(distributor)).to eq(nil) end end @@ -410,7 +410,7 @@ describe OrderCycle do distributor = create(:distributor_enterprise) oc = create(:simple_order_cycle, name: 'oc 1', distributors: [distributor], orders_open_at: 1.days.ago, orders_close_at: 11.days.from_now) oc2 = create(:simple_order_cycle, name: 'oc 2', distributors: [distributor], orders_open_at: 2.days.ago, orders_close_at: 12.days.from_now) - OrderCycle.first_closing_for(distributor).should == oc + expect(OrderCycle.first_closing_for(distributor)).to eq(oc) end end @@ -425,11 +425,11 @@ describe OrderCycle do let!(:oc3) { create(:simple_order_cycle, orders_close_at: time3, distributors: [e2]) } it "returns the closing time, indexed by enterprise id" do - OrderCycle.earliest_closing_times[e1.id].should == time1 + expect(OrderCycle.earliest_closing_times[e1.id]).to eq(time1) end it "returns the earliest closing time" do - OrderCycle.earliest_closing_times[e2.id].should == time2 + expect(OrderCycle.earliest_closing_times[e2.id]).to eq(time2) end end diff --git a/spec/models/order_updater_spec.rb b/spec/models/order_updater_spec.rb index 40a12a9119..6e985c14fb 100644 --- a/spec/models/order_updater_spec.rb +++ b/spec/models/order_updater_spec.rb @@ -5,10 +5,10 @@ describe OrderUpdater do let(:order_updater) { described_class.new(Spree::OrderUpdater.new(order)) } it "is failed if no valid payments" do - order.stub_chain(:payments, :valid, :empty?).and_return(true) + allow(order).to receive_message_chain(:payments, :valid, :empty?).and_return(true) order_updater.update_payment_state - order.payment_state.should == 'failed' + expect(order.payment_state).to eq('failed') end context "payment total is greater than order total" do @@ -63,8 +63,8 @@ describe OrderUpdater do it "is credit_owed" do order.payment_total = 30 order.total = 30 - order.stub_chain(:payments, :valid, :empty?).and_return(false) - order.stub_chain(:payments, :completed, :empty?).and_return(false) + allow(order).to receive_message_chain(:payments, :valid, :empty?).and_return(false) + allow(order).to receive_message_chain(:payments, :completed, :empty?).and_return(false) expect { order_updater.update_payment_state }.to change { order.payment_state }.to 'credit_owed' @@ -75,8 +75,8 @@ describe OrderUpdater do it "is void" do order.payment_total = 0 order.total = 30 - order.stub_chain(:payments, :valid, :empty?).and_return(false) - order.stub_chain(:payments, :completed, :empty?).and_return(false) + allow(order).to receive_message_chain(:payments, :valid, :empty?).and_return(false) + allow(order).to receive_message_chain(:payments, :completed, :empty?).and_return(false) expect { order_updater.update_payment_state }.to change { order.payment_state }.to 'void' diff --git a/spec/models/spree/ability_spec.rb b/spec/models/spree/ability_spec.rb index a6957f917b..02ac8d628c 100644 --- a/spec/models/spree/ability_spec.rb +++ b/spec/models/spree/ability_spec.rb @@ -22,10 +22,10 @@ module Spree user.enterprise_roles.create! enterprise: enterprise_any end - it { subject.can_manage_products?(user).should be true } - it { subject.can_manage_enterprises?(user).should be true } - it { subject.can_manage_orders?(user).should be true } - it { subject.can_manage_order_cycles?(user).should be true } + it { expect(subject.can_manage_products?(user)).to be true } + it { expect(subject.can_manage_enterprises?(user)).to be true } + it { expect(subject.can_manage_orders?(user)).to be true } + it { expect(subject.can_manage_order_cycles?(user)).to be true } end context "as manager of an enterprise who sell 'own'" do @@ -33,10 +33,10 @@ module Spree user.enterprise_roles.create! enterprise: enterprise_own end - it { subject.can_manage_products?(user).should be true } - it { subject.can_manage_enterprises?(user).should be true } - it { subject.can_manage_orders?(user).should be true } - it { subject.can_manage_order_cycles?(user).should be true } + it { expect(subject.can_manage_products?(user)).to be true } + it { expect(subject.can_manage_enterprises?(user)).to be true } + it { expect(subject.can_manage_orders?(user)).to be true } + it { expect(subject.can_manage_order_cycles?(user)).to be true } end context "as manager of an enterprise who sells 'none'" do @@ -44,10 +44,10 @@ module Spree user.enterprise_roles.create! enterprise: enterprise_none end - it { subject.can_manage_products?(user).should be false } - it { subject.can_manage_enterprises?(user).should be true } - it { subject.can_manage_orders?(user).should be false } - it { subject.can_manage_order_cycles?(user).should be false } + it { expect(subject.can_manage_products?(user)).to be false } + it { expect(subject.can_manage_enterprises?(user)).to be true } + it { expect(subject.can_manage_orders?(user)).to be false } + it { expect(subject.can_manage_order_cycles?(user)).to be false } end context "as manager of a producer enterprise who sells 'any'" do @@ -55,10 +55,10 @@ module Spree user.enterprise_roles.create! enterprise: enterprise_any_producer end - it { subject.can_manage_products?(user).should be true } - it { subject.can_manage_enterprises?(user).should be true } - it { subject.can_manage_orders?(user).should be true } - it { subject.can_manage_order_cycles?(user).should be true } + it { expect(subject.can_manage_products?(user)).to be true } + it { expect(subject.can_manage_enterprises?(user)).to be true } + it { expect(subject.can_manage_orders?(user)).to be true } + it { expect(subject.can_manage_order_cycles?(user)).to be true } end context "as manager of a producer enterprise who sell 'own'" do @@ -66,10 +66,10 @@ module Spree user.enterprise_roles.create! enterprise: enterprise_own_producer end - it { subject.can_manage_products?(user).should be true } - it { subject.can_manage_enterprises?(user).should be true } - it { subject.can_manage_orders?(user).should be true } - it { subject.can_manage_order_cycles?(user).should be true } + it { expect(subject.can_manage_products?(user)).to be true } + it { expect(subject.can_manage_enterprises?(user)).to be true } + it { expect(subject.can_manage_orders?(user)).to be true } + it { expect(subject.can_manage_order_cycles?(user)).to be true } end context "as manager of a producer enterprise who sells 'none'" do @@ -84,10 +84,10 @@ module Spree enterprise_none_producer.save! end - it { subject.can_manage_products?(user).should be true } - it { subject.can_manage_enterprises?(user).should be true } - it { subject.can_manage_orders?(user).should be false } - it { subject.can_manage_order_cycles?(user).should be false } + it { expect(subject.can_manage_products?(user)).to be true } + it { expect(subject.can_manage_enterprises?(user)).to be true } + it { expect(subject.can_manage_orders?(user)).to be false } + it { expect(subject.can_manage_order_cycles?(user)).to be false } end context "as a profile" do @@ -97,21 +97,21 @@ module Spree enterprise_none_producer.save! end - it { subject.can_manage_products?(user).should be false } - it { subject.can_manage_enterprises?(user).should be true } - it { subject.can_manage_orders?(user).should be false } - it { subject.can_manage_order_cycles?(user).should be false } + it { expect(subject.can_manage_products?(user)).to be false } + it { expect(subject.can_manage_enterprises?(user)).to be true } + it { expect(subject.can_manage_orders?(user)).to be false } + it { expect(subject.can_manage_order_cycles?(user)).to be false } end end context "as a new user with no enterprises" do - it { subject.can_manage_products?(user).should be false } - it { subject.can_manage_enterprises?(user).should be false } - it { subject.can_manage_orders?(user).should be false } - it { subject.can_manage_order_cycles?(user).should be false } + it { expect(subject.can_manage_products?(user)).to be false } + it { expect(subject.can_manage_enterprises?(user)).to be false } + it { expect(subject.can_manage_orders?(user)).to be false } + it { expect(subject.can_manage_order_cycles?(user)).to be false } it "can create enterprises straight off the bat" do - subject.is_new_user?(user).should be true + expect(subject.is_new_user?(user)).to be true expect(user).to have_ability :create, for: Enterprise end end @@ -149,82 +149,82 @@ module Spree let(:order) { create(:order) } it "should be able to read/write their enterprises' products and variants" do - should have_ability([:admin, :read, :update, :bulk_update, :clone, :destroy], for: p1) - should have_ability([:admin, :index, :read, :edit, :update, :search, :destroy, :delete], for: p1.master) + is_expected.to have_ability([:admin, :read, :update, :bulk_update, :clone, :destroy], for: p1) + is_expected.to have_ability([:admin, :index, :read, :edit, :update, :search, :destroy, :delete], for: p1.master) end it "should be able to read/write related enterprises' products and variants with manage_products permission" do er_ps - should have_ability([:admin, :read, :update, :bulk_update, :clone, :destroy], for: p_related) - should have_ability([:admin, :index, :read, :edit, :update, :search, :destroy, :delete], for: p_related.master) + is_expected.to have_ability([:admin, :read, :update, :bulk_update, :clone, :destroy], for: p_related) + is_expected.to have_ability([:admin, :index, :read, :edit, :update, :search, :destroy, :delete], for: p_related.master) end it "should not be able to read/write other enterprises' products and variants" do - should_not have_ability([:admin, :read, :update, :bulk_update, :clone, :destroy], for: p2) - should_not have_ability([:admin, :index, :read, :edit, :update, :search, :destroy], for: p2.master) + is_expected.not_to have_ability([:admin, :read, :update, :bulk_update, :clone, :destroy], for: p2) + is_expected.not_to have_ability([:admin, :index, :read, :edit, :update, :search, :destroy], for: p2.master) end it "should not be able to access admin actions on orders" do - should_not have_ability([:admin], for: Spree::Order) + is_expected.not_to have_ability([:admin], for: Spree::Order) end it "should be able to create a new product" do - should have_ability(:create, for: Spree::Product) + is_expected.to have_ability(:create, for: Spree::Product) end it "should be able to read/write their enterprises' product variants" do - should have_ability([:create], for: Spree::Variant) - should have_ability([:admin, :index, :read, :create, :edit, :search, :update, :destroy, :delete], for: p1.master) + is_expected.to have_ability([:create], for: Spree::Variant) + is_expected.to have_ability([:admin, :index, :read, :create, :edit, :search, :update, :destroy, :delete], for: p1.master) end it "should not be able to read/write other enterprises' product variants" do - should_not have_ability([:admin, :index, :read, :create, :edit, :search, :update, :destroy], for: p2.master) + is_expected.not_to have_ability([:admin, :index, :read, :create, :edit, :search, :update, :destroy], for: p2.master) end it "should be able to read/write their enterprises' product properties" do - should have_ability([:admin, :index, :read, :create, :edit, :update_positions, :destroy], for: Spree::ProductProperty) + is_expected.to have_ability([:admin, :index, :read, :create, :edit, :update_positions, :destroy], for: Spree::ProductProperty) end it "should be able to read/write their enterprises' product images" do - should have_ability([:admin, :index, :read, :create, :edit, :update, :destroy], for: Spree::Image) + is_expected.to have_ability([:admin, :index, :read, :create, :edit, :update, :destroy], for: Spree::Image) end it "should be able to read Taxons (in order to create classifications)" do - should have_ability([:admin, :index, :read, :search], for: Spree::Taxon) + is_expected.to have_ability([:admin, :index, :read, :search], for: Spree::Taxon) end it "should be able to read/write Classifications on a product" do - should have_ability([:admin, :index, :read, :create, :edit], for: Spree::Classification) + is_expected.to have_ability([:admin, :index, :read, :create, :edit], for: Spree::Classification) end it "should be able to read/write their enterprises' producer properties" do - should have_ability([:admin, :index, :read, :create, :edit, :update_positions, :destroy], for: ProducerProperty) + is_expected.to have_ability([:admin, :index, :read, :create, :edit, :update_positions, :destroy], for: ProducerProperty) end it "should be able to read and create enterprise relationships" do - should have_ability([:admin, :index, :create], for: EnterpriseRelationship) + is_expected.to have_ability([:admin, :index, :create], for: EnterpriseRelationship) end it "should be able to destroy enterprise relationships for its enterprises" do - should have_ability(:destroy, for: er1) + is_expected.to have_ability(:destroy, for: er1) end it "should not be able to destroy enterprise relationships for other enterprises" do - should_not have_ability(:destroy, for: er2) + is_expected.not_to have_ability(:destroy, for: er2) end it "should be able to read some reports" do - should have_ability([:admin, :index, :customers, :bulk_coop, :orders_and_fulfillment, :products_and_inventory, :order_cycle_management], for: Spree::Admin::ReportsController) + is_expected.to have_ability([:admin, :index, :customers, :bulk_coop, :orders_and_fulfillment, :products_and_inventory, :order_cycle_management], for: Spree::Admin::ReportsController) end include_examples "allows access to Enterprise Fee Summary only if feature flag enabled" it "should not be able to read other reports" do - should_not have_ability([:sales_total, :group_buys, :payments, :orders_and_distributors, :users_and_enterprises, :xero_invoices], for: Spree::Admin::ReportsController) + is_expected.not_to have_ability([:sales_total, :group_buys, :payments, :orders_and_distributors, :users_and_enterprises, :xero_invoices], for: Spree::Admin::ReportsController) end it "should not be able to access customer actions" do - should_not have_ability([:admin, :index, :update], for: Customer) + is_expected.not_to have_ability([:admin, :index, :update], for: Customer) end describe "order_cycles abilities" do @@ -232,19 +232,19 @@ module Spree let!(:order_cycle) { create(:simple_order_cycle) } it "should not be able to access read/update order_cycle actions" do - should_not have_ability([:admin, :index, :read, :edit, :update], for: order_cycle) + is_expected.not_to have_ability([:admin, :index, :read, :edit, :update], for: order_cycle) end it "should not be able to access bulk_update, clone order cycle actions" do - should_not have_ability([:bulk_update, :clone], for: order_cycle) + is_expected.not_to have_ability([:bulk_update, :clone], for: order_cycle) end it "cannot request permitted enterprises for an order cycle" do - should_not have_ability([:for_order_cycle], for: Enterprise) + is_expected.not_to have_ability([:for_order_cycle], for: Enterprise) end it "cannot request permitted enterprise fees for an order cycle" do - should_not have_ability([:for_order_cycle], for: EnterpriseFee) + is_expected.not_to have_ability([:for_order_cycle], for: EnterpriseFee) end end @@ -253,19 +253,19 @@ module Spree let!(:exchange){ create(:exchange, incoming: true, order_cycle: order_cycle, receiver: order_cycle.coordinator, sender: s1) } it "should be able to access read/update order cycle actions" do - should have_ability([:admin, :index, :read, :edit, :update], for: order_cycle) + is_expected.to have_ability([:admin, :index, :read, :edit, :update], for: order_cycle) end it "should not be able to access bulk/update, clone order cycle actions" do - should_not have_ability([:bulk_update, :clone], for: order_cycle) + is_expected.not_to have_ability([:bulk_update, :clone], for: order_cycle) end it "can request permitted enterprises for an order cycle" do - should have_ability([:for_order_cycle], for: Enterprise) + is_expected.to have_ability([:for_order_cycle], for: Enterprise) end it "can request permitted enterprise fees for an order cycle" do - should have_ability([:for_order_cycle], for: EnterpriseFee) + is_expected.to have_ability([:for_order_cycle], for: EnterpriseFee) end end end @@ -301,19 +301,19 @@ module Spree let!(:er_pd) { create(:enterprise_relationship, parent: d_related, child: d1, permissions_list: [:edit_profile]) } it "should be able to edit enterprises it manages" do - should have_ability([:read, :edit, :update, :remove_logo, :remove_promo_image, :bulk_update, :resend_confirmation], for: d1) + is_expected.to have_ability([:read, :edit, :update, :remove_logo, :remove_promo_image, :bulk_update, :resend_confirmation], for: d1) end it "should be able to edit enterprises it has permission to" do - should have_ability([:read, :edit, :update, :remove_logo, :remove_promo_image, :bulk_update, :resend_confirmation], for: d_related) + is_expected.to have_ability([:read, :edit, :update, :remove_logo, :remove_promo_image, :bulk_update, :resend_confirmation], for: d_related) end it "should be able to manage shipping methods, payment methods and enterprise fees for enterprises it manages" do - should have_ability([:manage_shipping_methods, :manage_payment_methods, :manage_enterprise_fees], for: d1) + is_expected.to have_ability([:manage_shipping_methods, :manage_payment_methods, :manage_enterprise_fees], for: d1) end it "should not be able to manage shipping methods, payment methods and enterprise fees for enterprises it has edit profile permission to" do - should_not have_ability([:manage_shipping_methods, :manage_payment_methods, :manage_enterprise_fees], for: d_related) + is_expected.not_to have_ability([:manage_shipping_methods, :manage_payment_methods, :manage_enterprise_fees], for: d_related) end end @@ -326,98 +326,98 @@ module Spree let!(:er1) { create(:enterprise_relationship, parent: s1, child: d1, permissions_list: [:create_variant_overrides]) } it "should be able to access variant overrides page" do - should have_ability([:admin, :index, :bulk_update, :bulk_reset], for: VariantOverride) + is_expected.to have_ability([:admin, :index, :bulk_update, :bulk_reset], for: VariantOverride) end it "should be able to read/write their own variant overrides" do - should have_ability([:admin, :index, :read, :update], for: vo1) + is_expected.to have_ability([:admin, :index, :read, :update], for: vo1) end it "should not be able to read/write variant overrides when producer of product hasn't granted permission" do - should_not have_ability([:admin, :index, :read, :update], for: vo2) + is_expected.not_to have_ability([:admin, :index, :read, :update], for: vo2) end it "should not be able to read/write variant overrides when we can't add hub to order cycle" do - should_not have_ability([:admin, :index, :read, :update], for: vo3) + is_expected.not_to have_ability([:admin, :index, :read, :update], for: vo3) end it "should not be able to read/write other enterprises' variant overrides" do - should_not have_ability([:admin, :index, :read, :update], for: vo4) + is_expected.not_to have_ability([:admin, :index, :read, :update], for: vo4) end end it "should be able to read/write their enterprises' orders" do - should have_ability([:admin, :index, :read, :edit], for: o1) + is_expected.to have_ability([:admin, :index, :read, :edit], for: o1) end it "should not be able to read/write other enterprises' orders" do - should_not have_ability([:admin, :index, :read, :edit], for: o2) + is_expected.not_to have_ability([:admin, :index, :read, :edit], for: o2) end it "should be able to read/write orders that are in the process of being created" do - should have_ability([:admin, :index, :read, :edit], for: o3) + is_expected.to have_ability([:admin, :index, :read, :edit], for: o3) end it "should be able to create and search on nil (required for creating an order)" do - should have_ability([:create, :search], for: nil) + is_expected.to have_ability([:create, :search], for: nil) end it "should be able to create a new order" do - should have_ability([:admin, :index, :read, :create, :update], for: Spree::Order) + is_expected.to have_ability([:admin, :index, :read, :create, :update], for: Spree::Order) end it "should be able to create a new line item" do - should have_ability([:admin, :create], for: Spree::LineItem) + is_expected.to have_ability([:admin, :create], for: Spree::LineItem) end it "should be able to read/write Payments on a product" do - should have_ability([:admin, :index, :read, :create, :edit, :update, :fire], for: Spree::Payment) + is_expected.to have_ability([:admin, :index, :read, :create, :edit, :update, :fire], for: Spree::Payment) end it "should be able to read/write Shipments on a product" do - should have_ability([:admin, :index, :read, :create, :edit, :update, :fire], for: Spree::Shipment) + is_expected.to have_ability([:admin, :index, :read, :create, :edit, :update, :fire], for: Spree::Shipment) end it "should be able to read/write Adjustments on a product" do - should have_ability([:admin, :index, :read, :create, :edit, :update, :fire], for: Spree::Adjustment) + is_expected.to have_ability([:admin, :index, :read, :create, :edit, :update, :fire], for: Spree::Adjustment) end it "should be able to read/write ReturnAuthorizations on a product" do - should have_ability([:admin, :index, :read, :create, :edit, :update, :fire], for: Spree::ReturnAuthorization) + is_expected.to have_ability([:admin, :index, :read, :create, :edit, :update, :fire], for: Spree::ReturnAuthorization) end it "should be able to read/write PaymentMethods" do - should have_ability([:admin, :index, :create, :update, :destroy], for: Spree::PaymentMethod) + is_expected.to have_ability([:admin, :index, :create, :update, :destroy], for: Spree::PaymentMethod) end it "should be able to read/write ShippingMethods" do - should have_ability([:admin, :index, :create, :update, :destroy], for: Spree::ShippingMethod) + is_expected.to have_ability([:admin, :index, :create, :update, :destroy], for: Spree::ShippingMethod) end it "should be able to read and create enterprise relationships" do - should have_ability([:admin, :index, :create], for: EnterpriseRelationship) + is_expected.to have_ability([:admin, :index, :create], for: EnterpriseRelationship) end it "should be able to destroy enterprise relationships for its enterprises" do - should have_ability(:destroy, for: er2) + is_expected.to have_ability(:destroy, for: er2) end it "should not be able to destroy enterprise relationships for other enterprises" do - should_not have_ability(:destroy, for: er1) + is_expected.not_to have_ability(:destroy, for: er1) end it "should be able to read some reports" do - should have_ability([:admin, :index, :customers, :sales_tax, :group_buys, :bulk_coop, :payments, :orders_and_distributors, :orders_and_fulfillment, :products_and_inventory, :order_cycle_management, :xero_invoices], for: Spree::Admin::ReportsController) + is_expected.to have_ability([:admin, :index, :customers, :sales_tax, :group_buys, :bulk_coop, :payments, :orders_and_distributors, :orders_and_fulfillment, :products_and_inventory, :order_cycle_management, :xero_invoices], for: Spree::Admin::ReportsController) end include_examples "allows access to Enterprise Fee Summary only if feature flag enabled" it "should not be able to read other reports" do - should_not have_ability([:sales_total, :users_and_enterprises], for: Spree::Admin::ReportsController) + is_expected.not_to have_ability([:sales_total, :users_and_enterprises], for: Spree::Admin::ReportsController) end it "should be able to access customer actions" do - should have_ability([:admin, :index, :update], for: Customer) + is_expected.to have_ability([:admin, :index, :update], for: Customer) end context "for a given order_cycle" do @@ -425,20 +425,20 @@ module Spree let!(:exchange){ create(:exchange, incoming: false, order_cycle: order_cycle, receiver: d1, sender: order_cycle.coordinator) } it "should be able to access read and update order cycle actions" do - should have_ability([:admin, :index, :read, :edit, :update], for: order_cycle) + is_expected.to have_ability([:admin, :index, :read, :edit, :update], for: order_cycle) end it "should not be able to access bulk_update, clone order cycle actions" do - should_not have_ability([:bulk_update, :clone], for: order_cycle) + is_expected.not_to have_ability([:bulk_update, :clone], for: order_cycle) end end it "can request permitted enterprises for an order cycle" do - should have_ability([:for_order_cycle], for: Enterprise) + is_expected.to have_ability([:for_order_cycle], for: Enterprise) end it "can request permitted enterprise fees for an order cycle" do - should have_ability([:for_order_cycle], for: EnterpriseFee) + is_expected.to have_ability([:for_order_cycle], for: EnterpriseFee) end end @@ -454,7 +454,7 @@ module Spree let(:oc2) { create(:simple_order_cycle) } it "should be able to read/write OrderCycles they are the co-ordinator of" do - should have_ability([:admin, :index, :read, :edit, :update, :bulk_update, :clone, :destroy], for: oc1) + is_expected.to have_ability([:admin, :index, :read, :edit, :update, :bulk_update, :clone, :destroy], for: oc1) end it "should not be able to read/write OrderCycles they are not the co-ordinator of" do @@ -462,15 +462,15 @@ module Spree end it "should be able to create OrderCycles" do - should have_ability([:create], for: OrderCycle) + is_expected.to have_ability([:create], for: OrderCycle) end it "should be able to read/write EnterpriseFees" do - should have_ability([:admin, :index, :read, :create, :edit, :bulk_update, :destroy, :for_order_cycle], for: EnterpriseFee) + is_expected.to have_ability([:admin, :index, :read, :create, :edit, :bulk_update, :destroy, :for_order_cycle], for: EnterpriseFee) end it "should be able to add enterprises to order cycles" do - should have_ability([:admin, :index, :for_order_cycle, :create], for: Enterprise) + is_expected.to have_ability([:admin, :index, :for_order_cycle, :create], for: Enterprise) end end @@ -483,28 +483,28 @@ module Spree end it 'should have the ability to view the admin account page' do - should have_ability([:admin, :show], for: :account) + is_expected.to have_ability([:admin, :show], for: :account) end it 'should have the ability to read and edit enterprises that I manage' do - should have_ability([:read, :edit, :update, :bulk_update], for: s1) + is_expected.to have_ability([:read, :edit, :update, :bulk_update], for: s1) end it 'should not have the ability to read and edit enterprises that I do not manage' do - should_not have_ability([:read, :edit, :update, :bulk_update], for: s2) + is_expected.not_to have_ability([:read, :edit, :update, :bulk_update], for: s2) end it 'should not have the ability to welcome and register enterprises that I do not own' do - should_not have_ability([:welcome, :register], for: s1) + is_expected.not_to have_ability([:welcome, :register], for: s1) end it 'should have the ability administrate and create enterpises' do - should have_ability([:admin, :index, :create], for: Enterprise) + is_expected.to have_ability([:admin, :index, :create], for: Enterprise) end it "should have the ability to search for users which share management of its enterprises" do - should have_ability([:admin, :known_users, :customers], for: :search) - should_not have_ability([:users], for: :search) + is_expected.to have_ability([:admin, :known_users, :customers], for: :search) + is_expected.not_to have_ability([:users], for: :search) end end @@ -512,11 +512,11 @@ module Spree let(:user) { s1.owner } it 'should have the ability to welcome and register enterprises that I own' do - should have_ability([:welcome, :register], for: s1) + is_expected.to have_ability([:welcome, :register], for: s1) end it 'should have the ability to view the admin account page' do - should have_ability([:admin, :show], for: :account) + is_expected.to have_ability([:admin, :show], for: :account) end end end diff --git a/spec/models/spree/adjustment_spec.rb b/spec/models/spree/adjustment_spec.rb index a8693843b0..d4ca03788e 100644 --- a/spec/models/spree/adjustment_spec.rb +++ b/spec/models/spree/adjustment_spec.rb @@ -4,7 +4,7 @@ module Spree describe Adjustment do it "has metadata" do adjustment = create(:adjustment, metadata: create(:adjustment_metadata)) - adjustment.metadata.should be + expect(adjustment.metadata).to be end describe "querying included tax" do @@ -13,23 +13,23 @@ module Spree describe "finding adjustments with and without tax included" do it "finds adjustments with tax" do - Adjustment.with_tax.should include adjustment_with_tax - Adjustment.with_tax.should_not include adjustment_without_tax + expect(Adjustment.with_tax).to include adjustment_with_tax + expect(Adjustment.with_tax).not_to include adjustment_without_tax end it "finds adjustments without tax" do - Adjustment.without_tax.should include adjustment_without_tax - Adjustment.without_tax.should_not include adjustment_with_tax + expect(Adjustment.without_tax).to include adjustment_without_tax + expect(Adjustment.without_tax).not_to include adjustment_with_tax end end describe "checking if an adjustment includes tax" do it "returns true when it has > 0 tax" do - adjustment_with_tax.should have_tax + expect(adjustment_with_tax).to have_tax end it "returns false when it has 0 tax" do - adjustment_without_tax.should_not have_tax + expect(adjustment_without_tax).not_to have_tax end end end @@ -48,8 +48,8 @@ module Spree end it "has 100% tax included" do - adjustment.amount.should be > 0 - adjustment.included_tax.should == adjustment.amount + expect(adjustment.amount).to be > 0 + expect(adjustment.included_tax).to eq(adjustment.amount) end it "does not crash when order data has been updated previously" do @@ -151,7 +151,7 @@ module Spree # The fee is $50, tax is 10%, and the fee is inclusive of tax # Therefore, the included tax should be 0.1/1.1 * 50 = $4.55 - adjustment.included_tax.should == 4.55 + expect(adjustment.included_tax).to eq(4.55) end end @@ -163,8 +163,8 @@ module Spree end it "records the tax on TaxRate adjustment on the order" do - adjustment.included_tax.should == 0 - order.adjustments.tax.first.amount.should == 5.0 + expect(adjustment.included_tax).to eq(0) + expect(order.adjustments.tax.first.amount).to eq(5.0) end end @@ -176,7 +176,7 @@ module Spree end it "records no tax as charged" do - adjustment.included_tax.should == 0 + expect(adjustment.included_tax).to eq(0) end end end @@ -186,7 +186,7 @@ module Spree describe "when the tax rate includes the tax in the price" do it "records the tax on the enterprise fee adjustments" do - adjustment.included_tax.should == 4.55 + expect(adjustment.included_tax).to eq(4.55) end end @@ -198,8 +198,8 @@ module Spree end it "records the tax on TaxRate adjustment on the order" do - adjustment.included_tax.should == 0 - order.adjustments.tax.first.amount.should == 5.0 + expect(adjustment.included_tax).to eq(0) + expect(order.adjustments.tax.first.amount).to eq(5.0) end end end @@ -224,8 +224,8 @@ module Spree # EnterpriseFee tax category is nil and inheritance only applies to per item fees # so tax on the enterprise_fee adjustment will be 0 # Tax on line item is: 0.2/1.2 x $10 = $1.67 - adjustment.included_tax.should == 0.0 - line_item.adjustments.first.included_tax.should == 1.67 + expect(adjustment.included_tax).to eq(0.0) + expect(line_item.adjustments.first.included_tax).to eq(1.67) end end @@ -240,8 +240,8 @@ module Spree # EnterpriseFee tax category is nil and inheritance only applies to per item fees # so total tax on the order is only that which applies to the line_item itself # ie. $10 x 0.2 = $2.0 - adjustment.included_tax.should == 0 - order.adjustments.tax.first.amount.should == 2.0 + expect(adjustment.included_tax).to eq(0) + expect(order.adjustments.tax.first.amount).to eq(2.0) end end end @@ -254,8 +254,8 @@ module Spree # Applying product tax rate of 0.2 to enterprise fee of $50 # gives tax on fee of 0.2/1.2 x $50 = $8.33 # Tax on line item is: 0.2/1.2 x $10 = $1.67 - adjustment.included_tax.should == 8.33 - line_item.adjustments.first.included_tax.should == 1.67 + expect(adjustment.included_tax).to eq(8.33) + expect(line_item.adjustments.first.included_tax).to eq(1.67) end end @@ -270,8 +270,8 @@ module Spree # EnterpriseFee inherits tax_category from product so total tax on # the order is that which applies to the line item itself, plus the # same rate applied to the fee of $50. ie. ($10 + $50) x 0.2 = $12.0 - adjustment.included_tax.should == 0 - order.adjustments.tax.first.amount.should == 12.0 + expect(adjustment.included_tax).to eq(0) + expect(order.adjustments.tax.first.amount).to eq(12.0) end end end @@ -283,7 +283,7 @@ module Spree it "sets it, rounding to two decimal places" do adjustment.set_included_tax! 0.25 - adjustment.included_tax.should == 10.00 + expect(adjustment.included_tax).to eq(10.00) end end end diff --git a/spec/models/spree/calculator/flat_percent_item_total_spec.rb b/spec/models/spree/calculator/flat_percent_item_total_spec.rb index c31de2f1ef..529c2b11d9 100644 --- a/spec/models/spree/calculator/flat_percent_item_total_spec.rb +++ b/spec/models/spree/calculator/flat_percent_item_total_spec.rb @@ -4,10 +4,10 @@ describe Spree::Calculator::FlatPercentItemTotal do let(:calculator) { Spree::Calculator::FlatPercentItemTotal.new } let(:line_item) { build(:line_item, price: 10, quantity: 1) } - before { calculator.stub preferred_flat_percent: 10 } + before { allow(calculator).to receive_messages preferred_flat_percent: 10 } it "computes amount correctly for a single line item" do - calculator.compute(line_item).should == 1.0 + expect(calculator.compute(line_item)).to eq(1.0) end context "extends LocalizedNumber" do @@ -18,6 +18,6 @@ describe Spree::Calculator::FlatPercentItemTotal do order = double(:order, line_items: [line_item] ) package = double(:package, order: order) - calculator.compute(package).should == 1.0 + expect(calculator.compute(package)).to eq(1.0) end end diff --git a/spec/models/spree/calculator/flat_rate_spec.rb b/spec/models/spree/calculator/flat_rate_spec.rb index 42b594b30f..be8c4911c7 100644 --- a/spec/models/spree/calculator/flat_rate_spec.rb +++ b/spec/models/spree/calculator/flat_rate_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' describe Spree::Calculator::FlatRate do let(:calculator) { Spree::Calculator::FlatRate.new } - before { calculator.stub :preferred_amount => 10 } + before { allow(calculator).to receive_messages :preferred_amount => 10 } context "extends LocalizedNumber" do it_behaves_like "a model using the LocalizedNumber module", [:preferred_amount] diff --git a/spec/models/spree/calculator/per_item_spec.rb b/spec/models/spree/calculator/per_item_spec.rb index a50c5264b3..640c4b32f6 100644 --- a/spec/models/spree/calculator/per_item_spec.rb +++ b/spec/models/spree/calculator/per_item_spec.rb @@ -6,8 +6,8 @@ describe Spree::Calculator::PerItem do let(:line_item) { build(:line_item, quantity: 5) } it "correctly calculates on a single line item object" do - calculator.stub(calculable: shipping_calculable) - calculator.compute(line_item).to_f.should == 50 # 5 x 10 + allow(calculator).to receive_messages(calculable: shipping_calculable) + expect(calculator.compute(line_item).to_f).to eq(50) # 5 x 10 end context "extends LocalizedNumber" do diff --git a/spec/models/spree/classification_spec.rb b/spec/models/spree/classification_spec.rb index f8a58fd693..c93825aeaa 100644 --- a/spec/models/spree/classification_spec.rb +++ b/spec/models/spree/classification_spec.rb @@ -8,8 +8,8 @@ module Spree it "won't destroy if classification is the primary taxon" do product.primary_taxon = taxon - classification.destroy.should be false - classification.errors.messages[:base].should == ["Taxon #{taxon.name} is the primary taxon of #{product.name} and cannot be deleted"] + expect(classification.destroy).to be false + expect(classification.errors.messages[:base]).to eq(["Taxon #{taxon.name} is the primary taxon of #{product.name} and cannot be deleted"]) end describe "callbacks" do diff --git a/spec/models/spree/image_spec.rb b/spec/models/spree/image_spec.rb index c9a9c1243c..63350817b8 100644 --- a/spec/models/spree/image_spec.rb +++ b/spec/models/spree/image_spec.rb @@ -7,11 +7,11 @@ module Spree let(:formatted) { {mini: ["48x48>", "png"]} } it "converts style names to symbols" do - Image.format_styles(name_str).should == {:mini => "48x48>"} + expect(Image.format_styles(name_str)).to eq({:mini => "48x48>"}) end it "converts formats to symbols" do - Image.format_styles(formatted).should == {:mini => ["48x48>", :png]} + expect(Image.format_styles(formatted)).to eq({:mini => ["48x48>", :png]}) end end diff --git a/spec/models/spree/line_item_spec.rb b/spec/models/spree/line_item_spec.rb index 9f85774bf9..dd449501ca 100644 --- a/spec/models/spree/line_item_spec.rb +++ b/spec/models/spree/line_item_spec.rb @@ -28,14 +28,14 @@ module Spree let(:oc_order) { create :order_with_totals_and_distribution } it "finds line items for products supplied by a particular enterprise" do - LineItem.supplied_by(s1).should == [li1] - LineItem.supplied_by(s2).should == [li2] + expect(LineItem.supplied_by(s1)).to eq([li1]) + expect(LineItem.supplied_by(s2)).to eq([li2]) end it "finds line items for products supplied by one of a number of enterprises" do - LineItem.supplied_by_any([s1]).should == [li1] - LineItem.supplied_by_any([s2]).should == [li2] - LineItem.supplied_by_any([s1, s2]).should match_array [li1, li2] + expect(LineItem.supplied_by_any([s1])).to eq([li1]) + expect(LineItem.supplied_by_any([s2])).to eq([li2]) + expect(LineItem.supplied_by_any([s1, s2])).to match_array [li1, li2] end describe "finding line items with and without tax" do @@ -46,11 +46,11 @@ module Spree before { li1; li2 } it "finds line items with tax" do - LineItem.with_tax.should == [li1] + expect(LineItem.with_tax).to eq([li1]) end it "finds line items without tax" do - LineItem.without_tax.should == [li2] + expect(LineItem.without_tax).to eq([li2]) end end @@ -225,10 +225,10 @@ module Spree it "does not return fractional cents" do li = LineItem.new - li.stub(:price) { 55.55 } - li.stub_chain(:order, :adjustments, :where, :sum) { 11.11 } - li.stub(:quantity) { 2 } - li.price_with_adjustments.should == 61.11 + allow(li).to receive(:price) { 55.55 } + allow(li).to receive_message_chain(:order, :adjustments, :where, :sum) { 11.11 } + allow(li).to receive(:quantity) { 2 } + expect(li.price_with_adjustments).to eq(61.11) end end @@ -236,10 +236,10 @@ module Spree it "returns a value consistent with price_with_adjustments" do li = LineItem.new - li.stub(:price) { 55.55 } - li.stub_chain(:order, :adjustments, :where, :sum) { 11.11 } - li.stub(:quantity) { 2 } - li.amount_with_adjustments.should == 122.22 + allow(li).to receive(:price) { 55.55 } + allow(li).to receive_message_chain(:order, :adjustments, :where, :sum) { 11.11 } + allow(li).to receive(:quantity) { 2 } + expect(li.amount_with_adjustments).to eq(122.22) end end @@ -407,45 +407,45 @@ module Spree context "when display_name is blank" do before do - li.stub(:unit_to_display) { 'unit_to_display' } - li.stub(:display_name) { '' } + allow(li).to receive(:unit_to_display) { 'unit_to_display' } + allow(li).to receive(:display_name) { '' } end it "returns unit_to_display" do - li.full_name.should == 'unit_to_display' + expect(li.full_name).to eq('unit_to_display') end end context "when unit_to_display contains display_name" do before do - li.stub(:unit_to_display) { '1kg Jar' } - li.stub(:display_name) { '1kg' } + allow(li).to receive(:unit_to_display) { '1kg Jar' } + allow(li).to receive(:display_name) { '1kg' } end it "returns unit_to_display" do - li.full_name.should == '1kg Jar' + expect(li.full_name).to eq('1kg Jar') end end context "when display_name contains unit_to_display" do before do - li.stub(:unit_to_display) { '10kg' } - li.stub(:display_name) { '10kg Box' } + allow(li).to receive(:unit_to_display) { '10kg' } + allow(li).to receive(:display_name) { '10kg Box' } end it "returns display_name" do - li.full_name.should == '10kg Box' + expect(li.full_name).to eq('10kg Box') end end context "otherwise" do before do - li.stub(:unit_to_display) { '1 Loaf' } - li.stub(:display_name) { 'Spelt Sourdough' } + allow(li).to receive(:unit_to_display) { '1 Loaf' } + allow(li).to receive(:display_name) { 'Spelt Sourdough' } end it "returns unit_to_display" do - li.full_name.should == 'Spelt Sourdough (1 Loaf)' + expect(li.full_name).to eq('Spelt Sourdough (1 Loaf)') end end end @@ -459,7 +459,7 @@ module Spree before { allow(li).to receive(:full_name) { p.name + " - something" } } it "does not show the product name twice" do - li.product_and_full_name.should == 'product - something' + expect(li.product_and_full_name).to eq('product - something') end end @@ -467,7 +467,7 @@ module Spree before { allow(li).to receive(:full_name) { "display_name (unit)" } } it "prepends the product name to the full name" do - li.product_and_full_name.should == 'product - display_name (unit)' + expect(li.product_and_full_name).to eq('product - display_name (unit)') end end end @@ -475,15 +475,15 @@ module Spree describe "getting name for display" do it "returns product name" do li = create(:line_item, product: create(:product)) - li.name_to_display.should == li.product.name + expect(li.name_to_display).to eq(li.product.name) end end describe "getting unit for display" do it "returns options_text" do li = create(:line_item) - li.stub(:options_text).and_return "ponies" - li.unit_to_display.should == "ponies" + allow(li).to receive(:options_text).and_return "ponies" + expect(li.unit_to_display).to eq("ponies") end end @@ -503,10 +503,10 @@ module Spree li.update_attribute(:final_weight_volume, 10) }.to change(Spree::OptionValue, :count).by(1) - li.option_values.should_not include ov_orig - li.option_values.should_not include ov_var + expect(li.option_values).not_to include ov_orig + expect(li.option_values).not_to include ov_var ov = li.option_values.last - ov.name.should == "10g foo" + expect(ov.name).to eq("10g foo") end end @@ -526,8 +526,8 @@ module Spree li.update_attribute(:final_weight_volume, 10) }.to change(Spree::OptionValue, :count).by(0) - li.option_values.should_not include ov_orig - li.option_values.should include ov_new + expect(li.option_values).not_to include ov_orig + expect(li.option_values).to include ov_new end end diff --git a/spec/models/spree/order_spec.rb b/spec/models/spree/order_spec.rb index 54d181916c..f14c5ff1cf 100644 --- a/spec/models/spree/order_spec.rb +++ b/spec/models/spree/order_spec.rb @@ -14,7 +14,7 @@ describe Spree::Order do subject.add_variant(p.master, 1, 3) li = Spree::LineItem.last - li.max_quantity.should == 3 + expect(li.max_quantity).to eq(3) end it "does nothing when the line item is not found" do @@ -27,45 +27,45 @@ describe Spree::Order do let(:order) { build(:order) } it "clears all enterprise fee adjustments on the order" do - EnterpriseFee.should_receive(:clear_all_adjustments_on_order).with(subject) + expect(EnterpriseFee).to receive(:clear_all_adjustments_on_order).with(subject) subject.update_distribution_charge! end it "skips order cycle per-order adjustments for orders that don't have an order cycle" do - EnterpriseFee.stub(:clear_all_adjustments_on_order) - subject.stub(:line_items) { [] } + allow(EnterpriseFee).to receive(:clear_all_adjustments_on_order) + allow(subject).to receive(:line_items) { [] } - subject.stub(:order_cycle) { nil } + allow(subject).to receive(:order_cycle) { nil } subject.update_distribution_charge! end it "ensures the correct adjustment(s) are created for order cycles" do - EnterpriseFee.stub(:clear_all_adjustments_on_order) + allow(EnterpriseFee).to receive(:clear_all_adjustments_on_order) line_item = double(:line_item) - subject.stub(:line_items) { [line_item] } - subject.stub(:provided_by_order_cycle?) { true } + allow(subject).to receive(:line_items) { [line_item] } + allow(subject).to receive(:provided_by_order_cycle?) { true } order_cycle = double(:order_cycle) - OpenFoodNetwork::EnterpriseFeeCalculator.any_instance. - should_receive(:create_line_item_adjustments_for). + expect_any_instance_of(OpenFoodNetwork::EnterpriseFeeCalculator). + to receive(:create_line_item_adjustments_for). with(line_item) - OpenFoodNetwork::EnterpriseFeeCalculator.any_instance.stub(:create_order_adjustments_for) - subject.stub(:order_cycle) { order_cycle } + allow_any_instance_of(OpenFoodNetwork::EnterpriseFeeCalculator).to receive(:create_order_adjustments_for) + allow(subject).to receive(:order_cycle) { order_cycle } subject.update_distribution_charge! end it "ensures the correct per-order adjustment(s) are created for order cycles" do - EnterpriseFee.stub(:clear_all_adjustments_on_order) - subject.stub(:line_items) { [] } + allow(EnterpriseFee).to receive(:clear_all_adjustments_on_order) + allow(subject).to receive(:line_items) { [] } order_cycle = double(:order_cycle) - OpenFoodNetwork::EnterpriseFeeCalculator.any_instance. - should_receive(:create_order_adjustments_for). + expect_any_instance_of(OpenFoodNetwork::EnterpriseFeeCalculator). + to receive(:create_order_adjustments_for). with(subject) - subject.stub(:order_cycle) { order_cycle } + allow(subject).to receive(:order_cycle) { order_cycle } subject.update_distribution_charge! end @@ -76,26 +76,26 @@ describe Spree::Order do v = double(:variant) line_item = double(:line_item, variant: v) order_cycle = double(:order_cycle, variants: [v]) - subject.stub(:order_cycle) { order_cycle } + allow(subject).to receive(:order_cycle) { order_cycle } - subject.send(:provided_by_order_cycle?, line_item).should be true + expect(subject.send(:provided_by_order_cycle?, line_item)).to be true end it "returns false otherwise" do v = double(:variant) line_item = double(:line_item, variant: v) order_cycle = double(:order_cycle, variants: []) - subject.stub(:order_cycle) { order_cycle } + allow(subject).to receive(:order_cycle) { order_cycle } - subject.send(:provided_by_order_cycle?, line_item).should be false + expect(subject.send(:provided_by_order_cycle?, line_item)).to be false end it "returns false when there is no order cycle" do v = double(:variant) line_item = double(:line_item, variant: v) - subject.stub(:order_cycle) { nil } + allow(subject).to receive(:order_cycle) { nil } - subject.send(:provided_by_order_cycle?, line_item).should be false + expect(subject.send(:provided_by_order_cycle?, line_item)).to be false end end @@ -108,7 +108,7 @@ describe Spree::Order do ef.calculator.set_preference :amount, 123.45 a = ef.create_adjustment("adjustment", o, o, true) - o.admin_and_handling_total.should == 123.45 + expect(o.admin_and_handling_total).to eq(123.45) end it "does not include ineligible adjustments" do @@ -118,7 +118,7 @@ describe Spree::Order do a.update_column :eligible, false - o.admin_and_handling_total.should == 0 + expect(o.admin_and_handling_total).to eq(0) end it "does not include adjustments that do not originate from enterprise fees" do @@ -126,7 +126,7 @@ describe Spree::Order do sm.calculator.set_preference :amount, 123.45 sm.create_adjustment("adjustment", o, o, true) - o.admin_and_handling_total.should == 0 + expect(o.admin_and_handling_total).to eq(0) end it "does not include adjustments whose source is a line item" do @@ -134,7 +134,7 @@ describe Spree::Order do ef.calculator.set_preference :amount, 123.45 ef.create_adjustment("adjustment", li.order, li, true) - o.admin_and_handling_total.should == 0 + expect(o.admin_and_handling_total).to eq(0) end end @@ -142,7 +142,7 @@ describe Spree::Order do let(:order) { create(:order) } it "cannot be shipped" do - order.ready_to_ship?.should == false + expect(order.ready_to_ship?).to eq(false) end end @@ -156,7 +156,7 @@ describe Spree::Order do end it "cannot be shipped" do - order.ready_to_ship?.should == false + expect(order.ready_to_ship?).to eq(false) end end @@ -169,7 +169,7 @@ describe Spree::Order do end it "cannot be shipped" do - order.ready_to_ship?.should == false + expect(order.ready_to_ship?).to eq(false) end end @@ -183,7 +183,7 @@ describe Spree::Order do end it "can be shipped" do - order.ready_to_ship?.should == true + expect(order.ready_to_ship?).to eq(true) end end @@ -200,13 +200,13 @@ describe Spree::Order do let!(:shipment) { create(:shipment_with, :shipping_method, shipping_method: shipping_method, order: order) } it "returns the shipping tax" do - order.shipping_tax.should == 10 + expect(order.shipping_tax).to eq(10) end end context 'when the order has not been shipped' do it "returns zero when the order has not been shipped" do - order.shipping_tax.should == 0 + expect(order.shipping_tax).to eq(0) end end end @@ -219,7 +219,7 @@ describe Spree::Order do let!(:adjustment2) { create(:adjustment, adjustable: order, originator: enterprise_fee2, label: "EF 2", amount: 123, included_tax: 2.00) } it "returns a sum of the tax included in all enterprise fees" do - order.reload.enterprise_fee_tax.should == 12 + expect(order.reload.enterprise_fee_tax).to eq(12) end end @@ -322,7 +322,7 @@ describe Spree::Order do it "sets the distributor when no order cycle is set" do d = create(:distributor_enterprise) subject.set_distributor! d - subject.distributor.should == d + expect(subject.distributor).to eq(d) end it "keeps the order cycle when it is available at the new distributor" do @@ -333,8 +333,8 @@ describe Spree::Order do subject.order_cycle = oc subject.set_distributor! d - subject.distributor.should == d - subject.order_cycle.should == oc + expect(subject.distributor).to eq(d) + expect(subject.order_cycle).to eq(oc) end it "clears the order cycle if it is not available at that distributor" do @@ -344,8 +344,8 @@ describe Spree::Order do subject.order_cycle = oc subject.set_distributor! d - subject.distributor.should == d - subject.order_cycle.should be_nil + expect(subject.distributor).to eq(d) + expect(subject.order_cycle).to be_nil end it "clears the distributor when setting to nil" do @@ -353,7 +353,7 @@ describe Spree::Order do subject.set_distributor! d subject.set_distributor! nil - subject.distributor.should be_nil + expect(subject.distributor).to be_nil end end @@ -370,7 +370,7 @@ describe Spree::Order do it "removes the variant's line item" do order.remove_variant v1 - order.line_items(:reload).map(&:variant).should == [v2] + expect(order.line_items(:reload).map(&:variant)).to eq([v2]) end it "does nothing when there is no matching line item" do @@ -400,18 +400,18 @@ describe Spree::Order do let(:oc) { create(:simple_order_cycle) } it "empties the cart when changing the order cycle" do - subject.should_receive(:empty!) + expect(subject).to receive(:empty!) subject.set_order_cycle! oc end it "doesn't empty the cart if the order cycle is not different" do - subject.should_not_receive(:empty!) + expect(subject).not_to receive(:empty!) subject.set_order_cycle! subject.order_cycle end it "sets the order cycle when no distributor is set" do subject.set_order_cycle! oc - subject.order_cycle.should == oc + expect(subject.order_cycle).to eq(oc) end it "keeps the distributor when it is available in the new order cycle" do @@ -421,8 +421,8 @@ describe Spree::Order do subject.distributor = d subject.set_order_cycle! oc - subject.order_cycle.should == oc - subject.distributor.should == d + expect(subject.order_cycle).to eq(oc) + expect(subject.distributor).to eq(d) end it "clears the distributor if it is not available at that order cycle" do @@ -431,8 +431,8 @@ describe Spree::Order do subject.distributor = d subject.set_order_cycle! oc - subject.order_cycle.should == oc - subject.distributor.should be_nil + expect(subject.order_cycle).to eq(oc) + expect(subject.distributor).to be_nil end it "clears the order cycle when setting to nil" do @@ -442,8 +442,8 @@ describe Spree::Order do subject.set_order_cycle! nil - subject.order_cycle.should be_nil - subject.distributor.should == d + expect(subject.order_cycle).to be_nil + expect(subject.distributor).to eq(d) end end @@ -467,9 +467,9 @@ describe Spree::Order do new_order_cycle = create(:simple_order_cycle, distributors: [new_distributor], variants: [variant1, variant2]) subject.distributor = new_distributor - subject.should_not be_valid + expect(subject).not_to be_valid subject.order_cycle = new_order_cycle - subject.should be_valid + expect(subject).to be_valid end it "does not allow the change when not all variants in the order are provided by the new distributor" do @@ -477,8 +477,8 @@ describe Spree::Order do create(:simple_order_cycle, distributors: [new_distributor], variants: [variant1]) subject.distributor = new_distributor - subject.should_not be_valid - subject.errors.messages.should == {:base => ["Distributor or order cycle cannot supply the products in your cart"]} + expect(subject).not_to be_valid + expect(subject.errors.messages).to eq({:base => ["Distributor or order cycle cannot supply the products in your cart"]}) end end @@ -491,7 +491,7 @@ describe Spree::Order do it "finds only orders not in specified state" do o = FactoryBot.create(:completed_order_with_totals, distributor: create(:distributor_enterprise)) o.cancel! - Spree::Order.not_state(:canceled).should_not include o + expect(Spree::Order.not_state(:canceled)).not_to include o end end end diff --git a/spec/models/spree/payment_method_spec.rb b/spec/models/spree/payment_method_spec.rb index 1c021c2ce2..1a75f8a17a 100644 --- a/spec/models/spree/payment_method_spec.rb +++ b/spec/models/spree/payment_method_spec.rb @@ -7,24 +7,24 @@ module Spree pm2 = create(:payment_method, name: 'AA') pm3 = create(:payment_method, name: 'BB') - PaymentMethod.by_name.should == [pm2, pm3, pm1] + expect(PaymentMethod.by_name).to eq([pm2, pm3, pm1]) end it "raises errors when required fields are missing" do pm = PaymentMethod.new() pm.save - pm.errors.to_a.should == ["Name can't be blank", "At least one hub must be selected"] + expect(pm.errors.to_a).to eq(["Name can't be blank", "At least one hub must be selected"]) end it "generates a clean name for known Payment Method types" do - Spree::PaymentMethod::Check.clean_name.should == "Cash/EFT/etc. (payments for which automatic validation is not required)" - Spree::Gateway::Migs.clean_name.should == "MasterCard Internet Gateway Service (MIGS)" - Spree::Gateway::Pin.clean_name.should == "Pin Payments" - Spree::Gateway::PayPalExpress.clean_name.should == "PayPal Express" - Spree::Gateway::StripeConnect.clean_name.should == "Stripe" + expect(Spree::PaymentMethod::Check.clean_name).to eq("Cash/EFT/etc. (payments for which automatic validation is not required)") + expect(Spree::Gateway::Migs.clean_name).to eq("MasterCard Internet Gateway Service (MIGS)") + expect(Spree::Gateway::Pin.clean_name).to eq("Pin Payments") + expect(Spree::Gateway::PayPalExpress.clean_name).to eq("PayPal Express") + expect(Spree::Gateway::StripeConnect.clean_name).to eq("Stripe") # Testing else condition - Spree::Gateway::BogusSimple.clean_name.should == "BogusSimple" + expect(Spree::Gateway::BogusSimple.clean_name).to eq("BogusSimple") end it "computes the amount of fees" do diff --git a/spec/models/spree/payment_spec.rb b/spec/models/spree/payment_spec.rb index 64a25489c0..234df727a1 100644 --- a/spec/models/spree/payment_spec.rb +++ b/spec/models/spree/payment_spec.rb @@ -7,17 +7,17 @@ module Spree let(:payment) { create(:payment, source: create(:credit_card)) } it "can capture and void" do - payment.actions.should match_array %w(capture void) + expect(payment.actions).to match_array %w(capture void) end describe "when a payment has been taken" do before do - payment.stub(:state) { 'completed' } - payment.stub(:order) { double(:order, payment_state: 'credit_owed') } + allow(payment).to receive(:state) { 'completed' } + allow(payment).to receive(:order) { double(:order, payment_state: 'credit_owed') } end it "can void and credit" do - payment.actions.should match_array %w(void credit) + expect(payment.actions).to match_array %w(void credit) end end end @@ -28,18 +28,18 @@ module Spree let(:payment) { create(:payment, source: create(:credit_card), payment_method: pin) } it "does not void" do - payment.actions.should_not include 'void' + expect(payment.actions).not_to include 'void' end describe "when a payment has been taken" do before do - payment.stub(:state) { 'completed' } - payment.stub(:order) { double(:order, payment_state: 'credit_owed') } + allow(payment).to receive(:state) { 'completed' } + allow(payment).to receive(:order) { double(:order, payment_state: 'credit_owed') } end it "can refund instead of crediting" do - payment.actions.should_not include 'credit' - payment.actions.should include 'refund' + expect(payment.actions).not_to include 'credit' + expect(payment.actions).to include 'refund' end end end @@ -51,76 +51,76 @@ module Spree let(:failure) { double(:success? => false) } it "always checks the environment" do - payment.payment_method.stub(:refund) { success } - payment.should_receive(:check_environment) + allow(payment.payment_method).to receive(:refund) { success } + expect(payment).to receive(:check_environment) payment.refund! end describe "calculating refund amount" do it "returns the parameter amount when given" do - payment.send(:calculate_refund_amount, 123).should === 123.0 + expect(payment.send(:calculate_refund_amount, 123)).to be === 123.0 end it "refunds up to the value of the payment when the outstanding balance is larger" do - payment.stub(:credit_allowed) { 123 } - payment.stub(:order) { double(:order, outstanding_balance: 1000) } - payment.send(:calculate_refund_amount).should == 123 + allow(payment).to receive(:credit_allowed) { 123 } + allow(payment).to receive(:order) { double(:order, outstanding_balance: 1000) } + expect(payment.send(:calculate_refund_amount)).to eq(123) end it "refunds up to the outstanding balance of the order when the payment is larger" do - payment.stub(:credit_allowed) { 1000 } - payment.stub(:order) { double(:order, outstanding_balance: 123) } - payment.send(:calculate_refund_amount).should == 123 + allow(payment).to receive(:credit_allowed) { 1000 } + allow(payment).to receive(:order) { double(:order, outstanding_balance: 123) } + expect(payment.send(:calculate_refund_amount)).to eq(123) end end describe "performing refunds" do before do - payment.stub(:calculate_refund_amount) { 123 } - payment.payment_method.should_receive(:refund).and_return(success) + allow(payment).to receive(:calculate_refund_amount) { 123 } + expect(payment.payment_method).to receive(:refund).and_return(success) end it "performs the refund without payment profiles" do - payment.payment_method.stub(:payment_profiles_supported?) { false } + allow(payment.payment_method).to receive(:payment_profiles_supported?) { false } payment.refund! end it "performs the refund with payment profiles" do - payment.payment_method.stub(:payment_profiles_supported?) { true } + allow(payment.payment_method).to receive(:payment_profiles_supported?) { true } payment.refund! end end it "records the response" do - payment.stub(:calculate_refund_amount) { 123 } - payment.payment_method.stub(:refund).and_return(success) - payment.should_receive(:record_response).with(success) + allow(payment).to receive(:calculate_refund_amount) { 123 } + allow(payment.payment_method).to receive(:refund).and_return(success) + expect(payment).to receive(:record_response).with(success) payment.refund! end it "records a payment on success" do - payment.stub(:calculate_refund_amount) { 123 } - payment.payment_method.stub(:refund).and_return(success) - payment.stub(:record_response) + allow(payment).to receive(:calculate_refund_amount) { 123 } + allow(payment.payment_method).to receive(:refund).and_return(success) + allow(payment).to receive(:record_response) expect do payment.refund! end.to change(Payment, :count).by(1) p = Payment.last - p.order.should == payment.order - p.source.should == payment - p.payment_method.should == payment.payment_method - p.amount.should == -123 - p.response_code.should == success.authorization - p.state.should == 'completed' + expect(p.order).to eq(payment.order) + expect(p.source).to eq(payment) + expect(p.payment_method).to eq(payment.payment_method) + expect(p.amount).to eq(-123) + expect(p.response_code).to eq(success.authorization) + expect(p.state).to eq('completed') end it "logs the error on failure" do - payment.stub(:calculate_refund_amount) { 123 } - payment.payment_method.stub(:refund).and_return(failure) - payment.stub(:record_response) - payment.should_receive(:gateway_error).with(failure) + allow(payment).to receive(:calculate_refund_amount) { 123 } + allow(payment.payment_method).to receive(:refund).and_return(failure) + allow(payment).to receive(:record_response) + expect(payment).to receive(:gateway_error).with(failure) payment.refund! end end diff --git a/spec/models/spree/preferences/file_configuration_spec.rb b/spec/models/spree/preferences/file_configuration_spec.rb index 1ce12e031c..221a4b062a 100644 --- a/spec/models/spree/preferences/file_configuration_spec.rb +++ b/spec/models/spree/preferences/file_configuration_spec.rb @@ -16,40 +16,40 @@ module Spree describe "getting preferences" do it "returns regular preferences" do c.name = 'foo' - c.get_preference(:name).should == 'foo' + expect(c.get_preference(:name)).to eq('foo') end it "returns file preferences" do - c.get_preference(:logo).should be_a Paperclip::Attachment + expect(c.get_preference(:logo)).to be_a Paperclip::Attachment end it "returns regular preferences via []" do c.name = 'foo' - c[:name].should == 'foo' + expect(c[:name]).to eq('foo') end it "returns file preferences via []" do - c[:logo].should be_a Paperclip::Attachment + expect(c[:logo]).to be_a Paperclip::Attachment end end describe "getting preference types" do it "returns regular preference types" do - c.preference_type(:name).should == :string + expect(c.preference_type(:name)).to eq(:string) end it "returns file preference types" do - c.preference_type(:logo).should == :file + expect(c.preference_type(:logo)).to eq(:file) end end describe "respond_to?" do it "responds to preference getters" do - c.respond_to?(:name).should be true + expect(c.respond_to?(:name)).to be true end it "responds to preference setters" do - c.respond_to?(:name=).should be true + expect(c.respond_to?(:name=)).to be true end end end diff --git a/spec/models/spree/product_spec.rb b/spec/models/spree/product_spec.rb index d415947ba7..de144a2dc6 100644 --- a/spec/models/spree/product_spec.rb +++ b/spec/models/spree/product_spec.rb @@ -4,21 +4,21 @@ module Spree describe Product do describe "associations" do - it { should belong_to(:supplier) } - it { should belong_to(:primary_taxon) } + it { is_expected.to belong_to(:supplier) } + it { is_expected.to belong_to(:primary_taxon) } end describe "validations and defaults" do it "is valid when built from factory" do - build(:product).should be_valid + expect(build(:product)).to be_valid end it "requires a primary taxon" do - build(:simple_product, taxons: [], primary_taxon: nil).should_not be_valid + expect(build(:simple_product, taxons: [], primary_taxon: nil)).not_to be_valid end it "requires a supplier" do - build(:simple_product, supplier: nil).should_not be_valid + expect(build(:simple_product, supplier: nil)).not_to be_valid end it "does not save when master is invalid" do @@ -32,7 +32,7 @@ module Spree it "defaults available_on to now" do Timecop.freeze do product = Product.new - product.available_on.should == Time.zone.now + expect(product.available_on).to eq(Time.zone.now) end end @@ -40,7 +40,7 @@ module Spree context "when a tax category is required" do it "is invalid when a tax category is not provided" do with_products_require_tax_category(true) do - build(:product, tax_category_id: nil).should_not be_valid + expect(build(:product, tax_category_id: nil)).not_to be_valid end end end @@ -48,7 +48,7 @@ module Spree context "when a tax category is not required" do it "is valid when a tax category is not provided" do with_products_require_tax_category(false) do - build(:product, tax_category_id: nil).should be_valid + expect(build(:product, tax_category_id: nil)).to be_valid end end end @@ -63,7 +63,7 @@ module Spree it "requires a unit" do product.variant_unit = nil - product.should_not be_valid + expect(product).not_to be_valid end %w(weight volume).each do |unit| @@ -72,14 +72,14 @@ module Spree product.variant_unit = unit product.variant_unit_scale = 1 product.variant_unit_name = nil - product.should be_valid + expect(product).to be_valid end it "is invalid when unit scale is not set" do product.variant_unit = unit product.variant_unit_scale = nil product.variant_unit_name = nil - product.should_not be_valid + expect(product).not_to be_valid end end end @@ -118,14 +118,14 @@ module Spree product.variant_unit = 'items' product.variant_unit_name = 'loaf' product.variant_unit_scale = nil - product.should be_valid + expect(product).to be_valid end it "is invalid when unit name is not set" do product.variant_unit = 'items' product.variant_unit_name = nil product.variant_unit_scale = nil - product.should_not be_valid + expect(product).not_to be_valid end end end @@ -146,7 +146,7 @@ module Spree product.variant_unit_scale = nil product.variant_unit_name = nil - product.should_not be_valid + expect(product).not_to be_valid end end end @@ -211,7 +211,7 @@ module Spree s2 = create(:supplier_enterprise) p1 = create(:product, supplier: s1) p2 = create(:product, supplier: s2) - Product.in_supplier(s1).should == [p1] + expect(Product.in_supplier(s1)).to eq([p1]) end end @@ -224,7 +224,7 @@ module Spree p2 = create(:product) create(:simple_order_cycle, suppliers: [s], distributors: [d1], variants: [p1.master]) create(:simple_order_cycle, suppliers: [s], distributors: [d2], variants: [p2.master]) - Product.in_distributor(d1).should == [p1] + expect(Product.in_distributor(d1)).to eq([p1]) end it "shows products in order cycle distribution by variant" do @@ -237,7 +237,7 @@ module Spree v2 = create(:variant, product: p2) create(:simple_order_cycle, suppliers: [s], distributors: [d1], variants: [v1]) create(:simple_order_cycle, suppliers: [s], distributors: [d2], variants: [v2]) - Product.in_distributor(d1).should == [p1] + expect(Product.in_distributor(d1)).to eq([p1]) end it "doesn't show products listed in the incoming exchange only" do @@ -249,7 +249,7 @@ module Spree ex = oc.exchanges.incoming.first ex.variants << p.master - Product.in_distributor(d).should be_empty + expect(Product.in_distributor(d)).to be_empty end end @@ -259,7 +259,7 @@ module Spree s2 = create(:supplier_enterprise) p1 = create(:product, supplier: s1) p2 = create(:product, supplier: s2) - Product.in_supplier_or_distributor(s1).should == [p1] + expect(Product.in_supplier_or_distributor(s1)).to eq([p1]) end it "shows products in order cycle distribution" do @@ -270,7 +270,7 @@ module Spree p2 = create(:product) create(:simple_order_cycle, suppliers: [s], distributors: [d1], variants: [p1.master]) create(:simple_order_cycle, suppliers: [s], distributors: [d2], variants: [p2.master]) - Product.in_supplier_or_distributor(d1).should == [p1] + expect(Product.in_supplier_or_distributor(d1)).to eq([p1]) end it "shows products in all three without duplicates" do @@ -278,7 +278,7 @@ module Spree d = create(:distributor_enterprise) p = create(:product, supplier: s) create(:simple_order_cycle, suppliers: [s], distributors: [d], variants: [p.master]) - [s, d].each { |e| Product.in_supplier_or_distributor(e).should == [p] } + [s, d].each { |e| expect(Product.in_supplier_or_distributor(e)).to eq([p]) } end end @@ -291,7 +291,7 @@ module Spree p2 = create(:product) oc1 = create(:simple_order_cycle, suppliers: [s], distributors: [d1], variants: [p1.master]) oc2 = create(:simple_order_cycle, suppliers: [s], distributors: [d2], variants: [p2.master]) - Product.in_order_cycle(oc1).should == [p1] + expect(Product.in_order_cycle(oc1)).to eq([p1]) end end @@ -305,7 +305,7 @@ module Spree p3 = create(:product) oc2 = create(:simple_order_cycle, suppliers: [s], distributors: [d2], variants: [p2.master], orders_open_at: 8.days.ago, orders_close_at: 1.day.ago) oc2 = create(:simple_order_cycle, suppliers: [s], distributors: [d3], variants: [p3.master], orders_close_at: Date.tomorrow) - Product.in_an_active_order_cycle.should == [p3] + expect(Product.in_an_active_order_cycle).to eq([p3]) end end @@ -323,17 +323,17 @@ module Spree @e1.enterprise_roles.build(user: user).save product = Product.managed_by user - product.count.should == 1 - product.should include @p1 + expect(product.count).to eq(1) + expect(product).to include @p1 end it "shows all products for admin user" do user = create(:admin_user) product = Product.managed_by user - product.count.should == 2 - product.should include @p1 - product.should include @p2 + expect(product.count).to eq(2) + expect(product).to include @p1 + expect(product).to include @p2 end end @@ -380,7 +380,7 @@ module Spree product.set_property 'Organic Certified', 'NASAA 12345' property = product.properties.last - product.properties_including_inherited.should == [{id: property.id, name: "Organic Certified", value: 'NASAA 12345'}] + expect(product.properties_including_inherited).to eq([{id: property.id, name: "Organic Certified", value: 'NASAA 12345'}]) end it "returns producer properties as a hash" do @@ -390,7 +390,7 @@ module Spree supplier.set_producer_property 'Organic Certified', 'NASAA 54321' property = supplier.properties.last - product.properties_including_inherited.should == [{id: property.id, name: "Organic Certified", value: 'NASAA 54321'}] + expect(product.properties_including_inherited).to eq([{id: property.id, name: "Organic Certified", value: 'NASAA 54321'}]) end it "overrides producer properties with product properties" do @@ -401,7 +401,7 @@ module Spree supplier.set_producer_property 'Organic Certified', 'NASAA 54321' property = product.properties.last - product.properties_including_inherited.should == [{id: property.id, name: "Organic Certified", value: 'NASAA 12345'}] + expect(product.properties_including_inherited).to eq([{id: property.id, name: "Organic Certified", value: 'NASAA 12345'}]) end context "when product has an inherit_properties value set to true" do @@ -412,7 +412,7 @@ module Spree supplier.set_producer_property 'Organic Certified', 'NASAA 54321' property = supplier.properties.last - product.properties_including_inherited.should == [{id: property.id, name: "Organic Certified", value: 'NASAA 54321'}] + expect(product.properties_including_inherited).to eq([{id: property.id, name: "Organic Certified", value: 'NASAA 54321'}]) end end @@ -423,7 +423,7 @@ module Spree it "does not inherit producer properties" do supplier.set_producer_property 'Organic Certified', 'NASAA 54321' - product.properties_including_inherited.should == [] + expect(product.properties_including_inherited).to eq([]) end end @@ -439,10 +439,11 @@ module Spree product.product_properties.create!({property_id: pc.id, value: '3', position: 3}, {without_protection: true}) supplier.producer_properties.create!({property_id: pb.id, value: '2', position: 2}, {without_protection: true}) - product.properties_including_inherited.should == + expect(product.properties_including_inherited).to eq( [{id: pa.id, name: "A", value: '1'}, {id: pb.id, name: "B", value: '2'}, {id: pc.id, name: "C", value: '3'}] + ) end end @@ -455,8 +456,8 @@ module Spree oc1 = create(:simple_order_cycle, :distributors => [d1], :variants => [p1.master]) oc2 = create(:simple_order_cycle, :distributors => [d2], :variants => [p2.master]) - p1.should be_in_distributor d1 - p1.should_not be_in_distributor d2 + expect(p1).to be_in_distributor d1 + expect(p1).not_to be_in_distributor d2 end it "queries its membership of a particular order cycle" do @@ -467,8 +468,8 @@ module Spree oc1 = create(:simple_order_cycle, :distributors => [d1], :variants => [p1.master]) oc2 = create(:simple_order_cycle, :distributors => [d2], :variants => [p2.master]) - p1.should be_in_order_cycle oc1 - p1.should_not be_in_order_cycle oc2 + expect(p1).to be_in_order_cycle oc1 + expect(p1).not_to be_in_order_cycle oc2 end end @@ -484,11 +485,11 @@ module Spree it "removes the old option type and assigns the new one" do p.update_attributes!(variant_unit: 'volume', variant_unit_scale: 0.001) - p.option_types.should == [ot_volume] + expect(p.option_types).to eq([ot_volume]) end it "does not remove and re-add the option type if it is not changed" do - p.option_types.should_receive(:delete).never + expect(p.option_types).to receive(:delete).never p.update_attributes!(name: 'foo') end @@ -497,14 +498,14 @@ module Spree v = create(:variant, unit_value: 1, product: p) p.reload - v.option_values.map(&:name).include?("1L").should == false - v.option_values.map(&:name).include?("1g").should == true + expect(v.option_values.map(&:name).include?("1L")).to eq(false) + expect(v.option_values.map(&:name).include?("1g")).to eq(true) expect { p.update_attributes!(variant_unit: 'volume', variant_unit_scale: 0.001) }.to change(p.master.option_values(true), :count).by(0) v.reload - v.option_values.map(&:name).include?("1L").should == true - v.option_values.map(&:name).include?("1g").should == false + expect(v.option_values.map(&:name).include?("1L")).to eq(true) + expect(v.option_values.map(&:name).include?("1g")).to eq(false) end it "removes the related option values from its master variant and replaces them" do @@ -512,14 +513,14 @@ module Spree p.master.update_attributes!(unit_value: 1) p.reload - p.master.option_values.map(&:name).include?("1L").should == false - p.master.option_values.map(&:name).include?("1g").should == true + expect(p.master.option_values.map(&:name).include?("1L")).to eq(false) + expect(p.master.option_values.map(&:name).include?("1g")).to eq(true) expect { p.update_attributes!(variant_unit: 'volume', variant_unit_scale: 0.001) }.to change(p.master.option_values(true), :count).by(0) p.reload - p.master.option_values.map(&:name).include?("1L").should == true - p.master.option_values.map(&:name).include?("1g").should == false + expect(p.master.option_values.map(&:name).include?("1L")).to eq(true) + expect(p.master.option_values.map(&:name).include?("1g")).to eq(false) end end @@ -529,7 +530,7 @@ module Spree ot3 = create(:option_type, name: 'unit_items', presentation: 'Items') ot4 = create(:option_type, name: 'foo_unit_bar', presentation: 'Foo') - Spree::Product.all_variant_unit_option_types.should match_array [ot1, ot2, ot3] + expect(Spree::Product.all_variant_unit_option_types).to match_array [ot1, ot2, ot3] end end @@ -553,11 +554,11 @@ module Spree p.option_type_ids = p.option_type_ids.reject { |id| id == ot.id } # Then the associated option values should have been removed from the variants - v1.option_values(true).should_not include ov1 - v2.option_values(true).should_not include ov2 + expect(v1.option_values(true)).not_to include ov1 + expect(v2.option_values(true)).not_to include ov2 # And the option values themselves should still exist - Spree::OptionValue.where(id: [ov1.id, ov2.id]).count.should == 2 + expect(Spree::OptionValue.where(id: [ov1.id, ov2.id]).count).to eq(2) end end end @@ -566,7 +567,7 @@ module Spree it "considers products that are on_demand as being in stock" do product = create(:simple_product, on_demand: true) product.master.update_attribute(:on_hand, 0) - product.has_stock?.should == true + expect(product.has_stock?).to eq(true) end describe "finding products in stock for a particular distribution" do @@ -577,7 +578,7 @@ module Spree oc = create(:simple_order_cycle, distributors: [d]) oc.exchanges.outgoing.first.variants << p.variants.first - p.should have_stock_for_distribution(oc, d) + expect(p).to have_stock_for_distribution(oc, d) end it "returns products with in-stock variants" do @@ -588,7 +589,7 @@ module Spree oc = create(:simple_order_cycle, distributors: [d]) oc.exchanges.outgoing.first.variants << v - p.should have_stock_for_distribution(oc, d) + expect(p).to have_stock_for_distribution(oc, d) end it "returns products with on-demand variants" do @@ -599,7 +600,7 @@ module Spree oc = create(:simple_order_cycle, distributors: [d]) oc.exchanges.outgoing.first.variants << v - p.should have_stock_for_distribution(oc, d) + expect(p).to have_stock_for_distribution(oc, d) end it "does not return products that have stock not in the distribution" do @@ -608,7 +609,7 @@ module Spree d = create(:distributor_enterprise) oc = create(:simple_order_cycle, distributors: [d]) - p.should_not have_stock_for_distribution(oc, d) + expect(p).not_to have_stock_for_distribution(oc, d) end end end @@ -619,7 +620,7 @@ module Spree let(:product) { create(:simple_product) } it "returns the first taxon as the primary taxon" do - product.taxons.should == [product.primary_taxon] + expect(product.taxons).to eq([product.primary_taxon]) end end @@ -633,13 +634,13 @@ module Spree it "removes the master variant from all order cycles" do e.variants << p.master p.destroy - e.variants(true).should be_empty + expect(e.variants(true)).to be_empty end it "removes all other variants from order cycles" do e.variants << v p.destroy - e.variants(true).should be_empty + expect(e.variants(true)).to be_empty end end end diff --git a/spec/models/spree/shipping_method_spec.rb b/spec/models/spree/shipping_method_spec.rb index d6d4ce61fb..2b77f06767 100644 --- a/spec/models/spree/shipping_method_spec.rb +++ b/spec/models/spree/shipping_method_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' module Spree describe ShippingMethod do it "is valid when built from factory" do - create(:shipping_method).should be_valid + expect(create(:shipping_method)).to be_valid end it "can have distributors" do @@ -15,7 +15,7 @@ module Spree sm.distributors << d1 sm.distributors << d2 - sm.reload.distributors.should match_array [d1, d2] + expect(sm.reload.distributors).to match_array [d1, d2] end describe "scope" do @@ -42,7 +42,7 @@ module Spree sm1 = create(:shipping_method, distributors: [d1]) sm2 = create(:shipping_method, distributors: [d2]) - ShippingMethod.for_distributor(d1).should == [sm1] + expect(ShippingMethod.for_distributor(d1)).to eq([sm1]) end end @@ -51,7 +51,7 @@ module Spree sm2 = create(:shipping_method, name: 'AA') sm3 = create(:shipping_method, name: 'BB') - ShippingMethod.by_name.should == [sm2, sm3, sm1] + expect(ShippingMethod.by_name).to eq([sm2, sm3, sm1]) end describe "finding services offered by all distributors" do @@ -65,19 +65,19 @@ module Spree let!(:d3_delivery) { create(:shipping_method, require_ship_address: true, distributors: [d3]) } it "reports when the services are available" do - ShippingMethod.services[d1.id].should == {pickup: true, delivery: true} + expect(ShippingMethod.services[d1.id]).to eq({pickup: true, delivery: true}) end it "reports when only pickup is available" do - ShippingMethod.services[d2.id].should == {pickup: true, delivery: false} + expect(ShippingMethod.services[d2.id]).to eq({pickup: true, delivery: false}) end it "reports when only delivery is available" do - ShippingMethod.services[d3.id].should == {pickup: false, delivery: true} + expect(ShippingMethod.services[d3.id]).to eq({pickup: false, delivery: true}) end it "returns no entry when no service is available" do - ShippingMethod.services[d4.id].should be_nil + expect(ShippingMethod.services[d4.id]).to be_nil end end diff --git a/spec/models/spree/tax_rate_spec.rb b/spec/models/spree/tax_rate_spec.rb index 528a11c301..2ee7e24b4e 100644 --- a/spec/models/spree/tax_rate_spec.rb +++ b/spec/models/spree/tax_rate_spec.rb @@ -9,7 +9,7 @@ module Spree let(:hub) { create(:distributor_enterprise, charges_sales_tax: true) } it "selects all tax rates" do - TaxRate.match(order).should == [tax_rate] + expect(TaxRate.match(order)).to eq([tax_rate]) end end @@ -17,7 +17,7 @@ module Spree let(:hub) { create(:distributor_enterprise, charges_sales_tax: false) } it "selects no tax rates" do - TaxRate.match(order).should be_empty + expect(TaxRate.match(order)).to be_empty end end @@ -25,7 +25,7 @@ module Spree let!(:order) { create(:order, distributor: nil, bill_address: create(:address)) } it "selects all tax rates" do - TaxRate.match(order).should == [tax_rate] + expect(TaxRate.match(order)).to eq([tax_rate]) end end end @@ -35,26 +35,26 @@ module Spree it "sets included_in_price to true" do tax_rate.send(:with_tax_included_in_price) do - tax_rate.included_in_price.should be true + expect(tax_rate.included_in_price).to be true end end it "sets the included_in_price value accessible to the calculator to true" do tax_rate.send(:with_tax_included_in_price) do - tax_rate.calculator.calculable.included_in_price.should be true + expect(tax_rate.calculator.calculable.included_in_price).to be true end end it "passes through the return value of the block" do - tax_rate.send(:with_tax_included_in_price) do + expect(tax_rate.send(:with_tax_included_in_price) do 'asdf' - end.should == 'asdf' + end).to eq('asdf') end it "restores both values to their original afterwards" do tax_rate.send(:with_tax_included_in_price) {} - tax_rate.included_in_price.should be false - tax_rate.calculator.calculable.included_in_price.should be false + expect(tax_rate.included_in_price).to be false + expect(tax_rate.calculator.calculable.included_in_price).to be false end it "restores both values when an exception is raised" do @@ -62,8 +62,8 @@ module Spree tax_rate.send(:with_tax_included_in_price) { raise Exception.new 'oops' } end.to raise_error 'oops' - tax_rate.included_in_price.should be false - tax_rate.calculator.calculable.included_in_price.should be false + expect(tax_rate.included_in_price).to be false + expect(tax_rate.calculator.calculable.included_in_price).to be false end end end diff --git a/spec/models/spree/taxon_spec.rb b/spec/models/spree/taxon_spec.rb index a031823bee..cfb7505555 100644 --- a/spec/models/spree/taxon_spec.rb +++ b/spec/models/spree/taxon_spec.rb @@ -25,7 +25,7 @@ module Spree let!(:p1) { create(:simple_product, supplier: e, taxons: [t1, t2]) } it "finds taxons" do - Taxon.supplied_taxons.should == {e.id => Set.new(p1.taxons.map(&:id))} + expect(Taxon.supplied_taxons).to eq({e.id => Set.new(p1.taxons.map(&:id))}) end end diff --git a/spec/models/spree/user_spec.rb b/spec/models/spree/user_spec.rb index 801d9ef9a7..31b6dbbfd8 100644 --- a/spec/models/spree/user_spec.rb +++ b/spec/models/spree/user_spec.rb @@ -4,7 +4,7 @@ describe Spree.user_class do include OpenFoodNetwork::EmailHelper describe "associations" do - it { should have_many(:owned_enterprises) } + it { is_expected.to have_many(:owned_enterprises) } describe "addresses" do let(:user) { create(:user, bill_address: create(:address)) } @@ -68,7 +68,7 @@ describe Spree.user_class do e = create(:enterprise) c = create(:customer, user: u, enterprise: e) - u.customer_of(e).should == c + expect(u.customer_of(e)).to eq(c) end end diff --git a/spec/models/spree/variant_spec.rb b/spec/models/spree/variant_spec.rb index b5643e0109..3fbc6f80f5 100644 --- a/spec/models/spree/variant_spec.rb +++ b/spec/models/spree/variant_spec.rb @@ -22,12 +22,12 @@ module Spree let!(:oc2) { create(:simple_order_cycle, distributors: [d2], variants: [p2.master]) } it "shows variants in an order cycle distribution" do - Variant.in_distributor(d1).should == [p1.master] + expect(Variant.in_distributor(d1)).to eq([p1.master]) end it "doesn't show duplicates" do oc_dup = create(:simple_order_cycle, distributors: [d1], variants: [p1.master]) - Variant.in_distributor(d1).should == [p1.master] + expect(Variant.in_distributor(d1)).to eq([p1.master]) end end @@ -40,14 +40,14 @@ module Spree let!(:oc2) { create(:simple_order_cycle, distributors: [d2], variants: [p2.master]) } it "shows variants in an order cycle" do - Variant.in_order_cycle(oc1).should == [p1.master] + expect(Variant.in_order_cycle(oc1)).to eq([p1.master]) end it "doesn't show duplicates" do ex = create(:exchange, order_cycle: oc1, sender: oc1.coordinator, receiver: d2) ex.variants << p1.master - Variant.in_order_cycle(oc1).should == [p1.master] + expect(Variant.in_order_cycle(oc1)).to eq([p1.master]) end end @@ -76,17 +76,17 @@ module Spree } it "returns variants in the order cycle and distributor" do - p1.variants.for_distribution(oc, d1).should == [v1] - p2.variants.for_distribution(oc, d2).should == [v2] + expect(p1.variants.for_distribution(oc, d1)).to eq([v1]) + expect(p2.variants.for_distribution(oc, d2)).to eq([v2]) end it "does not return variants in the order cycle but not the distributor" do - p1.variants.for_distribution(oc, d2).should be_empty - p2.variants.for_distribution(oc, d1).should be_empty + expect(p1.variants.for_distribution(oc, d2)).to be_empty + expect(p2.variants.for_distribution(oc, d1)).to be_empty end it "does not return variants not in the order cycle" do - p_external.variants.for_distribution(oc, d1).should be_empty + expect(p_external.variants.for_distribution(oc, d1)).to be_empty end end @@ -201,8 +201,9 @@ module Spree let!(:v3) { create(:variant) } it "indexes variants by id" do - Variant.where(id: [v1, v2, v3]).indexed.should == + expect(Variant.where(id: [v1, v2, v3]).indexed).to eq( {v1.id => v1, v2.id => v2, v3.id => v3} + ) end end @@ -215,7 +216,7 @@ module Spree before { allow(v).to receive(:full_name) { p.name + " - something" } } it "does not show the product name twice" do - v.product_and_full_name.should == 'product - something' + expect(v.product_and_full_name).to eq('product - something') end end @@ -223,7 +224,7 @@ module Spree before { allow(v).to receive(:full_name) { "display_name (unit)" } } it "prepends the product name to the full name" do - v.product_and_full_name.should == 'product - display_name (unit)' + expect(v.product_and_full_name).to eq('product - display_name (unit)') end end end @@ -234,8 +235,8 @@ module Spree order_cycle = double(:order_cycle) variant = Variant.new price: 100 - variant.should_receive(:fees_for).with(distributor, order_cycle) { 23 } - variant.price_with_fees(distributor, order_cycle).should == 123 + expect(variant).to receive(:fees_for).with(distributor, order_cycle) { 23 } + expect(variant.price_with_fees(distributor, order_cycle)).to eq(123) end end @@ -246,9 +247,9 @@ module Spree order_cycle = double(:order_cycle) variant = Variant.new - OpenFoodNetwork::EnterpriseFeeCalculator.any_instance.should_receive(:fees_for).with(variant) { 23 } + expect_any_instance_of(OpenFoodNetwork::EnterpriseFeeCalculator).to receive(:fees_for).with(variant) { 23 } - variant.fees_for(distributor, order_cycle).should == 23 + expect(variant.fees_for(distributor, order_cycle)).to eq(23) end end @@ -260,9 +261,9 @@ module Spree variant = Variant.new fees = double(:fees) - OpenFoodNetwork::EnterpriseFeeCalculator.any_instance.should_receive(:fees_by_type_for).with(variant) { fees } + expect_any_instance_of(OpenFoodNetwork::EnterpriseFeeCalculator).to receive(:fees_by_type_for).with(variant) { fees } - variant.fees_by_type_for(distributor, order_cycle).should == fees + expect(variant.fees_by_type_for(distributor, order_cycle)).to eq(fees) end end @@ -281,16 +282,16 @@ module Spree it "is valid when unit value is set and unit description is not" do variant.unit_value = 1 variant.unit_description = nil - variant.should be_valid + expect(variant).to be_valid end it "is invalid when unit value is not set" do variant.unit_value = nil - variant.should_not be_valid + expect(variant).not_to be_valid end it "has a valid master variant" do - product.master.should be_valid + expect(product.master).to be_valid end end end @@ -304,23 +305,23 @@ module Spree it "is valid with only unit value set" do variant.unit_value = 1 variant.unit_description = nil - variant.should be_valid + expect(variant).to be_valid end it "is valid with only unit description set" do variant.unit_value = nil variant.unit_description = 'Medium' - variant.should be_valid + expect(variant).to be_valid end it "is invalid when neither unit value nor unit description are set" do variant.unit_value = nil variant.unit_description = nil - variant.should_not be_valid + expect(variant).not_to be_valid end it "has a valid master variant" do - product.master.should be_valid + expect(product.master).to be_valid end end end @@ -330,67 +331,67 @@ module Spree let(:v) { Variant.new } before do - v.stub(:display_name) { 'display_name' } - v.stub(:unit_to_display) { 'unit_to_display' } + allow(v).to receive(:display_name) { 'display_name' } + allow(v).to receive(:unit_to_display) { 'unit_to_display' } end it "returns unit_to_display when display_name is blank" do - v.stub(:display_name) { '' } - v.full_name.should == 'unit_to_display' + allow(v).to receive(:display_name) { '' } + expect(v.full_name).to eq('unit_to_display') end it "returns display_name when it contains unit_to_display" do - v.stub(:display_name) { 'DiSpLaY_name' } - v.stub(:unit_to_display) { 'name' } - v.full_name.should == 'DiSpLaY_name' + allow(v).to receive(:display_name) { 'DiSpLaY_name' } + allow(v).to receive(:unit_to_display) { 'name' } + expect(v.full_name).to eq('DiSpLaY_name') end it "returns unit_to_display when it contains display_name" do - v.stub(:display_name) { '_to_' } - v.stub(:unit_to_display) { 'unit_TO_display' } - v.full_name.should == 'unit_TO_display' + allow(v).to receive(:display_name) { '_to_' } + allow(v).to receive(:unit_to_display) { 'unit_TO_display' } + expect(v.full_name).to eq('unit_TO_display') end it "returns a combination otherwise" do - v.stub(:display_name) { 'display_name' } - v.stub(:unit_to_display) { 'unit_to_display' } - v.full_name.should == 'display_name (unit_to_display)' + allow(v).to receive(:display_name) { 'display_name' } + allow(v).to receive(:unit_to_display) { 'unit_to_display' } + expect(v.full_name).to eq('display_name (unit_to_display)') end it "is resilient to regex chars" do v = Variant.new display_name: ")))" - v.stub(:unit_to_display) { ")))" } - v.full_name.should == ")))" + allow(v).to receive(:unit_to_display) { ")))" } + expect(v.full_name).to eq(")))") end end describe "getting name for display" do it "returns display_name if present" do v = create(:variant, display_name: "foo") - v.name_to_display.should == "foo" + expect(v.name_to_display).to eq("foo") end it "returns product name if display_name is empty" do v = create(:variant, product: create(:product)) - v.name_to_display.should == v.product.name + expect(v.name_to_display).to eq(v.product.name) v1 = create(:variant, display_name: "", product: create(:product)) - v1.name_to_display.should == v1.product.name + expect(v1.name_to_display).to eq(v1.product.name) end end describe "getting unit for display" do it "returns display_as if present" do v = create(:variant, display_as: "foo") - v.unit_to_display.should == "foo" + expect(v.unit_to_display).to eq("foo") end it "returns options_text if display_as is blank" do v = create(:variant) v1 = create(:variant, display_as: "") - v.stub(:options_text).and_return "ponies" - v1.stub(:options_text).and_return "ponies" - v.unit_to_display.should == "ponies" - v1.unit_to_display.should == "ponies" + allow(v).to receive(:options_text).and_return "ponies" + allow(v1).to receive(:options_text).and_return "ponies" + expect(v.unit_to_display).to eq("ponies") + expect(v1.unit_to_display).to eq("ponies") end end @@ -402,7 +403,7 @@ module Spree p.update_attributes! variant_unit: 'weight', variant_unit_scale: 1 v.update_attributes! unit_value: 10, unit_description: 'foo' - v.reload.weight.should == 0.01 + expect(v.reload.weight).to eq(0.01) end it "does nothing when unit is not weight" do @@ -412,7 +413,7 @@ module Spree p.update_attributes! variant_unit: 'volume', variant_unit_scale: 1 v.update_attributes! unit_value: 10, unit_description: 'foo' - v.reload.weight.should == 123 + expect(v.reload.weight).to eq(123) end it "does nothing when unit_value is not set" do @@ -423,9 +424,9 @@ module Spree # Although invalid, this calls the before_validation callback, which would # error if not handling unit_value == nil case - v.update_attributes(unit_value: nil, unit_description: 'foo').should be false + expect(v.update_attributes(unit_value: nil, unit_description: 'foo')).to be false - v.reload.weight.should == 123 + expect(v.reload.weight).to eq(123) end end @@ -440,7 +441,7 @@ module Spree v.update_attributes!(unit_value: 10, unit_description: 'foo') }.to change(Spree::OptionValue, :count).by(1) - v.option_values.should_not include ov_orig + expect(v.option_values).not_to include ov_orig end end @@ -459,8 +460,8 @@ module Spree v.update_attributes!(unit_value: 10, unit_description: 'foo') }.to change(Spree::OptionValue, :count).by(0) - v.option_values.should_not include ov_orig - v.option_values.should include ov_new + expect(v.option_values).not_to include ov_orig + expect(v.option_values).to include ov_new end end @@ -469,10 +470,10 @@ module Spree let!(:v) { create(:variant, product: p, unit_value: 5, unit_description: 'bar', display_as: '') } it "requests the name of the new option_value from OptionValueName" do - OpenFoodNetwork::OptionValueNamer.any_instance.should_receive(:name).exactly(1).times.and_call_original + expect_any_instance_of(OpenFoodNetwork::OptionValueNamer).to receive(:name).exactly(1).times.and_call_original v.update_attributes(unit_value: 10, unit_description: 'foo') ov = v.option_values.last - ov.name.should == "10g foo" + expect(ov.name).to eq("10g foo") end end @@ -481,10 +482,10 @@ module Spree let!(:v) { create(:variant, product: p, unit_value: 5, unit_description: 'bar', display_as: 'FOOS!') } it "does not request the name of the new option_value from OptionValueName" do - OpenFoodNetwork::OptionValueNamer.any_instance.should_not_receive(:name) + expect_any_instance_of(OpenFoodNetwork::OptionValueNamer).not_to receive(:name) v.update_attributes!(unit_value: 10, unit_description: 'foo') ov = v.option_values.last - ov.name.should == "FOOS!" + expect(ov.name).to eq("FOOS!") end end end @@ -522,7 +523,7 @@ module Spree e = create(:exchange, variants: [v]) v.destroy - e.reload.variant_ids.should be_empty + expect(e.reload.variant_ids).to be_empty end end end diff --git a/spec/serializers/admin/enterprise_serializer_spec.rb b/spec/serializers/admin/enterprise_serializer_spec.rb index 5bf40559d0..fab8f50731 100644 --- a/spec/serializers/admin/enterprise_serializer_spec.rb +++ b/spec/serializers/admin/enterprise_serializer_spec.rb @@ -4,7 +4,7 @@ describe Api::Admin::EnterpriseSerializer do let(:enterprise) { create(:distributor_enterprise) } it "serializes an enterprise" do serializer = Api::Admin::EnterpriseSerializer.new enterprise - serializer.to_json.should match enterprise.name + expect(serializer.to_json).to match enterprise.name end context "for logo" do diff --git a/spec/serializers/admin/index_enterprise_serializer_spec.rb b/spec/serializers/admin/index_enterprise_serializer_spec.rb index a6ad4d8d02..f1d084b946 100644 --- a/spec/serializers/admin/index_enterprise_serializer_spec.rb +++ b/spec/serializers/admin/index_enterprise_serializer_spec.rb @@ -12,7 +12,7 @@ describe Api::Admin::IndexEnterpriseSerializer do it "sets 'owned' to false" do serializer = Api::Admin::IndexEnterpriseSerializer.new enterprise, spree_current_user: user - serializer.to_json.should match "\"owned\":false" + expect(serializer.to_json).to match "\"owned\":false" end end @@ -21,7 +21,7 @@ describe Api::Admin::IndexEnterpriseSerializer do it "sets 'owned' to true" do serializer = Api::Admin::IndexEnterpriseSerializer.new enterprise, spree_current_user: user - serializer.to_json.should match "\"owned\":true" + expect(serializer.to_json).to match "\"owned\":true" end end @@ -30,7 +30,7 @@ describe Api::Admin::IndexEnterpriseSerializer do it "sets 'owned' to true" do serializer = Api::Admin::IndexEnterpriseSerializer.new enterprise, spree_current_user: user - serializer.to_json.should match "\"owned\":true" + expect(serializer.to_json).to match "\"owned\":true" end end end diff --git a/spec/serializers/admin/variant_override_serializer_spec.rb b/spec/serializers/admin/variant_override_serializer_spec.rb index 80158b93cf..42e0e8f909 100644 --- a/spec/serializers/admin/variant_override_serializer_spec.rb +++ b/spec/serializers/admin/variant_override_serializer_spec.rb @@ -7,9 +7,9 @@ describe Api::Admin::VariantOverrideSerializer do it "serializes a variant override" do serializer = Api::Admin::VariantOverrideSerializer.new variant_override - serializer.to_json.should match variant.id.to_s - serializer.to_json.should match hub.id.to_s - serializer.to_json.should match price.to_s - serializer.to_json.should match count_on_hand.to_s + expect(serializer.to_json).to match variant.id.to_s + expect(serializer.to_json).to match hub.id.to_s + expect(serializer.to_json).to match price.to_s + expect(serializer.to_json).to match count_on_hand.to_s end end diff --git a/spec/serializers/enterprise_serializer_spec.rb b/spec/serializers/enterprise_serializer_spec.rb index 10f41a16dd..c332008d17 100644 --- a/spec/serializers/enterprise_serializer_spec.rb +++ b/spec/serializers/enterprise_serializer_spec.rb @@ -14,20 +14,20 @@ describe Api::EnterpriseSerializer do } it "serializes an enterprise" do - serializer.to_json.should match enterprise.name + expect(serializer.to_json).to match enterprise.name end it "serializes taxons as ids only" do - serializer.serializable_hash[:taxons].should == [{id: 123}] - serializer.serializable_hash[:supplied_taxons].should == [{id: 456}] + expect(serializer.serializable_hash[:taxons]).to eq([{id: 123}]) + expect(serializer.serializable_hash[:supplied_taxons]).to eq([{id: 456}]) end it "serializes producers and hubs as ids only" do - serializer.serializable_hash[:producers].should == [{id: 123}] - serializer.serializable_hash[:hubs].should == [{id: 456}] + expect(serializer.serializable_hash[:producers]).to eq([{id: 123}]) + expect(serializer.serializable_hash[:hubs]).to eq([{id: 456}]) end it "serializes icons" do - serializer.to_json.should match "map_005-hub.svg" + expect(serializer.to_json).to match "map_005-hub.svg" end end diff --git a/spec/serializers/spree/variant_serializer_spec.rb b/spec/serializers/spree/variant_serializer_spec.rb index 8f6b1e0bf5..c7ad285970 100644 --- a/spec/serializers/spree/variant_serializer_spec.rb +++ b/spec/serializers/spree/variant_serializer_spec.rb @@ -2,6 +2,6 @@ describe Api::Admin::VariantSerializer do let(:variant) { create(:variant) } it "serializes a variant" do serializer = Api::Admin::VariantSerializer.new variant - serializer.to_json.should match variant.options_text + expect(serializer.to_json).to match variant.options_text end end diff --git a/spec/support/feature_toggle_helper.rb b/spec/support/feature_toggle_helper.rb index 7471103e4f..6d9e1fadf5 100644 --- a/spec/support/feature_toggle_helper.rb +++ b/spec/support/feature_toggle_helper.rb @@ -3,7 +3,7 @@ module OpenFoodNetwork def set_feature_toggle(feature, status) features = OpenFoodNetwork::FeatureToggle.features features[feature] = status - OpenFoodNetwork::FeatureToggle.stub(:features) { features } + allow(OpenFoodNetwork::FeatureToggle).to receive(:features) { features } end end end diff --git a/spec/support/request/authentication_workflow.rb b/spec/support/request/authentication_workflow.rb index 7645db0012..7806676781 100644 --- a/spec/support/request/authentication_workflow.rb +++ b/spec/support/request/authentication_workflow.rb @@ -66,4 +66,15 @@ end RSpec.configure do |config| config.extend AuthenticationWorkflow, :type => :feature + + # rspec-rails 3 will no longer automatically infer an example group's spec type + # from the file location. You can explicitly opt-in to the feature using this + # config option. + # To explicitly tag specs without using automatic inference, set the `:type` + # metadata manually: + # + # describe ThingsController, :type => :controller do + # # Equivalent to being in spec/controllers + # end + config.infer_spec_type_from_file_location! end diff --git a/spec/support/request/ui_component_helper.rb b/spec/support/request/ui_component_helper.rb index 27f5cdae0a..cc304a9364 100644 --- a/spec/support/request/ui_component_helper.rb +++ b/spec/support/request/ui_component_helper.rb @@ -50,7 +50,7 @@ module UIComponentHelper def modal_should_be_open_for(object) within ".reveal-modal" do - page.should have_content object.name + expect(page).to have_content object.name end end diff --git a/spec/support/request/web_helper.rb b/spec/support/request/web_helper.rb index 52ffc306ac..837483544f 100644 --- a/spec/support/request/web_helper.rb +++ b/spec/support/request/web_helper.rb @@ -21,7 +21,7 @@ module WebHelper selector += "[placeholder='#{opts[:placeholder]}']" if opts.key? :placeholder element = page.all(selector).first - element.value.should == opts[:with] if element && opts.key?(:with) + expect(element.value).to eq(opts[:with]) if element && opts.key?(:with) have_selector selector end