Sha256: fe867becda6304a429ebc0c21dfd372616e9483b6b6fdd13d5b427143f46de43

Contents?: true

Size: 1.63 KB

Versions: 17

Compression:

Stored size: 1.63 KB

Contents

require 'spec_helper'

module Spree
  describe Api::AddressesController do
    render_views

    before do
      stub_authentication!
      @address = create(:address)
      @order = create(:order, :bill_address => @address)
    end

    context "with their own address" do
      before do
        Order.any_instance.stub :user => current_api_user
      end

      it "gets an address" do
        api_get :show, :id => @address.id, :order_id => @order.number
        json_response['address1'].should eq @address.address1
      end

      it "updates an address" do
        api_put :update, :id => @address.id, :order_id => @order.number,
                         :address => { :address1 => "123 Test Lane" }
        json_response['address1'].should eq '123 Test Lane'
      end

      it "receives the errors object if address is invalid" do
        api_put :update, :id => @address.id, :order_id => @order.number,
                         :address => { :address1 => "" }

        json_response['error'].should_not be_nil
        json_response['errors'].should_not be_nil
        json_response['errors']['address1'].first.should eq "can't be blank"
      end
    end

    context "on an address that does not belong to this order" do
      before do
        @order.bill_address_id = nil
        @order.ship_address = nil
      end

      it "cannot retreive address information" do
        api_get :show, :id => @address.id, :order_id => @order.number
        assert_unauthorized!
      end

      it "cannot update address information" do
        api_get :update, :id => @address.id, :order_id => @order.number
        assert_unauthorized!
      end
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
spree_api-2.1.12 spec/controllers/spree/api/addresses_controller_spec.rb
spree_api-2.1.11 spec/controllers/spree/api/addresses_controller_spec.rb
spree_api-2.1.10 spec/controllers/spree/api/addresses_controller_spec.rb
spree_api-2.4.0.rc2 spec/controllers/spree/api/addresses_controller_spec.rb
spree_api-2.4.0.rc1 spec/controllers/spree/api/addresses_controller_spec.rb
spree_api-2.3.4 spec/controllers/spree/api/addresses_controller_spec.rb
spree_api-2.1.9 spec/controllers/spree/api/addresses_controller_spec.rb
spree_api-2.3.3 spec/controllers/spree/api/addresses_controller_spec.rb
spree_api-2.1.8 spec/controllers/spree/api/addresses_controller_spec.rb
spree_api-2.1.7 spec/controllers/spree/api/addresses_controller_spec.rb
spree_api-2.1.6 spec/controllers/spree/api/addresses_controller_spec.rb
spree_api-2.1.5 spec/controllers/spree/api/addresses_controller_spec.rb
spree_api-2.1.4 spec/controllers/spree/api/addresses_controller_spec.rb
spree_api-2.1.3 spec/controllers/spree/api/addresses_controller_spec.rb
spree_api-2.1.2 spec/controllers/spree/api/addresses_controller_spec.rb
spree_api-2.1.1 spec/controllers/spree/api/addresses_controller_spec.rb
spree_api-2.1.0 spec/controllers/spree/api/addresses_controller_spec.rb