spree_api 3.3.6 → 3.4.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (85) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/spree/api/base_controller.rb +17 -21
  3. data/app/controllers/spree/api/v1/countries_controller.rb +2 -4
  4. data/app/controllers/spree/api/v1/credit_cards_controller.rb +9 -10
  5. data/app/controllers/spree/api/v1/images_controller.rb +1 -2
  6. data/app/controllers/spree/api/v1/inventory_units_controller.rb +2 -2
  7. data/app/controllers/spree/api/v1/line_items_controller.rb +24 -28
  8. data/app/controllers/spree/api/v1/option_types_controller.rb +5 -5
  9. data/app/controllers/spree/api/v1/option_values_controller.rb +16 -17
  10. data/app/controllers/spree/api/v1/orders_controller.rb +39 -49
  11. data/app/controllers/spree/api/v1/payments_controller.rb +15 -17
  12. data/app/controllers/spree/api/v1/product_properties_controller.rb +2 -3
  13. data/app/controllers/spree/api/v1/products_controller.rb +24 -25
  14. data/app/controllers/spree/api/v1/promotions_controller.rb +9 -8
  15. data/app/controllers/spree/api/v1/properties_controller.rb +14 -16
  16. data/app/controllers/spree/api/v1/return_authorizations_controller.rb +0 -1
  17. data/app/controllers/spree/api/v1/shipments_controller.rb +17 -26
  18. data/app/controllers/spree/api/v1/states_controller.rb +9 -10
  19. data/app/controllers/spree/api/v1/stock_items_controller.rb +2 -2
  20. data/app/controllers/spree/api/v1/stores_controller.rb +0 -1
  21. data/app/controllers/spree/api/v1/tags_controller.rb +1 -1
  22. data/app/controllers/spree/api/v1/taxonomies_controller.rb +1 -3
  23. data/app/controllers/spree/api/v1/taxons_controller.rb +15 -16
  24. data/app/controllers/spree/api/v1/users_controller.rb +1 -4
  25. data/app/controllers/spree/api/v1/variants_controller.rb +22 -22
  26. data/app/controllers/spree/api/v1/zones_controller.rb +0 -1
  27. data/app/helpers/spree/api/api_helpers.rb +5 -5
  28. data/app/views/spree/api/errors/gateway_error.v1.rabl +1 -1
  29. data/app/views/spree/api/errors/invalid_api_key.v1.rabl +1 -1
  30. data/app/views/spree/api/errors/invalid_resource.v1.rabl +1 -1
  31. data/app/views/spree/api/errors/must_specify_api_key.v1.rabl +1 -1
  32. data/app/views/spree/api/errors/not_found.v1.rabl +1 -1
  33. data/app/views/spree/api/errors/unauthorized.v1.rabl +1 -1
  34. data/app/views/spree/api/v1/addresses/show.v1.rabl +2 -2
  35. data/app/views/spree/api/v1/credit_cards/index.v1.rabl +1 -1
  36. data/app/views/spree/api/v1/images/index.v1.rabl +1 -1
  37. data/app/views/spree/api/v1/images/show.v1.rabl +1 -1
  38. data/app/views/spree/api/v1/line_items/show.v1.rabl +3 -3
  39. data/app/views/spree/api/v1/option_types/index.v1.rabl +1 -1
  40. data/app/views/spree/api/v1/option_types/show.v1.rabl +1 -1
  41. data/app/views/spree/api/v1/option_values/index.v1.rabl +1 -1
  42. data/app/views/spree/api/v1/option_values/show.v1.rabl +1 -1
  43. data/app/views/spree/api/v1/orders/could_not_transition.v1.rabl +1 -1
  44. data/app/views/spree/api/v1/orders/index.v1.rabl +1 -1
  45. data/app/views/spree/api/v1/orders/invalid_shipping_method.v1.rabl +1 -1
  46. data/app/views/spree/api/v1/orders/mine.v1.rabl +1 -1
  47. data/app/views/spree/api/v1/orders/order.v1.rabl +5 -5
  48. data/app/views/spree/api/v1/orders/show.v1.rabl +7 -7
  49. data/app/views/spree/api/v1/product_properties/index.v1.rabl +1 -1
  50. data/app/views/spree/api/v1/product_properties/new.v1.rabl +1 -1
  51. data/app/views/spree/api/v1/products/index.v1.rabl +1 -1
  52. data/app/views/spree/api/v1/products/show.v1.rabl +5 -5
  53. data/app/views/spree/api/v1/return_authorizations/show.v1.rabl +1 -1
  54. data/app/views/spree/api/v1/shared/stock_location_required.v1.rabl +1 -1
  55. data/app/views/spree/api/v1/shipments/big.v1.rabl +8 -8
  56. data/app/views/spree/api/v1/shipments/cannot_ready_shipment.v1.rabl +1 -1
  57. data/app/views/spree/api/v1/shipments/mine.v1.rabl +1 -1
  58. data/app/views/spree/api/v1/shipments/show.v1.rabl +5 -5
  59. data/app/views/spree/api/v1/shipments/small.v1.rabl +5 -5
  60. data/app/views/spree/api/v1/shipping_rates/show.v1.rabl +1 -1
  61. data/app/views/spree/api/v1/states/index.v1.rabl +1 -3
  62. data/app/views/spree/api/v1/stock_items/show.v1.rabl +1 -1
  63. data/app/views/spree/api/v1/stock_locations/show.v1.rabl +2 -2
  64. data/app/views/spree/api/v1/stock_movements/show.v1.rabl +1 -1
  65. data/app/views/spree/api/v1/taxonomies/index.v1.rabl +1 -1
  66. data/app/views/spree/api/v1/taxonomies/jstree.rabl +2 -3
  67. data/app/views/spree/api/v1/taxonomies/nested.v1.rabl +1 -1
  68. data/app/views/spree/api/v1/taxonomies/show.v1.rabl +1 -1
  69. data/app/views/spree/api/v1/taxons/index.v1.rabl +1 -3
  70. data/app/views/spree/api/v1/taxons/jstree.rabl +3 -4
  71. data/app/views/spree/api/v1/taxons/taxons.v1.rabl +1 -1
  72. data/app/views/spree/api/v1/users/index.v1.rabl +1 -1
  73. data/app/views/spree/api/v1/users/show.v1.rabl +3 -3
  74. data/app/views/spree/api/v1/variants/big.v1.rabl +1 -1
  75. data/app/views/spree/api/v1/variants/index.v1.rabl +1 -1
  76. data/app/views/spree/api/v1/variants/show.v1.rabl +1 -1
  77. data/app/views/spree/api/v1/variants/small.v1.rabl +7 -7
  78. data/config/routes.rb +3 -3
  79. data/lib/spree/api/controller_setup.rb +2 -2
  80. data/lib/spree/api/engine.rb +3 -3
  81. data/lib/spree/api/responders/rabl_template.rb +1 -3
  82. data/lib/spree/api/testing_support/caching.rb +3 -3
  83. data/lib/spree/api/testing_support/helpers.rb +4 -4
  84. data/lib/spree/api/testing_support/setup.rb +2 -2
  85. metadata +7 -7
