spree_api 3.0.10 → 3.1.0.rc1
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 +21 -22
- data/app/controllers/spree/api/v1/addresses_controller.rb +46 -0
- data/app/controllers/spree/api/v1/checkouts_controller.rb +103 -0
- data/app/controllers/spree/api/v1/classifications_controller.rb +20 -0
- data/app/controllers/spree/api/v1/countries_controller.rb +24 -0
- data/app/controllers/spree/api/v1/credit_cards_controller.rb +27 -0
- data/app/controllers/spree/api/v1/images_controller.rb +56 -0
- data/app/controllers/spree/api/v1/inventory_units_controller.rb +54 -0
- data/app/controllers/spree/api/v1/line_items_controller.rb +70 -0
- data/app/controllers/spree/api/v1/option_types_controller.rb +51 -0
- data/app/controllers/spree/api/v1/option_values_controller.rb +60 -0
- data/app/controllers/spree/api/v1/orders_controller.rb +137 -0
- data/app/controllers/spree/api/v1/payments_controller.rb +82 -0
- data/app/controllers/spree/api/v1/product_properties_controller.rb +73 -0
- data/app/controllers/spree/api/v1/products_controller.rb +126 -0
- data/app/controllers/spree/api/v1/promotions_controller.rb +28 -0
- data/app/controllers/spree/api/v1/properties_controller.rb +72 -0
- data/app/controllers/spree/api/v1/return_authorizations_controller.rb +71 -0
- data/app/controllers/spree/api/v1/shipments_controller.rb +163 -0
- data/app/controllers/spree/api/v1/states_controller.rb +37 -0
- data/app/controllers/spree/api/v1/stock_items_controller.rb +77 -0
- data/app/controllers/spree/api/v1/stock_locations_controller.rb +52 -0
- data/app/controllers/spree/api/v1/stock_movements_controller.rb +45 -0
- data/app/controllers/spree/api/v1/stores_controller.rb +57 -0
- data/app/controllers/spree/api/v1/taxonomies_controller.rb +66 -0
- data/app/controllers/spree/api/v1/taxons_controller.rb +95 -0
- data/app/controllers/spree/api/v1/users_controller.rb +60 -0
- data/app/controllers/spree/api/v1/variants_controller.rb +75 -0
- data/app/controllers/spree/api/v1/zones_controller.rb +51 -0
- data/app/helpers/spree/api/api_helpers.rb +3 -2
- data/app/views/spree/api/{addresses → v1/addresses}/show.v1.rabl +0 -0
- data/app/views/spree/api/{adjustments → v1/adjustments}/show.v1.rabl +0 -0
- data/app/views/spree/api/{config → v1/config}/money.v1.rabl +0 -0
- data/app/views/spree/api/{config → v1/config}/show.v1.rabl +0 -0
- data/app/views/spree/api/{countries → v1/countries}/index.v1.rabl +0 -0
- data/app/views/spree/api/{countries → v1/countries}/show.v1.rabl +0 -0
- data/app/views/spree/api/{credit_cards → v1/credit_cards}/index.v1.rabl +1 -1
- data/app/views/spree/api/{credit_cards → v1/credit_cards}/show.v1.rabl +0 -0
- data/app/views/spree/api/{images → v1/images}/index.v1.rabl +1 -1
- data/app/views/spree/api/v1/images/new.v1.rabl +3 -0
- data/app/views/spree/api/{images → v1/images}/show.v1.rabl +0 -0
- data/app/views/spree/api/{inventory_units → v1/inventory_units}/show.rabl +0 -0
- data/app/views/spree/api/{line_items → v1/line_items}/new.v1.rabl +0 -0
- data/app/views/spree/api/{line_items → v1/line_items}/show.v1.rabl +3 -3
- data/app/views/spree/api/v1/option_types/index.v1.rabl +3 -0
- data/app/views/spree/api/v1/option_types/new.v1.rabl +3 -0
- data/app/views/spree/api/{option_types → v1/option_types}/show.v1.rabl +0 -0
- data/app/views/spree/api/v1/option_values/index.v1.rabl +3 -0
- data/app/views/spree/api/v1/option_values/new.v1.rabl +3 -0
- data/app/views/spree/api/{option_values → v1/option_values}/show.v1.rabl +0 -0
- data/app/views/spree/api/{orders → v1/orders}/address.v1.rabl +0 -0
- data/app/views/spree/api/{orders → v1/orders}/canceled.v1.rabl +0 -0
- data/app/views/spree/api/{orders → v1/orders}/cart.v1.rabl +0 -0
- data/app/views/spree/api/{orders → v1/orders}/complete.v1.rabl +0 -0
- data/app/views/spree/api/{orders → v1/orders}/could_not_apply_coupon.v1.rabl +0 -0
- data/app/views/spree/api/{orders → v1/orders}/could_not_transition.v1.rabl +0 -0
- data/app/views/spree/api/{orders → v1/orders}/index.v1.rabl +1 -1
- data/app/views/spree/api/{orders → v1/orders}/invalid_shipping_method.v1.rabl +0 -0
- data/app/views/spree/api/{orders → v1/orders}/mine.v1.rabl +1 -1
- data/app/views/spree/api/{orders → v1/orders}/order.v1.rabl +1 -0
- data/app/views/spree/api/{orders → v1/orders}/payment.v1.rabl +0 -0
- data/app/views/spree/api/{orders → v1/orders}/show.v1.rabl +9 -9
- data/app/views/spree/api/{payments → v1/payments}/credit_over_limit.v1.rabl +0 -0
- data/app/views/spree/api/{payments → v1/payments}/index.v1.rabl +0 -0
- data/app/views/spree/api/{payments → v1/payments}/new.v1.rabl +0 -0
- data/app/views/spree/api/{payments → v1/payments}/show.v1.rabl +0 -0
- data/app/views/spree/api/{payments → v1/payments}/update_forbidden.v1.rabl +0 -0
- data/app/views/spree/api/{product_properties → v1/product_properties}/index.v1.rabl +0 -0
- data/app/views/spree/api/{product_properties → v1/product_properties}/new.v1.rabl +0 -0
- data/app/views/spree/api/{product_properties → v1/product_properties}/show.v1.rabl +0 -0
- data/app/views/spree/api/{products → v1/products}/index.v1.rabl +1 -1
- data/app/views/spree/api/{products → v1/products}/new.v1.rabl +0 -0
- data/app/views/spree/api/{products → v1/products}/product.v1.rabl +0 -0
- data/app/views/spree/api/{products → v1/products}/show.v1.rabl +3 -3
- data/app/views/spree/api/{promotions → v1/promotions}/handler.v1.rabl +0 -0
- data/app/views/spree/api/{promotions → v1/promotions}/show.v1.rabl +0 -0
- data/app/views/spree/api/{properties → v1/properties}/index.v1.rabl +0 -0
- data/app/views/spree/api/{properties → v1/properties}/new.v1.rabl +0 -0
- data/app/views/spree/api/{properties → v1/properties}/show.v1.rabl +0 -0
- data/app/views/spree/api/{return_authorizations → v1/return_authorizations}/index.v1.rabl +0 -0
- data/app/views/spree/api/{return_authorizations → v1/return_authorizations}/new.v1.rabl +0 -0
- data/app/views/spree/api/{return_authorizations → v1/return_authorizations}/show.v1.rabl +0 -0
- data/app/views/spree/api/{shared → v1/shared}/stock_location_required.v1.rabl +0 -0
- data/app/views/spree/api/{shipments → v1/shipments}/big.v1.rabl +7 -7
- data/app/views/spree/api/{shipments → v1/shipments}/cannot_ready_shipment.v1.rabl +0 -0
- data/app/views/spree/api/{shipments → v1/shipments}/mine.v1.rabl +1 -1
- data/app/views/spree/api/{shipments → v1/shipments}/show.v1.rabl +3 -3
- data/app/views/spree/api/{shipments → v1/shipments}/small.v1.rabl +3 -3
- data/app/views/spree/api/{shipping_rates → v1/shipping_rates}/show.v1.rabl +0 -0
- data/app/views/spree/api/{states → v1/states}/index.v1.rabl +0 -0
- data/app/views/spree/api/{states → v1/states}/show.v1.rabl +0 -0
- data/app/views/spree/api/{stock_items → v1/stock_items}/index.v1.rabl +1 -1
- data/app/views/spree/api/{stock_items → v1/stock_items}/show.v1.rabl +1 -1
- data/app/views/spree/api/{stock_locations → v1/stock_locations}/index.v1.rabl +1 -1
- data/app/views/spree/api/{stock_locations → v1/stock_locations}/show.v1.rabl +0 -0
- data/app/views/spree/api/{stock_movements → v1/stock_movements}/index.v1.rabl +1 -1
- data/app/views/spree/api/{stock_movements → v1/stock_movements}/show.v1.rabl +1 -1
- data/app/views/spree/api/{stores → v1/stores}/index.v1.rabl +0 -0
- data/app/views/spree/api/{stores → v1/stores}/show.v1.rabl +0 -0
- data/app/views/spree/api/{taxonomies → v1/taxonomies}/index.v1.rabl +1 -1
- data/app/views/spree/api/{taxonomies → v1/taxonomies}/jstree.rabl +0 -0
- data/app/views/spree/api/{taxonomies → v1/taxonomies}/nested.v1.rabl +1 -1
- data/app/views/spree/api/{taxonomies → v1/taxonomies}/new.v1.rabl +0 -0
- data/app/views/spree/api/{taxonomies → v1/taxonomies}/show.v1.rabl +4 -4
- data/app/views/spree/api/{taxons → v1/taxons}/index.v1.rabl +1 -1
- data/app/views/spree/api/{taxons → v1/taxons}/jstree.rabl +0 -0
- data/app/views/spree/api/{taxons → v1/taxons}/new.v1.rabl +0 -0
- data/app/views/spree/api/{taxons → v1/taxons}/show.v1.rabl +0 -0
- data/app/views/spree/api/v1/taxons/taxons.v1.rabl +5 -0
- data/app/views/spree/api/{users → v1/users}/index.v1.rabl +1 -1
- data/app/views/spree/api/{users → v1/users}/new.v1.rabl +0 -0
- data/app/views/spree/api/{users → v1/users}/show.v1.rabl +2 -2
- data/app/views/spree/api/{variants → v1/variants}/big.v1.rabl +1 -1
- data/app/views/spree/api/{variants → v1/variants}/index.v1.rabl +1 -1
- data/app/views/spree/api/{variants → v1/variants}/new.v1.rabl +0 -0
- data/app/views/spree/api/{variants → v1/variants}/show.v1.rabl +1 -1
- data/app/views/spree/api/{variants → v1/variants}/small.v1.rabl +1 -1
- data/app/views/spree/api/{zones → v1/zones}/index.v1.rabl +1 -1
- data/app/views/spree/api/{zones → v1/zones}/show.v1.rabl +0 -0
- data/config/routes.rb +85 -88
- data/spec/controllers/spree/api/base_controller_spec.rb +14 -42
- data/spec/controllers/spree/api/{addresses_controller_spec.rb → v1/addresses_controller_spec.rb} +1 -1
- data/spec/controllers/spree/api/{checkouts_controller_spec.rb → v1/checkouts_controller_spec.rb} +51 -3
- data/spec/controllers/spree/api/{classifications_controller_spec.rb → v1/classifications_controller_spec.rb} +2 -2
- data/spec/controllers/spree/api/{countries_controller_spec.rb → v1/countries_controller_spec.rb} +1 -1
- data/spec/controllers/spree/api/{credit_cards_controller_spec.rb → v1/credit_cards_controller_spec.rb} +1 -1
- data/spec/controllers/spree/api/{images_controller_spec.rb → v1/images_controller_spec.rb} +23 -1
- data/spec/controllers/spree/api/{inventory_units_controller_spec.rb → v1/inventory_units_controller_spec.rb} +1 -1
- data/spec/controllers/spree/api/{line_items_controller_spec.rb → v1/line_items_controller_spec.rb} +2 -2
- data/spec/controllers/spree/api/{option_types_controller_spec.rb → v1/option_types_controller_spec.rb} +9 -3
- data/spec/controllers/spree/api/{option_values_controller_spec.rb → v1/option_values_controller_spec.rb} +8 -2
- data/spec/controllers/spree/api/{orders_controller_spec.rb → v1/orders_controller_spec.rb} +29 -8
- data/spec/controllers/spree/api/{payments_controller_spec.rb → v1/payments_controller_spec.rb} +2 -2
- data/spec/controllers/spree/api/{product_properties_controller_spec.rb → v1/product_properties_controller_spec.rb} +1 -1
- data/spec/controllers/spree/api/{products_controller_spec.rb → v1/products_controller_spec.rb} +5 -5
- data/spec/controllers/spree/api/{promotion_application_spec.rb → v1/promotion_application_spec.rb} +2 -2
- data/spec/controllers/spree/api/{promotions_controller_spec.rb → v1/promotions_controller_spec.rb} +1 -1
- data/spec/controllers/spree/api/{properties_controller_spec.rb → v1/properties_controller_spec.rb} +1 -1
- data/spec/controllers/spree/api/{return_authorizations_controller_spec.rb → v1/return_authorizations_controller_spec.rb} +1 -1
- data/spec/controllers/spree/api/{shipments_controller_spec.rb → v1/shipments_controller_spec.rb} +4 -4
- data/spec/controllers/spree/api/{states_controller_spec.rb → v1/states_controller_spec.rb} +14 -10
- data/spec/controllers/spree/api/{stock_items_controller_spec.rb → v1/stock_items_controller_spec.rb} +1 -1
- data/spec/controllers/spree/api/{stock_locations_controller_spec.rb → v1/stock_locations_controller_spec.rb} +1 -1
- data/spec/controllers/spree/api/{stock_movements_controller_spec.rb → v1/stock_movements_controller_spec.rb} +1 -1
- data/spec/controllers/spree/api/{stores_controller_spec.rb → v1/stores_controller_spec.rb} +1 -1
- data/spec/controllers/spree/api/{taxonomies_controller_spec.rb → v1/taxonomies_controller_spec.rb} +1 -1
- data/spec/controllers/spree/api/{taxons_controller_spec.rb → v1/taxons_controller_spec.rb} +1 -1
- data/spec/controllers/spree/api/{unauthenticated_products_controller_spec.rb → v1/unauthenticated_products_controller_spec.rb} +1 -1
- data/spec/controllers/spree/api/{users_controller_spec.rb → v1/users_controller_spec.rb} +1 -1
- data/spec/controllers/spree/api/{variants_controller_spec.rb → v1/variants_controller_spec.rb} +3 -3
- data/spec/controllers/spree/api/{zones_controller_spec.rb → v1/zones_controller_spec.rb} +7 -5
- data/spec/requests/rabl_cache_spec.rb +2 -2
- data/spec/requests/ransackable_attributes_spec.rb +6 -6
- data/spec/requests/version_spec.rb +19 -0
- data/spree_api.gemspec +1 -1
- metadata +188 -185
- data/CHANGELOG.md +0 -3
- data/app/controllers/spree/api/addresses_controller.rb +0 -43
- data/app/controllers/spree/api/checkouts_controller.rb +0 -98
- data/app/controllers/spree/api/classifications_controller.rb +0 -18
- data/app/controllers/spree/api/countries_controller.rb +0 -23
- data/app/controllers/spree/api/credit_cards_controller.rb +0 -25
- data/app/controllers/spree/api/images_controller.rb +0 -47
- data/app/controllers/spree/api/inventory_units_controller.rb +0 -52
- data/app/controllers/spree/api/line_items_controller.rb +0 -69
- data/app/controllers/spree/api/option_types_controller.rb +0 -49
- data/app/controllers/spree/api/option_values_controller.rb +0 -58
- data/app/controllers/spree/api/orders_controller.rb +0 -130
- data/app/controllers/spree/api/payments_controller.rb +0 -80
- data/app/controllers/spree/api/product_properties_controller.rb +0 -72
- data/app/controllers/spree/api/products_controller.rb +0 -124
- data/app/controllers/spree/api/promotions_controller.rb +0 -26
- data/app/controllers/spree/api/properties_controller.rb +0 -70
- data/app/controllers/spree/api/return_authorizations_controller.rb +0 -69
- data/app/controllers/spree/api/shipments_controller.rb +0 -149
- data/app/controllers/spree/api/states_controller.rb +0 -38
- data/app/controllers/spree/api/stock_items_controller.rb +0 -75
- data/app/controllers/spree/api/stock_locations_controller.rb +0 -50
- data/app/controllers/spree/api/stock_movements_controller.rb +0 -43
- data/app/controllers/spree/api/stores_controller.rb +0 -55
- data/app/controllers/spree/api/taxonomies_controller.rb +0 -64
- data/app/controllers/spree/api/taxons_controller.rb +0 -93
- data/app/controllers/spree/api/users_controller.rb +0 -56
- data/app/controllers/spree/api/variants_controller.rb +0 -73
- data/app/controllers/spree/api/zones_controller.rb +0 -49
- data/app/models/spree/option_value_decorator.rb +0 -9
- data/app/views/spree/api/option_types/index.v1.rabl +0 -3
- data/app/views/spree/api/option_values/index.v1.rabl +0 -3
- data/app/views/spree/api/taxons/taxons.v1.rabl +0 -5
|
@@ -60,12 +60,22 @@ describe Spree::Api::BaseController, :type => :controller do
|
|
|
60
60
|
end
|
|
61
61
|
end
|
|
62
62
|
|
|
63
|
-
it 'handles exceptions' do
|
|
63
|
+
it 'handles parameter missing exceptions' do
|
|
64
64
|
expect(subject).to receive(:authenticate_user).and_return(true)
|
|
65
65
|
expect(subject).to receive(:load_user_roles).and_return(true)
|
|
66
|
-
expect(subject).to receive(:index).and_raise(
|
|
67
|
-
get :index, :
|
|
68
|
-
expect(json_response).to
|
|
66
|
+
expect(subject).to receive(:index).and_raise(ActionController::ParameterMissing.new('foo'))
|
|
67
|
+
get :index, token: 'exception-message'
|
|
68
|
+
expect(json_response).to eql('exception' => 'param is missing or the value is empty: foo')
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
it 'handles record invalid exceptions' do
|
|
72
|
+
expect(subject).to receive(:authenticate_user).and_return(true)
|
|
73
|
+
expect(subject).to receive(:load_user_roles).and_return(true)
|
|
74
|
+
resource = Spree::Product.new
|
|
75
|
+
resource.valid? # get some errors
|
|
76
|
+
expect(subject).to receive(:index).and_raise(ActiveRecord::RecordInvalid.new(resource))
|
|
77
|
+
get :index, token: 'exception-message'
|
|
78
|
+
expect(json_response).to eql('exception' => "Validation failed: Name can't be blank, Shipping Category can't be blank, Price can't be blank")
|
|
69
79
|
end
|
|
70
80
|
|
|
71
81
|
it "maps semantic keys to nested_attributes keys" do
|
|
@@ -83,42 +93,4 @@ describe Spree::Api::BaseController, :type => :controller do
|
|
|
83
93
|
it "lets a subclass override the product associations that are eager-loaded" do
|
|
84
94
|
expect(controller.respond_to?(:product_includes, true)).to be
|
|
85
95
|
end
|
|
86
|
-
|
|
87
|
-
describe '#error_during_processing' do
|
|
88
|
-
controller(FakesController) do
|
|
89
|
-
# GET /foo
|
|
90
|
-
# Simulates a failed API call.
|
|
91
|
-
def foo
|
|
92
|
-
raise StandardError
|
|
93
|
-
end
|
|
94
|
-
end
|
|
95
|
-
|
|
96
|
-
# What would be placed in config/initializers/spree.rb
|
|
97
|
-
Spree::Api::BaseController.error_notifier = Proc.new do |e, controller|
|
|
98
|
-
MockHoneybadger.notify_or_ignore(e, rack_env: controller.request.env)
|
|
99
|
-
end
|
|
100
|
-
|
|
101
|
-
##
|
|
102
|
-
# Fake HB alert class
|
|
103
|
-
class MockHoneybadger
|
|
104
|
-
# https://github.com/honeybadger-io/honeybadger-ruby/blob/master/lib/honeybadger.rb#L136
|
|
105
|
-
def self.notify_or_ignore(exception, opts = {})
|
|
106
|
-
end
|
|
107
|
-
end
|
|
108
|
-
|
|
109
|
-
before do
|
|
110
|
-
user = double(email: "spree@example.com")
|
|
111
|
-
allow(user).to receive_message_chain :spree_roles, pluck: []
|
|
112
|
-
allow(Spree.user_class).to receive_messages find_by: user
|
|
113
|
-
@routes = ActionDispatch::Routing::RouteSet.new.tap do |r|
|
|
114
|
-
r.draw { get 'foo' => 'fakes#foo' }
|
|
115
|
-
end
|
|
116
|
-
end
|
|
117
|
-
|
|
118
|
-
it 'should notify notify_error_during_processing' do
|
|
119
|
-
expect(MockHoneybadger).to receive(:notify_or_ignore).once.with(kind_of(Exception), rack_env: kind_of(Hash))
|
|
120
|
-
api_get :foo, token: 123
|
|
121
|
-
expect(response.status).to eq(422)
|
|
122
|
-
end
|
|
123
|
-
end
|
|
124
96
|
end
|
data/spec/controllers/spree/api/{checkouts_controller_spec.rb → v1/checkouts_controller_spec.rb}
RENAMED
|
@@ -1,9 +1,39 @@
|
|
|
1
1
|
require 'spec_helper'
|
|
2
2
|
|
|
3
3
|
module Spree
|
|
4
|
-
describe Api::CheckoutsController, type: :controller do
|
|
4
|
+
describe Api::V1::CheckoutsController, type: :controller do
|
|
5
5
|
render_views
|
|
6
6
|
|
|
7
|
+
shared_examples_for 'action which loads order using load_order_with_lock' do
|
|
8
|
+
before do
|
|
9
|
+
allow(controller).to receive(:load_order).with(true).and_return(true)
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
it 'should invoke load_order_with_lock' do
|
|
13
|
+
expect(controller).to receive(:load_order_with_lock).exactly(1).times
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
it 'should invoke load_order' do
|
|
17
|
+
expect(controller).to receive(:load_order).with(true).exactly(1).times.and_return(true)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
context 'ensure no double_render_error' do
|
|
21
|
+
before do
|
|
22
|
+
def controller.load_order(*)
|
|
23
|
+
respond_with(@order, default_template: 'spree/api/v1/orders/show', status: 200)
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
it 'should not generate double_render_error' do
|
|
28
|
+
expect(response).to be_success
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
after do
|
|
33
|
+
send_request
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
|
|
7
37
|
before(:each) do
|
|
8
38
|
stub_authentication!
|
|
9
39
|
Spree::Config[:track_inventory_levels] = false
|
|
@@ -211,7 +241,7 @@ module Spree
|
|
|
211
241
|
end
|
|
212
242
|
|
|
213
243
|
it "can transition from confirm to complete" do
|
|
214
|
-
order.update_columns(
|
|
244
|
+
order.update_columns(state: 'confirm')
|
|
215
245
|
allow_any_instance_of(Spree::Order).to receive_messages(payment_required?: false)
|
|
216
246
|
api_put :update, id: order.to_param, order_token: order.guest_token
|
|
217
247
|
expect(json_response['state']).to eq('complete')
|
|
@@ -219,7 +249,7 @@ module Spree
|
|
|
219
249
|
end
|
|
220
250
|
|
|
221
251
|
it "returns the order if the order is already complete" do
|
|
222
|
-
order.update_columns(completed_at: Time.
|
|
252
|
+
order.update_columns(completed_at: Time.current, state: 'complete')
|
|
223
253
|
api_put :update, id: order.to_param, order_token: order.guest_token
|
|
224
254
|
expect(json_response['number']).to eq(order.number)
|
|
225
255
|
expect(response.status).to eq(200)
|
|
@@ -260,6 +290,12 @@ module Spree
|
|
|
260
290
|
expect_any_instance_of(PromotionHandler::Coupon).to receive(:apply).and_return({ coupon_applied?: true })
|
|
261
291
|
api_put :update, :id => order.to_param, order_token: order.guest_token, order: { coupon_code: "foobar" }
|
|
262
292
|
end
|
|
293
|
+
|
|
294
|
+
def send_request
|
|
295
|
+
api_put :update, id: order.to_param, order_token: order.guest_token
|
|
296
|
+
end
|
|
297
|
+
|
|
298
|
+
it_should_behave_like 'action which loads order using load_order_with_lock'
|
|
263
299
|
end
|
|
264
300
|
|
|
265
301
|
context "PUT 'next'" do
|
|
@@ -296,6 +332,12 @@ module Spree
|
|
|
296
332
|
api_put :next, id: order.to_param, order_token: order.guest_token, order: {}
|
|
297
333
|
expect(json_response["errors"]["base"]).to include(Spree.t(:no_payment_found))
|
|
298
334
|
end
|
|
335
|
+
|
|
336
|
+
def send_request
|
|
337
|
+
api_put :next, id: order.to_param, order_token: order.guest_token
|
|
338
|
+
end
|
|
339
|
+
|
|
340
|
+
it_should_behave_like 'action which loads order using load_order_with_lock'
|
|
299
341
|
end
|
|
300
342
|
|
|
301
343
|
context "PUT 'advance'" do
|
|
@@ -310,6 +352,12 @@ module Spree
|
|
|
310
352
|
api_put :advance, id: order.to_param, order_token: order.guest_token
|
|
311
353
|
expect(json_response['id']).to eq(order.id)
|
|
312
354
|
end
|
|
355
|
+
|
|
356
|
+
def send_request
|
|
357
|
+
api_put :advance, id: order.to_param, order_token: order.guest_token
|
|
358
|
+
end
|
|
359
|
+
|
|
360
|
+
it_should_behave_like 'action which loads order using load_order_with_lock'
|
|
313
361
|
end
|
|
314
362
|
end
|
|
315
363
|
end
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
require 'spec_helper'
|
|
2
2
|
|
|
3
3
|
module Spree
|
|
4
|
-
describe Api::ClassificationsController, type: :controller do
|
|
4
|
+
describe Api::V1::ClassificationsController, type: :controller do
|
|
5
5
|
let(:taxon) do
|
|
6
6
|
taxon = create(:taxon)
|
|
7
7
|
|
|
@@ -37,7 +37,7 @@ module Spree
|
|
|
37
37
|
end
|
|
38
38
|
|
|
39
39
|
it "should touch the taxon" do
|
|
40
|
-
taxon.update_attributes(updated_at: Time.
|
|
40
|
+
taxon.update_attributes(updated_at: Time.current - 10.seconds)
|
|
41
41
|
taxon_last_updated_at = taxon.updated_at
|
|
42
42
|
api_put :update, taxon_id: taxon, product_id: last_product, position: 0
|
|
43
43
|
taxon.reload
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
require 'spec_helper'
|
|
2
2
|
|
|
3
3
|
module Spree
|
|
4
|
-
describe
|
|
4
|
+
describe Api::V1::ImagesController, :type => :controller do
|
|
5
5
|
render_views
|
|
6
6
|
|
|
7
7
|
let!(:product) { create(:product) }
|
|
@@ -16,6 +16,12 @@ module Spree
|
|
|
16
16
|
context "as an admin" do
|
|
17
17
|
sign_in_as_admin!
|
|
18
18
|
|
|
19
|
+
it "can learn how to create a new image" do
|
|
20
|
+
api_get :new, product_id: product.id
|
|
21
|
+
expect(json_response["attributes"]).to eq(attributes.map(&:to_s))
|
|
22
|
+
expect(json_response["required_attributes"]).to be_empty
|
|
23
|
+
end
|
|
24
|
+
|
|
19
25
|
it "can upload a new image for a variant" do
|
|
20
26
|
expect do
|
|
21
27
|
api_post :create,
|
|
@@ -28,6 +34,15 @@ module Spree
|
|
|
28
34
|
end.to change(Image, :count).by(1)
|
|
29
35
|
end
|
|
30
36
|
|
|
37
|
+
it "can't upload a new image for a variant without attachment" do
|
|
38
|
+
api_post :create,
|
|
39
|
+
image: { viewable_type: 'Spree::Variant',
|
|
40
|
+
viewable_id: product.master.to_param
|
|
41
|
+
},
|
|
42
|
+
product_id: product.id
|
|
43
|
+
expect(response.status).to eq(422)
|
|
44
|
+
end
|
|
45
|
+
|
|
31
46
|
context "working with an existing image" do
|
|
32
47
|
let!(:product_image) { product.master.images.create!(:attachment => image('thinking-cat.jpg')) }
|
|
33
48
|
|
|
@@ -65,6 +80,13 @@ module Spree
|
|
|
65
80
|
expect(product_image.reload.position).to eq(2)
|
|
66
81
|
end
|
|
67
82
|
|
|
83
|
+
it "can't update a image without attachment" do
|
|
84
|
+
api_post :update,
|
|
85
|
+
image: { attachment: nil },
|
|
86
|
+
id: product_image.id, product_id: product.id
|
|
87
|
+
expect(response.status).to eq(422)
|
|
88
|
+
end
|
|
89
|
+
|
|
68
90
|
it "can delete an image" do
|
|
69
91
|
api_delete :destroy, :id => product_image.id, :product_id => product.id
|
|
70
92
|
expect(response.status).to eq(204)
|
data/spec/controllers/spree/api/{line_items_controller_spec.rb → v1/line_items_controller_spec.rb}
RENAMED
|
@@ -10,9 +10,9 @@ module Spree
|
|
|
10
10
|
end
|
|
11
11
|
|
|
12
12
|
# This should go in an initializer
|
|
13
|
-
Spree::Api::LineItemsController.line_item_options += [:some_option]
|
|
13
|
+
Spree::Api::V1::LineItemsController.line_item_options += [:some_option]
|
|
14
14
|
|
|
15
|
-
describe Api::LineItemsController, :type => :controller do
|
|
15
|
+
describe Api::V1::LineItemsController, :type => :controller do
|
|
16
16
|
render_views
|
|
17
17
|
|
|
18
18
|
let!(:order) { create(:order_with_line_items, line_items_count: 1) }
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
require 'spec_helper'
|
|
2
2
|
|
|
3
3
|
module Spree
|
|
4
|
-
describe Api::OptionTypesController, :type => :controller do
|
|
4
|
+
describe Api::V1::OptionTypesController, :type => :controller do
|
|
5
5
|
render_views
|
|
6
6
|
|
|
7
|
-
let(:attributes) { [:id, :name, :
|
|
7
|
+
let(:attributes) { [:id, :name, :presentation, :position] }
|
|
8
8
|
let!(:option_value) { create(:option_value) }
|
|
9
9
|
let!(:option_type) { option_value.option_type }
|
|
10
10
|
|
|
@@ -15,7 +15,7 @@ module Spree
|
|
|
15
15
|
def check_option_values(option_values)
|
|
16
16
|
expect(option_values.count).to eq(1)
|
|
17
17
|
expect(option_values.first).to have_attributes([:id, :name, :presentation,
|
|
18
|
-
|
|
18
|
+
:option_type_id, :option_type_name])
|
|
19
19
|
end
|
|
20
20
|
|
|
21
21
|
it "can list all option types" do
|
|
@@ -48,6 +48,12 @@ module Spree
|
|
|
48
48
|
check_option_values(json_response["option_values"])
|
|
49
49
|
end
|
|
50
50
|
|
|
51
|
+
it "can learn how to create a new option type" do
|
|
52
|
+
api_get :new
|
|
53
|
+
expect(json_response["attributes"]).to eq(attributes.map(&:to_s))
|
|
54
|
+
expect(json_response["required_attributes"]).to_not be_empty
|
|
55
|
+
end
|
|
56
|
+
|
|
51
57
|
it "cannot create a new option type" do
|
|
52
58
|
api_post :create, :option_type => {
|
|
53
59
|
:name => "Option Type",
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
require 'spec_helper'
|
|
2
2
|
|
|
3
3
|
module Spree
|
|
4
|
-
describe Api::OptionValuesController, :type => :controller do
|
|
4
|
+
describe Api::V1::OptionValuesController, :type => :controller do
|
|
5
5
|
render_views
|
|
6
6
|
|
|
7
|
-
let(:attributes) { [:id, :name, :presentation, :option_type_name, :
|
|
7
|
+
let(:attributes) { [:id, :name, :presentation, :option_type_name, :option_type_id, :option_type_presentation] }
|
|
8
8
|
let!(:option_value) { create(:option_value) }
|
|
9
9
|
let!(:option_type) { option_value.option_type }
|
|
10
10
|
|
|
@@ -86,6 +86,12 @@ module Spree
|
|
|
86
86
|
context "as an admin" do
|
|
87
87
|
sign_in_as_admin!
|
|
88
88
|
|
|
89
|
+
it "can learn how to create a new option value" do
|
|
90
|
+
api_get :new
|
|
91
|
+
expect(json_response["attributes"]).to eq(attributes.map(&:to_s))
|
|
92
|
+
expect(json_response["required_attributes"]).to_not be_empty
|
|
93
|
+
end
|
|
94
|
+
|
|
89
95
|
it "can create an option value" do
|
|
90
96
|
api_post :create, :option_value => {
|
|
91
97
|
:name => "Option Value",
|
|
@@ -2,7 +2,7 @@ require 'spec_helper'
|
|
|
2
2
|
require 'spree/testing_support/bar_ability'
|
|
3
3
|
|
|
4
4
|
module Spree
|
|
5
|
-
describe Api::OrdersController, :type => :controller do
|
|
5
|
+
describe Api::V1::OrdersController, :type => :controller do
|
|
6
6
|
render_views
|
|
7
7
|
|
|
8
8
|
let!(:order) { create(:order) }
|
|
@@ -12,7 +12,7 @@ module Spree
|
|
|
12
12
|
let(:attributes) do
|
|
13
13
|
[:number, :item_total, :display_total, :total, :state, :adjustment_total, :user_id,
|
|
14
14
|
:created_at, :updated_at, :completed_at, :payment_total, :shipment_state, :payment_state,
|
|
15
|
-
:email, :special_instructions, :total_quantity, :display_item_total, :currency]
|
|
15
|
+
:email, :special_instructions, :total_quantity, :display_item_total, :currency, :considered_risky]
|
|
16
16
|
end
|
|
17
17
|
|
|
18
18
|
let(:address_params) { { :country_id => Country.first.id, :state_id => State.first.id } }
|
|
@@ -65,9 +65,9 @@ module Spree
|
|
|
65
65
|
end
|
|
66
66
|
|
|
67
67
|
it "returns orders in reverse chronological order by completed_at" do
|
|
68
|
-
order.update_columns completed_at: Time.
|
|
68
|
+
order.update_columns completed_at: Time.current
|
|
69
69
|
|
|
70
|
-
order2 = Order.create user: order.user, completed_at: Time.
|
|
70
|
+
order2 = Order.create user: order.user, completed_at: Time.current - 1.day
|
|
71
71
|
expect(order2.created_at).to be > order.created_at
|
|
72
72
|
order3 = Order.create user: order.user, completed_at: nil
|
|
73
73
|
expect(order3.created_at).to be > order2.created_at
|
|
@@ -222,7 +222,7 @@ module Spree
|
|
|
222
222
|
end
|
|
223
223
|
|
|
224
224
|
it "cannot cancel an order that doesn't belong to them" do
|
|
225
|
-
order.update_attribute(:completed_at, Time.
|
|
225
|
+
order.update_attribute(:completed_at, Time.current)
|
|
226
226
|
order.update_attribute(:shipment_state, "ready")
|
|
227
227
|
api_put :cancel, :id => order.to_param
|
|
228
228
|
assert_unauthorized!
|
|
@@ -291,7 +291,9 @@ module Spree
|
|
|
291
291
|
it "does not update line item needlessly" do
|
|
292
292
|
expect(Order).to receive(:create!).and_return(order = Spree::Order.new)
|
|
293
293
|
allow(order).to receive(:associate_user!)
|
|
294
|
-
|
|
294
|
+
line_item = double('LineItem')
|
|
295
|
+
allow(line_item).to receive_messages(save!: line_item)
|
|
296
|
+
allow(order).to receive_message_chain(:contents, :add).and_return(line_item)
|
|
295
297
|
expect(line_item).not_to receive(:update_attributes)
|
|
296
298
|
api_post :create, order: { line_items: [{ variant_id: variant.to_param, quantity: 5 }] }
|
|
297
299
|
end
|
|
@@ -694,17 +696,36 @@ module Spree
|
|
|
694
696
|
|
|
695
697
|
context "can cancel an order" do
|
|
696
698
|
before do
|
|
697
|
-
order.completed_at = Time.
|
|
699
|
+
order.completed_at = Time.current
|
|
698
700
|
order.state = 'complete'
|
|
699
701
|
order.shipment_state = 'ready'
|
|
700
702
|
order.save!
|
|
701
703
|
end
|
|
702
704
|
|
|
703
705
|
specify do
|
|
704
|
-
api_put :cancel, :
|
|
706
|
+
api_put :cancel, id: order.to_param
|
|
705
707
|
expect(json_response["state"]).to eq("canceled")
|
|
708
|
+
expect(json_response["canceler_id"]).to eq(current_api_user.id)
|
|
709
|
+
end
|
|
710
|
+
end
|
|
711
|
+
|
|
712
|
+
context "can approve an order" do
|
|
713
|
+
before do
|
|
714
|
+
order.completed_at = Time.current
|
|
715
|
+
order.state = 'complete'
|
|
716
|
+
order.shipment_state = 'ready'
|
|
717
|
+
order.considered_risky = true
|
|
718
|
+
order.save!
|
|
719
|
+
end
|
|
720
|
+
|
|
721
|
+
specify do
|
|
722
|
+
api_put :approve, id: order.to_param
|
|
723
|
+
order.reload
|
|
724
|
+
expect(order.approver_id).to eq(current_api_user.id)
|
|
725
|
+
expect(order.considered_risky).to eq(false)
|
|
706
726
|
end
|
|
707
727
|
end
|
|
728
|
+
|
|
708
729
|
end
|
|
709
730
|
end
|
|
710
731
|
end
|
data/spec/controllers/spree/api/{payments_controller_spec.rb → v1/payments_controller_spec.rb}
RENAMED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
require 'spec_helper'
|
|
2
2
|
|
|
3
3
|
module Spree
|
|
4
|
-
describe
|
|
4
|
+
describe Api::V1::PaymentsController, :type => :controller do
|
|
5
5
|
render_views
|
|
6
6
|
let!(:order) { create(:order) }
|
|
7
7
|
let!(:payment) { create(:payment, :order => order) }
|
|
8
8
|
let!(:attributes) { [:id, :source_type, :source_id, :amount, :display_amount,
|
|
9
9
|
:payment_method_id, :state, :avs_response,
|
|
10
|
-
:created_at, :updated_at] }
|
|
10
|
+
:created_at, :updated_at, :number] }
|
|
11
11
|
|
|
12
12
|
let(:resource_scoping) { { :order_id => order.to_param } }
|
|
13
13
|
|