Sha256: edece5118b47d2b1dafe7c147ab0c68cac054b1bf44ec71d94cd31d04f269806

Contents?: true

Size: 1.97 KB

Versions: 12

Compression:

Stored size: 1.97 KB

Contents

require 'spec_helper'

describe Spree::Api::BaseController do
  render_views
  controller(Spree::Api::BaseController) do
    def index
      render :text => { "products" => [] }.to_json
    end
  end

  context "signed in as a user using an authentication extension" do
    before do
      controller.stub :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
    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
    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
    end

    it "using an invalid token param" do
      get :index, :token => "fake_key"
      json_response.should == { "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" }
  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 },
                   'name' => 'test order' }

    mapped = subject.map_nested_attributes_keys(klass, attributes)
    mapped.has_key?('line_items_attributes').should be_true
    mapped.has_key?('name').should be_true
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
spree_api-2.0.13 spec/controllers/spree/api/base_controller_spec.rb
spree_api-2.0.12 spec/controllers/spree/api/base_controller_spec.rb
spree_api-2.0.11 spec/controllers/spree/api/base_controller_spec.rb
spree_api-2.0.10 spec/controllers/spree/api/base_controller_spec.rb
spree_api-2.0.9 spec/controllers/spree/api/base_controller_spec.rb
spree_api-2.0.8 spec/controllers/spree/api/base_controller_spec.rb
spree_api-2.0.7 spec/controllers/spree/api/base_controller_spec.rb
spree_api-2.0.6 spec/controllers/spree/api/base_controller_spec.rb
spree_api-2.1.1 spec/controllers/spree/api/base_controller_spec.rb
spree_api-2.0.5 spec/controllers/spree/api/base_controller_spec.rb
spree_api-2.1.0 spec/controllers/spree/api/base_controller_spec.rb
spree_api-2.0.4 spec/controllers/spree/api/base_controller_spec.rb