spree_api 2.2.4 → 2.2.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 413eb33e48024baa6bf0e9f9e774278b74ea977c
4
- data.tar.gz: be1fad955d1c3d9cdca565d3e551560974b16d7d
3
+ metadata.gz: dc3a1a431b9b8d9c5d32ba386030f0d55ea3554d
4
+ data.tar.gz: 4264b2c93575c1336f335afeceb46d5f16b5a60a
5
5
  SHA512:
6
- metadata.gz: 5f3dd086ec26934adb2b797afc20ff5b793dc3db8b0496a44bd721ce3525264854b32dbaa66353b04af087bc756e85c0cd2a745e83bea3110e25c47857ac2fda
7
- data.tar.gz: a808bada61806c4d29a075da18eb8e58ae6c9faf6524501c20274da31216ca9930c78d7bbbe9faac67bbc97c4bfb4e2b512cc4ae0f4a5e5b24c1d00e2ce7f775
6
+ metadata.gz: 58a12d74ec252e62aee0b65f79e66584057f05b65ffb72f85beb3792b7262477fff435eaf767047f04fe496c255d9ecf0430adf2ef532be961311e234cb863f2
7
+ data.tar.gz: 579e9bca1dd148464a67e49c1fbd50ae53138170b31a9e948071390094289863d0701cf47bbea56387f49edcccb9453752294ba3427a79ed25ec4c7e667afd19
data/CHANGELOG.md CHANGED
@@ -1,9 +1 @@
1
- ## Spree 2.2.2 (unreleased) ##
2
-
3
- * refactor the api to use a general importer in core gem.
4
-
5
- * Peter Berkenbosch
6
-
7
- * Allow for linking of users to orders by admins
8
-
9
- * Ryan Bigg
1
+ ## Spree 2.2.5 (unreleased) ##
@@ -129,22 +129,27 @@ module Spree
129
129
  end
130
130
 
131
131
  def product_scope
132
- variants_associations = [{ option_values: :option_type }, :default_price, :prices, :images]
133
132
  if current_api_user.has_spree_role?("admin")
134
- scope = Product.with_deleted.accessible_by(current_ability, :read)
135
- .includes(:properties, :option_types, variants: variants_associations, master: variants_associations)
133
+ scope = Product.with_deleted.accessible_by(current_ability, :read).includes(*product_includes)
136
134
 
137
135
  unless params[:show_deleted]
138
136
  scope = scope.not_deleted
139
137
  end
140
138
  else
141
- scope = Product.accessible_by(current_ability, :read).active
142
- .includes(:properties, :option_types, variants: variants_associations, master: variants_associations)
139
+ scope = Product.accessible_by(current_ability, :read).active.includes(*product_includes)
143
140
  end
144
141
 
145
142
  scope
146
143
  end
147
144
 
145
+ def variants_associations
146
+ [{ option_values: :option_type }, :default_price, :images]
147
+ end
148
+
149
+ def product_includes
150
+ [ :option_types, variants: variants_associations, master: variants_associations ]
151
+ end
152
+
148
153
  def order_id
149
154
  params[:order_id] || params[:checkout_id] || params[:order_number]
150
155
  end
@@ -62,7 +62,7 @@ module Spree
62
62
  if object_params[:payments_attributes].is_a?(Hash)
63
63
  object_params[:payments_attributes] = [object_params[:payments_attributes]]
64
64
  end
65
- if object_params[:payment_source].present? && source_params = object_params.delete(:payment_source)[object_params[:payments_attributes].first[:payment_method_id]]
65
+ if object_params[:payment_source].present? && source_params = object_params.delete(:payment_source)[object_params[:payments_attributes].first[:payment_method_id].to_s]
66
66
  object_params[:payments_attributes].first[:source_attributes] = source_params
67
67
  end
68
68
  if object_params[:payments_attributes]
@@ -5,6 +5,7 @@ module Spree
5
5
 
6
6
  def show
7
7
  @inventory_unit = inventory_unit
8
+ respond_with(@inventory_unit)
8
9
  end
9
10
 
10
11
  def update
@@ -4,9 +4,8 @@ module Spree
4
4
 
5
5
  def create
6
6
  variant = Spree::Variant.find(params[:line_item][:variant_id])
7
- @line_item = order.contents.add(variant, params[:line_item][:quantity])
8
- if @line_item.save
9
- @order.ensure_updated_shipments
7
+ @line_item = order.contents.add(variant, params[:line_item][:quantity] || 1)
8
+ if @line_item.errors.empty?
10
9
  respond_with(@line_item, status: 201, default_template: :show)
11
10
  else
12
11
  invalid_resource!(@line_item)
@@ -28,7 +27,6 @@ module Spree
28
27
  @line_item = find_line_item
29
28
  variant = Spree::Variant.find(@line_item.variant_id)
30
29
  @order.contents.remove(variant, @line_item.quantity)
31
- @order.ensure_updated_shipments
32
30
  respond_with(@line_item, status: 204)
33
31
  end
34
32
 
@@ -1,6 +1,7 @@
1
1
  module Spree
2
2
  module Api
3
3
  class OrdersController < Spree::Api::BaseController
4
+ wrap_parameters false
4
5
 
5
6
  skip_before_filter :check_for_user_or_api_key, only: :apply_coupon_code
6
7
  skip_before_filter :authenticate_user, only: :apply_coupon_code
@@ -17,7 +18,7 @@ module Spree
17
18
  find_order
18
19
  authorize! :update, @order, params[:token]
19
20
  @order.cancel!
20
- render :show
21
+ respond_with(@order, :default_template => :show)
21
22
  end
22
23
 
23
24
  def create
