spree_api 2.4.0.rc2 → 2.4.0.rc3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
 - data/app/controllers/spree/api/base_controller.rb +4 -6
 - data/app/controllers/spree/api/option_types_controller.rb +2 -2
 - data/app/controllers/spree/api/orders_controller.rb +9 -1
 - data/app/controllers/spree/api/return_authorizations_controller.rb +0 -9
 - data/app/controllers/spree/api/taxons_controller.rb +3 -3
 - data/app/helpers/spree/api/api_helpers.rb +0 -2
 - data/app/views/spree/api/orders/show.v1.rabl +4 -0
 - data/app/views/spree/api/products/show.v1.rabl +4 -0
 - data/app/views/spree/api/shipments/small.v1.rabl +4 -0
 - data/lib/spree/api/testing_support/helpers.rb +6 -6
 - data/lib/spree/api/testing_support/setup.rb +2 -2
 - data/spec/controllers/spree/api/addresses_controller_spec.rb +8 -8
 - data/spec/controllers/spree/api/base_controller_spec.rb +22 -22
 - data/spec/controllers/spree/api/checkouts_controller_spec.rb +53 -53
 - data/spec/controllers/spree/api/classifications_controller_spec.rb +5 -5
 - data/spec/controllers/spree/api/config_controller_spec.rb +9 -9
 - data/spec/controllers/spree/api/countries_controller_spec.rb +11 -11
 - data/spec/controllers/spree/api/credit_cards_controller_spec.rb +16 -16
 - data/spec/controllers/spree/api/images_controller_spec.rb +21 -21
 - data/spec/controllers/spree/api/inventory_units_controller_spec.rb +6 -6
 - data/spec/controllers/spree/api/line_items_controller_spec.rb +33 -33
 - data/spec/controllers/spree/api/option_types_controller_spec.rb +19 -19
 - data/spec/controllers/spree/api/option_values_controller_spec.rb +23 -23
 - data/spec/controllers/spree/api/orders_controller_spec.rb +186 -143
 - data/spec/controllers/spree/api/payments_controller_spec.rb +39 -39
 - data/spec/controllers/spree/api/product_properties_controller_spec.rb +21 -21
 - data/spec/controllers/spree/api/products_controller_spec.rb +71 -66
 - data/spec/controllers/spree/api/promotion_application_spec.rb +13 -13
 - data/spec/controllers/spree/api/promotions_controller_spec.rb +1 -1
 - data/spec/controllers/spree/api/properties_controller_spec.rb +25 -25
 - data/spec/controllers/spree/api/return_authorizations_controller_spec.rb +27 -36
 - data/spec/controllers/spree/api/shipments_controller_spec.rb +22 -22
 - data/spec/controllers/spree/api/states_controller_spec.rb +18 -18
 - data/spec/controllers/spree/api/stock_items_controller_spec.rb +26 -26
 - data/spec/controllers/spree/api/stock_locations_controller_spec.rb +22 -22
 - data/spec/controllers/spree/api/stock_movements_controller_spec.rb +16 -16
 - data/spec/controllers/spree/api/taxonomies_controller_spec.rb +24 -24
 - data/spec/controllers/spree/api/taxons_controller_spec.rb +39 -39
 - data/spec/controllers/spree/api/unauthenticated_products_controller_spec.rb +6 -6
 - data/spec/controllers/spree/api/users_controller_spec.rb +25 -25
 - data/spec/controllers/spree/api/variants_controller_spec.rb +36 -36
 - data/spec/controllers/spree/api/zones_controller_spec.rb +20 -20
 - data/spec/models/spree/legacy_user_spec.rb +5 -5
 - data/spec/requests/rabl_cache_spec.rb +9 -9
 - data/spec/spec_helper.rb +0 -1
 - data/spec/support/controller_hacks.rb +4 -0
 - metadata +4 -4
 
| 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            require 'spec_helper'
         
     | 
| 
       2 
2 
     | 
    
         | 
| 
       3 
3 
     | 
    
         
             
            module Spree
         
     | 
| 
       4 
     | 
    
         
            -
              describe Spree::Api::PaymentsController do
         
     | 
| 
      
 4 
     | 
    
         
            +
              describe Spree::Api::PaymentsController, :type => :controller do
         
     | 
| 
       5 
5 
     | 
    
         
             
                render_views
         
     | 
| 
       6 
6 
     | 
    
         
             
                let!(:order) { create(:order) }
         
     | 
| 
       7 
7 
     | 
    
         
             
                let!(:payment) { create(:payment, :order => order) }
         
     | 
| 
         @@ -18,30 +18,30 @@ module Spree 
     | 
|
| 
       18 
18 
     | 
    
         
             
                context "as a user" do
         
     | 
| 
       19 
19 
     | 
    
         
             
                  context "when the order belongs to the user" do
         
     | 
| 
       20 
20 
     | 
    
         
             
                    before do
         
     | 
| 
       21 
     | 
    
         
            -
                      Order. 
     | 
| 
      
 21 
     | 
    
         
            +
                      allow_any_instance_of(Order).to receive_messages :user => current_api_user
         
     | 
| 
       22 
22 
     | 
    
         
             
                    end
         
     | 
| 
       23 
23 
     | 
    
         | 
| 
       24 
24 
     | 
    
         
             
                    it "can view the payments for their order" do
         
     | 
| 
       25 
25 
     | 
    
         
             
                      api_get :index
         
     | 
| 
       26 
     | 
    
         
            -
                      json_response["payments"].first. 
     | 
| 
      
 26 
     | 
    
         
            +
                      expect(json_response["payments"].first).to have_attributes(attributes)
         
     | 
| 
       27 
27 
     | 
    
         
             
                    end
         
     | 
| 
       28 
28 
     | 
    
         | 
| 
       29 
29 
     | 
    
         
             
                    it "can learn how to create a new payment" do
         
     | 
| 
       30 
30 
     | 
    
         
             
                      api_get :new
         
     | 
| 
       31 
     | 
    
         
            -
                      json_response["attributes"]. 
     | 
| 
       32 
     | 
    
         
            -
                      json_response["payment_methods"]. 
     | 
| 
       33 
     | 
    
         
            -
                      json_response["payment_methods"].first. 
     | 
| 
      
 31 
     | 
    
         
            +
                      expect(json_response["attributes"]).to eq(attributes.map(&:to_s))
         
     | 
| 
      
 32 
     | 
    
         
            +
                      expect(json_response["payment_methods"]).not_to be_empty
         
     | 
| 
      
 33 
     | 
    
         
            +
                      expect(json_response["payment_methods"].first).to have_attributes([:id, :name, :description])
         
     | 
| 
       34 
34 
     | 
    
         
             
                    end
         
     | 
| 
       35 
35 
     | 
    
         | 
| 
       36 
36 
     | 
    
         
             
                    it "can create a new payment" do
         
     | 
| 
       37 
37 
     | 
    
         
             
                      api_post :create, :payment => { :payment_method_id => PaymentMethod.first.id, :amount => 50 }
         
     | 
| 
       38 
     | 
    
         
            -
                      response.status. 
     | 
| 
       39 
     | 
    
         
            -
                      json_response. 
     | 
| 
      
 38 
     | 
    
         
            +
                      expect(response.status).to eq(201)
         
     | 
| 
      
 39 
     | 
    
         
            +
                      expect(json_response).to have_attributes(attributes)
         
     | 
| 
       40 
40 
     | 
    
         
             
                    end
         
     | 
| 
       41 
41 
     | 
    
         | 
| 
       42 
42 
     | 
    
         
             
                    it "can view a pre-existing payment's details" do
         
     | 
| 
       43 
43 
     | 
    
         
             
                      api_get :show, :id => payment.to_param
         
     | 
| 
       44 
     | 
    
         
            -
                      json_response. 
     | 
| 
      
 44 
     | 
    
         
            +
                      expect(json_response).to have_attributes(attributes)
         
     | 
| 
       45 
45 
     | 
    
         
             
                    end
         
     | 
| 
       46 
46 
     | 
    
         | 
| 
       47 
