solidus_api 1.3.2 → 1.4.0.beta1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of solidus_api might be problematic. Click here for more details.

Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +13 -0
  3. data/app/controllers/spree/api/address_books_controller.rb +1 -1
  4. data/app/controllers/spree/api/checkouts_controller.rb +7 -7
  5. data/app/controllers/spree/api/classifications_controller.rb +1 -1
  6. data/app/controllers/spree/api/line_items_controller.rb +2 -2
  7. data/app/controllers/spree/api/orders_controller.rb +3 -13
  8. data/app/controllers/spree/api/payments_controller.rb +3 -4
  9. data/app/controllers/spree/api/promotions_controller.rb +2 -2
  10. data/app/controllers/spree/api/return_authorizations_controller.rb +2 -2
  11. data/app/controllers/spree/api/shipments_controller.rb +4 -9
  12. data/app/controllers/spree/api/stock_items_controller.rb +1 -1
  13. data/app/controllers/spree/api/stores_controller.rb +1 -1
  14. data/app/controllers/spree/api/taxons_controller.rb +1 -1
  15. data/app/helpers/spree/api/api_helpers.rb +1 -1
  16. data/app/views/spree/api/countries/index.v1.rabl +1 -1
  17. data/app/views/spree/api/credit_cards/index.v1.rabl +1 -1
  18. data/app/views/spree/api/orders/index.v1.rabl +1 -1
  19. data/app/views/spree/api/orders/mine.v1.rabl +1 -1
  20. data/app/views/spree/api/payments/index.v1.rabl +1 -1
  21. data/app/views/spree/api/product_properties/index.v1.rabl +1 -1
  22. data/app/views/spree/api/products/index.v1.rabl +2 -2
  23. data/app/views/spree/api/properties/index.v1.rabl +1 -1
  24. data/app/views/spree/api/return_authorizations/index.v1.rabl +1 -1
  25. data/app/views/spree/api/shipments/mine.v1.rabl +1 -1
  26. data/app/views/spree/api/states/index.v1.rabl +1 -1
  27. data/app/views/spree/api/stock_items/index.v1.rabl +1 -1
  28. data/app/views/spree/api/stock_locations/index.v1.rabl +1 -1
  29. data/app/views/spree/api/stock_movements/index.v1.rabl +1 -1
  30. data/app/views/spree/api/store_credit_events/mine.v1.rabl +1 -1
  31. data/app/views/spree/api/taxonomies/index.v1.rabl +1 -1
  32. data/app/views/spree/api/taxons/index.v1.rabl +2 -2
  33. data/app/views/spree/api/users/index.v1.rabl +1 -1
  34. data/app/views/spree/api/variants/index.v1.rabl +1 -1
  35. data/app/views/spree/api/zones/index.v1.rabl +1 -1
  36. data/config/routes.rb +1 -1
  37. data/spec/controllers/spree/api/addresses_controller_spec.rb +0 -9
  38. data/spec/controllers/spree/api/base_controller_spec.rb +1 -1
  39. data/spec/controllers/spree/api/checkouts_controller_spec.rb +5 -18
  40. data/spec/controllers/spree/api/classifications_controller_spec.rb +2 -2
  41. data/spec/controllers/spree/api/line_items_controller_spec.rb +4 -4
  42. data/spec/controllers/spree/api/orders_controller_spec.rb +5 -52
  43. data/spec/controllers/spree/api/payments_controller_spec.rb +0 -11
  44. data/spec/controllers/spree/api/products_controller_spec.rb +1 -1
  45. data/spec/controllers/spree/api/shipments_controller_spec.rb +1 -1
  46. data/spec/controllers/spree/api/states_controller_spec.rb +7 -20
  47. data/spec/controllers/spree/api/taxons_controller_spec.rb +1 -1
  48. metadata +8 -7
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d04f6cc4456a153fc293ddd59af262eb561d73b8
4
- data.tar.gz: b526820b388b52a98e5157fe951ea6ef4b513054
3
+ metadata.gz: 458c60c64203fa11109611f14f1c306f4515801d
4
+ data.tar.gz: 8174fd109b920284baad60c854c8a72e290ee754
5
5
  SHA512:
