Sha256: 61b6de5518fd0af3c91b16f8ad2f5efdf0c217a1dc052434f1117e363574381b

Contents?: true

Size: 1.31 KB

Versions: 12

Compression:

Stored size: 1.31 KB

Contents

require 'spec_helper'

describe Spree::Api::V1::BaseController do
  controller(Spree::Api::V1::BaseController) do
    def index
      render :json => { "products" => [] }
    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 "maps symantec keys to nested_attributes keys" do
    klass = stub(: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-1.1.6 spec/controllers/spree/api/v1/base_controller_spec.rb
spree_api-1.1.5 spec/controllers/spree/api/v1/base_controller_spec.rb
spree_api-1.1.4 spec/controllers/spree/api/v1/base_controller_spec.rb
spree_api-1.2.0 spec/controllers/spree/api/v1/base_controller_spec.rb
spree_api-1.2.0.rc2 spec/controllers/spree/api/v1/base_controller_spec.rb
spree_api-1.2.0.rc1 spec/controllers/spree/api/v1/base_controller_spec.rb
spree_api-1.1.3 spec/controllers/spree/api/v1/base_controller_spec.rb
spree_api-1.1.2 spec/controllers/spree/api/v1/base_controller_spec.rb
spree_api-1.1.2.rc1 spec/controllers/spree/api/v1/base_controller_spec.rb
spree_api-1.1.1 spec/controllers/spree/api/v1/base_controller_spec.rb
spree_api-1.1.0 spec/controllers/spree/api/v1/base_controller_spec.rb
spree_api-1.1.0.rc2 spec/controllers/spree/api/v1/base_controller_spec.rb