47 
     | 
    
         
             
                    it "cannot update a payment" do
         
     | 
| 
         @@ -57,7 +57,7 @@ module Spree 
     | 
|
| 
       57 
57 
     | 
    
         | 
| 
       58 
58 
     | 
    
         
             
                  context "when the order does not belong to the user" do
         
     | 
| 
       59 
59 
     | 
    
         
             
                    before do
         
     | 
| 
       60 
     | 
    
         
            -
                      Order. 
     | 
| 
      
 60 
     | 
    
         
            +
                      allow_any_instance_of(Order).to receive_messages :user => stub_model(LegacyUser)
         
     | 
| 
       61 
61 
     | 
    
         
             
                    end
         
     | 
| 
       62 
62 
     | 
    
         | 
| 
       63 
63 
     | 
    
         
             
                    it "cannot view payments for somebody else's order" do
         
     | 
| 
         @@ -67,7 +67,7 @@ module Spree 
     | 
|
| 
       67 
67 
     | 
    
         | 
| 
       68 
68 
     | 
    
         
             
                    it "can view the payments for an order given the order token" do
         
     | 
| 
       69 
69 
     | 
    
         
             
                      api_get :index, :order_id => order.to_param, :order_token => order.guest_token
         
     | 
| 
       70 
     | 
    
         
            -
                      json_response["payments"].first. 
     | 
| 
      
 70 
     | 
    
         
            +
                      expect(json_response["payments"].first).to have_attributes(attributes)
         
     | 
| 
       71 
71 
     | 
    
         
             
                    end
         
     | 
| 
       72 
72 
     | 
    
         
             
                  end
         
     | 
| 
       73 
73 
     | 
    
         
             
                end
         
     | 
| 
         @@ -77,8 +77,8 @@ module Spree 
     | 
|
| 
       77 
77 
     | 
    
         | 
| 
       78 
78 
     | 
    
         
             
                  it "can view the payments on any order" do
         
     | 
| 
       79 
79 
     | 
    
         
             
                    api_get :index
         
     | 
| 
       80 
     | 
    
         
            -
                    response.status. 
     | 
| 
       81 
     | 
    
         
            -
                    json_response["payments"].first. 
     | 
| 
      
 80 
     | 
    
         
            +
                    expect(response.status).to eq(200)
         
     | 
| 
      
 81 
     | 
    
         
            +
                    expect(json_response["payments"].first).to have_attributes(attributes)
         
     | 
| 
       82 
82 
     | 
    
         
             
                  end
         
     | 
| 
       83 
83 
     | 
    
         | 
| 
       84 
84 
     | 
    
         
             
                  context "multiple payments" do
         
     | 
| 
         @@ -86,20 +86,20 @@ module Spree 
     | 
|
| 
       86 
86 
     | 
    
         | 
| 
       87 
87 
     | 
    
         
             
                    it "can view all payments on an order" do
         
     | 
| 
       88 
88 
     | 
    
         
             
                      api_get :index
         
     | 
| 
       89 
     | 
    
         
            -
                      json_response["count"]. 
     | 
| 
      
 89 
     | 
    
         
            +
                      expect(json_response["count"]).to eq(2)
         
     | 
| 
       90 
90 
     | 
    
         
             
                    end
         
     | 
| 
       91 
91 
     | 
    
         | 
| 
       92 
92 
     | 
    
         
             
                    it 'can control the page size through a parameter' do
         
     | 
| 
       93 
93 
     | 
    
         
             
                      api_get :index, :per_page => 1
         
     | 
| 
       94 
     | 
    
         
            -
                      json_response['count']. 
     | 
| 
       95 
     | 
    
         
            -
                      json_response['current_page']. 
     | 
| 
       96 
     | 
    
         
            -
                      json_response['pages']. 
     | 
| 
      
 94 
     | 
    
         
            +
                      expect(json_response['count']).to eq(1)
         
     | 
| 
      
 95 
     | 
    
         
            +
                      expect(json_response['current_page']).to eq(1)
         
     | 
| 
      
 96 
     | 
    
         
            +
                      expect(json_response['pages']).to eq(2)
         
     | 
| 
       97 
97 
     | 
    
         
             
                    end
         
     | 
| 
       98 
98 
     | 
    
         | 
| 
       99 
99 
     | 
    
         
             
                    it 'can query the results through a paramter' do
         
     | 
| 
       100 
100 
     | 
    
         
             
                      api_get :index, :q => { :response_code_cont => '999' }
         
     | 
| 
       101 
     | 
    
         
            -
                      json_response['count']. 
     | 
| 
       102 
     | 
    
         
            -
                      json_response['payments'].first['response_code']. 
     | 
| 
      
 101 
     | 
    
         
            +
                      expect(json_response['count']).to eq(1)
         
     | 
| 
      
 102 
     | 
    
         
            +
                      expect(json_response['payments'].first['response_code']).to eq @payment.response_code
         
     | 
| 
       103 
103 
     | 
    
         
             
                    end
         
     | 
| 
       104 
104 
     | 
    
         
             
                  end
         
     | 
| 
       105 
105 
     | 
    
         | 
| 
         @@ -108,23 +108,23 @@ module Spree 
     | 
|
| 
       108 
108 
     | 
    
         
             
                      it "can update" do
         
     | 
| 
       109 
109 
     | 
    
         
             
                        payment.update_attributes(:state => 'pending')
         
     | 
| 
       110 
110 
     | 
    
         
             
                        api_put :update, :id => payment.to_param, :payment => { :amount => 2.01 }
         
     | 
| 
       111 
     | 
    
         
            -
                        response.status. 
     | 
| 
       112 
     | 
    
         
            -
                        payment.reload.amount. 
     | 
| 
      
 111 
     | 
    
         
            +
                        expect(response.status).to eq(200)
         
     | 
| 
      
 112 
     | 
    
         
            +
                        expect(payment.reload.amount).to eq(2.01)
         
     | 
| 
       113 
113 
     | 
    
         
             
                      end
         
     | 
| 
       114 
114 
     | 
    
         | 
| 
       115 
115 
     | 
    
         
             
                      context "update fails" do
         
     | 
| 
       116 
116 
     | 
    
         
             
                        it "returns a 422 status when the amount is invalid" do
         
     | 
| 
       117 
117 
     | 
    
         
             
                          payment.update_attributes(:state => 'pending')
         
     | 
| 
       118 
118 
     | 
    
         
             
                          api_put :update, :id => payment.to_param, :payment => { :amount => 'invalid' }
         
     | 
| 
       119 
     | 
    
         
            -
                          response.status. 
     | 
| 
       120 
     | 
    
         
            -
                          json_response["error"]. 
     | 
| 
      
 119 
     | 
    
         
            +
                          expect(response.status).to eq(422)
         
     | 
| 
      
 120 
     | 
    
         
            +
                          expect(json_response["error"]).to eq("Invalid resource. Please fix errors and try again.")
         
     | 
| 
       121 
121 
     | 
    
         
             
                        end
         
     | 
| 
       122 
122 
     | 
    
         | 
| 
       123 
123 
     | 
    
         
             
                        it "returns a 403 status when the payment is not pending" do
         
     | 
| 
       124 
124 
     | 
    
         
             
                          payment.update_attributes(:state => 'completed')
         
     | 
| 
       125 
125 
     | 
    
         
             
                          api_put :update, :id => payment.to_param, :payment => { :amount => 2.01 }
         
     | 
| 
       126 
     | 
    
         
            -
                          response.status. 
     | 
| 
       127 
     | 
    
         
            -
                          json_response["error"]. 
     | 
| 
      
 126 
     | 
    
         
            +
                          expect(response.status).to eq(403)
         
     | 
| 
      
 127 
     | 
    
         
            +
                          expect(json_response["error"]).to eq("This payment cannot be updated because it is completed.")
         
     | 
| 
       128 
128 
     | 
    
         
             
                        end
         
     | 
| 
       129 
129 
     | 
    
         
             
                      end
         
     | 
| 
       130 
130 
     | 
    
         
             
                    end
         
     | 