6
- metadata.gz: a23afc17baf4b4d8c7a91c26190e687e864d07b42a40114bba65e4203464efbff6c6a4bcda307d5de80bef96fab26d4f63f4d3d9713661cb5e3acddcdf190ff0
7
- data.tar.gz: 12c43e774fb74191066715d16327609888c87220119581f2bc53358b412a95c317fa277d4d4fe02b0a6aefbcd91093d5b1edba2ef2063d330d5b1a86ea0832eb
6
+ metadata.gz: fd71cfd47f66448c80b9d7037d62be471d059d80d818bcf8a027b25c2a5e9b660583ac8cace39b00b8278c79a6e2dca855324ce867088e86fd1fd08c28bc0fd9
7
+ data.tar.gz: 74bb76480dc1352a60f18ddbdae708f5d536825425993fab7832a69edf723dcd1ba108fb0e936d8f65a5b74d6a99f1553b527d10f8f953a6a7a174ed8d43691f
data/README.md ADDED
@@ -0,0 +1,13 @@
1
+ # solidus\_api
2
+
3
+ API contains controllers and rabl views implementing the REST API of solidus.
4
+
5
+ ## Testing
6
+
7
+ Create the test site
8
+
9
+ bundle exec rake test_app
10
+
11
+ Run the tests
12
+
13
+ bundle exec rake spec
@@ -2,7 +2,7 @@ module Spree
2
2
  module Api
3
3
  class AddressBooksController < Spree::Api::BaseController
4
4
  # Note: the AddressBook is the resource to think about here, not individual addresses
5
- before_filter :load_user_addresses
5
+ before_action :load_user_addresses
6
6
 
7
7
  def show
8
8
  authorize! :show, address_book_user
@@ -1,9 +1,9 @@
1
1
  module Spree
2
2
  module Api
3
3
  class CheckoutsController < Spree::Api::BaseController
4
- before_filter :load_order, only: [:next, :advance, :update, :complete]
5
- around_filter :lock_order, only: [:next, :advance, :update, :complete]
6
- before_filter :update_order_state, only: [:next, :advance, :update, :complete]
4
+ before_action :load_order, only: [:next, :advance, :update, :complete]
5
+ around_action :lock_order, only: [:next, :advance, :update, :complete]
6
+ before_action :update_order_state, only: [:next, :advance, :update, :complete]
7
7
 
8
8
  rescue_from Spree::Order::InsufficientStock, with: :insufficient_stock_error
9
9
 
@@ -11,12 +11,12 @@ module Spree
11
11
  # TODO: Remove this after deprecated usage in #update is removed
12
12
  include Spree::Core::ControllerHelpers::PaymentParameters
13
13
 
14
- # This before_filter comes from Spree::Core::ControllerHelpers::Order
14
+ # This before_action comes from Spree::Core::ControllerHelpers::Order
15
15
  skip_before_action :set_current_order
16
16
 
17
17
  def next
18
18
  if @order.confirm?
19
- ActiveSupport::Deprecation.warn "Using Spree::Api::CheckoutsController#next to transition to complete is deprecated. Please use #complete instead of #next.", caller
19
+ Spree::Deprecation.warn "Using Spree::Api::CheckoutsController#next to transition to complete is deprecated. Please use #complete instead of #next.", caller
20
20
  complete
21
21
  return
22
22
  end
@@ -94,12 +94,12 @@ module Spree
94
94
  massaged_params = params.deep_dup
95
95
 
96
96
  if params[:payment_source].present?
97
- ActiveSupport::Deprecation.warn("Passing payment_source is deprecated. Send source parameters inside payments_attributes[:source_attributes].", caller)
97
+ Spree::Deprecation.warn("Passing payment_source is deprecated. Send source parameters inside payments_attributes[:source_attributes].", caller)
98
98
  move_payment_source_into_payments_attributes(massaged_params)
99
99
  end
100
100
 
101
101
  if params[:order] && params[:order][:existing_card].present?
102
- ActiveSupport::Deprecation.warn("Passing order[:existing_card] is deprecated. Send existing_card_id inside of payments_attributes[:source_attributes].", caller)
102
+ Spree::Deprecation.warn("Passing order[:existing_card] is deprecated. Send existing_card_id inside of payments_attributes[:source_attributes].", caller)
103
103
  move_existing_card_into_payments_attributes(massaged_params)
104
104
  end
105
105
 
@@ -11,7 +11,7 @@ module Spree
11
11
  # Because position we get back is 0-indexed.
12
12
  # acts_as_list is 1-indexed.
13
13
  classification.insert_at(params[:position].to_i + 1)
14
- render nothing: true
14
+ head :ok
15
15
  end
16
16
  end
17
17
  end
@@ -5,8 +5,8 @@ module Spree
5
5
 
6
6
  self.line_item_options = []
7
7
 
8
- before_filter :load_order, only: [:create, :update, :destroy]
9
- around_filter :lock_order, only: [:create, :update, :destroy]
8
+ before_action :load_order, only: [:create, :update, :destroy]
9
+ around_action :lock_order, only: [:create, :update, :destroy]
10
10
 
11
11
  def new
12
12
  end
@@ -10,7 +10,7 @@ module Spree
10
10
  skip_before_action :authenticate_user, only: :apply_coupon_code
11
11
 
12
12
  before_action :find_order, except: [:create, :mine, :current, :index]
13
- around_filter :lock_order, except: [:create, :mine, :current, :index]
13
+ around_action :lock_order, except: [:create, :mine, :current, :index]
14
14
 
