spree_api 3.1.14 → 3.2.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +3 -1
- data/app/controllers/spree/api/base_controller.rb +2 -2
- data/app/controllers/spree/api/v1/addresses_controller.rb +1 -1
- data/app/controllers/spree/api/v1/classifications_controller.rb +1 -1
- data/app/controllers/spree/api/v1/images_controller.rb +3 -0
- data/app/controllers/spree/api/v1/inventory_units_controller.rb +3 -3
- data/app/controllers/spree/api/v1/line_items_controller.rb +3 -0
- data/app/controllers/spree/api/v1/option_types_controller.rb +16 -7
- data/app/controllers/spree/api/v1/option_values_controller.rb +6 -3
- data/app/controllers/spree/api/v1/orders_controller.rb +13 -24
- data/app/controllers/spree/api/v1/payments_controller.rb +0 -1
- data/app/controllers/spree/api/v1/products_controller.rb +8 -5
- data/app/controllers/spree/api/v1/stock_items_controller.rb +1 -1
- data/app/controllers/spree/api/v1/stock_locations_controller.rb +1 -1
- data/app/controllers/spree/api/v1/tags_controller.rb +28 -0
- data/app/controllers/spree/api/v1/taxonomies_controller.rb +7 -4
- data/app/controllers/spree/api/v1/taxons_controller.rb +4 -1
- data/app/controllers/spree/api/v1/users_controller.rb +5 -3
- data/app/controllers/spree/api/v1/zones_controller.rb +3 -3
- data/app/helpers/spree/api/api_helpers.rb +4 -1
- data/app/models/spree/api_configuration.rb +1 -1
- data/app/views/spree/api/errors/invalid_api_key.v1.rabl +1 -1
- data/app/views/spree/api/errors/invalid_resource.v1.rabl +1 -1
- data/app/views/spree/api/errors/must_specify_api_key.v1.rabl +1 -1
- data/app/views/spree/api/errors/not_found.v1.rabl +1 -1
- data/app/views/spree/api/errors/unauthorized.v1.rabl +1 -1
- data/app/views/spree/api/v1/countries/show.v1.rabl +1 -1
- data/app/views/spree/api/v1/line_items/show.v1.rabl +2 -2
- data/app/views/spree/api/v1/option_types/show.v1.rabl +1 -1
- data/app/views/spree/api/v1/orders/invalid_shipping_method.v1.rabl +1 -1
- data/app/views/spree/api/v1/orders/payment.v1.rabl +1 -1
- data/app/views/spree/api/v1/orders/show.v1.rabl +9 -9
- data/app/views/spree/api/v1/payments/credit_over_limit.v1.rabl +1 -1
- data/app/views/spree/api/v1/payments/update_forbidden.v1.rabl +1 -1
- data/app/views/spree/api/v1/products/show.v1.rabl +5 -5
- data/app/views/spree/api/v1/shipments/cannot_ready_shipment.v1.rabl +1 -1
- data/app/views/spree/api/v1/shipments/show.v1.rabl +7 -7
- data/app/views/spree/api/v1/shipments/small.v1.rabl +8 -8
- data/app/views/spree/api/v1/tags/index.v1.rabl +9 -0
- data/app/views/spree/api/v1/taxonomies/jstree.rabl +2 -2
- data/app/views/spree/api/v1/taxonomies/nested.v1.rabl +2 -2
- data/app/views/spree/api/v1/taxons/jstree.rabl +3 -3
- data/app/views/spree/api/v1/taxons/show.v1.rabl +1 -1
- data/app/views/spree/api/v1/taxons/taxons.v1.rabl +1 -1
- data/app/views/spree/api/v1/users/show.v1.rabl +3 -2
- data/app/views/spree/api/v1/variants/big.v1.rabl +3 -3
- data/app/views/spree/api/v1/variants/small.v1.rabl +3 -2
- data/app/views/spree/api/v1/zones/show.v1.rabl +1 -1
- data/config/routes.rb +4 -6
- data/db/migrate/20100107141738_add_api_key_to_spree_users.rb +2 -2
- data/db/migrate/20120411123334_resize_api_key_field.rb +2 -2
- data/db/migrate/20120530054546_rename_api_key_to_spree_api_key.rb +1 -1
- data/db/migrate/20131017162334_add_index_to_user_spree_api_key.rb +1 -1
- data/lib/spree/api/engine.rb +11 -3
- data/lib/spree/api/responders/rabl_template.rb +1 -1
- data/lib/spree/api/testing_support/caching.rb +2 -2
- data/spec/controllers/spree/api/base_controller_spec.rb +96 -0
- data/spec/controllers/spree/api/v1/addresses_controller_spec.rb +56 -0
- data/spec/controllers/spree/api/v1/checkouts_controller_spec.rb +363 -0
- data/spec/controllers/spree/api/v1/classifications_controller_spec.rb +48 -0
- data/spec/controllers/spree/api/v1/countries_controller_spec.rb +48 -0
- data/spec/controllers/spree/api/v1/credit_cards_controller_spec.rb +80 -0
- data/spec/controllers/spree/api/v1/images_controller_spec.rb +114 -0
- data/spec/controllers/spree/api/v1/inventory_units_controller_spec.rb +48 -0
- data/spec/controllers/spree/api/v1/line_items_controller_spec.rb +203 -0
- data/spec/controllers/spree/api/v1/option_types_controller_spec.rb +122 -0
- data/spec/controllers/spree/api/v1/option_values_controller_spec.rb +141 -0
- data/spec/controllers/spree/api/v1/orders_controller_spec.rb +735 -0
- data/spec/controllers/spree/api/v1/payments_controller_spec.rb +234 -0
- data/spec/controllers/spree/api/v1/product_properties_controller_spec.rb +147 -0
- data/spec/controllers/spree/api/v1/products_controller_spec.rb +409 -0
- data/spec/controllers/spree/api/v1/promotion_application_spec.rb +50 -0
- data/spec/controllers/spree/api/v1/promotions_controller_spec.rb +64 -0
- data/spec/controllers/spree/api/v1/properties_controller_spec.rb +102 -0
- data/spec/controllers/spree/api/v1/return_authorizations_controller_spec.rb +161 -0
- data/spec/controllers/spree/api/v1/shipments_controller_spec.rb +187 -0
- data/spec/controllers/spree/api/v1/states_controller_spec.rb +86 -0
- data/spec/controllers/spree/api/v1/stock_items_controller_spec.rb +143 -0
- data/spec/controllers/spree/api/v1/stock_locations_controller_spec.rb +113 -0
- data/spec/controllers/spree/api/v1/stock_movements_controller_spec.rb +84 -0
- data/spec/controllers/spree/api/v1/stores_controller_spec.rb +133 -0
- data/spec/controllers/spree/api/v1/tags_controller_spec.rb +102 -0
- data/spec/controllers/spree/api/v1/taxonomies_controller_spec.rb +114 -0
- data/spec/controllers/spree/api/v1/taxons_controller_spec.rb +177 -0
- data/spec/controllers/spree/api/v1/unauthenticated_products_controller_spec.rb +26 -0
- data/spec/controllers/spree/api/v1/users_controller_spec.rb +153 -0
- data/spec/controllers/spree/api/v1/variants_controller_spec.rb +205 -0
- data/spec/controllers/spree/api/v1/zones_controller_spec.rb +91 -0
- data/spec/models/spree/legacy_user_spec.rb +19 -0
- data/spec/requests/rabl_cache_spec.rb +32 -0
- data/spec/requests/ransackable_attributes_spec.rb +79 -0
- data/spec/requests/version_spec.rb +19 -0
- data/spec/shared_examples/protect_product_actions.rb +17 -0
- data/spec/spec_helper.rb +60 -0
- data/spec/support/controller_hacks.rb +40 -0
- data/spec/support/database_cleaner.rb +14 -0
- data/spec/support/have_attributes_matcher.rb +13 -0
- data/spree_api.gemspec +7 -4
- metadata +99 -14
@@ -7,7 +7,7 @@ module Spree
|
|
7
7
|
authorize! :create, Zone
|
8
8
|
@zone = Zone.new(map_nested_attributes_keys(Spree::Zone, zone_params))
|
9
9
|
if @zone.save
|
10
|
-
respond_with(@zone, :
|
10
|
+
respond_with(@zone, status: 201, default_template: :show)
|
11
11
|
else
|
12
12
|
invalid_resource!(@zone)
|
13
13
|
end
|
@@ -16,7 +16,7 @@ module Spree
|
|
16
16
|
def destroy
|
17
17
|
authorize! :destroy, zone
|
18
18
|
zone.destroy
|
19
|
-
respond_with(zone, :
|
19
|
+
respond_with(zone, status: 204)
|
20
20
|
end
|
21
21
|
|
22
22
|
def index
|
@@ -31,7 +31,7 @@ module Spree
|
|
31
31
|
def update
|
32
32
|
authorize! :update, zone
|
33
33
|
if zone.update_attributes(map_nested_attributes_keys(Spree::Zone, zone_params))
|
34
|
-
respond_with(zone, :
|
34
|
+
respond_with(zone, status: 200, default_template: :show)
|
35
35
|
else
|
36
36
|
invalid_resource!(zone)
|
37
37
|
end
|
@@ -29,7 +29,8 @@ module Spree
|
|
29
29
|
:stock_movement_attributes,
|
30
30
|
:stock_item_attributes,
|
31
31
|
:promotion_attributes,
|
32
|
-
:store_attributes
|
32
|
+
:store_attributes,
|
33
|
+
:tag_attributes
|
33
34
|
]
|
34
35
|
|
35
36
|
mattr_reader *ATTRIBUTES
|
@@ -161,6 +162,8 @@ module Spree
|
|
161
162
|
:mail_from_address, :default_currency, :code, :default
|
162
163
|
]
|
163
164
|
|
165
|
+
@@tag_attributes = [:id, :name]
|
166
|
+
|
164
167
|
def variant_attributes
|
165
168
|
if @current_user_roles && @current_user_roles.include?("admin")
|
166
169
|
@@variant_attributes + [:cost_price]
|
@@ -1,2 +1,2 @@
|
|
1
1
|
object false
|
2
|
-
node(:error) { I18n.t(:invalid_api_key, :
|
2
|
+
node(:error) { I18n.t(:invalid_api_key, key: api_key, scope: "spree.api") }
|
@@ -1,2 +1,2 @@
|
|
1
1
|
object false
|
2
|
-
node(:error) { I18n.t(:must_specify_api_key, :
|
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, :
|
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, :
|
2
|
+
node(:error) { I18n.t(:unauthorized, scope: "spree.api") }
|
@@ -7,9 +7,9 @@ node(:total) { |li| li.total }
|
|
7
7
|
child :variant do
|
8
8
|
extends "spree/api/v1/variants/small"
|
9
9
|
attributes :product_id
|
10
|
-
child(:
|
10
|
+
child(images: :images) { extends "spree/api/v1/images/show" }
|
11
11
|
end
|
12
12
|
|
13
|
-
child :
|
13
|
+
child adjustments: :adjustments do
|
14
14
|
extends "spree/api/v1/adjustments/show"
|
15
15
|
end
|
@@ -1,2 +1,2 @@
|
|
1
1
|
object false
|
2
|
-
node(:errors) { [I18n.t(:invalid_shipping_method, :
|
2
|
+
node(:errors) { [I18n.t(:invalid_shipping_method, scope: "spree.api.order")] }
|
@@ -5,26 +5,26 @@ 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
|
-
child :
|
8
|
+
child billing_address: :bill_address do
|
9
9
|
extends "spree/api/v1/addresses/show"
|
10
10
|
end
|
11
11
|
|
12
|
-
child :
|
12
|
+
child shipping_address: :ship_address do
|
13
13
|
extends "spree/api/v1/addresses/show"
|
14
14
|
end
|
15
15
|
|
16
|
-
child :
|
16
|
+
child line_items: :line_items do
|
17
17
|
extends "spree/api/v1/line_items/show"
|
18
18
|
end
|
19
19
|
|
20
|
-
child :
|
20
|
+
child payments: :payments do
|
21
21
|
attributes *payment_attributes
|
22
22
|
|
23
|
-
child :
|
23
|
+
child payment_method: :payment_method do
|
24
24
|
attributes :id, :name
|
25
25
|
end
|
26
26
|
|
27
|
-
child :
|
27
|
+
child source: :source do
|
28
28
|
if @current_user_roles.include?('admin')
|
29
29
|
attributes *payment_source_attributes + [:gateway_customer_profile_id, :gateway_payment_profile_id]
|
30
30
|
else
|
@@ -33,11 +33,11 @@ child :payments => :payments do
|
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
36
|
-
child :
|
36
|
+
child shipments: :shipments do
|
37
37
|
extends "spree/api/v1/shipments/small"
|
38
38
|
end
|
39
39
|
|
40
|
-
child :
|
40
|
+
child adjustments: :adjustments do
|
41
41
|
extends "spree/api/v1/adjustments/show"
|
42
42
|
end
|
43
43
|
|
@@ -46,6 +46,6 @@ node :permissions do
|
|
46
46
|
{ can_update: current_ability.can?(:update, root_object) }
|
47
47
|
end
|
48
48
|
|
49
|
-
child :
|
49
|
+
child valid_credit_cards: :credit_cards do
|
50
50
|
extends "spree/api/v1/credit_cards/show"
|
51
51
|
end
|
@@ -1,2 +1,2 @@
|
|
1
1
|
object false
|
2
|
-
node(:error) { I18n.t(:credit_over_limit, :
|
2
|
+
node(:error) { I18n.t(:credit_over_limit, limit: @payment.credit_allowed, scope: 'spree.api.payment') }
|
@@ -1,2 +1,2 @@
|
|
1
1
|
object false
|
2
|
-
node(:error) { I18n.t(:update_forbidden, :
|
2
|
+
node(:error) { I18n.t(:update_forbidden, state: @payment.state, scope: 'spree.api.payment') }
|
@@ -7,23 +7,23 @@ node(:display_price) { |p| p.display_price.to_s }
|
|
7
7
|
node(:has_variants) { |p| p.has_variants? }
|
8
8
|
node(:taxon_ids) { |p| p.taxon_ids }
|
9
9
|
|
10
|
-
child :
|
10
|
+
child master: :master do
|
11
11
|
extends "spree/api/v1/variants/small"
|
12
12
|
end
|
13
13
|
|
14
|
-
child :
|
14
|
+
child variants: :variants do
|
15
15
|
extends "spree/api/v1/variants/small"
|
16
16
|
end
|
17
17
|
|
18
|
-
child :
|
18
|
+
child option_types: :option_types do
|
19
19
|
attributes *option_type_attributes
|
20
20
|
end
|
21
21
|
|
22
|
-
child :
|
22
|
+
child product_properties: :product_properties do
|
23
23
|
attributes *product_property_attributes
|
24
24
|
end
|
25
25
|
|
26
|
-
child :
|
26
|
+
child classifications: :classifications do
|
27
27
|
attributes :taxon_id, :position
|
28
28
|
|
29
29
|
child(:taxon) do
|
@@ -1,2 +1,2 @@
|
|
1
1
|
object false
|
2
|
-
node(:error) { I18n.t(:cannot_ready, :
|
2
|
+
node(:error) { I18n.t(:cannot_ready, scope: "spree.api.shipment") }
|
@@ -4,27 +4,27 @@ attributes *shipment_attributes
|
|
4
4
|
node(:order_id) { |shipment| shipment.order.number }
|
5
5
|
node(:stock_location_name) { |shipment| shipment.stock_location.name }
|
6
6
|
|
7
|
-
child :
|
7
|
+
child shipping_rates: :shipping_rates do
|
8
8
|
extends "spree/api/v1/shipping_rates/show"
|
9
9
|
end
|
10
10
|
|
11
|
-
child :
|
11
|
+
child selected_shipping_rate: :selected_shipping_rate do
|
12
12
|
extends "spree/api/v1/shipping_rates/show"
|
13
13
|
end
|
14
14
|
|
15
|
-
child :
|
15
|
+
child shipping_methods: :shipping_methods do
|
16
16
|
attributes :id, :name
|
17
|
-
child :
|
17
|
+
child zones: :zones do
|
18
18
|
attributes :id, :name, :description
|
19
19
|
end
|
20
20
|
|
21
|
-
child :
|
21
|
+
child shipping_categories: :shipping_categories do
|
22
22
|
attributes :id, :name
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
26
|
-
child :
|
27
|
-
child :
|
26
|
+
child manifest: :manifest do
|
27
|
+
child variant: :variant do
|
28
28
|
extends "spree/api/v1/variants/small"
|
29
29
|
end
|
30
30
|
node(:quantity) { |m| m.quantity }
|
@@ -5,33 +5,33 @@ attributes *shipment_attributes
|
|
5
5
|
node(:order_id) { |shipment| shipment.order.number }
|
6
6
|
node(:stock_location_name) { |shipment| shipment.stock_location.name }
|
7
7
|
|
8
|
-
child :
|
8
|
+
child shipping_rates: :shipping_rates do
|
9
9
|
extends "spree/api/v1/shipping_rates/show"
|
10
10
|
end
|
11
11
|
|
12
|
-
child :
|
12
|
+
child selected_shipping_rate: :selected_shipping_rate do
|
13
13
|
extends "spree/api/v1/shipping_rates/show"
|
14
14
|
end
|
15
15
|
|
16
|
-
child :
|
16
|
+
child shipping_methods: :shipping_methods do
|
17
17
|
attributes :id, :code, :name
|
18
|
-
child :
|
18
|
+
child zones: :zones do
|
19
19
|
attributes :id, :name, :description
|
20
20
|
end
|
21
21
|
|
22
|
-
child :
|
22
|
+
child shipping_categories: :shipping_categories do
|
23
23
|
attributes :id, :name
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
27
|
-
child :
|
27
|
+
child manifest: :manifest do
|
28
28
|
glue(:variant) do
|
29
|
-
attribute :
|
29
|
+
attribute id: :variant_id
|
30
30
|
end
|
31
31
|
node(:quantity) { |m| m.quantity }
|
32
32
|
node(:states) { |m| m.states }
|
33
33
|
end
|
34
34
|
|
35
|
-
child :
|
35
|
+
child adjustments: :adjustments do
|
36
36
|
extends "spree/api/v1/adjustments/show"
|
37
37
|
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
object false
|
2
|
+
node(:count) { @tags.count }
|
3
|
+
node(:total_count) { @tags.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 }
|
6
|
+
node(:pages) { @tags.total_pages }
|
7
|
+
child(@tags => :tags) do
|
8
|
+
attributes :name, :id
|
9
|
+
end
|
@@ -1,8 +1,8 @@
|
|
1
|
-
collection @taxon.children, :
|
1
|
+
collection @taxon.children, object_root: false
|
2
2
|
node(:data) { |taxon| taxon.name }
|
3
3
|
node(:attr) do |taxon|
|
4
|
-
{ :
|
5
|
-
:
|
4
|
+
{ id: taxon.id,
|
5
|
+
name: taxon.name
|
6
6
|
}
|
7
7
|
end
|
8
8
|
node(:state) { "closed" }
|
@@ -1,10 +1,11 @@
|
|
1
1
|
object @user
|
2
|
+
cache [I18n.locale, root_object]
|
2
3
|
|
3
4
|
attributes *user_attributes
|
4
|
-
child(:
|
5
|
+
child(bill_address: :bill_address) do
|
5
6
|
extends "spree/api/v1/addresses/show"
|
6
7
|
end
|
7
8
|
|
8
|
-
child(:
|
9
|
+
child(ship_address: :ship_address) do
|
9
10
|
extends "spree/api/v1/addresses/show"
|
10
11
|
end
|
@@ -4,11 +4,11 @@ cache [I18n.locale, @current_user_roles.include?('admin'), 'big_variant', root_o
|
|
4
4
|
|
5
5
|
extends "spree/api/v1/variants/small"
|
6
6
|
|
7
|
-
child(:
|
7
|
+
child(stock_items: :stock_items) do
|
8
8
|
attributes :id, :count_on_hand, :stock_location_id, :backorderable
|
9
|
-
attribute
|
9
|
+
attribute available?: :available
|
10
10
|
|
11
11
|
glue(:stock_location) do
|
12
|
-
attribute :
|
12
|
+
attribute name: :stock_location_name
|
13
13
|
end
|
14
14
|
end
|
@@ -7,11 +7,12 @@ node(:options_text) { |v| v.options_text }
|
|
7
7
|
node(:track_inventory) { |v| v.should_track_inventory? }
|
8
8
|
node(:in_stock) { |v| v.in_stock? }
|
9
9
|
node(:is_backorderable) { |v| v.is_backorderable? }
|
10
|
+
node(:is_orderable) { |v| v.is_backorderable? || v.in_stock? }
|
10
11
|
node(:total_on_hand) { |v| v.total_on_hand }
|
11
12
|
node(:is_destroyed) { |v| v.destroyed? }
|
12
13
|
|
13
|
-
child :
|
14
|
+
child option_values: :option_values do
|
14
15
|
attributes *option_value_attributes
|
15
16
|
end
|
16
17
|
|
17
|
-
child(:
|
18
|
+
child(images: :images) { extends "spree/api/v1/images/show" }
|
data/config/routes.rb
CHANGED
@@ -111,18 +111,16 @@ Spree::Core::Engine.add_routes do
|
|
111
111
|
resources :stock_items, only: [:index, :update, :destroy]
|
112
112
|
resources :stores
|
113
113
|
|
114
|
+
resources :tags, only: :index
|
115
|
+
|
114
116
|
put '/classifications', to: 'classifications#update', as: :classifications
|
115
117
|
get '/taxons/products', to: 'taxons#products', as: :taxon_products
|
116
118
|
end
|
117
119
|
|
118
|
-
|
119
|
-
match 'v:api/*path', to: redirect("#{spree_path}api/v1/%{path}"), via: [:get, :post, :put, :patch, :delete]
|
120
|
+
match 'v:api/*path', to: redirect("/api/v1/%{path}"), via: [:get, :post, :put, :patch, :delete]
|
120
121
|
|
121
122
|
match '*path', to: redirect{ |params, request|
|
122
|
-
|
123
|
-
query = "?#{request.query_string}" unless request.query_string.blank?
|
124
|
-
|
125
|
-
"#{spree_path}api/v1/#{params[:path]}#{format}#{query}"
|
123
|
+
"/api/v1/#{params[:path]}?#{request.query_string}"
|
126
124
|
}, via: [:get, :post, :put, :patch, :delete]
|
127
125
|
end
|
128
126
|
end
|