From 2490cbfccb51db5413f91d54e2b3d4710eb2c676 Mon Sep 17 00:00:00 2001 From: luisramos0 Date: Thu, 18 Jul 2019 20:04:00 +0100 Subject: [PATCH] Transpec and fix rubocop issues in spree/api/base_controller_spec --- .../spree/api/base_controller_spec.rb | 41 ++++++++++--------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/spec/controllers/spree/api/base_controller_spec.rb b/spec/controllers/spree/api/base_controller_spec.rb index 73121c989e..b8ad0580a1 100644 --- a/spec/controllers/spree/api/base_controller_spec.rb +++ b/spec/controllers/spree/api/base_controller_spec.rb @@ -4,7 +4,7 @@ describe Spree::Api::BaseController do render_views controller(Spree::Api::BaseController) do def index - render :text => { "products" => [] }.to_json + render text: { "products" => [] }.to_json end def spree_current_user; end @@ -12,53 +12,54 @@ describe Spree::Api::BaseController do context "signed in as a user using an authentication extension" do before do - controller.stub :try_spree_current_user => double(:email => "spree@example.com") + allow(controller).to receive_messages try_spree_current_user: + double(email: "spree@example.com") Spree::Api::Config[:requires_authentication] = true end it "can make a request" do api_get :index - json_response.should == { "products" => [] } - response.status.should == 200 + expect(json_response).to eq( "products" => [] ) + expect(response.status).to eq(200) end end context "cannot make a request to the API" do it "without an API key" do api_get :index - json_response.should == { "error" => "You must specify an API key." } - response.status.should == 401 + expect(json_response).to eq( "error" => "You must specify an API key." ) + expect(response.status).to eq(401) end it "with an invalid API key" do request.env["X-Spree-Token"] = "fake_key" get :index, {} - json_response.should == { "error" => "Invalid API key (fake_key) specified." } - response.status.should == 401 + expect(json_response).to eq( "error" => "Invalid API key (fake_key) specified." ) + expect(response.status).to eq(401) end it "using an invalid token param" do - get :index, :token => "fake_key" - json_response.should == { "error" => "Invalid API key (fake_key) specified." } + get :index, token: "fake_key" + expect(json_response).to eq( "error" => "Invalid API key (fake_key) specified." ) end end it 'handles exceptions' do - subject.should_receive(:authenticate_user).and_return(true) - subject.should_receive(:index).and_raise(Exception.new("no joy")) - get :index, :token => "fake_key" - json_response.should == { "exception" => "no joy" } + expect(subject).to receive(:authenticate_user).and_return(true) + expect(subject).to receive(:index).and_raise(Exception.new("no joy")) + get :index, token: "fake_key" + expect(json_response).to eq( "exception" => "no joy" ) end it "maps symantec keys to nested_attributes keys" do - klass = double(:nested_attributes_options => { :line_items => {}, - :bill_address => {} }) - attributes = { 'line_items' => { :id => 1 }, - 'bill_address' => { :id => 2 }, + klass = double(nested_attributes_options: { line_items: {}, + bill_address: {} }) + attributes = { 'line_items' => { id: 1 }, + 'bill_address' => { id: 2 }, 'name' => 'test order' } mapped = subject.map_nested_attributes_keys(klass, attributes) - mapped.has_key?('line_items_attributes').should be_truthy - mapped.has_key?('name').should be_truthy + expect(mapped.key?('line_items_attributes')).to be_truthy + expect(mapped.key?('name')).to be_truthy end end