| 
         @@ -132,26 +132,26 @@ module Spree 
     | 
|
| 
       132 
132 
     | 
    
         
             
                    context "authorizing" do
         
     | 
| 
       133 
133 
     | 
    
         
             
                      it "can authorize" do
         
     | 
| 
       134 
134 
     | 
    
         
             
                        api_put :authorize, :id => payment.to_param
         
     | 
| 
       135 
     | 
    
         
            -
                        response.status. 
     | 
| 
       136 
     | 
    
         
            -
                        payment.reload.state. 
     | 
| 
      
 135 
     | 
    
         
            +
                        expect(response.status).to eq(200)
         
     | 
| 
      
 136 
     | 
    
         
            +
                        expect(payment.reload.state).to eq("pending")
         
     | 
| 
       137 
137 
     | 
    
         
             
                      end
         
     | 
| 
       138 
138 
     | 
    
         | 
| 
       139 
139 
     | 
    
         
             
                      context "authorization fails" do
         
     | 
| 
       140 
140 
     | 
    
         
             
                        before do
         
     | 
| 
       141 
141 
     | 
    
         
             
                          fake_response = double(:success? => false, :to_s => "Could not authorize card")
         
     | 
| 
       142 
     | 
    
         
            -
                          Spree::Gateway::Bogus. 
     | 
| 
      
 142 
     | 
    
         
            +
                          expect_any_instance_of(Spree::Gateway::Bogus).to receive(:authorize).and_return(fake_response)
         
     | 
| 
       143 
143 
     | 
    
         
             
                          api_put :authorize, :id => payment.to_param
         
     | 
| 
       144 
144 
     | 
    
         
             
                        end
         
     | 
| 
       145 
145 
     | 
    
         | 
| 
       146 
146 
     | 
    
         
             
                        it "returns a 422 status" do
         
     | 
| 
       147 
     | 
    
         
            -
                          response.status. 
     | 
| 
      
 147 
     | 
    
         
            +
                          expect(response.status).to eq(422)
         
     | 
| 
       148 
148 
     | 
    
         
             
                          expect(json_response["error"]).to eq "Invalid resource. Please fix errors and try again."
         
     | 
| 
       149 
149 
     | 
    
         
             
                          expect(json_response["errors"]["base"][0]).to eq "Could not authorize card"
         
     | 
| 
       150 
150 
     | 
    
         
             
                        end
         
     | 
| 
       151 
151 
     | 
    
         | 
| 
       152 
152 
     | 
    
         
             
                        it "does not raise a stack level error" do
         
     | 
| 
       153 
153 
     | 
    
         
             
                          skip "Investigate why a payment.reload after the request raises 'stack level too deep'"
         
     | 
| 
       154 
     | 
    
         
            -
                          payment.reload.state. 
     | 
| 
      
 154 
     | 
    
         
            +
                          expect(payment.reload.state).to eq("failed")
         
     | 
| 
       155 
155 
     | 
    
         
             
                        end
         
     | 
| 
       156 
156 
     | 
    
         
             
                      end
         
     | 
| 
       157 
157 
     | 
    
         
             
                    end
         
     | 
| 
         @@ -159,19 +159,19 @@ module Spree 
     | 
|
| 
       159 
159 
     | 
    
         
             
                    context "capturing" do
         
     | 
| 
       160 
160 
     | 
    
         
             
                      it "can capture" do
         
     | 
| 
       161 
161 
     | 
    
         
             
                        api_put :capture, :id => payment.to_param
         
     | 
| 
       162 
     | 
    
         
            -
                        response.status. 
     | 
| 
       163 
     | 
    
         
            -
                        payment.reload.state. 
     | 
| 
      
 162 
     | 
    
         
            +
                        expect(response.status).to eq(200)
         
     | 
| 
      
 163 
     | 
    
         
            +
                        expect(payment.reload.state).to eq("completed")
         
     | 
| 
       164 
164 
     | 
    
         
             
                      end
         
     | 
| 
       165 
165 
     | 
    
         | 
| 
       166 
166 
     | 
    
         
             
                      context "capturing fails" do
         
     | 
| 
       167 
167 
     | 
    
         
             
                        before do
         
     | 
| 
       168 
168 
     | 
    
         
             
                          fake_response = double(:success? => false, :to_s => "Insufficient funds")
         
     | 
| 
       169 
     | 
    
         
            -
                          Spree::Gateway::Bogus. 
     | 
| 
      
 169 
     | 
    
         
            +
                          expect_any_instance_of(Spree::Gateway::Bogus).to receive(:capture).and_return(fake_response)
         
     | 
| 
       170 
170 
     | 
    
         
             
                        end
         
     | 
| 
       171 
171 
     | 
    
         | 
| 
       172 
172 
     | 
    
         
             
                        it "returns a 422 status" do
         
     | 
| 
       173 
173 
     | 
    
         
             
                          api_put :capture, :id => payment.to_param
         
     | 
| 
       174 
     | 
    
         
            -
                          response.status. 
     | 
| 
      
 174 
     | 
    
         
            +
                          expect(response.status).to eq(422)
         
     | 
| 
       175 
175 
     | 
    
         
             
                          expect(json_response["error"]).to eq "Invalid resource. Please fix errors and try again."
         
     | 
| 
       176 
176 
     | 
    
         
             
                          expect(json_response["errors"]["base"][0]).to eq "Insufficient funds"
         
     | 
| 
       177 
177 
     | 
    
         
             
                        end
         
     | 
| 
         @@ -181,19 +181,19 @@ module Spree 
     | 
|
| 
       181 
181 
     | 
    
         
             
                    context "purchasing" do
         
     | 
| 
       182 
182 
     | 
    
         
             
                      it "can purchase" do
         
     | 
| 
       183 
183 
     | 
    
         
             
                        api_put :purchase, :id => payment.to_param
         
     | 
| 
       184 
     | 
    
         
            -
                        response.status. 
     | 
| 
       185 
     | 
    
         
            -
                        payment.reload.state. 
     | 
| 
      
 184 
     | 
    
         
            +
                        expect(response.status).to eq(200)
         
     | 
| 
      
 185 
     | 
    
         
            +
                        expect(payment.reload.state).to eq("completed")
         
     | 
| 
       186 
186 
     | 
    
         
             
                      end
         
     | 
| 
       187 
187 
     | 
    
         | 
| 
       188 
188 
     | 
    
         
             
                      context "purchasing fails" do
         
     | 
| 
       189 
189 
     | 
    
         
             
                        before do
         
     | 
| 
       190 
190 
     | 
    
         
             
                          fake_response = double(:success? => false, :to_s => "Insufficient funds")
         
     | 
| 
       191 
     | 
    
         
            -
                          Spree::Gateway::Bogus. 
     | 
| 
      
 191 
     | 
    
         
            +
                          expect_any_instance_of(Spree::Gateway::Bogus).to receive(:purchase).and_return(fake_response)
         
     | 
| 
       192 
192 
     | 
    
         
             
                        end
         
     | 
| 
       193 
193 
     | 
    
         | 
| 
       194 
194 
     | 
    
         
             
                        it "returns a 422 status" do
         
     | 
| 
       195 
195 
     | 
    
         
             
                          api_put :purchase, :id => payment.to_param
         
     | 
| 
       196 
     | 
    
         
            -
                          response.status. 
     | 
| 
      
 196 
     | 
    
         
            +
                          expect(response.status).to eq(422)
         
     | 
| 
       197 
197 
     | 
    
         
             
                          expect(json_response["error"]).to eq "Invalid resource. Please fix errors and try again."
         
     | 
| 
       198 
198 
     | 
    
         
             
                          expect(json_response["errors"]["base"][0]).to eq "Insufficient funds"
         
     | 
| 
       199 
199 
     | 
    
         
             
                        end
         
     | 
| 
         @@ -210,7 +210,7 @@ module Spree 
     | 
|
| 
       210 
210 
     | 
    
         
             
                      context "voiding fails" do
         
     | 
| 
       211 
211 
     | 
    
         
             
                        before do
         
     | 
