spree_api 2.0.6 → 2.0.7

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9cb2106c19046c8db51461b87b224d461e21fec1
4
- data.tar.gz: e6acefe01a95c4b55e83b2ea0d651d7c205cf30f
3
+ metadata.gz: 31009b464b6105afeae033af555ebf099230ff51
4
+ data.tar.gz: 9a6294c2ddcfa6044efede92b4821544acfbf82e
5
5
  SHA512:
6
- metadata.gz: f93f7762a47e706f13da9958f4d3993c9a69662cace7a8f68e3b47ee066e3df5a054309265d9a11bd59db7a5bb0c6df1cce8c3e5562617921317cc618b616578
7
- data.tar.gz: 5da0e8c9a2b8960985e22049190a677d7415bbedf3e03d29b47a66a68c7707152df13a5336fa2433628d10337078f6a647893ec19c28f260defa7c10387710ef
6
+ metadata.gz: e8bccb730f13c6867b1e46a175b52edfb128445f0c81aaa25580eb4d08781d0b63102cd179854d22c5017dc8ef4536a3f869aac7614e5048ff801d2688e759a8
7
+ data.tar.gz: 9b2e19265e60d63e04a3ff1380955cebd8c751eed12ce4ab4e34afafa62de307b17e8de50eb3c34942afd4321bad45f4eb78666974c8d7bd6bea0d87c527c5d0
data/CHANGELOG.md CHANGED
@@ -1,49 +1,17 @@
1
- ## Spree 2.0.6 ##
1
+ ## Spree 2.0.7 (unreleased) ##
2
2
 
3
- * Normal users can no longer read stock item, stock location or stock movements API endpoints.
3
+ *For all commits, please see [the GitHub compare view](https://github.com/spree/spree/compare/v2.0.6...v2.0.7).*
4
4
 
5
- *Ryan Bigg*
6
-
7
- ## Spree 2.0.x ##
5
+ * Admin users can set the order channel when importing orders. By sing the
6
+ channel attribute on Order model
8
7
 
9
- * PUT requests to Checkouts API endpoints now require authorization to alter an order.
8
+ Washington Luiz
10
9
 
11
- *Ryan Bigg*
10
+ * Added missing per_page node to products/index
12
11
 
13
- * The Products API endpoint now returns an additional key called `shipping_category_id`, and also requires `shipping_category_id` on create.
12
+ Ryan Bigg
14
13
 
15
- *Jeff Dutil*
14
+ * `ship_total` is now returned on order results.
16
15
 
17
- * Checkouts API's update action will now correctly process line item attributes (either `line_items` or `line_item_attributes`)
18
-
19
- * Ryan Bigg*
20
-
21
- * Checkouts API now correctly processes incoming payment data during the payment step.
22
-
23
- *Ryan Bigg*
24
-
25
- * Fix issue where `set_current_order` before filter would be called when CheckoutsController actions were run, causing the order object to be deleted. #3306
26
-
27
- *Ryan Bigg*
28
-
29
- * An order can no longer transition past the "cart" state without first having a line item. #3312
30
-
31
- *Ryan Bigg*
32
-
33
- * Attributes other than "quantity" and "variant_id" will be added to a line item when creating along with an order. #3404
34
-
35
- *Alex Marles & Ryan Bigg*
36
-
37
- * Taxon attributes from `/api/taxons` are now returned within `taxons` subkey. Before:
38
-
39
- ```json
40
- [{ name: 'Ruby' ... }]
41
- ```
42
-
43
- Now:
44
-
45
- ```json
46
- { taxons: [{ name: 'Ruby' }]}
47
- ```
48
-
49
- * Ryan Bigg
16
+ Washington Luiz
17
+
@@ -7,6 +7,7 @@ module Spree
7
7
  authorize! :read, order
8
8
  @line_item = order.line_items.build(params[:line_item], :as => :api)
9
9
  if @line_item.save
10
+ @order.ensure_updated_shipments
10
11
  respond_with(@line_item, :status => 201, :default_template => :show)
11
12
  else
12
13
  invalid_resource!(@line_item)
@@ -17,6 +18,7 @@ module Spree
17
18
  authorize! :read, order
18
19
  @line_item = order.line_items.find(params[:id])
19
20
  if @line_item.update_attributes(params[:line_item], :as => :api)
21
+ @order.ensure_updated_shipments
20
22
  respond_with(@line_item, :default_template => :show)
21
23
  else
22
24
  invalid_resource!(@line_item)
@@ -58,6 +58,8 @@ module Spree
58
58
  def sanitize_line_items(line_item_attributes)
59
59
  return {} if line_item_attributes.blank?
60
60
  line_item_attributes = line_item_attributes.map do |id, attributes|
61
+ attributes ||= id
62
+
61
63
  # Faux Strong-Parameters code to strip price if user isn't an admin
62
64
  if current_api_user.has_spree_role?("admin")
63
65
  [id, attributes.slice(*Spree::LineItem.attr_accessible[:api])]
@@ -5,7 +5,7 @@ module Spree
5
5
 
6
6
  def index
7
7
  if params[:ids]
8
- @products = product_scope.where(:id => params[:ids])
8
+ @products = product_scope.where(:id => params[:ids].split(","))
9
9
  else
10
10
  @products = product_scope.ransack(params[:q]).result
11
11
  end
@@ -32,7 +32,7 @@ module Spree
32
32
  end
33
33
 
34
34
  def order_attributes
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, :token]
35
+ [:id, :number, :item_total, :total, :ship_total, :state, :adjustment_total, :user_id, :created_at, :updated_at, :completed_at, :payment_total, :shipment_state, :payment_state, :email, :special_instructions, :token, :channel]
36
36
  end