15
15
  # Dynamically defines our stores checkout steps to ensure we check authorization on each step.
16
16
  Order.checkout_steps.keys.each do |step|
@@ -27,18 +27,8 @@ module Spree
27
27
 
28
28
  def create
29
29
  authorize! :create, Order
30
-
31
- if can?(:admin, Order)
32
- @order = Spree::Core::Importer::Order.import(determine_order_user, order_params)
33
- respond_with(@order, default_template: :show, status: 201)
34
- else
35
- @order = Spree::Order.create!(user: current_api_user, store: current_store)
36
- if OrderUpdateAttributes.new(@order, order_params).apply
37
- respond_with(@order, default_template: :show, status: 201)
38
- else
39
- invalid_resource!(@order)
40
- end
41
- end
30
+ @order = Spree::Core::Importer::Order.import(determine_order_user, order_params)
31
+ respond_with(@order, default_template: :show, status: 201)
42
32
  end
43
33
 
44
34
  def empty
@@ -1,9 +1,9 @@
1
1
  module Spree
2
2
  module Api
3
3
  class PaymentsController < Spree::Api::BaseController
4
- before_filter :find_order
5
- around_filter :lock_order, only: [:create, :update, :destroy, :authorize, :capture, :purchase, :void, :credit]
6
- before_filter :find_payment, only: [:update, :show, :authorize, :purchase, :capture, :void, :credit]
4
+ before_action :find_order
5
+ around_action :lock_order, only: [:create, :update, :destroy, :authorize, :capture, :purchase, :void, :credit]
6
+ before_action :find_payment, only: [:update, :show, :authorize, :purchase, :capture, :void, :credit]
7
7
 
8
8
  def index
9
9
  @payments = @order.payments.ransack(params[:q]).result.page(params[:page]).per(params[:per_page])
@@ -16,7 +16,6 @@ module Spree
16
16
  end
17
17
 
18
18
  def create
19
- @order.validate_payments_attributes(payment_params)
20
19
  @payment = PaymentCreate.new(@order, payment_params).build
21
20
  if @payment.save
22
21
  respond_with(@payment, status: 201, default_template: :show)
@@ -1,8 +1,8 @@
1
1
  module Spree
2
2
  module Api
3
3
  class PromotionsController < Spree::Api::BaseController
4
- before_filter :requires_admin
5
- before_filter :load_promotion
4
+ before_action :requires_admin
5
+ before_action :load_promotion
6
6
 
7
7
  def show
8
8
  if @promotion
@@ -1,8 +1,8 @@
1
1
  module Spree
2
2
  module Api
3
3
  class ReturnAuthorizationsController < Spree::Api::BaseController
4
- before_filter :load_order
5
- around_filter :lock_order, only: [:create, :update, :destroy, :add, :receive, :cancel]
4
+ before_action :load_order
5
+ around_action :lock_order, only: [:create, :update, :destroy, :add, :receive, :cancel]
6
6
 
7
7
  rescue_from Spree::Order::InsufficientStock, with: :insufficient_stock_error
8
8
 
@@ -1,11 +1,11 @@
1
1
  module Spree
2
2
  module Api
3
3
  class ShipmentsController < Spree::Api::BaseController
4
- before_filter :find_order_on_create, only: :create
5
- before_filter :find_shipment, only: [:update, :ship, :ready, :add, :remove]
4
+ before_action :find_order_on_create, only: :create
5
+ before_action :find_shipment, only: [:update, :ship, :ready, :add, :remove]
6
6
  before_action :load_transfer_params, only: [:transfer_to_location, :transfer_to_shipment]
7
- around_filter :lock_order, except: [:mine]
8
- before_filter :update_shipment, only: [:ship, :ready, :add, :remove]
7
+ around_action :lock_order, except: [:mine]
8
+ before_action :update_shipment, only: [:ship, :ready, :add, :remove]
9
9
 
10
10
  def mine
11
11
  if current_api_user
@@ -21,11 +21,6 @@ module Spree
21
21
  end
22
22
 
23
23
  def create
24
- # TODO: Can remove conditional here once deprecated #find_order is removed.
25
- unless @order.present?
26
- @order = Spree::Order.find_by!(number: params[:shipment][:order_id])
27
- authorize! :read, @order
28
- end
29
24
  authorize! :create, Shipment
30
25
  quantity = params[:quantity].to_i
31
26
  @shipment = @order.shipments.create(stock_location_id: params.fetch(:stock_location_id))
@@ -1,7 +1,7 @@
1
1
  module Spree
2
2
  module Api
3
3
  class StockItemsController < Spree::Api::BaseController
4
- before_filter :load_stock_location, only: [:index, :show, :create]
4
+ before_action :load_stock_location, only: [:index, :show, :create]
5
5
 