| 
       212 
212 
     | 
    
         
             
                          fake_response = double(success?: false, to_s: "NO REFUNDS")
         
     | 
| 
       213 
     | 
    
         
            -
                          Spree::Gateway::Bogus. 
     | 
| 
      
 213 
     | 
    
         
            +
                          expect_any_instance_of(Spree::Gateway::Bogus).to receive(:void).and_return(fake_response)
         
     | 
| 
       214 
214 
     | 
    
         
             
                        end
         
     | 
| 
       215 
215 
     | 
    
         | 
| 
       216 
216 
     | 
    
         
             
                        it "returns a 422 status" do
         
     | 
| 
         @@ -2,7 +2,7 @@ require 'spec_helper' 
     | 
|
| 
       2 
2 
     | 
    
         
             
            require 'shared_examples/protect_product_actions'
         
     | 
| 
       3 
3 
     | 
    
         | 
| 
       4 
4 
     | 
    
         
             
            module Spree
         
     | 
| 
       5 
     | 
    
         
            -
              describe Spree::Api::ProductPropertiesController do
         
     | 
| 
      
 5 
     | 
    
         
            +
              describe Spree::Api::ProductPropertiesController, :type => :controller do
         
     | 
| 
       6 
6 
     | 
    
         
             
                render_views
         
     | 
| 
       7 
7 
     | 
    
         | 
| 
       8 
8 
     | 
    
         
             
                let!(:product) { create(:product) }
         
     | 
| 
         @@ -23,40 +23,40 @@ module Spree 
     | 
|
| 
       23 
23 
     | 
    
         | 
| 
       24 
24 
     | 
    
         
             
                  it "can not see a list of product properties" do
         
     | 
| 
       25 
25 
     | 
    
         
             
                    api_get :index
         
     | 
| 
       26 
     | 
    
         
            -
                    response.status. 
     | 
| 
      
 26 
     | 
    
         
            +
                    expect(response.status).to eq(404)
         
     | 
| 
       27 
27 
     | 
    
         
             
                  end
         
     | 
| 
       28 
28 
     | 
    
         
             
                end
         
     | 
| 
       29 
29 
     | 
    
         | 
| 
       30 
30 
     | 
    
         
             
                it "can see a list of all product properties" do
         
     | 
| 
       31 
31 
     | 
    
         
             
                  api_get :index
         
     | 
| 
       32 
     | 
    
         
            -
                  json_response["product_properties"].count. 
     | 
| 
       33 
     | 
    
         
            -
                  json_response["product_properties"].first. 
     | 
| 
      
 32 
     | 
    
         
            +
                  expect(json_response["product_properties"].count).to eq 2
         
     | 
| 
      
 33 
     | 
    
         
            +
                  expect(json_response["product_properties"].first).to have_attributes(attributes)
         
     | 
| 
       34 
34 
     | 
    
         
             
                end
         
     | 
| 
       35 
35 
     | 
    
         | 
| 
       36 
36 
     | 
    
         
             
                it "can control the page size through a parameter" do
         
     | 
| 
       37 
37 
     | 
    
         
             
                  api_get :index, :per_page => 1
         
     | 
| 
       38 
     | 
    
         
            -
                  json_response['product_properties'].count. 
     | 
| 
       39 
     | 
    
         
            -
                  json_response['current_page']. 
     | 
| 
       40 
     | 
    
         
            -
                  json_response['pages']. 
     | 
| 
      
 38 
     | 
    
         
            +
                  expect(json_response['product_properties'].count).to eq(1)
         
     | 
| 
      
 39 
     | 
    
         
            +
                  expect(json_response['current_page']).to eq(1)
         
     | 
| 
      
 40 
     | 
    
         
            +
                  expect(json_response['pages']).to eq(2)
         
     | 
| 
       41 
41 
     | 
    
         
             
                end
         
     | 
| 
       42 
42 
     | 
    
         | 
| 
       43 
43 
     | 
    
         
             
                it 'can query the results through a parameter' do
         
     | 
| 
       44 
44 
     | 
    
         
             
                  Spree::ProductProperty.last.update_attribute(:value, 'loose')
         
     | 
| 
       45 
45 
     | 
    
         
             
                  property = Spree::ProductProperty.last
         
     | 
| 
       46 
46 
     | 
    
         
             
                  api_get :index, :q => { :value_cont => 'loose' }
         
     | 
| 
       47 
     | 
    
         
            -
                  json_response['count']. 
     | 
| 
       48 
     | 
    
         
            -
                  json_response['product_properties'].first['value']. 
     | 
| 
      
 47 
     | 
    
         
            +
                  expect(json_response['count']).to eq(1)
         
     | 
| 
      
 48 
     | 
    
         
            +
                  expect(json_response['product_properties'].first['value']).to eq property.value
         
     | 
| 
       49 
49 
     | 
    
         
             
                end
         
     | 
| 
       50 
50 
     | 
    
         | 
| 
       51 
51 
     | 
    
         
             
                it "can see a single product_property" do
         
     | 
| 
       52 
52 
     | 
    
         
             
                  api_get :show, :id => property_1.property_name
         
     | 
| 
       53 
     | 
    
         
            -
                  json_response. 
     | 
| 
      
 53 
     | 
    
         
            +
                  expect(json_response).to have_attributes(attributes)
         
     | 
| 
       54 
54 
     | 
    
         
             
                end
         
     | 
| 
       55 
55 
     | 
    
         | 
| 
       56 
56 
     | 
    
         
             
                it "can learn how to create a new product property" do
         
     | 
| 
       57 
57 
     | 
    
         
             
                  api_get :new
         
     | 
| 
       58 
     | 
    
         
            -
                  json_response["attributes"]. 
     | 
| 
       59 
     | 
    
         
            -
                  json_response["required_attributes"]. 
     | 
| 
      
 58 
     | 
    
         
            +
                  expect(json_response["attributes"]).to eq(attributes.map(&:to_s))
         
     | 
| 
      
 59 
     | 
    
         
            +
                  expect(json_response["required_attributes"]).to be_empty
         
     | 
| 
       60 
60 
     | 
    
         
             
                end
         
     | 
| 
       61 
61 
     | 
    
         | 
| 
       62 
62 
     | 
    
         
             
                it "cannot create a new product property if not an admin" do
         
     | 
| 
         @@ -72,7 +72,7 @@ module Spree 
     | 
|
| 
       72 
72 
     | 
    
         
             
                it "cannot delete a product property" do
         
     | 
| 
       73 
73 
     | 
    
         
             
                  api_delete :destroy, :property_name => property_1.property_name
         
     | 
| 
       74 
74 
     | 
    
         
             
                  assert_unauthorized!
         
     | 
| 
       75 
     | 
    
         
            -
                   
     | 
| 
      
 75 
     | 
    
         
            +
                  expect { property_1.reload }.not_to raise_error
         
     | 
| 
       76 
76 
     | 
    
         
             
                end
         
     | 
| 
       77 
77 
     | 
    
         | 
| 
       78 
78 
     | 
    
         
             
                context "as an admin" do
         
     | 
| 
         @@ -82,19 +82,19 @@ module Spree 
     | 
|
| 
       82 
82 
     | 
    
         
             
                    expect do
         
     | 
| 
       83 
83 
     | 
    
         
             
                      api_post :create, :product_property => { :property_name => "My Property 3", :value => "my value 3" }
         
     | 
| 
       84 
84 
     | 
    
         
             
                    end.to change(product.product_properties, :count).by(1)
         
     | 
| 
       85 
     | 
    
         
            -
                    json_response. 
     | 
| 
       86 
     | 
    
         
            -
                    response.status. 
     | 
| 
      
 85 
     | 
    
         
            +
                    expect(json_response).to have_attributes(attributes)
         
     | 
| 
      
 86 
     | 
    
         
            +
                    expect(response.status).to eq(201)
         
     | 
| 
       87 
87 
     | 
    
         
             
                  end
         
     | 
| 
       88 
88 
     | 
    
         | 
| 
       89 
89 
     | 
    
         
             
                  it "can update a product property" do
         
     | 