@@ -2,7 +2,6 @@ module Spree
2
2
  module Api
3
3
  module V1
4
4
  class UsersController < Spree::Api::BaseController
5
-
6
5
  rescue_from Spree::Core::DestroyWithOrdersError, with: :error_during_processing
7
6
 
8
7
  def index
@@ -24,8 +23,7 @@ module Spree
24
23
  respond_with(user)
25
24
  end
26
25
 
27
- def new
28
- end
26
+ def new; end
29
27
 
30
28
  def create
31
29
  authorize! :create, Spree.user_class
@@ -63,7 +61,6 @@ module Spree
63
61
  [bill_address_attributes: permitted_address_attributes,
64
62
  ship_address_attributes: permitted_address_attributes])
65
63
  end
66
-
67
64
  end
68
65
  end
69
66
  end
@@ -24,17 +24,16 @@ module Spree
24
24
  # we render on the view so we better update it any time a node is included
25
25
  # or removed from the views.
26
26
  def index
27
- @variants = scope.includes({ option_values: :option_type }, :product, :default_price, :images, { stock_items: :stock_location })
28
- .ransack(params[:q]).result.page(params[:page]).per(params[:per_page])
27
+ @variants = scope.includes({ option_values: :option_type }, :product, :default_price, :images, stock_items: :stock_location).
28
+ ransack(params[:q]).result.page(params[:page]).per(params[:per_page])
29
29
  respond_with(@variants)
