spree_api 2.2.0 → 2.2.1
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 +2 -49
- data/LICENSE +1 -1
- data/app/controllers/spree/api/addresses_controller.rb +0 -4
- data/app/controllers/spree/api/base_controller.rb +20 -18
- data/app/controllers/spree/api/checkouts_controller.rb +2 -7
- data/app/controllers/spree/api/images_controller.rb +11 -3
- data/app/controllers/spree/api/line_items_controller.rb +9 -7
- data/app/controllers/spree/api/orders_controller.rb +1 -5
- data/app/controllers/spree/api/products_controller.rb +1 -2
- data/app/helpers/spree/api/api_helpers.rb +1 -1
- data/app/views/spree/api/line_items/show.v1.rabl +2 -2
- data/app/views/spree/api/products/show.v1.rabl +3 -3
- data/app/views/spree/api/shipments/show.v1.rabl +1 -1
- data/app/views/spree/api/stock_items/show.v1.rabl +1 -1
- data/app/views/spree/api/variants/{variant_full.v1.rabl → big.v1.rabl} +4 -8
- data/app/views/spree/api/variants/index.v1.rabl +1 -1
- data/app/views/spree/api/variants/show.v1.rabl +2 -3
- data/app/views/spree/api/variants/{variant.v1.rabl → small.v1.rabl} +5 -0
- data/config/routes.rb +4 -2
- data/lib/spree/api/controller_setup.rb +0 -12
- data/lib/spree/api/responders/rabl_template.rb +9 -0
- data/lib/spree/api/testing_support/caching.rb +10 -0
- data/lib/spree/api/testing_support/helpers.rb +0 -1
- data/spec/controllers/spree/api/base_controller_spec.rb +23 -0
- data/spec/controllers/spree/api/checkouts_controller_spec.rb +10 -0
- data/spec/controllers/spree/api/images_controller_spec.rb +7 -6
- data/spec/controllers/spree/api/line_items_controller_spec.rb +20 -4
- data/spec/controllers/spree/api/orders_controller_spec.rb +1 -1
- data/spec/controllers/spree/api/products_controller_spec.rb +18 -0
- data/spec/controllers/spree/api/users_controller_spec.rb +2 -3
- data/spec/controllers/spree/api/variants_controller_spec.rb +9 -0
- data/spec/requests/rabl_cache_spec.rb +29 -0
- data/spec/spec_helper.rb +1 -0
- metadata +10 -13
- data/app/models/spree/order_decorator.rb +0 -171
- data/app/models/spree/user_decorator.rb +0 -13
- data/app/overrides/api_admin_user_edit_form.rb +0 -7
- data/app/views/spree/admin/users/_api_fields.html.erb +0 -31
- data/spec/models/spree/order_spec.rb +0 -301
@@ -31,6 +31,24 @@ module Spree
|
|
31
31
|
end
|
32
32
|
|
33
33
|
context "as a normal user" do
|
34
|
+
context "with caching enabled" do
|
35
|
+
let!(:product_2) { create(:product) }
|
36
|
+
|
37
|
+
before do
|
38
|
+
ActionController::Base.perform_caching = true
|
39
|
+
end
|
40
|
+
|
41
|
+
it "returns unique products" do
|
42
|
+
api_get :index
|
43
|
+
product_ids = json_response["products"].map { |p| p["id"] }
|
44
|
+
expect(product_ids.uniq.count).to eq(product_ids.count)
|
45
|
+
end
|
46
|
+
|
47
|
+
after do
|
48
|
+
ActionController::Base.perform_caching = false
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
34
52
|
it "retrieves a list of products" do
|
35
53
|
api_get :index
|
36
54
|
json_response["products"].first.should have_attributes(show_attributes)
|
@@ -12,8 +12,7 @@ module Spree
|
|
12
12
|
|
13
13
|
context "as a normal user" do
|
14
14
|
before do
|
15
|
-
|
16
|
-
Spree::LegacyUser.stub :find_by_spree_api_key => user
|
15
|
+
controller.stub :try_spree_current_user => user
|
17
16
|
end
|
18
17
|
|
19
18
|
it "can get own details" do
|
@@ -120,7 +119,7 @@ module Spree
|
|
120
119
|
it "cannot destroy user with orders" do
|
121
120
|
create(:completed_order_with_totals, :user => user)
|
122
121
|
api_delete :destroy, :id => user.id
|
123
|
-
json_response["exception"].should eq "Spree::
|
122
|
+
json_response["exception"].should eq "Spree::Core::DestroyWithOrdersError"
|
124
123
|
response.status.should == 422
|
125
124
|
end
|
126
125
|
|
@@ -59,6 +59,15 @@ module Spree
|
|
59
59
|
api_get :index
|
60
60
|
|
61
61
|
json_response["variants"].last.should have_attributes([:images])
|
62
|
+
json_response['variants'].first['images'].first.should have_attributes([:attachment_file_name,
|
63
|
+
:attachment_width,
|
64
|
+
:attachment_height,
|
65
|
+
:attachment_content_type,
|
66
|
+
:mini_url,
|
67
|
+
:small_url,
|
68
|
+
:product_url,
|
69
|
+
:large_url])
|
70
|
+
|
62
71
|
end
|
63
72
|
|
64
73
|
# Regression test for #2141
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "Rabl Cache", :caching => true do
|
4
|
+
let!(:user) { create(:admin_user) }
|
5
|
+
|
6
|
+
before do
|
7
|
+
create(:variant)
|
8
|
+
user.generate_spree_api_key!
|
9
|
+
Spree::Product.count.should == 1
|
10
|
+
end
|
11
|
+
|
12
|
+
it "doesn't create a cache key collision for models with different rabl templates" do
|
13
|
+
get "/api/variants", :token => user.spree_api_key
|
14
|
+
response.status.should == 200
|
15
|
+
|
16
|
+
# Make sure we get a non master variant
|
17
|
+
variant_a = JSON.parse(response.body)['variants'].last
|
18
|
+
variant_a['is_master'].should be_false
|
19
|
+
variant_a['stock_items'].should_not be_nil
|
20
|
+
|
21
|
+
get "/api/products/#{Spree::Product.first.id}", :token => user.spree_api_key
|
22
|
+
response.status.should == 200
|
23
|
+
variant_b = JSON.parse(response.body)['variants'].last
|
24
|
+
variant_b['is_master'].should be_false
|
25
|
+
|
26
|
+
variant_a['id'].should == variant_b['id']
|
27
|
+
variant_b['stock_items'].should be_nil
|
28
|
+
end
|
29
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -32,6 +32,7 @@ Dir[File.dirname(__FILE__) + "/support/**/*.rb"].each {|f| require f}
|
|
32
32
|
require 'spree/testing_support/factories'
|
33
33
|
require 'spree/testing_support/preferences'
|
34
34
|
|
35
|
+
require 'spree/api/testing_support/caching'
|
35
36
|
require 'spree/api/testing_support/helpers'
|
36
37
|
require 'spree/api/testing_support/setup'
|
37
38
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: spree_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.2.
|
4
|
+
version: 2.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryan Bigg
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-03-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: spree_core
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - '='
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 2.2.
|
19
|
+
version: 2.2.1
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - '='
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 2.2.
|
26
|
+
version: 2.2.1
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rabl
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -94,10 +94,6 @@ files:
|
|
94
94
|
- app/helpers/spree/api/api_helpers.rb
|
95
95
|
- app/models/spree/api_configuration.rb
|
96
96
|
- app/models/spree/option_value_decorator.rb
|
97
|
-
- app/models/spree/order_decorator.rb
|
98
|
-
- app/models/spree/user_decorator.rb
|
99
|
-
- app/overrides/api_admin_user_edit_form.rb
|
100
|
-
- app/views/spree/admin/users/_api_fields.html.erb
|
101
97
|
- app/views/spree/api/addresses/show.v1.rabl
|
102
98
|
- app/views/spree/api/adjustments/show.v1.rabl
|
103
99
|
- app/views/spree/api/config/money.v1.rabl
|
@@ -176,11 +172,11 @@ files:
|
|
176
172
|
- app/views/spree/api/users/index.v1.rabl
|
177
173
|
- app/views/spree/api/users/new.v1.rabl
|
178
174
|
- app/views/spree/api/users/show.v1.rabl
|
175
|
+
- app/views/spree/api/variants/big.v1.rabl
|
179
176
|
- app/views/spree/api/variants/index.v1.rabl
|
180
177
|
- app/views/spree/api/variants/new.v1.rabl
|
181
178
|
- app/views/spree/api/variants/show.v1.rabl
|
182
|
-
- app/views/spree/api/variants/
|
183
|
-
- app/views/spree/api/variants/variant_full.v1.rabl
|
179
|
+
- app/views/spree/api/variants/small.v1.rabl
|
184
180
|
- app/views/spree/api/zones/index.v1.rabl
|
185
181
|
- app/views/spree/api/zones/show.v1.rabl
|
186
182
|
- config/initializers/metal_load_paths.rb
|
@@ -195,6 +191,7 @@ files:
|
|
195
191
|
- lib/spree/api/engine.rb
|
196
192
|
- lib/spree/api/responders.rb
|
197
193
|
- lib/spree/api/responders/rabl_template.rb
|
194
|
+
- lib/spree/api/testing_support/caching.rb
|
198
195
|
- lib/spree/api/testing_support/helpers.rb
|
199
196
|
- lib/spree/api/testing_support/setup.rb
|
200
197
|
- lib/spree/api/version.rb
|
@@ -231,7 +228,7 @@ files:
|
|
231
228
|
- spec/controllers/spree/api/zones_controller_spec.rb
|
232
229
|
- spec/fixtures/thinking-cat.jpg
|
233
230
|
- spec/models/spree/legacy_user_spec.rb
|
234
|
-
- spec/
|
231
|
+
- spec/requests/rabl_cache_spec.rb
|
235
232
|
- spec/shared_examples/protect_product_actions.rb
|
236
233
|
- spec/spec_helper.rb
|
237
234
|
- spec/support/controller_hacks.rb
|
@@ -257,7 +254,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
257
254
|
version: '0'
|
258
255
|
requirements: []
|
259
256
|
rubyforge_project:
|
260
|
-
rubygems_version: 2.2.
|
257
|
+
rubygems_version: 2.2.2
|
261
258
|
signing_key:
|
262
259
|
specification_version: 4
|
263
260
|
summary: Spree's API
|
@@ -293,7 +290,7 @@ test_files:
|
|
293
290
|
- spec/controllers/spree/api/zones_controller_spec.rb
|
294
291
|
- spec/fixtures/thinking-cat.jpg
|
295
292
|
- spec/models/spree/legacy_user_spec.rb
|
296
|
-
- spec/
|
293
|
+
- spec/requests/rabl_cache_spec.rb
|
297
294
|
- spec/shared_examples/protect_product_actions.rb
|
298
295
|
- spec/spec_helper.rb
|
299
296
|
- spec/support/controller_hacks.rb
|
@@ -1,171 +0,0 @@
|
|
1
|
-
Spree::Order.class_eval do
|
2
|
-
def self.build_from_api(user, params)
|
3
|
-
begin
|
4
|
-
ensure_country_id_from_api params[:ship_address_attributes]
|
5
|
-
ensure_state_id_from_api params[:ship_address_attributes]
|
6
|
-
ensure_country_id_from_api params[:bill_address_attributes]
|
7
|
-
ensure_state_id_from_api params[:bill_address_attributes]
|
8
|
-
|
9
|
-
order = create!
|
10
|
-
order.associate_user!(user)
|
11
|
-
|
12
|
-
order.create_shipments_from_api params.delete(:shipments_attributes) || []
|
13
|
-
order.create_line_items_from_api params.delete(:line_items_attributes) || {}
|
14
|
-
order.create_adjustments_from_api params.delete(:adjustments_attributes) || []
|
15
|
-
order.create_payments_from_api params.delete(:payments_attributes) || []
|
16
|
-
order.complete_from_api params.delete(:completed_at)
|
17
|
-
|
18
|
-
order.update_attributes!(params)
|
19
|
-
order.reload
|
20
|
-
rescue Exception => e
|
21
|
-
order.destroy if order && order.persisted?
|
22
|
-
raise e.message
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
def complete_from_api(completed_at)
|
27
|
-
if completed_at
|
28
|
-
self.completed_at = completed_at
|
29
|
-
self.state = 'complete'
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
def create_shipments_from_api(shipments_hash)
|
34
|
-
shipments_hash.each do |s|
|
35
|
-
begin
|
36
|
-
shipment = shipments.build
|
37
|
-
shipment.tracking = s[:tracking]
|
38
|
-
shipment.stock_location = Spree::StockLocation.find_by_name!(s[:stock_location])
|
39
|
-
|
40
|
-
inventory_units = s[:inventory_units] || []
|
41
|
-
inventory_units.each do |iu|
|
42
|
-
self.class.ensure_variant_id_from_api(iu)
|
43
|
-
|
44
|
-
unit = shipment.inventory_units.build
|
45
|
-
unit.order = self
|
46
|
-
unit.variant_id = iu[:variant_id]
|
47
|
-
end
|
48
|
-
|
49
|
-
shipment.save!
|
50
|
-
|
51
|
-
shipping_method = Spree::ShippingMethod.find_by_name!(s[:shipping_method])
|
52
|
-
shipment.shipping_rates.create!(:shipping_method => shipping_method,
|
53
|
-
:cost => s[:cost])
|
54
|
-
rescue Exception => e
|
55
|
-
raise "Order import shipments: #{e.message} #{s}"
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
def create_payments_from_api(payments_hash)
|
61
|
-
payments_hash.each do |p|
|
62
|
-
begin
|
63
|
-
payment = payments.build
|
64
|
-
payment.amount = p[:amount].to_f
|
65
|
-
payment.state = p.fetch(:state, 'completed')
|
66
|
-
payment.payment_method = Spree::PaymentMethod.find_by_name!(p[:payment_method])
|
67
|
-
payment.save!
|
68
|
-
rescue Exception => e
|
69
|
-
raise "Order import payments: #{e.message} #{p}"
|
70
|
-
end
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
|
-
def create_line_items_from_api(line_items_hash)
|
75
|
-
line_items_hash.each_key do |k|
|
76
|
-
begin
|
77
|
-
line_item = line_items_hash[k]
|
78
|
-
self.class.ensure_variant_id_from_api(line_item)
|
79
|
-
|
80
|
-
extra_params = line_item.except(:variant_id, :quantity)
|
81
|
-
line_item = self.contents.add(Spree::Variant.find(line_item[:variant_id]), line_item[:quantity])
|
82
|
-
line_item.update_attributes(extra_params) unless extra_params.empty?
|
83
|
-
rescue Exception => e
|
84
|
-
raise "Order import line items: #{e.message} #{line_item}"
|
85
|
-
end
|
86
|
-
end
|
87
|
-
end
|
88
|
-
|
89
|
-
def create_adjustments_from_api(adjustments)
|
90
|
-
adjustments.each do |a|
|
91
|
-
begin
|
92
|
-
adjustment = self.adjustments.build(:amount => a[:amount].to_f,
|
93
|
-
:label => a[:label])
|
94
|
-
adjustment.save!
|
95
|
-
adjustment.close!
|
96
|
-
rescue Exception => e
|
97
|
-
raise "Order import adjustments: #{e.message} #{a}"
|
98
|
-
end
|
99
|
-
end
|
100
|
-
end
|
101
|
-
|
102
|
-
def self.ensure_variant_id_from_api(hash)
|
103
|
-
begin
|
104
|
-
unless hash[:variant_id].present?
|
105
|
-
hash[:variant_id] = Spree::Variant.active.find_by_sku!(hash[:sku]).id
|
106
|
-
hash.delete(:sku)
|
107
|
-
end
|
108
|
-
rescue Exception => e
|
109
|
-
raise "Ensure order import variant: #{e.message} #{hash}"
|
110
|
-
end
|
111
|
-
end
|
112
|
-
|
113
|
-
def self.ensure_country_id_from_api(address)
|
114
|
-
return if address.nil? or address[:country_id].present? or address[:country].nil?
|
115
|
-
|
116
|
-
begin
|
117
|
-
search = {}
|
118
|
-
if name = address[:country]['name']
|
119
|
-
search[:name] = name
|
120
|
-
elsif iso_name = address[:country]['iso_name']
|
121
|
-
search[:iso_name] = iso_name.upcase
|
122
|
-
elsif iso = address[:country]['iso']
|
123
|
-
search[:iso] = iso.upcase
|
124
|
-
elsif iso3 = address[:country]['iso3']
|
125
|
-
search[:iso3] = iso3.upcase
|
126
|
-
end
|
127
|
-
|
128
|
-
address.delete(:country)
|
129
|
-
address[:country_id] = Spree::Country.where(search).first!.id
|
130
|
-
|
131
|
-
rescue Exception => e
|
132
|
-
raise "Ensure order import address country: #{e.message} #{search}"
|
133
|
-
end
|
134
|
-
end
|
135
|
-
|
136
|
-
def self.ensure_state_id_from_api(address)
|
137
|
-
return if address.nil? or address[:state_id].present? or address[:state].nil?
|
138
|
-
|
139
|
-
begin
|
140
|
-
search = {}
|
141
|
-
if name = address[:state]['name']
|
142
|
-
search[:name] = name
|
143
|
-
elsif abbr = address[:state]['abbr']
|
144
|
-
search[:abbr] = abbr.upcase
|
145
|
-
end
|
146
|
-
|
147
|
-
address.delete(:state)
|
148
|
-
search[:country_id] = address[:country_id]
|
149
|
-
|
150
|
-
if state = Spree::State.where(search).first
|
151
|
-
address[:state_id] = state.id
|
152
|
-
else
|
153
|
-
address[:state_name] = search[:name] || search[:abbr]
|
154
|
-
end
|
155
|
-
rescue Exception => e
|
156
|
-
raise "Ensure order import address state: #{e.message} #{search}"
|
157
|
-
end
|
158
|
-
end
|
159
|
-
|
160
|
-
def update_line_items(line_item_params)
|
161
|
-
return if line_item_params.blank?
|
162
|
-
line_item_params.each_value do |attributes|
|
163
|
-
if attributes[:id].present?
|
164
|
-
self.line_items.find(attributes[:id]).update_attributes!(attributes)
|
165
|
-
else
|
166
|
-
self.line_items.create!(attributes)
|
167
|
-
end
|
168
|
-
end
|
169
|
-
self.ensure_updated_shipments
|
170
|
-
end
|
171
|
-
end
|
@@ -1,31 +0,0 @@
|
|
1
|
-
<fieldset data-hook="admin_user_api_key" class="omega six columns">
|
2
|
-
<legend><%= Spree.t('access', :scope => 'api') %></legend>
|
3
|
-
|
4
|
-
<% if @user.spree_api_key.present? %>
|
5
|
-
<div class="field">
|
6
|
-
<%= label_tag Spree.t('key', :scope => 'api') %>:
|
7
|
-
<%= @user.spree_api_key %>
|
8
|
-
</div>
|
9
|
-
<div class="filter-actions actions">
|
10
|
-
<%= form_tag spree.clear_api_key_admin_user_path(@user), :method => :put do %>
|
11
|
-
<%= button Spree.t('clear_key', :scope => 'api'), 'icon-trash' %>
|
12
|
-
<% end %>
|
13
|
-
|
14
|
-
<span class="or"><%= Spree.t(:or)%></span>
|
15
|
-
|
16
|
-
<%= form_tag spree.generate_api_key_admin_user_path(@user), :method => :put do %>
|
17
|
-
<%= button Spree.t('regenerate_key', :scope => 'api'), 'icon-refresh' %>
|
18
|
-
<% end %>
|
19
|
-
</div>
|
20
|
-
|
21
|
-
<% else %>
|
22
|
-
|
23
|
-
<div class="no-objects-found"><%= Spree.t('no_key', :scope => 'api') %></div>
|
24
|
-
|
25
|
-
<div class="filter-actions actions">
|
26
|
-
<%= form_tag spree.generate_api_key_admin_user_path(@user), :method => :put do %>
|
27
|
-
<%= button Spree.t('generate_key', :scope => 'api'), 'icon-key' %>
|
28
|
-
<% end %>
|
29
|
-
</div>
|
30
|
-
<% end %>
|
31
|
-
</fieldset>
|