| 
       90 
90 
     | 
    
         
             
                    api_put :update, :id => property_1.property_name, :product_property => { :value => "my value 456" }
         
     | 
| 
       91 
     | 
    
         
            -
                    response.status. 
     | 
| 
      
 91 
     | 
    
         
            +
                    expect(response.status).to eq(200)
         
     | 
| 
       92 
92 
     | 
    
         
             
                  end
         
     | 
| 
       93 
93 
     | 
    
         | 
| 
       94 
94 
     | 
    
         
             
                  it "can delete a product property" do
         
     | 
| 
       95 
95 
     | 
    
         
             
                    api_delete :destroy, :id => property_1.property_name
         
     | 
| 
       96 
     | 
    
         
            -
                    response.status. 
     | 
| 
       97 
     | 
    
         
            -
                     
     | 
| 
      
 96 
     | 
    
         
            +
                    expect(response.status).to eq(204)
         
     | 
| 
      
 97 
     | 
    
         
            +
                    expect { property_1.reload }.to raise_error(ActiveRecord::RecordNotFound)
         
     | 
| 
       98 
98 
     | 
    
         
             
                  end
         
     | 
| 
       99 
99 
     | 
    
         
             
                end
         
     | 
| 
       100 
100 
     | 
    
         | 
| 
         @@ -102,13 +102,13 @@ module Spree 
     | 
|
| 
       102 
102 
     | 
    
         
             
                  let(:resource_scoping) { { :product_id => product.id } }
         
     | 
| 
       103 
103 
     | 
    
         
             
                  it "can see a list of all product properties" do
         
     | 
| 
       104 
104 
     | 
    
         
             
                    api_get :index
         
     | 
| 
       105 
     | 
    
         
            -
                    json_response["product_properties"].count. 
     | 
| 
       106 
     | 
    
         
            -
                    json_response["product_properties"].first. 
     | 
| 
      
 105 
     | 
    
         
            +
                    expect(json_response["product_properties"].count).to eq 2
         
     | 
| 
      
 106 
     | 
    
         
            +
                    expect(json_response["product_properties"].first).to have_attributes(attributes)
         
     | 
| 
       107 
107 
     | 
    
         
             
                  end
         
     | 
| 
       108 
108 
     | 
    
         | 
| 
       109 
109 
     | 
    
         
             
                  it "can see a single product_property by id" do
         
     | 
| 
       110 
110 
     | 
    
         
             
                    api_get :show, :id => property_1.id
         
     | 
| 
       111 
     | 
    
         
            -
                    json_response. 
     | 
| 
      
 111 
     | 
    
         
            +
                    expect(json_response).to have_attributes(attributes)
         
     | 
| 
       112 
112 
     | 
    
         
             
                  end
         
     | 
| 
       113 
113 
     | 
    
         
             
                end
         
     | 
| 
       114 
114 
     | 
    
         | 
| 
         @@ -2,7 +2,7 @@ require 'spec_helper' 
     | 
|
| 
       2 
2 
     | 
    
         
             
            require 'shared_examples/protect_product_actions'
         
     | 
| 
       3 
3 
     | 
    
         | 
| 
       4 
4 
     | 
    
         
             
            module Spree
         
     | 
| 
       5 
     | 
    
         
            -
              describe Spree::Api::ProductsController do
         
     | 
| 
      
 5 
     | 
    
         
            +
              describe Spree::Api::ProductsController, :type => :controller do
         
     | 
| 
       6 
6 
     | 
    
         
             
                render_views
         
     | 
| 
       7 
7 
     | 
    
         | 
| 
       8 
8 
     | 
    
         
             
                let!(:product) { create(:product) }
         
     | 
| 
         @@ -51,20 +51,20 @@ module Spree 
     | 
|
| 
       51 
51 
     | 
    
         | 
| 
       52 
52 
     | 
    
         
             
                  it "retrieves a list of products" do
         
     | 
| 
       53 
53 
     | 
    
         
             
                    api_get :index
         
     | 
| 
       54 
     | 
    
         
            -
                    json_response["products"].first. 
     | 
| 
       55 
     | 
    
         
            -
                    json_response["total_count"]. 
     | 
| 
       56 
     | 
    
         
            -
                    json_response["current_page"]. 
     | 
| 
       57 
     | 
    
         
            -
                    json_response["pages"]. 
     | 
| 
       58 
     | 
    
         
            -
                    json_response["per_page"]. 
     | 
| 
      
 54 
     | 
    
         
            +
                    expect(json_response["products"].first).to have_attributes(show_attributes)
         
     | 
| 
      
 55 
     | 
    
         
            +
                    expect(json_response["total_count"]).to eq(1)
         
     | 
| 
      
 56 
     | 
    
         
            +
                    expect(json_response["current_page"]).to eq(1)
         
     | 
| 
      
 57 
     | 
    
         
            +
                    expect(json_response["pages"]).to eq(1)
         
     | 
| 
      
 58 
     | 
    
         
            +
                    expect(json_response["per_page"]).to eq(Kaminari.config.default_per_page)
         
     | 
| 
       59 
59 
     | 
    
         
             
                  end
         
     | 
| 
       60 
60 
     | 
    
         | 
| 
       61 
61 
     | 
    
         
             
                  it "retrieves a list of products by id" do
         
     | 
| 
       62 
62 
     | 
    
         
             
                    api_get :index, :ids => [product.id]
         
     | 
| 
       63 
     | 
    
         
            -
                    json_response["products"].first. 
     | 
| 
       64 
     | 
    
         
            -
                    json_response["total_count"]. 
     | 
| 
       65 
     | 
    
         
            -
                    json_response["current_page"]. 
     | 
| 
       66 
     | 
    
         
            -
                    json_response["pages"]. 
     | 
| 
       67 
     | 
    
         
            -
                    json_response["per_page"]. 
     | 
| 
      
 63 
     | 
    
         
            +
                    expect(json_response["products"].first).to have_attributes(show_attributes)
         
     | 
| 
      
 64 
     | 
    
         
            +
                    expect(json_response["total_count"]).to eq(1)
         
     | 
| 
      
 65 
     | 
    
         
            +
                    expect(json_response["current_page"]).to eq(1)
         
     | 
| 
      
 66 
     | 
    
         
            +
                    expect(json_response["pages"]).to eq(1)
         
     | 
| 
      
 67 
     | 
    
         
            +
                    expect(json_response["per_page"]).to eq(Kaminari.config.default_per_page)
         
     | 
| 
       68 
68 
     | 
    
         
             
                  end
         
     | 
| 
       69 
69 
     | 
    
         | 
| 
       70 
70 
     | 
    
         
             
                  context "specifying a rabl template for a custom action" do
         
     | 
| 
         @@ -80,18 +80,18 @@ module Spree 
     | 
|
| 
       80 
80 
     | 
    
         
             
                    it "uses the specified custom template through the request header" do
         
     | 
| 
       81 
81 
     | 
    
         
             
                      request.headers['X-Spree-Template'] = 'show'
         
     | 
| 
       82 
82 
     | 
    
         
             
                      api_get :custom_show, :id => product.id
         
     | 
| 
       83 
     | 
    
         
            -
                      response. 
     | 
| 
      
 83 
     | 
    
         
            +
                      expect(response).to render_template('spree/api/products/show')
         
     | 
| 
       84 
84 
     | 
    
         
             
                    end
         
     | 
| 
       85 
85 
     | 
    
         | 
| 
       86 
86 
     | 
    
         
             
                    it "uses the specified custom template through the template URL parameter" do
         
     | 
| 
       87 
87 
     | 
    
         
             
                      api_get :custom_show, :id => product.id, :template => 'show'
         
     | 
| 
       88 
     | 
    
         
            -
                      response. 
     | 
| 
      
 88 
     | 
    
         
            +
                      expect(response).to render_template('spree/api/products/show')
         
     | 
| 
       89 
89 
     | 
    
         
             
                    end
         
     | 
| 
       90 
90 
     | 
    
         | 
| 
       91 