6
6
  def index
7
7
  @stock_items = scope.ransack(params[:q]).result.page(params[:page]).per(params[:per_page])
@@ -1,7 +1,7 @@
1
1
  module Spree
2
2
  module Api
3
3
  class StoresController < Spree::Api::BaseController
4
- before_filter :get_store, except: [:index, :create]
4
+ before_action :get_store, except: [:index, :create]
5
5
 
6
6
  def index
7
7
  authorize! :read, Store
@@ -33,7 +33,7 @@ module Spree
33
33
  taxonomy = Spree::Taxonomy.find_by(id: params[:taxonomy_id])
34
34
 
35
35
  if taxonomy.nil?
36
- @taxon.errors[:taxonomy_id] = I18n.t(:invalid_taxonomy_id, scope: 'spree.api')
36
+ @taxon.errors.add(:taxonomy_id, I18n.t('spree.api.invalid_taxonomy_id'))
37
37
  invalid_resource!(@taxon) && return
38
38
  end
39
39
 
@@ -135,7 +135,7 @@ module Spree
135
135
 
136
136
  @@adjustment_attributes = [
137
137
  :id, :source_type, :source_id, :adjustable_type, :adjustable_id,
138
- :originator_type, :originator_id, :amount, :label, :promotion_code,
138
+ :amount, :label, :promotion_code,
139
139
  :locked, :eligible, :created_at, :updated_at
140
140
  ]
141
141
 
@@ -3,5 +3,5 @@ child(@countries => :countries) do
3
3
  attributes *country_attributes
4
4
  end
5
5
  node(:count) { @countries.count }
6
- node(:current_page) { params[:page] || 1 }
6
+ node(:current_page) { @countries.current_page }
7
7
  node(:pages) { @countries.total_pages }
@@ -3,5 +3,5 @@ child(@credit_cards => :credit_cards) do
3
3
  extends "spree/api/credit_cards/show"
4
4
  end
5
5
  node(:count) { @credit_cards.count }
6
- node(:current_page) { params[:page] || 1 }
6
+ node(:current_page) { @credit_cards.current_page }
7
7
  node(:pages) { @credit_cards.total_pages }
@@ -3,5 +3,5 @@ child(@orders => :orders) do
3
3
  extends "spree/api/orders/order"
4
4
  end
5
5
  node(:count) { @orders.count }
6
- node(:current_page) { params[:page] || 1 }
6
+ node(:current_page) { @orders.current_page }
7
7
  node(:pages) { @orders.total_pages }
@@ -5,5 +5,5 @@ child(@orders => :orders) do
5
5
  end
6
6
 
7
7
  node(:count) { @orders.count }
8
- node(:current_page) { params[:page] || 1 }
8
+ node(:current_page) { @orders.current_page }
9
9
  node(:pages) { @orders.total_pages }
@@ -3,5 +3,5 @@ child(@payments => :payments) do
3
3
  attributes *payment_attributes
4
4
  end
5
5
  node(:count) { @payments.count }
6
- node(:current_page) { params[:page] || 1 }
6
+ node(:current_page) { @payments.current_page }
7
7
  node(:pages) { @payments.total_pages }
@@ -3,5 +3,5 @@ child(@product_properties => :product_properties) do
3
3
  attributes *product_property_attributes
4
4
  end
5
5
  node(:count) { @product_properties.count }
6
- node(:current_page) { params[:page] || 1 }
6
+ node(:current_page) { @product_properties.current_page }
7
7
  node(:pages) { @product_properties.total_pages }
@@ -1,8 +1,8 @@
1
1
  object false
2
2
  node(:count) { @products.count }
3
3
  node(:total_count) { @products.total_count }
4
- node(:current_page) { params[:page] ? params[:page].to_i : 1 }
5
- node(:per_page) { params[:per_page] || Kaminari.config.default_per_page }
4
+ node(:current_page) { @products.current_page }
5
+ node(:per_page) { @products.limit_value }
6
6
  node(:pages) { @products.total_pages }
7
7
  child(@products => :products) do
8
8
  extends "spree/api/products/show"
@@ -3,5 +3,5 @@ child(@properties => :properties) do
3
3
  attributes *property_attributes
4
4
  end
5
5
  node(:count) { @properties.count }
6
- node(:current_page) { params[:page] || 1 }
6
+ node(:current_page) { @properties.current_page }
7
7
  node(:pages) { @properties.total_pages }
@@ -3,5 +3,5 @@ child(@return_authorizations => :return_authorizations) do
3
3
  attributes *return_authorization_attributes
4
4
  end
5
5
  node(:count) { @return_authorizations.count }
6
- node(:current_page) { params[:page] || 1 }
6
+ node(:current_page) { @return_authorizations.current_page }
7
7
  node(:pages) { @return_authorizations.total_pages }
@@ -1,7 +1,7 @@
1
1
  object false
