spree_api 2.0.13 → 2.1.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 +99 -1
- data/app/controllers/spree/api/addresses_controller.rb +5 -2
- data/app/controllers/spree/api/base_controller.rb +14 -21
- data/app/controllers/spree/api/checkouts_controller.rb +30 -27
- data/app/controllers/spree/api/config_controller.rb +6 -0
- data/app/controllers/spree/api/countries_controller.rb +7 -7
- data/app/controllers/spree/api/images_controller.rb +10 -8
- data/app/controllers/spree/api/inventory_units_controller.rb +7 -4
- data/app/controllers/spree/api/line_items_controller.rb +14 -14
- data/app/controllers/spree/api/option_types_controller.rb +14 -11
- data/app/controllers/spree/api/option_values_controller.rb +13 -11
- data/app/controllers/spree/api/orders_controller.rb +56 -53
- data/app/controllers/spree/api/payments_controller.rb +25 -33
- data/app/controllers/spree/api/product_properties_controller.rb +20 -13
- data/app/controllers/spree/api/products_controller.rb +11 -58
- data/app/controllers/spree/api/properties_controller.rb +19 -16
- data/app/controllers/spree/api/return_authorizations_controller.rb +30 -25
- data/app/controllers/spree/api/shipments_controller.rb +24 -19
- data/app/controllers/spree/api/states_controller.rb +9 -7
- data/app/controllers/spree/api/stock_items_controller.rb +9 -11
- data/app/controllers/spree/api/stock_locations_controller.rb +9 -7
- data/app/controllers/spree/api/stock_movements_controller.rb +7 -5
- data/app/controllers/spree/api/taxonomies_controller.rb +14 -8
- data/app/controllers/spree/api/taxons_controller.rb +25 -20
- data/app/controllers/spree/api/users_controller.rb +7 -5
- data/app/controllers/spree/api/variants_controller.rb +35 -33
- data/app/controllers/spree/api/zones_controller.rb +18 -17
- data/app/helpers/spree/api/api_helpers.rb +7 -6
- data/app/models/spree/option_value_decorator.rb +0 -4
- data/app/models/spree/order_decorator.rb +33 -54
- data/app/views/spree/api/adjustments/show.v1.rabl +2 -1
- data/app/views/spree/api/config/money.v1.rabl +6 -0
- data/app/views/spree/api/config/show.v1.rabl +2 -0
- data/app/views/spree/api/images/show.v1.rabl +0 -1
- data/app/views/spree/api/line_items/show.v1.rabl +3 -0
- data/app/views/spree/api/orders/index.v1.rabl +1 -1
- data/app/views/spree/api/orders/order.v1.rabl +6 -0
- data/app/views/spree/api/orders/payment.v1.rabl +1 -1
- data/app/views/spree/api/orders/show.v1.rabl +1 -1
- data/app/views/spree/api/payments/credit_over_limit.v1.rabl +1 -1
- data/app/views/spree/api/payments/new.v1.rabl +1 -0
- data/app/views/spree/api/products/index.v1.rabl +2 -2
- data/app/views/spree/api/products/show.v1.rabl +1 -0
- data/app/views/spree/api/shipments/show.v1.rabl +22 -5
- data/app/views/spree/api/shipping_rates/show.v1.rabl +2 -0
- data/app/views/spree/api/taxons/index.v1.rabl +2 -4
- data/app/views/spree/api/variants/index.v1.rabl +1 -1
- data/config/locales/en.yml +1 -3
- data/config/routes.rb +4 -1
- data/lib/spree/api/responders/rabl_template.rb +1 -1
- data/lib/spree/api/testing_support/helpers.rb +5 -0
- data/spec/controllers/spree/api/addresses_controller_spec.rb +2 -2
- data/spec/controllers/spree/api/checkouts_controller_spec.rb +32 -22
- data/spec/controllers/spree/api/config_controller_spec.rb +27 -0
- data/spec/controllers/spree/api/images_controller_spec.rb +2 -2
- data/spec/controllers/spree/api/inventory_units_controller_spec.rb +28 -24
- data/spec/controllers/spree/api/line_items_controller_spec.rb +25 -27
- data/spec/controllers/spree/api/option_types_controller_spec.rb +2 -2
- data/spec/controllers/spree/api/option_values_controller_spec.rb +2 -2
- data/spec/controllers/spree/api/orders_controller_spec.rb +130 -119
- data/spec/controllers/spree/api/payments_controller_spec.rb +77 -118
- data/spec/controllers/spree/api/products_controller_spec.rb +13 -143
- data/spec/controllers/spree/api/return_authorizations_controller_spec.rb +4 -19
- data/spec/controllers/spree/api/shipments_controller_spec.rb +3 -3
- data/spec/controllers/spree/api/states_controller_spec.rb +1 -1
- data/spec/controllers/spree/api/stock_items_controller_spec.rb +26 -62
- data/spec/controllers/spree/api/stock_locations_controller_spec.rb +29 -56
- data/spec/controllers/spree/api/stock_movements_controller_spec.rb +27 -51
- data/spec/controllers/spree/api/taxons_controller_spec.rb +18 -48
- data/spec/controllers/spree/api/users_controller_spec.rb +4 -6
- data/spec/controllers/spree/api/variants_controller_spec.rb +21 -38
- data/spec/controllers/spree/api/zones_controller_spec.rb +2 -2
- data/spec/models/spree/order_spec.rb +19 -111
- data/spec/spec_helper.rb +2 -26
- data/spec/support/controller_hacks.rb +1 -1
- data/spree_api.gemspec +1 -1
- metadata +19 -15
- data/app/models/spree/line_item_decorator.rb +0 -3
- data/app/views/spree/api/payments/update_forbidden.v1.rabl +0 -2
- data/db/migrate/20131017162334_add_index_to_user_spree_api_key.rb +0 -7
@@ -12,7 +12,7 @@ module Spree
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def product_attributes
|
15
|
-
[:id, :name, :description, :price, :available_on, :permalink, :meta_description, :meta_keywords, :shipping_category_id, :taxon_ids]
|
15
|
+
[:id, :name, :description, :price, :display_price, :available_on, :permalink, :meta_description, :meta_keywords, :shipping_category_id, :taxon_ids]
|
16
16
|
end
|
17
17
|
|
18
18
|
def product_property_attributes
|
@@ -20,7 +20,7 @@ module Spree
|
|
20
20
|
end
|
21
21
|
|
22
22
|
def variant_attributes
|
23
|
-
[:id, :name, :sku, :price, :weight, :height, :width, :depth, :is_master, :cost_price, :permalink]
|
23
|
+
[:id, :name, :sku, :price, :weight, :height, :width, :depth, :is_master, :cost_price, :permalink, :description]
|
24
24
|
end
|
25
25
|
|
26
26
|
def image_attributes
|
@@ -28,11 +28,11 @@ module Spree
|
|
28
28
|
end
|
29
29
|
|
30
30
|
def option_value_attributes
|
31
|
-
[:id, :name, :presentation, :option_type_name, :option_type_id
|
31
|
+
[:id, :name, :presentation, :option_type_name, :option_type_id]
|
32
32
|
end
|
33
33
|
|
34
34
|
def order_attributes
|
35
|
-
[:id, :number, :item_total, :total, :
|
35
|
+
[:id, :number, :item_total, :total, :state, :adjustment_total, :user_id, :created_at, :updated_at, :completed_at, :payment_total, :shipment_state, :payment_state, :email, :special_instructions]
|
36
36
|
end
|
37
37
|
|
38
38
|
def line_item_attributes
|
@@ -44,7 +44,7 @@ module Spree
|
|
44
44
|
end
|
45
45
|
|
46
46
|
def payment_attributes
|
47
|
-
[:id, :source_type, :source_id, :amount, :
|
47
|
+
[:id, :source_type, :source_id, :amount, :payment_method_id, :response_code, :state, :avs_response, :created_at, :updated_at]
|
48
48
|
end
|
49
49
|
|
50
50
|
def payment_method_attributes
|
@@ -60,7 +60,7 @@ module Spree
|
|
60
60
|
end
|
61
61
|
|
62
62
|
def taxon_attributes
|
63
|
-
[:id, :name, :pretty_name, :permalink, :parent_id, :taxonomy_id]
|
63
|
+
[:id, :name, :pretty_name, :permalink, :position, :parent_id, :taxonomy_id]
|
64
64
|
end
|
65
65
|
|
66
66
|
def inventory_unit_attributes
|
@@ -113,3 +113,4 @@ module Spree
|
|
113
113
|
end
|
114
114
|
end
|
115
115
|
end
|
116
|
+
|
@@ -1,41 +1,28 @@
|
|
1
1
|
Spree::Order.class_eval do
|
2
|
-
attr_accessible :channel, :as => :api_admin
|
3
|
-
|
4
2
|
def self.build_from_api(user, params)
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
order = create!
|
12
|
-
order.associate_user!(user)
|
13
|
-
|
14
|
-
order.create_shipments_from_api params.delete(:shipments_attributes) || []
|
15
|
-
order.create_line_items_from_api params.delete(:line_items_attributes) || {}
|
16
|
-
order.create_adjustments_from_api params.delete(:adjustments_attributes) || []
|
17
|
-
order.create_payments_from_api params.delete(:payments_attributes) || []
|
18
|
-
order.complete_from_api params.delete(:completed_at)
|
19
|
-
|
20
|
-
destroy_automatic_taxes_on_import(order, params)
|
21
|
-
|
22
|
-
if user.has_spree_role? "admin"
|
23
|
-
order.update_attributes!(params, as: :api_admin)
|
24
|
-
else
|
25
|
-
order.update_attributes!(params)
|
26
|
-
end
|
3
|
+
completed_at = params.delete(:completed_at)
|
4
|
+
line_items = params.delete(:line_items_attributes) || {}
|
5
|
+
shipments = params.delete(:shipments_attributes) || []
|
6
|
+
payments = params.delete(:payments_attributes) || []
|
7
|
+
adjustments = params.delete(:adjustments_attributes) || []
|
27
8
|
|
28
|
-
|
29
|
-
|
30
|
-
order.destroy if order && order.persisted?
|
31
|
-
raise e.message
|
32
|
-
end
|
33
|
-
end
|
9
|
+
ensure_country_id_from_api params[:ship_address_attributes]
|
10
|
+
ensure_state_id_from_api params[:ship_address_attributes]
|
34
11
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
12
|
+
ensure_country_id_from_api params[:bill_address_attributes]
|
13
|
+
ensure_state_id_from_api params[:bill_address_attributes]
|
14
|
+
|
15
|
+
order = create!(params)
|
16
|
+
order.associate_user!(user)
|
17
|
+
|
18
|
+
order.create_shipments_from_api(shipments)
|
19
|
+
order.create_line_items_from_api(line_items)
|
20
|
+
order.create_adjustments_from_api(adjustments)
|
21
|
+
order.create_payments_from_api(payments)
|
22
|
+
order.complete_from_api(completed_at)
|
23
|
+
|
24
|
+
order.save!
|
25
|
+
order.reload
|
39
26
|
end
|
40
27
|
|
41
28
|
def complete_from_api(completed_at)
|
@@ -50,7 +37,6 @@ Spree::Order.class_eval do
|
|
50
37
|
begin
|
51
38
|
shipment = shipments.build
|
52
39
|
shipment.tracking = s[:tracking]
|
53
|
-
shipment.stock_location = Spree::StockLocation.find_by_name!(s[:stock_location])
|
54
40
|
|
55
41
|
inventory_units = s[:inventory_units] || []
|
56
42
|
inventory_units.each do |iu|
|
@@ -64,11 +50,10 @@ Spree::Order.class_eval do
|
|
64
50
|
shipment.save!
|
65
51
|
|
66
52
|
shipping_method = Spree::ShippingMethod.find_by_name!(s[:shipping_method])
|
67
|
-
|
68
|
-
|
69
|
-
shipment.selected_shipping_rate_id = rate.id
|
53
|
+
shipment.shipping_rates.create!(:shipping_method => shipping_method,
|
54
|
+
:cost => s[:cost])
|
70
55
|
rescue Exception => e
|
71
|
-
raise "
|
56
|
+
raise "#{e.message} #{s}"
|
72
57
|
end
|
73
58
|
end
|
74
59
|
end
|
@@ -82,7 +67,7 @@ Spree::Order.class_eval do
|
|
82
67
|
payment.payment_method = Spree::PaymentMethod.find_by_name!(p[:payment_method])
|
83
68
|
payment.save!
|
84
69
|
rescue Exception => e
|
85
|
-
raise "
|
70
|
+
raise "#{e.message} #{p}"
|
86
71
|
end
|
87
72
|
end
|
88
73
|
end
|
@@ -95,9 +80,9 @@ Spree::Order.class_eval do
|
|
95
80
|
|
96
81
|
extra_params = line_item.except(:variant_id, :quantity)
|
97
82
|
line_item = self.contents.add(Spree::Variant.find(line_item[:variant_id]), line_item[:quantity])
|
98
|
-
line_item.update_attributes(extra_params
|
83
|
+
line_item.update_attributes(extra_params) unless extra_params.empty?
|
99
84
|
rescue Exception => e
|
100
|
-
raise "
|
85
|
+
raise "#{e.message} #{line_item}"
|
101
86
|
end
|
102
87
|
end
|
103
88
|
end
|
@@ -110,7 +95,7 @@ Spree::Order.class_eval do
|
|
110
95
|
adjustment.save!
|
111
96
|
adjustment.finalize!
|
112
97
|
rescue Exception => e
|
113
|
-
raise "
|
98
|
+
raise "#{e.message} #{a}"
|
114
99
|
end
|
115
100
|
end
|
116
101
|
end
|
@@ -122,7 +107,7 @@ Spree::Order.class_eval do
|
|
122
107
|
hash.delete(:sku)
|
123
108
|
end
|
124
109
|
rescue Exception => e
|
125
|
-
raise "
|
110
|
+
raise "#{e.message} #{hash}"
|
126
111
|
end
|
127
112
|
end
|
128
113
|
|
@@ -145,7 +130,7 @@ Spree::Order.class_eval do
|
|
145
130
|
address[:country_id] = Spree::Country.where(search).first!.id
|
146
131
|
|
147
132
|
rescue Exception => e
|
148
|
-
raise "
|
133
|
+
raise "#{e.message} #{search}"
|
149
134
|
end
|
150
135
|
end
|
151
136
|
|
@@ -161,22 +146,16 @@ Spree::Order.class_eval do
|
|
161
146
|
end
|
162
147
|
|
163
148
|
address.delete(:state)
|
164
|
-
|
165
|
-
|
166
|
-
if state = Spree::State.where(search).first
|
167
|
-
address[:state_id] = state.id
|
168
|
-
else
|
169
|
-
address[:state_name] = search[:name] || search[:abbr]
|
170
|
-
end
|
149
|
+
address[:state_id] = Spree::State.where(search).first!.id
|
171
150
|
rescue Exception => e
|
172
|
-
raise "
|
151
|
+
raise "#{e.message} #{search}"
|
173
152
|
end
|
174
153
|
end
|
175
154
|
|
176
155
|
def update_line_items(line_item_params)
|
177
156
|
return if line_item_params.blank?
|
178
157
|
line_item_params.each do |id, attributes|
|
179
|
-
self.line_items.find(id).update_attributes!(attributes
|
158
|
+
self.line_items.find(id).update_attributes!(attributes)
|
180
159
|
end
|
181
160
|
self.ensure_updated_shipments
|
182
161
|
end
|
@@ -0,0 +1,6 @@
|
|
1
|
+
object false
|
2
|
+
node(:symbol) { ::Money.new(1, Spree::Config[:currency]).symbol }
|
3
|
+
node(:symbol_position) { Spree::Config[:currency_symbol_position] }
|
4
|
+
node(:no_cents) { Spree::Config[:hide_cents] }
|
5
|
+
node(:decimal_mark) { Spree::Config[:currency_decimal_mark] }
|
6
|
+
node(:thousands_separator) { Spree::Config[:currency_thousands_separator] }
|
@@ -1,5 +1,8 @@
|
|
1
1
|
object @line_item
|
2
2
|
attributes *line_item_attributes
|
3
|
+
node(:single_display_amount) { |li| li.single_display_amount.to_s }
|
4
|
+
node(:display_amount) { |li| li.display_amount.to_s }
|
5
|
+
node(:total) { |li| li.total }
|
3
6
|
child :variant do
|
4
7
|
extends "spree/api/variants/variant"
|
5
8
|
attributes :product_id
|
@@ -0,0 +1,6 @@
|
|
1
|
+
attributes *order_attributes
|
2
|
+
node(:display_item_total) { |o| o.display_item_total.to_s }
|
3
|
+
node(:total_quantity) { |o| o.line_items.sum(:quantity) }
|
4
|
+
node(:display_total) { |o| o.display_total.to_s }
|
5
|
+
node(:token) { |o| o.token }
|
6
|
+
node(:checkout_steps) { |o| o.checkout_steps }
|
@@ -1,2 +1,2 @@
|
|
1
1
|
object false
|
2
|
-
node(:error) { I18n.t(:credit_over_limit, :limit => @payment.credit_allowed, :scope => 'spree.api
|
2
|
+
node(:error) { I18n.t(:credit_over_limit, :limit => @payment.credit_allowed, :scope => 'spree.api') }
|
@@ -2,8 +2,8 @@ object false
|
|
2
2
|
node(:count) { @products.count }
|
3
3
|
node(:total_count) { @products.total_count }
|
4
4
|
node(:current_page) { params[:page] ? params[:page].to_i : 1 }
|
5
|
-
node(:pages) { @products.num_pages }
|
6
5
|
node(:per_page) { params[:per_page] || Kaminari.config.default_per_page }
|
7
|
-
|
6
|
+
node(:pages) { @products.num_pages }
|
7
|
+
child(@products) do
|
8
8
|
extends "spree/api/products/show"
|
9
9
|
end
|
@@ -2,13 +2,30 @@ object @shipment
|
|
2
2
|
attributes *shipment_attributes
|
3
3
|
node(:order_id) { |shipment| shipment.order.number }
|
4
4
|
node(:stock_location_name) { |shipment| shipment.stock_location.name }
|
5
|
+
|
5
6
|
child :shipping_rates => :shipping_rates do
|
6
|
-
|
7
|
+
extends "spree/api/shipping_rates/show"
|
8
|
+
end
|
9
|
+
|
10
|
+
child :selected_shipping_rate => :selected_shipping_rate do
|
11
|
+
extends "spree/api/shipping_rates/show"
|
7
12
|
end
|
8
|
-
|
9
|
-
|
13
|
+
|
14
|
+
child :shipping_methods => :shipping_methods do
|
15
|
+
attributes :id, :name
|
16
|
+
child :zones => :zones do
|
17
|
+
attributes :id, :name, :description
|
18
|
+
end
|
19
|
+
|
20
|
+
child :shipping_categories => :shipping_categories do
|
21
|
+
attributes :id, :name
|
22
|
+
end
|
10
23
|
end
|
11
24
|
|
12
|
-
child :
|
13
|
-
|
25
|
+
child :manifest => :manifest do
|
26
|
+
child :variant => :variant do
|
27
|
+
extends "spree/api/variants/show"
|
28
|
+
end
|
29
|
+
node(:quantity) { |m| m.quantity }
|
30
|
+
node(:states) { |m| m.states }
|
14
31
|
end
|
@@ -4,9 +4,7 @@ node(:total_count) { @taxons.total_count }
|
|
4
4
|
node(:current_page) { params[:page] ? params[:page].to_i : 1 }
|
5
5
|
node(:per_page) { params[:per_page] || Kaminari.config.default_per_page }
|
6
6
|
node(:pages) { @taxons.num_pages }
|
7
|
-
child
|
7
|
+
child(@taxons) do
|
8
8
|
attributes *taxon_attributes
|
9
|
-
|
10
|
-
extends "spree/api/taxons/taxons"
|
11
|
-
end
|
9
|
+
extends "spree/api/taxons/taxons"
|
12
10
|
end
|
data/config/locales/en.yml
CHANGED
@@ -7,6 +7,7 @@ en:
|
|
7
7
|
invalid_resource: "Invalid resource. Please fix errors and try again."
|
8
8
|
resource_not_found: "The resource you were looking for could not be found."
|
9
9
|
gateway_error: "There was a problem with the payment gateway: %{text}"
|
10
|
+
credit_over_limit: "This payment can only be credited up to %{limit}. Please specify an amount less than or equal to this number."
|
10
11
|
access: "API Access"
|
11
12
|
key: "Key"
|
12
13
|
clear_key: "Clear key"
|
@@ -18,9 +19,6 @@ en:
|
|
18
19
|
order:
|
19
20
|
could_not_transition: "The order could not be transitioned. Please fix the errors and try again."
|
20
21
|
invalid_shipping_method: "Invalid shipping method specified."
|
21
|
-
payment:
|
22
|
-
credit_over_limit: "This payment can only be credited up to %{limit}. Please specify an amount less than or equal to this number."
|
23
|
-
update_forbidden: "This payment cannot be updated because it is %{state}."
|
24
22
|
shipment:
|
25
23
|
cannot_ready: "Cannot ready shipment."
|
26
24
|
stock_location_required: "A stock_location_id parameter must be provided in order to retrieve stock movements."
|
data/config/routes.rb
CHANGED
@@ -22,7 +22,7 @@ Spree::Core::Engine.routes.draw do
|
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
25
|
-
resources :variants, :only => [:index
|
25
|
+
resources :variants, :only => [:index]
|
26
26
|
|
27
27
|
resources :option_types do
|
28
28
|
resources :option_values
|
@@ -86,5 +86,8 @@ Spree::Core::Engine.routes.draw do
|
|
86
86
|
resources :stock_movements
|
87
87
|
resources :stock_items
|
88
88
|
end
|
89
|
+
|
90
|
+
get '/config/money', :to => 'config#money'
|
91
|
+
get '/config', :to => 'config#show'
|
89
92
|
end
|
90
93
|
end
|
@@ -14,7 +14,7 @@ module Spree
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def template
|
17
|
-
request.headers['X-Spree-Template'] || controller.params[:template] || options[:default_template]
|
17
|
+
request.headers.env['X-Spree-Template'] || controller.params[:template] || options[:default_template]
|
18
18
|
end
|
19
19
|
end
|
20
20
|
end
|
@@ -6,6 +6,11 @@ module Spree
|
|
6
6
|
JSON.parse(response.body)
|
7
7
|
end
|
8
8
|
|
9
|
+
def assert_not_found!
|
10
|
+
json_response.should == { "error" => "The resource you were looking for could not be found." }
|
11
|
+
response.status.should == 404
|
12
|
+
end
|
13
|
+
|
9
14
|
def assert_unauthorized!
|
10
15
|
json_response.should == { "error" => "You are not authorized to perform that action." }
|
11
16
|
response.status.should == 401
|
@@ -25,11 +25,11 @@ module Spree
|
|
25
25
|
:address => { :address1 => "123 Test Lane" }
|
26
26
|
json_response['address1'].should eq '123 Test Lane'
|
27
27
|
end
|
28
|
-
|
28
|
+
|
29
29
|
it "receives the errors object if address is invalid" do
|
30
30
|
api_put :update, :id => @address.id, :order_id => @order.number,
|
31
31
|
:address => { :address1 => "" }
|
32
|
-
|
32
|
+
|
33
33
|
json_response['error'].should_not be_nil
|
34
34
|
json_response['errors'].should_not be_nil
|
35
35
|
json_response['errors']['address1'].first.should eq "can't be blank"
|
@@ -22,16 +22,6 @@ module Spree
|
|
22
22
|
Spree::Config[:track_inventory_levels] = true
|
23
23
|
end
|
24
24
|
|
25
|
-
context "GET 'show'" do
|
26
|
-
let(:order) { create(:order) }
|
27
|
-
|
28
|
-
it "redirects to Orders#show" do
|
29
|
-
api_get :show, :id => order.number
|
30
|
-
response.status.should == 301
|
31
|
-
response.should redirect_to("/api/orders/#{order.number}")
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
25
|
context "POST 'create'" do
|
36
26
|
it "creates a new order when no parameters are passed" do
|
37
27
|
api_post :create
|
@@ -49,9 +39,14 @@ module Spree
|
|
49
39
|
Order.any_instance.stub(:payment_required? => true)
|
50
40
|
end
|
51
41
|
|
52
|
-
it "cannot
|
53
|
-
|
54
|
-
|
42
|
+
it "will return an error if the recently created order cannot transition from cart to address" do
|
43
|
+
order.state.should eq "cart"
|
44
|
+
order.update_column(:email, nil) # email is necessary to transition from cart to address
|
45
|
+
|
46
|
+
api_put :update, :id => order.to_param, :order_token => order.token
|
47
|
+
|
48
|
+
# Order has not transitioned
|
49
|
+
json_response['state'].should == 'cart'
|
55
50
|
end
|
56
51
|
|
57
52
|
it "should transition a recently created order from cart to address" do
|
@@ -66,6 +61,7 @@ module Spree
|
|
66
61
|
api_put :update, :id => order.to_param, :order_token => order.token,
|
67
62
|
:order => { :line_items_attributes => { line_item.id => { :quantity => 1 } } }
|
68
63
|
response.status.should == 200
|
64
|
+
order.reload.state.should eq "address"
|
69
65
|
end
|
70
66
|
|
71
67
|
it "can take line_items as a parameter" do
|
@@ -73,13 +69,16 @@ module Spree
|
|
73
69
|
api_put :update, :id => order.to_param, :order_token => order.token,
|
74
70
|
:order => { :line_items => { line_item.id => { :quantity => 1 } } }
|
75
71
|
response.status.should == 200
|
72
|
+
order.reload.state.should eq "address"
|
76
73
|
end
|
77
74
|
|
78
75
|
it "will return an error if the order cannot transition" do
|
76
|
+
pending "not sure if this test is valid"
|
79
77
|
order.bill_address = nil
|
80
78
|
order.save
|
81
79
|
order.update_column(:state, "address")
|
82
80
|
api_put :update, :id => order.to_param, :order_token => order.token
|
81
|
+
# Order has not transitioned
|
83
82
|
response.status.should == 422
|
84
83
|
end
|
85
84
|
|
@@ -107,18 +106,28 @@ module Spree
|
|
107
106
|
it "can update shipping method and transition from delivery to payment" do
|
108
107
|
order.update_column(:state, "delivery")
|
109
108
|
shipment = create(:shipment, :order => order)
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
109
|
+
shipment.refresh_rates
|
110
|
+
shipping_rate = shipment.shipping_rates.where(:selected => false).first
|
111
|
+
api_put :update, :id => order.to_param, :order_token => order.token,
|
112
|
+
:order => { :shipments_attributes => { "0" => { :selected_shipping_rate_id => shipping_rate.id, :id => shipment.id } } }
|
114
113
|
response.status.should == 200
|
114
|
+
# Find the correct shipment...
|
115
|
+
json_shipment = json_response['shipments'].detect { |s| s["id"] == shipment.id }
|
116
|
+
# Find the correct shipping rate for that shipment...
|
117
|
+
json_shipping_rate = json_shipment['shipping_rates'].detect { |sr| sr["id"] == shipping_rate.id }
|
118
|
+
# ... And finally ensure that it's selected
|
119
|
+
json_shipping_rate['selected'].should be_true
|
120
|
+
# Order should automatically transfer to payment because all criteria are met
|
121
|
+
json_response['state'].should == 'payment'
|
115
122
|
end
|
116
123
|
|
117
124
|
it "can update payment method and transition from payment to confirm" do
|
118
125
|
order.update_column(:state, "payment")
|
119
|
-
api_put :update, :id => order.to_param, :order_token => order.token,
|
126
|
+
api_put :update, :id => order.to_param, :order_token => order.token,
|
127
|
+
:order => { :payments_attributes => [{ :payment_method_id => @payment_method.id }] }
|
120
128
|
json_response['state'].should == 'confirm'
|
121
129
|
json_response['payments'][0]['payment_method']['name'].should == @payment_method.name
|
130
|
+
json_response['payments'][0]['amount'].should == order.total.to_s
|
122
131
|
response.status.should == 200
|
123
132
|
end
|
124
133
|
|
@@ -172,14 +181,16 @@ module Spree
|
|
172
181
|
it "can assign a user to the order" do
|
173
182
|
user = create(:user)
|
174
183
|
# Need to pass email as well so that validations succeed
|
175
|
-
api_put :update, :id => order.to_param, :
|
184
|
+
api_put :update, :id => order.to_param, :order_token => order.token,
|
185
|
+
:order => { :user_id => user.id, :email => "guest@spreecommerce.com" }
|
176
186
|
response.status.should == 200
|
177
187
|
json_response['user_id'].should == user.id
|
178
188
|
end
|
179
189
|
end
|
180
190
|
|
181
191
|
it "can assign an email to the order" do
|
182
|
-
api_put :update, :id => order.to_param, :
|
192
|
+
api_put :update, :id => order.to_param, :order_token => order.token,
|
193
|
+
:order => { :email => "guest@spreecommerce.com" }
|
183
194
|
json_response['email'].should == "guest@spreecommerce.com"
|
184
195
|
response.status.should == 200
|
185
196
|
end
|
@@ -188,7 +199,7 @@ module Spree
|
|
188
199
|
order.update_column(:state, "payment")
|
189
200
|
Spree::Promo::CouponApplicator.should_receive(:new).with(order).and_call_original
|
190
201
|
Spree::Promo::CouponApplicator.any_instance.should_receive(:apply).and_return({:coupon_applied? => true})
|
191
|
-
api_put :update, :id => order.to_param, :order => { :coupon_code => "foobar" }
|
202
|
+
api_put :update, :id => order.to_param, :order_token => order.token, :order => { :coupon_code => "foobar" }
|
192
203
|
end
|
193
204
|
|
194
205
|
it "can apply a coupon code to an order" do
|
@@ -220,7 +231,6 @@ module Spree
|
|
220
231
|
|
221
232
|
it "cannot transition if order email is blank" do
|
222
233
|
order.update_column(:email, nil)
|
223
|
-
order.update_column(:state, 'address')
|
224
234
|
|
225
235
|
api_put :next, :id => order.to_param, :order_token => order.token
|
226
236
|
response.status.should == 422
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Spree
|
4
|
+
describe Api::ConfigController do
|
5
|
+
render_views
|
6
|
+
|
7
|
+
before do
|
8
|
+
stub_authentication!
|
9
|
+
end
|
10
|
+
|
11
|
+
it "returns Spree::Money settings" do
|
12
|
+
api_get :money
|
13
|
+
response.should be_success
|
14
|
+
json_response["symbol"].should == "$"
|
15
|
+
json_response["symbol_position"].should == "before"
|
16
|
+
json_response["no_cents"].should == false
|
17
|
+
json_response["decimal_mark"].should == "."
|
18
|
+
json_response["thousands_separator"].should == ","
|
19
|
+
end
|
20
|
+
|
21
|
+
it "returns some configuration settings" do
|
22
|
+
api_get :show
|
23
|
+
response.should be_success
|
24
|
+
json_response["default_country_id"].should == Spree::Config[:default_country_id]
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -54,12 +54,12 @@ module Spree
|
|
54
54
|
|
55
55
|
it "cannot update an image" do
|
56
56
|
api_put :update, :id => 1
|
57
|
-
|
57
|
+
assert_not_found!
|
58
58
|
end
|
59
59
|
|
60
60
|
it "cannot delete an image" do
|
61
61
|
api_delete :destroy, :id => 1
|
62
|
-
|
62
|
+
assert_not_found!
|
63
63
|
end
|
64
64
|
end
|
65
65
|
end
|