91 
     | 
    
         
             
                    it "falls back to the default template if the specified template does not exist" do
         
     | 
| 
       92 
92 
     | 
    
         
             
                      request.headers['X-Spree-Template'] = 'invoice'
         
     | 
| 
       93 
93 
     | 
    
         
             
                      api_get :show, :id => product.id
         
     | 
| 
       94 
     | 
    
         
            -
                      response. 
     | 
| 
      
 94 
     | 
    
         
            +
                      expect(response).to render_template('spree/api/products/show')
         
     | 
| 
       95 
95 
     | 
    
         
             
                    end
         
     | 
| 
       96 
96 
     | 
    
         
             
                  end
         
     | 
| 
       97 
97 
     | 
    
         | 
| 
         @@ -107,64 +107,64 @@ module Spree 
     | 
|
| 
       107 
107 
     | 
    
         
             
                  it "retrieves a list of products by ids string" do
         
     | 
| 
       108 
108 
     | 
    
         
             
                    second_product = create(:product)
         
     | 
| 
       109 
109 
     | 
    
         
             
                    api_get :index, :ids => [product.id, second_product.id].join(",")
         
     | 
| 
       110 
     | 
    
         
            -
                    json_response["products"].first. 
     | 
| 
       111 
     | 
    
         
            -
                    json_response["products"][1]. 
     | 
| 
       112 
     | 
    
         
            -
                    json_response["total_count"]. 
     | 
| 
       113 
     | 
    
         
            -
                    json_response["current_page"]. 
     | 
| 
       114 
     | 
    
         
            -
                    json_response["pages"]. 
     | 
| 
       115 
     | 
    
         
            -
                    json_response["per_page"]. 
     | 
| 
      
 110 
     | 
    
         
            +
                    expect(json_response["products"].first).to have_attributes(show_attributes)
         
     | 
| 
      
 111 
     | 
    
         
            +
                    expect(json_response["products"][1]).to have_attributes(show_attributes)
         
     | 
| 
      
 112 
     | 
    
         
            +
                    expect(json_response["total_count"]).to eq(2)
         
     | 
| 
      
 113 
     | 
    
         
            +
                    expect(json_response["current_page"]).to eq(1)
         
     | 
| 
      
 114 
     | 
    
         
            +
                    expect(json_response["pages"]).to eq(1)
         
     | 
| 
      
 115 
     | 
    
         
            +
                    expect(json_response["per_page"]).to eq(Kaminari.config.default_per_page)
         
     | 
| 
       116 
116 
     | 
    
         
             
                  end
         
     | 
| 
       117 
117 
     | 
    
         | 
| 
       118 
118 
     | 
    
         
             
                  it "does not return inactive products when queried by ids" do
         
     | 
| 
       119 
119 
     | 
    
         
             
                    api_get :index, :ids => [inactive_product.id]
         
     | 
| 
       120 
     | 
    
         
            -
                    json_response["count"]. 
     | 
| 
      
 120 
     | 
    
         
            +
                    expect(json_response["count"]).to eq(0)
         
     | 
| 
       121 
121 
     | 
    
         
             
                  end
         
     | 
| 
       122 
122 
     | 
    
         | 
| 
       123 
123 
     | 
    
         
             
                  it "does not list unavailable products" do
         
     | 
| 
       124 
124 
     | 
    
         
             
                    api_get :index
         
     | 
| 
       125 
     | 
    
         
            -
                    json_response["products"].first["name"]. 
     | 
| 
      
 125 
     | 
    
         
            +
                    expect(json_response["products"].first["name"]).not_to eq("inactive")
         
     | 
| 
       126 
126 
     | 
    
         
             
                  end
         
     | 
| 
       127 
127 
     | 
    
         | 
| 
       128 
128 
     | 
    
         
             
                  context "pagination" do
         
     | 
| 
       129 
129 
     | 
    
         
             
                    it "can select the next page of products" do
         
     | 
| 
       130 
130 
     | 
    
         
             
                      second_product = create(:product)
         
     | 
| 
       131 
131 
     | 
    
         
             
                      api_get :index, :page => 2, :per_page => 1
         
     | 
| 
       132 
     | 
    
         
            -
                      json_response["products"].first. 
     | 
| 
       133 
     | 
    
         
            -
                      json_response["total_count"]. 
     | 
| 
       134 
     | 
    
         
            -
                      json_response["current_page"]. 
     | 
| 
       135 
     | 
    
         
            -
                      json_response["pages"]. 
     | 
| 
      
 132 
     | 
    
         
            +
                      expect(json_response["products"].first).to have_attributes(show_attributes)
         
     | 
| 
      
 133 
     | 
    
         
            +
                      expect(json_response["total_count"]).to eq(2)
         
     | 
| 
      
 134 
     | 
    
         
            +
                      expect(json_response["current_page"]).to eq(2)
         
     | 
| 
      
 135 
     | 
    
         
            +
                      expect(json_response["pages"]).to eq(2)
         
     | 
| 
       136 
136 
     | 
    
         
             
                    end
         
     | 
| 
       137 
137 
     | 
    
         | 
| 
       138 
138 
     | 
    
         
             
                    it 'can control the page size through a parameter' do
         
     | 
| 
       139 
139 
     | 
    
         
             
                      create(:product)
         
     | 
| 
       140 
140 
     | 
    
         
             
                      api_get :index, :per_page => 1
         
     | 
| 
       141 
     | 
    
         
            -
                      json_response['count']. 
     | 
| 
       142 
     | 
    
         
            -
                      json_response['total_count']. 
     | 
| 
       143 
     | 
    
         
            -
                      json_response['current_page']. 
     | 
| 
       144 
     | 
    
         
            -
                      json_response['pages']. 
     | 
| 
      
 141 
     | 
    
         
            +
                      expect(json_response['count']).to eq(1)
         
     | 
| 
      
 142 
     | 
    
         
            +
                      expect(json_response['total_count']).to eq(2)
         
     | 
| 
      
 143 
     | 
    
         
            +
                      expect(json_response['current_page']).to eq(1)
         
     | 
| 
      
 144 
     | 
    
         
            +
                      expect(json_response['pages']).to eq(2)
         
     | 
| 
       145 
145 
     | 
    
         
             
                    end
         
     | 
| 
       146 
146 
     | 
    
         
             
                  end
         
     | 
| 
       147 
147 
     | 
    
         | 
| 
       148 
148 
     | 
    
         
             
                  context "jsonp" do
         
     | 
| 
       149 
149 
     | 
    
         
             
                    it "retrieves a list of products of jsonp" do
         
     | 
| 
       150 
150 
     | 
    
         
             
                      api_get :index, {:callback => 'callback'}
         
     | 
| 
       151 
     | 
    
         
            -
                      response.body. 
     | 
| 
       152 
     | 
    
         
            -
                      response.header['Content-Type']. 
     | 
| 
      
 151 
     | 
    
         
            +
                      expect(response.body).to match(/^callback\(.*\)$/)
         
     | 
| 
      
 152 
     | 
    
         
            +
                      expect(response.header['Content-Type']).to include('application/javascript')
         
     | 
| 
       153 
153 
     | 
    
         
             
                    end
         
     | 
| 
       154 
154 
     | 
    
         | 
| 
       155 
155 
     | 
    
         
             
                    # Regression test for #4332
         
     | 
| 
       156 
156 
     | 
    
         
             
                    it "does not escape quotes" do
         
     | 
| 
       157 
157 
     | 
    
         
             
                      api_get :index, {:callback => 'callback'}
         
     | 
| 
       158 
     | 
    
         
            -
                      response.body. 
     | 
| 
       159 
     | 
    
         
            -
                      response.header['Content-Type']. 
     | 