2
2
 
3
3
  node(:count) { @shipments.count }
4
- node(:current_page) { params[:page] || 1 }
4
+ node(:current_page) { @shipments.current_page }
5
5
  node(:pages) { @shipments.total_pages }
6
6
 
7
7
  child(@shipments => :shipments) do
@@ -9,6 +9,6 @@ end
9
9
 
10
10
  if @states.respond_to?(:total_pages)
11
11
  node(:count) { @states.count }
12
- node(:current_page) { params[:page] || 1 }
12
+ node(:current_page) { @states.current_page }
13
13
  node(:pages) { @states.total_pages }
14
14
  end
@@ -3,5 +3,5 @@ child(@stock_items => :stock_items) do
3
3
  extends 'spree/api/stock_items/show'
4
4
  end
5
5
  node(:count) { @stock_items.count }
6
- node(:current_page) { params[:page] || 1 }
6
+ node(:current_page) { @stock_items.current_page }
7
7
  node(:pages) { @stock_items.total_pages }
@@ -3,5 +3,5 @@ child(@stock_locations => :stock_locations) do
3
3
  extends 'spree/api/stock_locations/show'
4
4
  end
5
5
  node(:count) { @stock_locations.count }
6
- node(:current_page) { params[:page] || 1 }
6
+ node(:current_page) { @stock_locations.current_page }
7
7
  node(:pages) { @stock_locations.total_pages }
@@ -3,5 +3,5 @@ child(@stock_movements => :stock_movements) do
3
3
  extends 'spree/api/stock_movements/show'
4
4
  end
5
5
  node(:count) { @stock_movements.count }
6
- node(:current_page) { params[:page] || 1 }
6
+ node(:current_page) { @stock_movements.current_page }
7
7
  node(:pages) { @stock_movements.total_pages }
@@ -6,5 +6,5 @@ child(@store_credit_events => :store_credit_events) do
6
6
  end
7
7
 
8
8
  node(:count) { @store_credit_events.count }
9
- node(:current_page) { params[:page] || 1 }
9
+ node(:current_page) { @store_credit_events.current_page }
10
10
  node(:pages) { @store_credit_events.total_pages }
@@ -3,5 +3,5 @@ child(@taxonomies => :taxonomies) do
3
3
  extends "spree/api/taxonomies/show"
4
4
  end
5
5
  node(:count) { @taxonomies.count }
6
- node(:current_page) { params[:page] || 1 }
6
+ node(:current_page) { @taxonomies.current_page }
7
7
  node(:pages) { @taxonomies.total_pages }
@@ -1,8 +1,8 @@
1
1
  object false
2
2
  node(:count) { @taxons.count }
3
3
  node(:total_count) { @taxons.total_count }
4
- node(:current_page) { params[:page] ? params[:page].to_i : 1 }
5
- node(:per_page) { params[:per_page] || Kaminari.config.default_per_page }
4
+ node(:current_page) { @taxons.current_page }
5
+ node(:per_page) { @taxons.limit_value }
6
6
  node(:pages) { @taxons.total_pages }
7
7
  child @taxons => :taxons do
8
8
  attributes *taxon_attributes
@@ -3,5 +3,5 @@ child(@users => :users) do
3
3
  extends "spree/api/users/show"
4
4
  end
5
5
  node(:count) { @users.count }
6
- node(:current_page) { params[:page] || 1 }
6
+ node(:current_page) { @users.current_page }
7
7
  node(:pages) { @users.total_pages }
@@ -1,7 +1,7 @@
1
1
  object false
2
2
  node(:count) { @variants.count }
3
3
  node(:total_count) { @variants.total_count }
4
- node(:current_page) { params[:page] ? params[:page].to_i : 1 }
4
+ node(:current_page) { @variants.current_page }
5
5
  node(:pages) { @variants.total_pages }
6
6
 
7
7
  child(@variants => :variants) do
@@ -3,5 +3,5 @@ child(@zones => :zones) do
3
3
  extends 'spree/api/zones/show'
4
4
  end
5
5
  node(:count) { @zones.count }
6
- node(:current_page) { params[:page] || 1 }
6
+ node(:current_page) { @zones.current_page }
7
7
  node(:pages) { @zones.total_pages }
data/config/routes.rb CHANGED
@@ -1,4 +1,4 @@
1
- Spree::Core::Engine.add_routes do
1
+ Spree::Core::Engine.routes.draw do
2
2
  namespace :admin do
3
3
  resources :users do
4
4
  member do
@@ -37,15 +37,6 @@ module Spree
37
37
  expect(json_response['errors']['address1'].first).to eq "can't be blank"
38
38
  end
39
39
  end