30
30
  end
31
31
 
32
- def new
33
- end
32
+ def new; end
34
33
 
35
34
  def show
36
- @variant = scope.includes({ option_values: :option_type }, :option_values, :product, :default_price, :images, { stock_items: :stock_location })
37
- .find(params[:id])
35
+ @variant = scope.includes({ option_values: :option_type }, :option_values, :product, :default_price, :images, stock_items: :stock_location).
36
+ find(params[:id])
38
37
  respond_with(@variant)
39
38
  end
40
39
 
@@ -48,27 +47,28 @@ module Spree
48
47
  end
49
48
 
50
49
  private
51
- def product
52
- @product ||= Spree::Product.accessible_by(current_ability, :read).friendly.find(params[:product_id]) if params[:product_id]
53
- end
54
50
 
55
- def scope
56
- if @product
57
- variants = @product.variants_including_master
58
- else
59
- variants = Variant
60
- end
51
+ def product
52
+ @product ||= Spree::Product.accessible_by(current_ability, :read).friendly.find(params[:product_id]) if params[:product_id]
53
+ end
61
54
 
62
- if current_ability.can?(:manage, Variant) && params[:show_deleted]
63
- variants = variants.with_deleted
64
- end
55
+ def scope
56
+ variants = if @product
57
+ @product.variants_including_master
58
+ else
59
+ Variant
60
+ end
65
61
 
66
- variants.accessible_by(current_ability, :read)
62
+ if current_ability.can?(:manage, Variant) && params[:show_deleted]
63
+ variants = variants.with_deleted
67
64
  end
68
65
 
69
- def variant_params
70
- params.require(:variant).permit(permitted_variant_attributes)
71
- end
66
+ variants.accessible_by(current_ability, :read)
67
+ end
68
+
69
+ def variant_params
70
+ params.require(:variant).permit(permitted_variant_attributes)
71
+ end
72
72
  end
73
73
  end
74
74
  end
@@ -2,7 +2,6 @@ module Spree
2
2
  module Api
3
3
  module V1
4
4
  class ZonesController < Spree::Api::BaseController
5
-
6
5
  def create
7
6
  authorize! :create, Zone
8
7
  @zone = Spree::Zone.new(zone_params)
@@ -38,14 +38,14 @@ module Spree
38
38
  mattr_reader *ATTRIBUTES
39
39
 
40
40
  def required_fields_for(model)
41
- required_fields = model._validators.select do |field, validations|
41
+ required_fields = model._validators.select do |_field, validations|
42
42
  validations.any? { |v| v.is_a?(ActiveModel::Validations::PresenceValidator) }
43
43
  end.map(&:first) # get fields that are invalid
44
44
  # Permalinks presence is validated, but are really automatically generated
45
45
  # Therefore we shouldn't tell API clients that they MUST send one through
46
- required_fields.map!(&:to_s).delete("permalink")
46
+ required_fields.map!(&:to_s).delete('permalink')
47
47
  # Do not require slugs, either
48
- required_fields.delete("slug")
48
+ required_fields.delete('slug')
49
49
  required_fields
50
50
  end
51
51
 
@@ -126,7 +126,7 @@ module Spree
126
126
  @@adjustment_attributes = [
127
127
  :id, :source_type, :source_id, :adjustable_type, :adjustable_id,
128
128
  :originator_type, :originator_id, :amount, :label, :mandatory,
129
- :locked, :eligible, :created_at, :updated_at
129
+ :locked, :eligible, :created_at, :updated_at
130
130
  ]
131
131
 
132
132
  @@creditcard_attributes = [
@@ -177,7 +177,7 @@ module Spree
177
177
  ]
178
178
 
179
179
  def variant_attributes
180
- if @current_user_roles && @current_user_roles.include?("admin")
180
+ if @current_user_roles && @current_user_roles.include?('admin')
181
181
  @@variant_attributes + [:cost_price]
182
182
  else
183
183
  @@variant_attributes
@@ -1,2 +1,2 @@
1
1
  object false
2
- node(:error) { I18n.t(:gateway_error, scope: "spree.api", text: @error) }
2
+ node(:error) { I18n.t(:gateway_error, scope: 'spree.api', text: @error) }
@@ -1,2 +1,2 @@
1
1
  object false