@@ -69,7 +70,7 @@ module Spree
69
70
 
70
71
  def mine
71
72
  if current_api_user.persisted?
72
- @orders = current_api_user.orders.ransack(params[:q]).result.page(params[:page]).per(params[:per_page])
73
+ @orders = current_api_user.orders.reverse_chronological.ransack(params[:q]).result.page(params[:page]).per(params[:per_page])
73
74
  else
74
75
  render "spree/api/errors/unauthorized", status: :unauthorized
75
76
  end
@@ -11,7 +11,7 @@ module Spree
11
11
  end
12
12
 
13
13
  def new
14
- @payment_methods = Spree::PaymentMethod.where(environment: Rails.env)
14
+ @payment_methods = Spree::PaymentMethod.available
15
15
  respond_with(@payment_method)
16
16
  end
17
17
 
@@ -12,6 +12,7 @@ module Spree
12
12
  @products = @products.distinct.page(params[:page]).per(params[:per_page])
13
13
  expires_in 15.minutes, :public => true
14
14
  headers['Surrogate-Control'] = "max-age=#{15.minutes}"
15
+ respond_with(@products)
15
16
  end
16
17
 
17
18
  def show
@@ -19,6 +20,7 @@ module Spree
19
20
  expires_in 15.minutes, :public => true
20
21
  headers['Surrogate-Control'] = "max-age=#{15.minutes}"
21
22
  headers['Surrogate-Key'] = "product_id=1"
23
+ respond_with(@product)
22
24
  end
23
25
 
24
26
  # Takes besides the products attributes either an array of variants or
@@ -17,7 +17,6 @@ module Spree
17
17
  @shipment = @order.shipments.create(stock_location_id: params[:stock_location_id])
18
18
  @order.contents.add(variant, quantity, nil, @shipment)
19
19
 
20
- @shipment.refresh_rates
21
20
  @shipment.save!
22
21
 
23
22
  respond_with(@shipment.reload, default_template: :show)
@@ -30,10 +29,8 @@ module Spree
30
29
  @shipment = Spree::Shipment.accessible_by(current_ability, :update).readonly(false).find_by!(number: params[:id])
31
30
  end
32
31
 
33
- @shipment.update_attributes(shipment_params)
34
-
35
- @shipment.reload
36
- respond_with(@shipment, default_template: :show)
32
+ @shipment.update_attributes_and_order(shipment_params)
33
+ respond_with(@shipment.reload, default_template: :show)
37
34
  end
38
35
 
39
36
  def ready
@@ -71,7 +71,7 @@ describe Spree::Api::BaseController do
71
71
  json_response.should == { "exception" => "no joy" }
72
72
  end
73
73
 
74
- it "maps symantec keys to nested_attributes keys" do
74
+ it "maps semantic keys to nested_attributes keys" do
75
75
  klass = double(:nested_attributes_options => { :line_items => {},
76
76
  :bill_address => {} })
77
77
  attributes = { 'line_items' => { :id => 1 },
@@ -82,4 +82,8 @@ describe Spree::Api::BaseController do
82
82
  mapped.has_key?('line_items_attributes').should be_true
83
83
  mapped.has_key?('name').should be_true
84
84
  end
85
+
86
+ it "lets a subclass override the product associations that are eager-loaded" do
87
+ controller.respond_to?(:product_includes, true).should be
88
+ end
85
89
  end
@@ -75,6 +75,18 @@ module Spree
75
75
  response.status.should == 200
76
76
  json_response["orders"].length.should == 0
77
77
  end
78
+
79
+ it "returns orders in reverse chronological order" do
80
+ order2 = create(:order, line_items: [line_item], user: order.user)
81
+ order2.created_at.should > order.created_at
82
+
83
+ api_get :mine
84
+ response.status.should == 200
85
+ json_response["pages"].should == 1
86
+ json_response["orders"].length.should == 2
87
+ json_response["orders"][0]["number"].should == order2.number
88
+ json_response["orders"][1]["number"].should == order.number
89
+ end
78
90
  end
79
91
 
80
92
  it "can view their own order" do
@@ -67,6 +67,34 @@ module Spree
67
67
  json_response["per_page"].should == Kaminari.config.default_per_page
68
68
  end
69
69
 
70
+ context "specifying a rabl template for a custom action" do
71
+ before do
72
+ Spree::Api::ProductsController.class_eval do
73
+ def custom_show
74
+ @product = find_product(params[:id])
75
+ respond_with(@product)
76
+ end
77
+ end
78
+ end
79
+
80
+ it "uses the specified custom template through the request header" do
81
+ request.headers['X-Spree-Template'] = 'show'
82
+ api_get :custom_show, :id => product.id
83
+ response.should render_template('spree/api/products/show')
84
+ end
85
+
86
+ it "uses the specified custom template through the template URL parameter" do
87
+ api_get :custom_show, :id => product.id, :template => 'show'
88
+ response.should render_template('spree/api/products/show')
89
+ end
90
+
91
+ it "falls back to the default template if the specified template does not exist" do
92
+ request.headers['X-Spree-Template'] = 'invoice'
93
+ api_get :show, :id => product.id
94
+ response.should render_template('spree/api/products/show')
95
+ end
96
+ end
97
+
70
98
  context "product has more than one price" do
71
99
  before { product.master.prices.create currency: "EUR", amount: 22 }
72
100
 
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
4
+ version: 2.2.5
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-07-01 00:00:00.000000000 Z
11
+ date: 2014-08-29 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.4
19
+ version: 2.2.5
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.4
26
+ version: 2.2.5
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rabl
29
29
  requirement: !ruby/object:Gem::Requirement