40
-
41
- it "receives the errors object if address is invalid" do
42
- api_put :update, id: @address.id, order_id: @order.number,
43
- address: { address1: "" }
44
-
45
- expect(json_response['error']).not_to be_nil
46
- expect(json_response['errors']).not_to be_nil
47
- expect(json_response['errors']['address1'].first).to eq "can't be blank"
48
- end
49
40
  end
50
41
 
51
42
  context "on an address that does not belong to this order" do
@@ -143,7 +143,7 @@ describe Spree::Api::BaseController, type: :controller do
143
143
  let!(:order) { create :order }
144
144
 
145
145
  controller(Spree::Api::BaseController) do
146
- around_filter :lock_order
146
+ around_action :lock_order
147
147
 
148
148
  def index
149
149
  render text: { "products" => [] }.to_json
@@ -136,7 +136,7 @@ module Spree
136
136
 
137
137
  it "can update shipping method and transition from delivery to payment" do
138
138
  order.update_column(:state, "delivery")
139
- shipment = create(:shipment, order: order, address: order.ship_address)
139
+ shipment = create(:shipment, order: order)
140
140
  shipment.refresh_rates
141
141
  shipping_rate = shipment.shipping_rates.where(selected: false).first
142
142
  api_put :update, id: order.to_param, order_token: order.guest_token,
@@ -163,19 +163,6 @@ module Spree
163
163
  expect(response.status).to eq(200)
164
164
  end
165
165
 
166
- context "with disallowed payment method" do
167
- it "returns not found" do
168
- order.update_column(:state, "payment")
169
- allow_any_instance_of(Spree::Gateway::Bogus).to receive(:source_required?).and_return(false)
170
- @payment_method.update!(display_on: "back_end")
171
- expect {
172
- api_put :update, id: order.to_param, order_token: order.guest_token, order: { payments_attributes: [{ payment_method_id: @payment_method.id }] }
173
- }.not_to change { Spree::Payment.count }
174
- expect(response.status).to eq(404)
175
- end
176
- end
177
-
178
-
179
166
  it "returns errors when source is required and missing" do
180
167
  order.update_column(:state, "payment")
181
168
  api_put :update, id: order.to_param, order_token: order.guest_token,
@@ -250,7 +237,7 @@ module Spree
250
237
  end
251
238
 
252
239
  it "succeeds" do
253
- ActiveSupport::Deprecation.silence do
240
+ Spree::Deprecation.silence do
254
241
  api_put(:update, params)
255
242
  end
256
243
  expect(response.status).to eq(200)
@@ -308,7 +295,7 @@ module Spree
308
295
  end
309
296
 
310
297
  it 'returns errors' do
311
- ActiveSupport::Deprecation.silence do
298
+ Spree::Deprecation.silence do
312
299
  api_put(:update, params)
313
300
  end
314
301
 
@@ -382,7 +369,7 @@ module Spree
382
369
  receive(:verification_value=).with('456').and_call_original
383
370
  )
384
371
 
385
- ActiveSupport::Deprecation.silence do
372
+ Spree::Deprecation.silence do
386
373
  api_put(:update, params)
387
374
  end
388
375
 
@@ -471,7 +458,7 @@ module Spree
471
458
  context "with order in confirm state" do
472
459
  subject do
473
460
  if action == :next
474
- ActiveSupport::Deprecation.silence do
461
+ Spree::Deprecation.silence do
475
462
  api_put action, params
476
463
  end
477
464
  else
@@ -31,7 +31,7 @@ module Spree
31
31
  it "can change the order a product" do
32
32
  classification = taxon.classifications.find_by(product_id: last_product.id)
33
33
  expect(classification.position).to eq(3)
34
- api_put :update, taxon_id: taxon, product_id: last_product, position: 0
34
+ api_put :update, taxon_id: taxon.id, product_id: last_product.id, position: 0
35
35
  expect(response.status).to eq(200)
36
36
  expect(classification.reload.position).to eq(1)
37
37
  end
@@ -39,7 +39,7 @@ module Spree
39
39
  it "should touch the taxon" do
40
40
  taxon.update_attributes(updated_at: Time.current - 10.seconds)
41
41
  taxon_last_updated_at = taxon.updated_at
42
- api_put :update, taxon_id: taxon, product_id: last_product, position: 0
42
+ api_put :update, taxon_id: taxon.id, product_id: last_product.id, position: 0
43
43
  taxon.reload
44
44
  expect(taxon_last_updated_at.to_i).to_not eq(taxon.updated_at.to_i)
45
45
  end
@@ -62,12 +62,12 @@ module Spree
62
62
  end
63
63
 
64
64
  it "can add a new line item to an existing order with options" do
65
- expect_any_instance_of(LineItem).to receive(:some_option=).with(4)
65
+ expect_any_instance_of(LineItem).to receive(:some_option=).with("foobar")
66
66
  api_post :create,