| 
      
 158 
     | 
    
         
            +
                      expect(response.body).to match(/^callback\({"count":1,"total_count":1/)
         
     | 
| 
      
 159 
     | 
    
         
            +
                      expect(response.header['Content-Type']).to include('application/javascript')
         
     | 
| 
       160 
160 
     | 
    
         
             
                    end
         
     | 
| 
       161 
161 
     | 
    
         
             
                  end
         
     | 
| 
       162 
162 
     | 
    
         | 
| 
       163 
163 
     | 
    
         
             
                  it "can search for products" do
         
     | 
| 
       164 
164 
     | 
    
         
             
                    create(:product, :name => "The best product in the world")
         
     | 
| 
       165 
165 
     | 
    
         
             
                    api_get :index, :q => { :name_cont => "best" }
         
     | 
| 
       166 
     | 
    
         
            -
                    json_response["products"].first. 
     | 
| 
       167 
     | 
    
         
            -
                    json_response["count"]. 
     | 
| 
      
 166 
     | 
    
         
            +
                    expect(json_response["products"].first).to have_attributes(show_attributes)
         
     | 
| 
      
 167 
     | 
    
         
            +
                    expect(json_response["count"]).to eq(1)
         
     | 
| 
       168 
168 
     | 
    
         
             
                  end
         
     | 
| 
       169 
169 
     | 
    
         | 
| 
       170 
170 
     | 
    
         
             
                  it "gets a single product" do
         
     | 
| 
         @@ -172,15 +172,18 @@ module Spree 
     | 
|
| 
       172 
172 
     | 
    
         
             
                    product.variants.create!
         
     | 
| 
       173 
173 
     | 
    
         
             
                    product.variants.first.images.create!(:attachment => image("thinking-cat.jpg"))
         
     | 
| 
       174 
174 
     | 
    
         
             
                    product.set_property("spree", "rocks")
         
     | 
| 
      
 175 
     | 
    
         
            +
                    product.taxons << create(:taxon)
         
     | 
| 
      
 176 
     | 
    
         
            +
             
     | 
| 
       175 
177 
     | 
    
         
             
                    api_get :show, :id => product.to_param
         
     | 
| 
       176 
     | 
    
         
            -
             
     | 
| 
       177 
     | 
    
         
            -
                    json_response 
     | 
| 
      
 178 
     | 
    
         
            +
             
     | 
| 
      
 179 
     | 
    
         
            +
                    expect(json_response).to have_attributes(show_attributes)
         
     | 
| 
      
 180 
     | 
    
         
            +
                    expect(json_response['variants'].first).to have_attributes([:name,
         
     | 
| 
       178 
181 
     | 
    
         
             
                                                                          :is_master,
         
     | 
| 
       179 
182 
     | 
    
         
             
                                                                          :price,
         
     | 
| 
       180 
183 
     | 
    
         
             
                                                                          :images,
         
     | 
| 
       181 
184 
     | 
    
         
             
                                                                          :in_stock])
         
     | 
| 
       182 
185 
     | 
    
         | 
| 
       183 
     | 
    
         
            -
                    json_response['variants'].first['images'].first. 
     | 
| 
      
 186 
     | 
    
         
            +
                    expect(json_response['variants'].first['images'].first).to have_attributes([:attachment_file_name,
         
     | 
| 
       184 
187 
     | 
    
         
             
                                                                                            :attachment_width,
         
     | 
| 
       185 
188 
     | 
    
         
             
                                                                                            :attachment_height,
         
     | 
| 
       186 
189 
     | 
    
         
             
                                                                                            :attachment_content_type,
         
     | 
| 
         @@ -189,9 +192,11 @@ module Spree 
     | 
|
| 
       189 
192 
     | 
    
         
             
                                                                                            :product_url,
         
     | 
| 
       190 
193 
     | 
    
         
             
                                                                                            :large_url])
         
     | 
| 
       191 
194 
     | 
    
         | 
| 
       192 
     | 
    
         
            -
                    json_response["product_properties"].first. 
     | 
| 
      
 195 
     | 
    
         
            +
                    expect(json_response["product_properties"].first).to have_attributes([:value,
         
     | 
| 
       193 
196 
     | 
    
         
             
                                                                                     :product_id,
         
     | 
| 
       194 
197 
     | 
    
         
             
                                                                                     :property_name])
         
     | 
| 
      
 198 
     | 
    
         
            +
             
     | 
| 
      
 199 
     | 
    
         
            +
                    expect(json_response["taxons"].first).to have_attributes([:id, :name, :pretty_name, :permalink, :taxonomy_id, :parent_id])
         
     | 
| 
       195 
200 
     | 
    
         
             
                  end
         
     | 
| 
       196 
201 
     | 
    
         | 
| 
       197 
202 
     | 
    
         
             
                  context "tracking is disabled" do
         
     | 
| 
         @@ -215,11 +220,11 @@ module Spree 
     | 
|
| 
       215 
220 
     | 
    
         | 
| 
       216 
221 
     | 
    
         
             
                    specify do
         
     | 
| 
       217 
222 
     | 
    
         
             
                      api_get :show, :id => product.to_param
         
     | 
| 
       218 
     | 
    
         
            -
                      json_response["slug"]. 
     | 
| 
      
 223 
     | 
    
         
            +
                      expect(json_response["slug"]).to match(/and-1-ways/)
         
     | 
| 
       219 
224 
     | 
    
         
             
                      product.destroy
         
     | 
| 
       220 
225 
     | 
    
         | 
| 
       221 
226 
     | 
    
         
             
                      api_get :show, :id => other_product.id
         
     | 
| 
       222 
     | 
    
         
            -
                      json_response["slug"]. 
     | 
| 
      
 227 
     | 
    
         
            +
                      expect(json_response["slug"]).to match(/droids/)
         
     | 
| 
       223 
228 
     | 
    
         
             
                    end
         
     | 
| 
       224 
229 
     | 
    
         
             
                  end
         
     | 
| 
       225 
230 
     | 
    
         | 
| 
         @@ -235,11 +240,11 @@ module Spree 
     | 
|
| 
       235 
240 
     | 
    
         | 
| 
       236 
241 
     | 
    
         
             
                  it "can learn how to create a new product" do
         
     | 
| 
       237 
242 
     | 
    
         
             
                    api_get :new
         
     | 
| 
       238 
     | 
    
         
            -
                    json_response["attributes"]. 
     | 
| 
      
 243 
     | 
    
         
            +
                    expect(json_response["attributes"]).to eq(new_attributes.map(&:to_s))
         
     | 
| 
       239 
244 
     | 
    
         
             
                    required_attributes = json_response["required_attributes"]
         
     | 
| 
       240 
     | 
    
         
            -
                    required_attributes. 
     | 
| 
       241 
     | 
    
         
            -
                    required_attributes. 
     | 
| 
       242 
     | 
    
         
            -
                    required_attributes. 
     | 
| 
      
 245 
     | 
    
         
            +
                    expect(required_attributes).to include("name")
         
     | 
| 
      
 246 
     | 
    
         
            +
                    expect(required_attributes).to include("price")
         
     | 
| 
      
 247 
     | 
    
         
            +
                    expect(required_attributes).to include("shipping_category_id")
         
     | 
| 
       243 
248 
     | 
    
         
             
                  end
         
     | 
| 
       244 
249 
     | 
    
         | 
| 
       245 
250 
     | 
    
         
             
                  it_behaves_like "modifying product actions are restricted"
         
     | 
| 
         @@ -253,10 +258,10 @@ module Spree 
     | 
|
| 
       253 
258 
     | 
    
         | 
| 
       254 
259 
     | 
    
         
             
                  it "can see all products" do
         
     | 
| 
       255 
260 
     | 
    
         
             
                    api_get :index
         
     | 
| 
       256 
     | 
    
         
            -
                    json_response["products"].count. 
     | 
| 
       257 
     | 
    
         
            -
                    json_response["count"]. 
     | 
| 
       258 
     | 
    
         
            -
                    json_response["current_page"]. 
     | 
| 
       259 
     | 
    
         
            -
                    json_response["pages"]. 
     | 
| 
      
 261 
     | 
    
         
            +
                    expect(json_response["products"].count).to eq(2)
         
     | 
| 
      
 262 
     | 
    
         
            +
                    expect(json_response["count"]).to eq(2)
         
     | 
| 
      
 263 
     | 
    
         
            +
                    expect(json_response["current_page"]).to eq(1)
         
     | 
| 
      
 264 
     | 
    
         
            +
                    expect(json_response["pages"]).to eq(1)
         
     | 
| 
       260 
265 
     | 
    
         
             
                  end
         
     | 
| 
       261 
266 
     | 
    
         | 
| 
       262 
267 
     | 
    
         
             
                  # Regression test for #1626
         
     | 
| 
         @@ -267,12 +272,12 @@ module Spree 
     | 
|
| 
       267 
272 
     | 
    
         | 
| 
       268 
273 
     | 
    
         
             
                    it "does not include deleted products" do
         
     | 
| 
       269 
274 
     | 
    
         
             
                      api_get :index
         
     | 
| 
       270 
     | 
    
         
            -
                      json_response["products"].count. 
     | 
| 
      
 275 
     | 
    
         
            +
                      expect(json_response["products"].count).to eq(2)
         
     | 
| 
       271 
276 
     | 
    
         
             
                    end
         
     | 
| 
       272 
277 
     | 
    
         | 
| 
       273 
278 
     | 
    
         
             
                    it "can include deleted products" do
         
     | 
| 
       274 
279 
     | 
    
         
             
                      api_get :index, :show_deleted => 1
         
     | 
| 
       275 
     | 
    
         
            -
                      json_response["products"].count. 
     | 
| 
      
 280 
     | 
    
         
            +
                      expect(json_response["products"].count).to eq(3)
         
     | 
| 
       276 
281 
     | 
    
         
             
                    end
         
     | 
| 
       277 
282 
     | 
    
         
             
                  end
         
     | 
| 
       278 
283 
     | 
    
         | 
| 
         @@ -281,8 +286,8 @@ module Spree 
     | 
|
| 
       281 
286 
     | 
    
         
             
                      api_post :create, :product => { :name => "The Other Product",
         
     | 
| 
       282 
287 
     | 
    
         
             
                                                      :price => 19.99,
         
     | 
| 
       283 
288 
     | 
    
         
             
                                                      :shipping_category_id => create(:shipping_category).id }
         
     | 
| 
       284 
     | 
    
         
            -
                      json_response. 
     | 
| 
       285 
     | 
    
         
            -
                      response.status. 
     | 
| 
      
 289 
     | 
    
         
            +
                      expect(json_response).to have_attributes(base_attributes)
         
     | 
| 
      
 290 
     | 
    
         
            +
                      expect(response.status).to eq(201)
         
     | 
| 
       286 
291 
     | 
    
         
             
                    end
         
     | 
| 
       287 
292 
     | 
    
         | 
| 
       288 
293 
     | 
    
         
             
                    it "creates with embedded variants" do
         
     | 
| 
         @@ -361,25 +366,25 @@ module Spree 
     | 
|
| 
       361 
366 
     | 
    
         | 
| 
       362 
367 
     | 
    
         
             
                      it "can still create a product" do
         
     | 
| 
       363 
368 
     | 
    
         
             
                        api_post :create, :product => product_data, :token => "fake"
         
     | 
| 
       364 
     | 
    
         
            -
                        json_response. 
     | 
| 
       365 
     | 
    
         
            -
                        response.status. 
     | 
| 
      
 369 
     | 
    
         
            +
                        expect(json_response).to have_attributes(show_attributes)
         
     | 
| 
      
 370 
     | 
    
         
            +
                        expect(response.status).to eq(201)
         
     | 
| 
       366 
371 
     | 
    
         
             
                      end
         
     | 
| 
       367 
372 
     | 
    
         
             
                    end
         
     | 
| 
       368 
373 
     | 
    
         | 
| 
       369 
374 
     | 
    
         
             
                    it "cannot create a new product with invalid attributes" do
         
     | 
| 
       370 
375 
     | 
    
         
             
                      api_post :create, :product => {}
         
     | 
| 
       371 
     | 
    
         
            -
                      response.status. 
     | 
| 
       372 
     | 
    
         
            -
                      json_response["error"]. 
     | 
| 
      
 376 
     | 
    
         
            +
                      expect(response.status).to eq(422)
         
     | 
| 
      
 377 
     | 
    
         
            +
                      expect(json_response["error"]).to eq("Invalid resource. Please fix errors and try again.")
         
     | 
| 
       373 
378 
     | 
    
         
             
                      errors = json_response["errors"]
         
     | 
| 
       374 
379 
     | 
    
         
             
                      errors.delete("slug") # Don't care about this one.
         
     | 
| 
       375 
     | 
    
         
            -
                      errors.keys. 
     | 
| 
      
 380 
     | 
    
         
            +
                      expect(errors.keys).to match_array(["name", "price", "shipping_category_id"])
         
     | 
| 
       376 
381 
     | 
    
         
             
                    end
         
     | 
| 
       377 
382 
     | 
    
         
             
                  end
         
     | 
| 
       378 
383 
     | 
    
         | 
| 
       379 
384 
     | 
    
         
             
                  context 'updating a product' do
         
     | 
| 
       380 
385 
     | 
    
         
             
                    it "can update a product" do
         
     | 
| 
       381 
386 
     | 
    
         
             
                      api_put :update, :id => product.to_param, :product => { :name => "New and Improved Product!" }
         
     | 
| 
       382 
     | 
    
         
            -
                      response.status. 
     | 
| 
      
 387 
     | 
    
         
            +
                      expect(response.status).to eq(200)
         
     | 
| 
       383 
388 
     | 
    
         
             
                    end
         
     | 
| 
       384 
389 
     | 
    
         | 
| 
       385 
390 
     | 
    
         
             
                    it "can create new option types on a product" do
         
     | 
| 
         @@ -424,9 +429,9 @@ module Spree 
     | 
|
| 
       424 
429 
     | 
    
         | 
| 
       425 
430 
     | 
    
         
             
                    it "cannot update a product with an invalid attribute" do
         
     | 
| 
       426 
431 
     | 
    
         
             
                      api_put :update, :id => product.to_param, :product => { :name => "" }
         
     | 
| 
       427 
     | 
    
         
            -
                      response.status. 
     | 
| 
       428 
     | 
    
         
            -
                      json_response["error"]. 
     | 
| 
       429 
     | 
    
         
            -
                      json_response["errors"]["name"]. 
     | 
| 
      
 432 
     | 
    
         
            +
                      expect(response.status).to eq(422)
         
     | 
| 
      
 433 
     | 
    
         
            +
                      expect(json_response["error"]).to eq("Invalid resource. Please fix errors and try again.")
         
     | 
| 
      
 434 
     | 
    
         
            +
                      expect(json_response["errors"]["name"]).to eq(["can't be blank"])
         
     | 
| 
       430 
435 
     | 
    
         
             
                    end
         
     | 
| 
       431 
436 
     | 
    
         | 
| 
       432 
437 
     | 
    
         
             
                    # Regression test for #4123
         
     | 
| 
         @@ -443,10 +448,10 @@ module Spree 
     | 
|
| 
       443 
448 
     | 
    
         
             
                  end
         
     | 
| 
       444 
449 
     | 
    
         | 
| 
       445 
450 
     | 
    
         
             
                  it "can delete a product" do
         
     | 
| 
       446 
     | 
    
         
            -
                    product.deleted_at. 
     | 
| 
      
 451 
     | 
    
         
            +
                    expect(product.deleted_at).to be_nil
         
     | 
| 
       447 
452 
     | 
    
         
             
                    api_delete :destroy, :id => product.to_param
         
     | 
| 
       448 
     | 
    
         
            -
                    response.status. 
     | 
| 
       449 
     | 
    
         
            -
                    product.reload.deleted_at. 
     | 
| 
      
 453 
     | 
    
         
            +
                    expect(response.status).to eq(204)
         
     | 
| 
      
 454 
     | 
    
         
            +
                    expect(product.reload.deleted_at).not_to be_nil
         
     | 
| 
       450 
455 
     | 
    
         
             
                  end
         
     | 
| 
       451 
456 
     | 
    
         
             
                end
         
     | 
| 
       452 
457 
     | 
    
         
             
              end
         
     |