37
37
 
38
38
  def line_item_attributes
@@ -60,7 +60,7 @@ module Spree
60
60
  end
61
61
 
62
62
  def taxon_attributes
63
- [:id, :name, :pretty_name, :permalink, :position, :parent_id, :taxonomy_id]
63
+ [:id, :name, :pretty_name, :permalink, :parent_id, :taxonomy_id]
64
64
  end
65
65
 
66
66
  def inventory_unit_attributes
@@ -1,3 +1,3 @@
1
1
  Spree::LineItem.class_eval do
2
- attr_accessible :quantity, :variant_id, :price, :as => :api
2
+ attr_accessible :quantity, :variant_id, :price, :sku, :as => :api
3
3
  end
@@ -1,4 +1,6 @@
1
1
  Spree::Order.class_eval do
2
+ attr_accessible :channel, :as => :api_admin
3
+
2
4
  def self.build_from_api(user, params)
3
5
  begin
4
6
  ensure_country_id_from_api params[:ship_address_attributes]
@@ -16,7 +18,12 @@ Spree::Order.class_eval do
16
18
  order.complete_from_api params.delete(:completed_at)
17
19
 
18
20
  destroy_automatic_taxes_on_import(order, params)
19
- order.update_attributes!(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
20
27
 
21
28
  order.reload
22
29
  rescue Exception => e
@@ -153,7 +160,13 @@ Spree::Order.class_eval do
153
160
  end
154
161
 
155
162
  address.delete(:state)
156
- address[:state_id] = Spree::State.where(search).first!.id
163
+ search[:country_id] = address[:country_id]
164
+
165
+ if state = Spree::State.where(search).first
166
+ address[:state_id] = state.id
167
+ else
168
+ address[:state_name] = search[:name] || search[:abbr]
169
+ end
157
170
  rescue Exception => e
158
171
  raise "#{e.message} #{search}"
159
172
  end
@@ -3,6 +3,7 @@ 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
5
  node(:pages) { @products.num_pages }
6
+ node(:per_page) { params[:per_page] || Kaminari.config.default_per_page }
6
7
  child(@products) do
7
8
  extends "spree/api/products/show"
8
9
  end
@@ -0,0 +1,7 @@
1
+ class AddIndexToUserSpreeApiKey < ActiveRecord::Migration
2
+ def change
3
+ unless defined?(User)
4
+ add_index :spree_users, :spree_api_key
5
+ end
6
+ end
7
+ end
@@ -46,6 +46,25 @@ module Spree
46
46
  response.status.should == 204
47
47
  lambda { line_item.reload }.should raise_error(ActiveRecord::RecordNotFound)
48
48
  end
49
+
50
+ context "order contents changed after shipments were created" do
51
+ let!(:order) { Order.create }
52
+ let!(:line_item) { order.contents.add(product.master) }
53
+
54
+ before { order.create_proposed_shipments }
55
+
56
+ it "clear out shipments on create" do
57
+ expect(order.reload.shipments).not_to be_empty
58
+ api_post :create, :line_item => { :variant_id => product.master.to_param, :quantity => 1 }
59
+ expect(order.reload.shipments).to be_empty
60
+ end
61
+
62
+ it "clear out shipments on update" do
63
+ expect(order.reload.shipments).not_to be_empty
64
+ api_put :update, :id => line_item.id, :line_item => { :quantity => 1000 }
65
+ expect(order.reload.shipments).to be_empty
66
+ end
67
+ end
49
68
  end
50
69
 
51
70
  context "as just another user" do
@@ -68,6 +87,5 @@ module Spree
68
87
  lambda { line_item.reload }.should_not raise_error
69
88
  end
70
89
  end
71
-
72
90
  end
73
91
  end
@@ -11,10 +11,9 @@ module Spree
11
11
  :completed_at, :payment_total, :shipment_state,
12
12
  :payment_state, :email, :special_instructions, :token] }