67
67
  line_item: {
68
68
  variant_id: product.master.to_param,
69
69
  quantity: 1,
70
- options: { some_option: 4 }
70
+ options: { some_option: "foobar" }
71
71
  }
72
72
  expect(response.status).to eq(201)
73
73
  end
@@ -100,11 +100,11 @@ module Spree
100
100
  end
101
101
 
102
102
  it "can update a line item's options on the order" do
103
- expect_any_instance_of(LineItem).to receive(:some_option=).with(12)
103
+ expect_any_instance_of(LineItem).to receive(:some_option=).with("foobar")
104
104
  line_item = order.line_items.first
105
105
  api_put :update,
106
106
  id: line_item.id,
107
- line_item: { quantity: 1, options: { some_option: 12 } }
107
+ line_item: { quantity: 1, options: { some_option: "foobar" } }
108
108
  expect(response.status).to eq(200)
109
109
  end
110
110
 
@@ -32,9 +32,8 @@ module Spree
32
32
  describe "POST create" do
33
33
  let(:target_user) { create :user }
34
34
  let(:date_override) { Time.parse('2015-01-01') }
35
- let(:attributes) { { user_id: target_user.id, created_at: date_override, email: target_user.email } }
36
35
 
37
- subject { api_post :create, order: attributes }
36
+ subject { api_post :create, order: { user_id: target_user.id, created_at: date_override, email: target_user.email } }
38
37
 
39
38
  context "when the current user cannot administrate the order" do
40
39
  stub_authorization! do |_|
@@ -43,37 +42,12 @@ module Spree
43
42
 
44
43
  it "does not include unpermitted params, or allow overriding the user", focus: true do
45
44
  subject
46
- expect(response).to be_success
47
45
  order = Spree::Order.last
48
46
  expect(order.user).to eq current_api_user
49
47
  expect(order.email).to eq target_user.email
50
48
  end
51
49
 
52
50
  it { is_expected.to be_success }
53
-
54
- context 'creating payment' do
55
- let(:attributes) { super().merge(payments_attributes: [{ payment_method_id: payment_method.id }]) }
56
-
57
- context "with allowed payment method" do
58
- let!(:payment_method) { create(:check_payment_method, name: "allowed" ) }
59
- it { is_expected.to be_success }
60
- it "creates a payment" do
61
- expect {
62
- subject
63
- }.to change { Spree::Payment.count }.by(1)
64
- end
65
- end
66
-
67
- context "with disallowed payment method" do
68
- let!(:payment_method) { create(:check_payment_method, name: "forbidden", display_on: "back_end") }
69
- it { is_expected.to be_not_found }
70
- it "creates no payments" do
71
- expect {
72
- subject
73
- }.not_to change { Spree::Payment.count }
74
- end
75
- end
76
- end
77
51
  end
78
52
 
79
53
  context "when the current user can administrate the order" do
@@ -123,30 +97,6 @@ module Spree
123
97
  subject
124
98
  }.to_not change{ order.reload.number }
125
99
  end
126
-
127
- context 'creating payment' do
128
- let(:order_params) { super().merge(payments_attributes: [{ payment_method_id: payment_method.id }]) }
129
-
130
- context "with allowed payment method" do
131
- let!(:payment_method) { create(:check_payment_method, name: "allowed" ) }
132
- it { is_expected.to be_success }
133
- it "creates a payment" do
134
- expect {
135
- subject
136
- }.to change { Spree::Payment.count }.by(1)
137
- end
138
- end
139
-
140
- context "with disallowed payment method" do
141
- let!(:payment_method) { create(:check_payment_method, name: "forbidden", display_on: "back_end") }
142
- it { is_expected.to be_not_found }
143
- it "creates no payments" do
144
- expect {
145
- subject
146
- }.not_to change { Spree::Payment.count }
147
- end
148
- end
149
- end
150
100
  end
151
101
 
152
102
  context "when the user can administer the order" do
@@ -383,7 +333,10 @@ module Spree
383
333
 
384
334
  # Regression test for https://github.com/spree/spree/issues/3404
385
335
  it "can specify additional parameters for a line item" do
386
- expect_any_instance_of(Spree::LineItem).to receive(:special=).with("foo")
336
+ expect(Order).to receive(:create!).and_return(order = Spree::Order.new)
337
+ allow(order).to receive(:associate_user!)
338
+ allow(order).to receive_message_chain(:contents, :add).and_return(line_item = double('LineItem'))
339
+ expect(line_item).to receive(:update_attributes!).with(hash_including("special" => "foo"))
387
340
 
388
341
  allow(controller).to receive_messages(permitted_line_item_attributes: [:id, :variant_id, :quantity, :special])
