spree_api 2.2.14 → 2.3.0
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/CHANGELOG.md +43 -1
- data/app/controllers/spree/api/base_controller.rb +8 -12
- data/app/controllers/spree/api/checkouts_controller.rb +4 -58
- data/app/controllers/spree/api/inventory_units_controller.rb +0 -1
- data/app/controllers/spree/api/line_items_controller.rb +3 -3
- data/app/controllers/spree/api/option_types_controller.rb +2 -2
- data/app/controllers/spree/api/orders_controller.rb +11 -36
- data/app/controllers/spree/api/payments_controller.rb +2 -2
- data/app/controllers/spree/api/products_controller.rb +6 -36
- data/app/controllers/spree/api/shipments_controller.rb +6 -25
- data/app/controllers/spree/api/taxonomies_controller.rb +8 -6
- data/app/controllers/spree/api/taxons_controller.rb +1 -1
- data/app/controllers/spree/api/variants_controller.rb +16 -19
- data/app/helpers/spree/api/api_helpers.rb +6 -1
- data/app/views/spree/api/errors/invalid_resource.v1.rabl +1 -1
- data/app/views/spree/api/orders/could_not_transition.v1.rabl +1 -1
- data/app/views/spree/api/orders/order.v1.rabl +1 -1
- data/app/views/spree/api/orders/show.v1.rabl +10 -4
- data/app/views/spree/api/shipments/small.v1.rabl +33 -0
- data/app/views/spree/api/taxonomies/show.v1.rabl +2 -2
- data/app/views/spree/api/users/show.v1.rabl +7 -0
- data/config/routes.rb +19 -28
- data/lib/spree/api/engine.rb +3 -3
- data/lib/spree/api/responders/rabl_template.rb +1 -1
- data/lib/spree/api/testing_support/helpers.rb +8 -3
- data/spec/controllers/spree/api/base_controller_spec.rb +15 -12
- data/spec/controllers/spree/api/checkouts_controller_spec.rb +78 -90
- data/spec/controllers/spree/api/line_items_controller_spec.rb +13 -9
- data/spec/controllers/spree/api/orders_controller_spec.rb +53 -31
- data/spec/controllers/spree/api/payments_controller_spec.rb +9 -8
- data/spec/controllers/spree/api/products_controller_spec.rb +1 -1
- data/spec/controllers/spree/api/promotion_application_spec.rb +5 -5
- data/spec/controllers/spree/api/shipments_controller_spec.rb +1 -11
- data/spec/controllers/spree/api/taxonomies_controller_spec.rb +2 -2
- data/spec/controllers/spree/api/users_controller_spec.rb +23 -23
- data/spec/controllers/spree/api/zones_controller_spec.rb +22 -0
- data/spec/requests/rabl_cache_spec.rb +2 -2
- data/spec/spec_helper.rb +0 -1
- data/spec/support/controller_hacks.rb +1 -1
- data/spree_api.gemspec +2 -2
- metadata +12 -15
- data/app/views/spree/api/orders/delivery.v1.rabl +0 -3
- data/lib/spree/api/version.rb +0 -5
- data/spec/requests/ransackable_attributes_spec.rb +0 -79
@@ -24,6 +24,7 @@ module Spree
|
|
24
24
|
:inventory_unit_attributes,
|
25
25
|
:return_authorization_attributes,
|
26
26
|
:creditcard_attributes,
|
27
|
+
:payment_source_attributes,
|
27
28
|
:user_attributes,
|
28
29
|
:property_attributes,
|
29
30
|
:stock_location_attributes,
|
@@ -84,7 +85,7 @@ module Spree
|
|
84
85
|
|
85
86
|
@@payment_attributes = [
|
86
87
|
:id, :source_type, :source_id, :amount, :display_amount,
|
87
|
-
:payment_method_id, :state, :avs_response, :created_at,
|
88
|
+
:payment_method_id, :response_code, :state, :avs_response, :created_at,
|
88
89
|
:updated_at
|
89
90
|
]
|
90
91
|
|
@@ -130,6 +131,10 @@ module Spree
|
|
130
131
|
:gateway_customer_profile_id, :gateway_payment_profile_id
|
131
132
|
]
|
132
133
|
|
134
|
+
@@payment_source_attributes = [
|
135
|
+
:id, :month, :year, :cc_type, :last_digits, :name
|
136
|
+
]
|
137
|
+
|
133
138
|
@@user_attributes = [:id, :email, :created_at, :updated_at]
|
134
139
|
|
135
140
|
@@property_attributes = [:id, :name, :presentation]
|
@@ -5,5 +5,5 @@ node(:total_quantity) { |o| o.line_items.sum(:quantity) }
|
|
5
5
|
node(:display_total) { |o| o.display_total.to_s }
|
6
6
|
node(:display_ship_total) { |o| o.display_ship_total }
|
7
7
|
node(:display_tax_total) { |o| o.display_tax_total }
|
8
|
-
node(:token) { |o| o.
|
8
|
+
node(:token) { |o| o.guest_token }
|
9
9
|
node(:checkout_steps) { |o| o.checkout_steps }
|
@@ -18,20 +18,26 @@ child :line_items => :line_items do
|
|
18
18
|
end
|
19
19
|
|
20
20
|
child :payments => :payments do
|
21
|
-
attributes
|
21
|
+
attributes *payment_attributes
|
22
|
+
|
22
23
|
child :payment_method => :payment_method do
|
23
24
|
attributes :id, :name, :environment
|
24
25
|
end
|
26
|
+
|
27
|
+
child :source => :source do
|
28
|
+
attributes *payment_source_attributes
|
29
|
+
end
|
25
30
|
end
|
26
31
|
|
27
32
|
child :shipments => :shipments do
|
28
|
-
extends "spree/api/shipments/
|
33
|
+
extends "spree/api/shipments/small"
|
29
34
|
end
|
30
35
|
|
31
36
|
child :adjustments => :adjustments do
|
32
37
|
extends "spree/api/adjustments/show"
|
33
38
|
end
|
34
39
|
|
35
|
-
|
36
|
-
|
40
|
+
# Necessary for backend's order interface
|
41
|
+
node :permissions do
|
42
|
+
{ can_update: current_ability.can?(:update, root_object) }
|
37
43
|
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
object @shipment
|
2
|
+
cache [I18n.locale, 'small_shipment', root_object]
|
3
|
+
|
4
|
+
attributes *shipment_attributes
|
5
|
+
node(:order_id) { |shipment| shipment.order.number }
|
6
|
+
node(:stock_location_name) { |shipment| shipment.stock_location.name }
|
7
|
+
|
8
|
+
child :shipping_rates => :shipping_rates do
|
9
|
+
extends "spree/api/shipping_rates/show"
|
10
|
+
end
|
11
|
+
|
12
|
+
child :selected_shipping_rate => :selected_shipping_rate do
|
13
|
+
extends "spree/api/shipping_rates/show"
|
14
|
+
end
|
15
|
+
|
16
|
+
child :shipping_methods => :shipping_methods do
|
17
|
+
attributes :id, :name
|
18
|
+
child :zones => :zones do
|
19
|
+
attributes :id, :name, :description
|
20
|
+
end
|
21
|
+
|
22
|
+
child :shipping_categories => :shipping_categories do
|
23
|
+
attributes :id, :name
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
child :manifest => :manifest do
|
28
|
+
glue(:variant) do
|
29
|
+
attribute :id => :variant_id
|
30
|
+
end
|
31
|
+
node(:quantity) { |m| m.quantity }
|
32
|
+
node(:states) { |m| m.states }
|
33
|
+
end
|
data/config/routes.rb
CHANGED
@@ -8,14 +8,14 @@ Spree::Core::Engine.add_routes do
|
|
8
8
|
end
|
9
9
|
end
|
10
10
|
|
11
|
-
namespace :api, :
|
11
|
+
namespace :api, defaults: { format: 'json' } do
|
12
12
|
resources :products do
|
13
13
|
resources :images
|
14
14
|
resources :variants
|
15
15
|
resources :product_properties
|
16
16
|
end
|
17
17
|
|
18
|
-
order_routes
|
18
|
+
concern :order_routes do
|
19
19
|
member do
|
20
20
|
put :cancel
|
21
21
|
put :empty
|
@@ -32,17 +32,8 @@ Spree::Core::Engine.add_routes do
|
|
32
32
|
put :credit
|
33
33
|
end
|
34
34
|
end
|
35
|
-
# TODO Remove after shipment api is no longer handled through order nesting.
|
36
|
-
resources :shipments, :only => [:create, :update] do
|
37
|
-
member do
|
38
|
-
put :ready
|
39
|
-
put :ship
|
40
|
-
put :add
|
41
|
-
put :remove
|
42
|
-
end
|
43
|
-
end
|
44
35
|
|
45
|
-
resources :addresses, :
|
36
|
+
resources :addresses, only: [:show, :update]
|
46
37
|
|
47
38
|
resources :return_authorizations do
|
48
39
|
member do
|
@@ -51,17 +42,16 @@ Spree::Core::Engine.add_routes do
|
|
51
42
|
put :receive
|
52
43
|
end
|
53
44
|
end
|
54
|
-
|
45
|
+
end
|
55
46
|
|
56
|
-
resources :checkouts do
|
47
|
+
resources :checkouts, only: [:update], concerns: :order_routes do
|
57
48
|
member do
|
58
49
|
put :next
|
59
50
|
put :advance
|
60
51
|
end
|
61
|
-
order_routes.call
|
62
52
|
end
|
63
53
|
|
64
|
-
resources :variants, :
|
54
|
+
resources :variants, only: [:index, :show] do
|
65
55
|
resources :images
|
66
56
|
end
|
67
57
|
|
@@ -69,15 +59,16 @@ Spree::Core::Engine.add_routes do
|
|
69
59
|
resources :option_values
|
70
60
|
end
|
71
61
|
|
72
|
-
get '/orders/mine', :
|
62
|
+
get '/orders/mine', to: 'orders#mine', as: 'my_orders'
|
73
63
|
|
74
|
-
resources :orders,
|
64
|
+
resources :orders, concerns: :order_routes
|
75
65
|
|
76
66
|
resources :zones
|
77
|
-
resources :countries, :
|
78
|
-
resources :states, :
|
67
|
+
resources :countries, only: [:index, :show] do
|
68
|
+
resources :states, only: [:index, :show]
|
79
69
|
end
|
80
|
-
|
70
|
+
|
71
|
+
resources :shipments, only: [:create, :update] do
|
81
72
|
member do
|
82
73
|
put :ready
|
83
74
|
put :ship
|
@@ -85,7 +76,7 @@ Spree::Core::Engine.add_routes do
|
|
85
76
|
put :remove
|
86
77
|
end
|
87
78
|
end
|
88
|
-
resources :states,
|
79
|
+
resources :states, only: [:index, :show]
|
89
80
|
|
90
81
|
resources :taxonomies do
|
91
82
|
member do
|
@@ -98,9 +89,9 @@ Spree::Core::Engine.add_routes do
|
|
98
89
|
end
|
99
90
|
end
|
100
91
|
|
101
|
-
resources :taxons, :
|
92
|
+
resources :taxons, only: [:index]
|
102
93
|
|
103
|
-
resources :inventory_units, :
|
94
|
+
resources :inventory_units, only: [:show, :update]
|
104
95
|
resources :users
|
105
96
|
resources :properties
|
106
97
|
resources :stock_locations do
|
@@ -108,10 +99,10 @@ Spree::Core::Engine.add_routes do
|
|
108
99
|
resources :stock_items
|
109
100
|
end
|
110
101
|
|
111
|
-
get '/config/money', :
|
112
|
-
get '/config', :
|
102
|
+
get '/config/money', to: 'config#money'
|
103
|
+
get '/config', to: 'config#show'
|
113
104
|
|
114
|
-
put '/classifications', :
|
115
|
-
get '/taxons/products', :
|
105
|
+
put '/classifications', to: 'classifications#update', as: :classifications
|
106
|
+
get '/taxons/products', to: 'taxons#products', as: :taxon_products
|
116
107
|
end
|
117
108
|
end
|
data/lib/spree/api/engine.rb
CHANGED
@@ -10,9 +10,9 @@ module Spree
|
|
10
10
|
config.include_json_root = false
|
11
11
|
config.include_child_root = false
|
12
12
|
|
13
|
-
# Motivation here it make it call as_json when rendering
|
14
|
-
#
|
15
|
-
#
|
13
|
+
# Motivation here it make it call as_json when rendering timestamps
|
14
|
+
# and therefore display miliseconds. Otherwise it would fall to
|
15
|
+
# JSON.dump which doesn't display the miliseconds
|
16
16
|
config.json_engine = ActiveSupport::JSON
|
17
17
|
end
|
18
18
|
|
@@ -3,7 +3,12 @@ module Spree
|
|
3
3
|
module TestingSupport
|
4
4
|
module Helpers
|
5
5
|
def json_response
|
6
|
-
JSON.parse(response.body)
|
6
|
+
case body = JSON.parse(response.body)
|
7
|
+
when Hash
|
8
|
+
body.with_indifferent_access
|
9
|
+
when Array
|
10
|
+
body
|
11
|
+
end
|
7
12
|
end
|
8
13
|
|
9
14
|
def assert_not_found!
|
@@ -17,7 +22,7 @@ module Spree
|
|
17
22
|
end
|
18
23
|
|
19
24
|
def stub_authentication!
|
20
|
-
|
25
|
+
Spree::LegacyUser.stub(:find_by).with(hash_including(:spree_api_key)) { current_api_user }
|
21
26
|
end
|
22
27
|
|
23
28
|
# This method can be overriden (with a let block) inside a context
|
@@ -31,7 +36,7 @@ module Spree
|
|
31
36
|
end
|
32
37
|
|
33
38
|
def upload_image(filename)
|
34
|
-
fixture_file_upload(image(filename).path)
|
39
|
+
fixture_file_upload(image(filename).path, 'image/jpg')
|
35
40
|
end
|
36
41
|
end
|
37
42
|
end
|
@@ -8,9 +8,16 @@ describe Spree::Api::BaseController do
|
|
8
8
|
end
|
9
9
|
end
|
10
10
|
|
11
|
-
|
12
|
-
|
13
|
-
|
11
|
+
context "signed in as a user using an authentication extension" do
|
12
|
+
before do
|
13
|
+
controller.stub :try_spree_current_user => double(:email => "spree@example.com")
|
14
|
+
Spree::Api::Config[:requires_authentication] = true
|
15
|
+
end
|
16
|
+
|
17
|
+
it "can make a request" do
|
18
|
+
api_get :index
|
19
|
+
json_response.should == { "products" => [] }
|
20
|
+
response.status.should == 200
|
14
21
|
end
|
15
22
|
end
|
16
23
|
|
@@ -19,12 +26,12 @@ describe Spree::Api::BaseController do
|
|
19
26
|
|
20
27
|
context "with a correct order token" do
|
21
28
|
it "succeeds" do
|
22
|
-
api_get :index, order_token: order.
|
29
|
+
api_get :index, order_token: order.guest_token, order_id: order.number
|
23
30
|
response.status.should == 200
|
24
31
|
end
|
25
32
|
|
26
33
|
it "succeeds with an order_number parameter" do
|
27
|
-
api_get :index, order_token: order.
|
34
|
+
api_get :index, order_token: order.guest_token, order_number: order.number
|
28
35
|
response.status.should == 200
|
29
36
|
end
|
30
37
|
end
|
@@ -64,7 +71,7 @@ describe Spree::Api::BaseController do
|
|
64
71
|
json_response.should == { "exception" => "no joy" }
|
65
72
|
end
|
66
73
|
|
67
|
-
it "maps
|
74
|
+
it "maps symantec keys to nested_attributes keys" do
|
68
75
|
klass = double(:nested_attributes_options => { :line_items => {},
|
69
76
|
:bill_address => {} })
|
70
77
|
attributes = { 'line_items' => { :id => 1 },
|
@@ -72,11 +79,7 @@ describe Spree::Api::BaseController do
|
|
72
79
|
'name' => 'test order' }
|
73
80
|
|
74
81
|
mapped = subject.map_nested_attributes_keys(klass, attributes)
|
75
|
-
mapped.has_key?('line_items_attributes').should
|
76
|
-
mapped.has_key?('name').should
|
77
|
-
end
|
78
|
-
|
79
|
-
it "lets a subclass override the product associations that are eager-loaded" do
|
80
|
-
controller.respond_to?(:product_includes, true).should be
|
82
|
+
mapped.has_key?('line_items_attributes').should be_true
|
83
|
+
mapped.has_key?('name').should be_true
|
81
84
|
end
|
82
85
|
end
|