13
13
 
14
+ let(:variant) { create(:variant) }
14
15
 
15
- before do
16
- stub_authentication!
17
- end
16
+ before { stub_authentication! }
18
17
 
19
18
  it "cannot view all orders" do
20
19
  api_get :index
@@ -76,6 +75,50 @@ module Spree
76
75
  json_response["user_id"].should == current_api_user.id
77
76
  end
78
77
 
78
+ context "import" do
79
+ let(:tax_rate) { create(:tax_rate, amount: 0.05, calculator: Calculator::DefaultTax.create) }
80
+ let(:other_variant) { create(:variant) }
81
+
82
+ # line items come in as an array when importing orders or when
83
+ # creating both an order an a line item at once
84
+ let(:order_params) do
85
+ {
86
+ :line_items => [
87
+ { :variant_id => variant.to_param, :quantity => 5 },
88
+ { :variant_id => other_variant.to_param, :quantity => 5 }
89
+ ]
90
+ }
91
+ end
92
+
93
+ before do
94
+ Zone.stub default_tax: tax_rate.zone
95
+ current_api_user.stub has_spree_role?: true
96
+ end
97
+
98
+ it "sets channel" do
99
+ api_post :create, :order => { channel: "amazon" }
100
+ expect(json_response['channel']).to eq "amazon"
101
+ end
102
+
103
+ it "doesnt persist any automatic tax adjustment" do
104
+ expect {
105
+ api_post :create, :order => order_params.merge(:import => true)
106
+ }.not_to change { Adjustment.count }
107
+ expect(response.status).to eq 201
108
+ end
109
+
110
+ context "provides sku rather than variant id" do
111
+ let(:order_params) do
112
+ { :line_items => [{ :sku => variant.sku, :quantity => 1 }] }
113
+ end
114
+
115
+ it "still finds the variant by sku and persist order" do
116
+ api_post :create, :order => order_params
117
+ expect(json_response['line_items'].count).to eq 1
118
+ end
119
+ end
120
+ end
121
+
79
122
  it "cannot create an order with an abitrary price for the line item" do
80
123
  variant = create(:variant)