2
- node(:error) { I18n.t(:invalid_api_key, key: api_key, scope: "spree.api") }
2
+ node(:error) { I18n.t(:invalid_api_key, key: api_key, scope: 'spree.api') }
@@ -1,3 +1,3 @@
1
1
  object false
2
- node(:error) { I18n.t(:invalid_resource, scope: "spree.api") }
2
+ node(:error) { I18n.t(:invalid_resource, scope: 'spree.api') }
3
3
  node(:errors) { @resource.errors.to_hash }
@@ -1,2 +1,2 @@
1
1
  object false
2
- node(:error) { I18n.t(:must_specify_api_key, scope: "spree.api") }
2
+ node(:error) { I18n.t(:must_specify_api_key, scope: 'spree.api') }
@@ -1,2 +1,2 @@
1
1
  object false
2
- node(:error) { I18n.t(:resource_not_found, scope: "spree.api") }
2
+ node(:error) { I18n.t(:resource_not_found, scope: 'spree.api') }
@@ -1,2 +1,2 @@
1
1
  object false
2
- node(:error) { I18n.t(:unauthorized, scope: "spree.api") }
2
+ node(:error) { I18n.t(:unauthorized, scope: 'spree.api') }
@@ -2,9 +2,9 @@ object @address
2
2
  cache [I18n.locale, root_object]
3
3
  attributes *address_attributes
4
4
 
5
- child(:country) do |address|
5
+ child(:country) do |_address|
6
6
  attributes *country_attributes
7
7
  end
8
- child(:state) do |address|
8
+ child(:state) do |_address|
9
9
  attributes *state_attributes
10
10
  end
@@ -1,6 +1,6 @@
1
1
  object false
2
2
  child(@credit_cards => :credit_cards) do
3
- extends "spree/api/v1/credit_cards/show"
3
+ extends 'spree/api/v1/credit_cards/show'
4
4
  end
5
5
  node(:count) { @credit_cards.count }
6
6
  node(:current_page) { params[:page].try(:to_i) || 1 }
@@ -1,4 +1,4 @@
1
1
  object false
2
2
  child(@images => :images) do
3
- extends "spree/api/v1/images/show"
3
+ extends 'spree/api/v1/images/show'
4
4
  end
@@ -1,6 +1,6 @@
1
1
  object @image
2
2
  attributes *image_attributes
3
3
  attributes :viewable_type, :viewable_id
4
- Spree::Image.attachment_definitions[:attachment][:styles].each do |k,v|
4
+ Spree::Image.attachment_definitions[:attachment][:styles].each do |k, _v|
5
5
  node("#{k}_url") { |i| i.attachment.url(k) }
6
6
  end
@@ -3,12 +3,12 @@ cache [I18n.locale, root_object]
3
3
  attributes *line_item_attributes
4
4
  node(:single_display_amount) { |li| li.single_display_amount.to_s }
5
5
  node(:display_amount) { |li| li.display_amount.to_s }
6
- node(:total) { |li| li.total }
6
+ node(:total, &:total)
7
7
  child :variant do
8
- extends "spree/api/v1/variants/small"
8
+ extends 'spree/api/v1/variants/small'
9
9
  attributes :product_id
10
10
  end
11
11
 
12
12
  child adjustments: :adjustments do
13
- extends "spree/api/v1/adjustments/show"
13
+ extends 'spree/api/v1/adjustments/show'
14
14
  end
@@ -1,3 +1,3 @@
1
1
  collection @option_types
2
2
 
3
- extends "spree/api/v1/option_types/show"
3
+ extends 'spree/api/v1/option_types/show'
@@ -2,4 +2,4 @@ object @option_type
2
2
  attributes *option_type_attributes
3
3
  child option_values: :option_values do
4
4
  attributes *option_value_attributes
5
- end
5
+ end
@@ -1,3 +1,3 @@
1
1
  collection @option_values
2
2
 
3
- extends "spree/api/v1/option_values/show"
3
+ extends 'spree/api/v1/option_values/show'
@@ -1,2 +1,2 @@
1
1
  object @option_value