389
342
  api_post :create, order: {
@@ -45,17 +45,6 @@ module Spree
45
45
  expect(response.status).to eq(201)
46
46
  expect(json_response).to have_attributes(attributes)
47
47
  end
48
-
49
- context "disallowed payment method" do
50
- it "does not create a new payment" do
51
- PaymentMethod.first.update!(display_on: "back_end")
52
-
53
- expect {
54
- api_post :create, payment: { payment_method_id: PaymentMethod.first.id, amount: 50 }
55
- }.not_to change { Spree::Payment.count }
56
- expect(response.status).to eq(404)
57
- end
58
- end
59
48
  end
60
49
 
61
50
  context "payment source is required" do
@@ -324,7 +324,7 @@ module Spree
324
324
  end
325
325
 
326
326
  it "cannot create a new product with invalid attributes" do
327
- api_post :create, product: {}
327
+ api_post :create, product: { foo: :bar }
328
328
  expect(response.status).to eq(422)
329
329
  expect(json_response["error"]).to eq("Invalid resource. Please fix errors and try again.")
330
330
  errors = json_response["errors"]
@@ -2,7 +2,7 @@ require 'spec_helper'
2
2
 
3
3
  describe Spree::Api::ShipmentsController, type: :controller do
4
4
  render_views
5
- let!(:shipment) { create(:shipment, address: create(:address), inventory_units: [build(:inventory_unit, shipment: nil)]) }
5
+ let!(:shipment) { create(:shipment, inventory_units: [build(:inventory_unit, shipment: nil)]) }
6
6
  let!(:attributes) { [:id, :tracking, :tracking_url, :number, :cost, :shipped_at, :stock_location_name, :order_id, :shipping_rates, :shipping_methods] }
7
7
 
8
8
  before do
@@ -24,27 +24,14 @@ module Spree
24
24
  end
25
25
 
26
26
  context "pagination" do
27
- before do
28
- expect(State).to receive(:accessible_by).and_return(@scope = double)
29
- allow(@scope).to receive_message_chain(:ransack, :result, :includes, :order).and_return(@scope)
30
- end
31
-
32
- it "does not paginate states results when asked not to do so" do
33
- expect(@scope).not_to receive(:page)
34
- expect(@scope).not_to receive(:per)
35
- api_get :index
36
- end
37
-
38
- it "paginates when page parameter is passed through" do
39
- expect(@scope).to receive(:page).with(1).and_return(@scope)
40
- expect(@scope).to receive(:per).with(nil)
41
- api_get :index, page: 1
42
- end
27
+ it "can select the next page and control page size" do
28
+ create(:state)
29
+ api_get :index, page: 2, per_page: 1
43
30
 
44
- it "paginates when per_page parameter is passed through" do
45
- expect(@scope).to receive(:page).with(nil).and_return(@scope)
46
- expect(@scope).to receive(:per).with(25)
47
- api_get :index, per_page: 25
31
+ expect(json_response["states"].size).to eq(1)
32
+ expect(json_response["pages"]).to eq(2)
33
+ expect(json_response["current_page"]).to eq(2)
34
+ expect(json_response["count"]).to eq(1)
48
35
  end
49
36
  end
50
37
 
@@ -147,7 +147,7 @@ module Spree
147
147
  end
148
148
 
149
149
  it "cannot create a new taxon with invalid attributes" do
150
- api_post :create, taxonomy_id: taxonomy.id, taxon: {}
150
+ api_post :create, taxonomy_id: taxonomy.id, taxon: { foo: :bar }
151
151
  expect(response.status).to eq(422)
152
152
  expect(json_response["error"]).to eq("Invalid resource. Please fix errors and try again.")
153
153
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: solidus_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.2
4
+ version: 1.4.0.beta1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Solidus Team
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-12-12 00:00:00.000000000 Z
11
+ date: 2016-08-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: solidus_core
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - '='
18
18
  - !ruby/object:Gem::Version
19
- version: 1.3.2
19
+ version: 1.4.0.beta1
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - '='
25
25
  - !ruby/object:Gem::Version
26
- version: 1.3.2
26
+ version: 1.4.0.beta1
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rabl
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -67,6 +67,7 @@ files:
67
67
  - ".gitignore"
68
68
  - Gemfile
69
69
  - LICENSE
70
+ - README.md
70
71
  - Rakefile
71
72
  - app/controllers/spree/api/address_books_controller.rb
72
73
  - app/controllers/spree/api/addresses_controller.rb
@@ -278,12 +279,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
278
279
  version: '0'
279
280
  required_rubygems_version: !ruby/object:Gem::Requirement
280
281
  requirements:
281
- - - ">="
282
+ - - ">"
282
283
  - !ruby/object:Gem::Version
283
- version: '0'
284
+ version: 1.3.1
284
285
  requirements: []
285
286
  rubyforge_project:
286
- rubygems_version: 2.6.11
287
+ rubygems_version: 2.5.1
287
288
  signing_key:
288
289
  specification_version: 4
289
290
  summary: REST API for the Solidus e-commerce framework.