81
124
  api_post :create, :order => {
@@ -104,8 +147,6 @@ module Spree
104
147
  end
105
148
 
106
149
  context "working with an order" do
107
-
108
- let(:variant) { create(:variant) }
109
150
  let!(:line_item) { order.contents.add(variant, 1) }
110
151
  let!(:payment_method) { create(:payment_method) }
111
152
 
@@ -254,6 +295,14 @@ module Spree
254
295
  end
255
296
  end
256
297
 
298
+ it "responds with orders updated_at with miliseconds precision" do
299
+ api_get :index
300
+ milisecond = order.updated_at.strftime("%L")
301
+ updated_at = json_response["orders"].first["updated_at"]
302
+
303
+ expect(updated_at.split("T").last).to have_content(milisecond)
304
+ end
305
+
257
306
  context "with two orders" do
258
307
  before { create(:order) }
259
308
 
@@ -30,6 +30,17 @@ module Spree
30
30
  json_response["pages"].should == 1
31
31
  end
32
32
 
33
+ it "retrieves a list of products by ids string" do
34
+ second_product = create(:product)
35
+ api_get :index, :ids => [product.id, second_product.id].join(",")
36
+ json_response["products"].first.should have_attributes(attributes)
37
+ json_response["products"][1].should have_attributes(attributes)
38
+ json_response["total_count"].should == 2
39
+ json_response["current_page"].should == 1
40
+ json_response["pages"].should == 1
41
+ json_response["per_page"].should == Kaminari.config.default_per_page
42
+ end
43
+
33
44
  it "does not return inactive products when queried by ids" do
34
45
  api_get :index, :ids => [inactive_product.id]
35
46
  json_response["count"].should == 0
@@ -7,7 +7,7 @@ module Spree
7
7
  let(:taxonomy) { create(:taxonomy) }
8
8
  let(:taxon) { create(:taxon, :name => "Ruby", :taxonomy => taxonomy) }
9
9
  let(:taxon2) { create(:taxon, :name => "Rails", :taxonomy => taxonomy) }
10
- let(:attributes) { ["id", "name", "pretty_name", "permalink", "position", "parent_id", "taxonomy_id"] }
10
+ let(:attributes) { ["id", "name", "pretty_name", "permalink", "parent_id", "taxonomy_id"] }
11
11
 
12
12
  before do
13
13
  stub_authentication!
@@ -105,9 +105,10 @@ module Spree
105
105
  response.status.should == 201
106
106
 
107
107
  taxonomy.reload.root.children.count.should eq 2
108
+ taxon = Spree::Taxon.where(:name => 'Colors').first
108
109
 
109
- Spree::Taxon.last.parent_id.should eq taxonomy.root.id
110
- Spree::Taxon.last.taxonomy_id.should eq taxonomy.id
110
+ taxon.parent_id.should eq taxonomy.root.id
111
+ taxon.taxonomy_id.should eq taxonomy.id
111
112
  end
112
113
 
113
114
  it "cannot create a new taxon with invalid attributes" do
@@ -130,7 +130,7 @@ module Spree
130
130
 
131
131
  it 'can build an order from API with state attributes' do
132
132
  ship_address.delete(:state_id)
133
- ship_address[:state] = { 'name' => 'Alabama' }
133
+ ship_address[:state] = { 'name' => state.name }
134
134
  params = { :ship_address_attributes => ship_address,
135
135
  :line_items_attributes => line_items }
136
136
 
@@ -138,15 +138,33 @@ module Spree
138
138
  order.ship_address.state.name.should eq 'Alabama'
139
139
  end
140
140
 
141
- it 'handles state lookup exceptions' do
141
+ context "state passed is not associated with country" do
142
+ let(:params) do
143
+ params = { :ship_address_attributes => ship_address,
144
+ :line_items_attributes => line_items }
145
+ end
146
+
147
+ let(:other_state) { create(:state, name: "Uhuhuh", country: create(:country)) }
148
+
149
+ before do
150
+ ship_address.delete(:state_id)
151
+ ship_address[:state] = { 'name' => other_state.name }
152
+ end
153
+
154
+ it 'sets states name instead of state id' do
155
+ order = Order.build_from_api(user, params)
156
+ expect(order.ship_address.state_name).to eq other_state.name
157
+ end
158
+ end
159
+
160
+ it 'sets state name if state record not found' do
142
161
  ship_address.delete(:state_id)
143
162
  ship_address[:state] = { 'name' => 'XXX' }
144
163
  params = { :ship_address_attributes => ship_address,
145
164
  :line_items_attributes => line_items }
146
165
 
147
- expect {
148
- order = Order.build_from_api(user, params)
149
- }.to raise_error /XXX/
166
+ order = Order.build_from_api(user, params)
167
+ expect(order.ship_address.state_name).to eq 'XXX'
150
168
  end
151
169
 
152
170
  context 'variant not deleted' do
@@ -184,19 +202,12 @@ module Spree
184
202
 
185
203
  it 'ensures_state_id for state fields' do
186
204
  [:name, :abbr].each do |field|
187
- address = { :state => { field => state.send(field) }}
205
+ address = { country_id: country.id, :state => { field => state.send(field) }}
188
206
  Order.ensure_state_id_from_api(address)
189
207
  address[:state_id].should eq state.id
190
208
  end
191
209
  end
192
210
 
193
- it "raises with proper message when cant find state" do
194
- address = { :state => { "name" => "NoNoState" } }
195
- expect {
196
- Order.ensure_state_id_from_api(address)
197
- }.to raise_error /NoNoState/
198
- end
199
-
200
211
  context "shippments" do
201
212
  let(:params) do
202
213
  { :shipments_attributes => [
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.0.6
4
+ version: 2.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Bigg
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-10-15 00:00:00.000000000 Z
11
+ date: 2013-11-19 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.0.6
19
+ version: 2.0.7
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.0.6
26
+ version: 2.0.7
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rabl
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -181,6 +181,7 @@ files:
181
181
  - db/migrate/20100107141738_add_api_key_to_spree_users.rb
182
182
  - db/migrate/20120411123334_resize_api_key_field.rb
183
183
  - db/migrate/20120530054546_rename_api_key_to_spree_api_key.rb
184
+ - db/migrate/20131017162334_add_index_to_user_spree_api_key.rb
184
185
  - lib/spree/api.rb
185
186
  - lib/spree/api/controller_setup.rb
186
187
  - lib/spree/api/engine.rb