2
- attributes *option_value_attributes
2
+ attributes *option_value_attributes
@@ -1,3 +1,3 @@
1
1
  object false
2
- node(:error) { I18n.t(:could_not_transition, scope: "spree.api.order") }
2
+ node(:error) { I18n.t(:could_not_transition, scope: 'spree.api.order') }
3
3
  node(:errors) { @order.errors.to_hash }
@@ -1,6 +1,6 @@
1
1
  object false
2
2
  child(@orders => :orders) do
3
- extends "spree/api/v1/orders/order"
3
+ extends 'spree/api/v1/orders/order'
4
4
  end
5
5
  node(:count) { @orders.count }
6
6
  node(:current_page) { params[:page].try(:to_i) || 1 }
@@ -1,2 +1,2 @@
1
1
  object false
2
- node(:errors) { [I18n.t(:invalid_shipping_method, scope: "spree.api.order")] }
2
+ node(:errors) { [I18n.t(:invalid_shipping_method, scope: 'spree.api.order')] }
@@ -1,7 +1,7 @@
1
1
  object false
2
2
 
3
3
  child(@orders => :orders) do
4
- extends "spree/api/v1/orders/show"
4
+ extends 'spree/api/v1/orders/show'
5
5
  end
6
6
 
7
7
  node(:count) { @orders.count }
@@ -3,8 +3,8 @@ attributes *order_attributes
3
3
  node(:display_item_total) { |o| o.display_item_total.to_s }
4
4
  node(:total_quantity) { |o| o.line_items.sum(:quantity) }
5
5
  node(:display_total) { |o| o.display_total.to_s }
6
- node(:display_ship_total) { |o| o.display_ship_total }
7
- node(:display_tax_total) { |o| o.display_tax_total }
8
- node(:display_adjustment_total) { |o| o.display_adjustment_total }
9
- node(:token) { |o| o.guest_token }
10
- node(:checkout_steps) { |o| o.checkout_steps }
6
+ node(:display_ship_total, &:display_ship_total)
7
+ node(:display_tax_total, &:display_tax_total)
8
+ node(:display_adjustment_total, &:display_adjustment_total)
9
+ node(:token, &:guest_token)
10
+ node(:checkout_steps, &:checkout_steps)
@@ -1,20 +1,20 @@
1
1
  object @order
2
- extends "spree/api/v1/orders/order"
2
+ extends 'spree/api/v1/orders/order'
3
3
 
4
4
  if lookup_context.find_all("spree/api/v1/orders/#{root_object.state}").present?
5
5
  extends "spree/api/v1/orders/#{root_object.state}"
6
6
  end
7
7
 
8
8
  child billing_address: :bill_address do
9
- extends "spree/api/v1/addresses/show"
9
+ extends 'spree/api/v1/addresses/show'
10
10
  end
11
11
 
12
12
  child shipping_address: :ship_address do
13
- extends "spree/api/v1/addresses/show"
13
+ extends 'spree/api/v1/addresses/show'
14
14
  end
15
15
 
16
16
  child line_items: :line_items do
17
- extends "spree/api/v1/line_items/show"
17
+ extends 'spree/api/v1/line_items/show'
18
18
  end
19
19
 
20
20
  child payments: :payments do
@@ -34,11 +34,11 @@ child payments: :payments do
34
34
  end
35
35
 
36
36
  child shipments: :shipments do
37
- extends "spree/api/v1/shipments/small"
37
+ extends 'spree/api/v1/shipments/small'
38
38
  end
39
39
 
40
40
  child adjustments: :adjustments do
41
- extends "spree/api/v1/adjustments/show"
41
+ extends 'spree/api/v1/adjustments/show'
42
42
  end
43
43
 
44
44
  # Necessary for backend's order interface
@@ -47,5 +47,5 @@ node :permissions do
47
47
  end
48
48
 
49
49
  child valid_credit_cards: :credit_cards do
50
- extends "spree/api/v1/credit_cards/show"
50
+ extends 'spree/api/v1/credit_cards/show'
51
51
  end
@@ -1,6 +1,6 @@
1
1
  object false
2
2
  child(@product_properties => :product_properties) do
3
- attributes *product_property_attributes
3
+ attributes *product_property_attributes
4
4
  end
5
5
  node(:count) { @product_properties.count }
6
6
  node(:current_page) { params[:page].try(:to_i) || 1 }
@@ -1,2 +1,2 @@
1
1
  node(:attributes) { [*product_property_attributes] }
2
- node(:required_attributes) { [] }
2
+ node(:required_attributes) { [] }
@@ -5,5 +5,5 @@ node(:current_page) { params[:page] ? params[:page].to_i : 1 }
5
5
  node(:per_page) { params[:per_page].try(:to_i) || Kaminari.config.default_per_page }
6
6
  node(:pages) { @products.total_pages }
7
7
  child(@products => :products) do
8
- extends "spree/api/v1/products/show"
8
+ extends 'spree/api/v1/products/show'
9
9
  end
@@ -4,15 +4,15 @@ cache [I18n.locale, @current_user_roles.include?('admin'), current_currency, roo
4
4
  attributes *product_attributes
5
5
 
6
6
  node(:display_price) { |p| p.display_price.to_s }
7
- node(:has_variants) { |p| p.has_variants? }
8
- node(:taxon_ids) { |p| p.taxon_ids }
7
+ node(:has_variants, &:has_variants?)
8
+ node(:taxon_ids, &:taxon_ids)
9
9
 
10
10
  child master: :master do
11
- extends "spree/api/v1/variants/small"
11
+ extends 'spree/api/v1/variants/small'
12
12
  end
13
13
 
14
14
  child variants: :variants do
15
- extends "spree/api/v1/variants/small"
15
+ extends 'spree/api/v1/variants/small'
16
16
  end
17
17
 
18
18
  child option_types: :option_types do
@@ -27,6 +27,6 @@ child classifications: :classifications do
27
27
  attributes :taxon_id, :position
28
28
 
29
29
  child(:taxon) do
30
- extends "spree/api/v1/taxons/show"
30
+ extends 'spree/api/v1/taxons/show'
31
31
  end
32
32
  end
@@ -1,2 +1,2 @@
1
1
  object @return_authorization
2
- attributes *return_authorization_attributes
2
+ attributes *return_authorization_attributes
@@ -1,2 +1,2 @@
1
1
  object false
2
- node(:error) { I18n.t(:stock_location_required, scope: "spree.api") }
2
+ node(:error) { I18n.t(:stock_location_required, scope: 'spree.api') }
@@ -3,7 +3,7 @@ cache @shipment
3
3
  attributes *shipment_attributes
4
4
 
5
5
  child selected_shipping_rate: :selected_shipping_rate do
6
- extends "spree/api/v1/shipping_rates/show"
6
+ extends 'spree/api/v1/shipping_rates/show'
7
7
  end
8
8
 
9
9
  child inventory_units: :inventory_units do
@@ -11,32 +11,32 @@ child inventory_units: :inventory_units do
11
11
  attributes *inventory_unit_attributes
12
12
 
13
13
  child :variant do
14
- extends "spree/api/v1/variants/small"
14
+ extends 'spree/api/v1/variants/small'
15
15
  attributes :product_id
16
- child(images: :images) { extends "spree/api/v1/images/show" }
16
+ child(images: :images) { extends 'spree/api/v1/images/show' }
17
17
  end
18
18
 
19
19
  child :line_item do
20
20
  attributes *line_item_attributes
21
21
  node(:single_display_amount) { |li| li.single_display_amount.to_s }
22
22
  node(:display_amount) { |li| li.display_amount.to_s }
23
- node(:total) { |li| li.total }
23
+ node(:total, &:total)
24
24
  end
25
25
  end
26
26
 
27
27
  child order: :order do
28
- extends "spree/api/v1/orders/order"
28
+ extends 'spree/api/v1/orders/order'
29
29
 
30
30
  child billing_address: :bill_address do
31
- extends "spree/api/v1/addresses/show"
31
+ extends 'spree/api/v1/addresses/show'
32
32
  end
33
33
 
34
34
  child shipping_address: :ship_address do
35
- extends "spree/api/v1/addresses/show"
35
+ extends 'spree/api/v1/addresses/show'
36
36
  end
37
37
 
38
38
  child adjustments: :adjustments do
39
- extends "spree/api/v1/adjustments/show"
39
+ extends 'spree/api/v1/adjustments/show'
40
40
  end
41
41
 
42
42
  child payments: :payments do