spree_api 2.4.1 → 2.4.2

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: 3736aa7fa433082c6e7771f2e1850ff8f7e14a76
4
- data.tar.gz: 51e229c7ed5a6d30f00ad17aa48ec58d8dc8a5b8
3
+ metadata.gz: d9c508f1db57c6d3162093a618db8ae73f80889e
4
+ data.tar.gz: c2d8de75c3961ac03fbc5bb4804d62890bdff4ca
5
5
  SHA512:
6
- metadata.gz: e9d188802236b8f7c836f98df8183b028dc4de465080f0382b5119f1017bf11dd1735b43b9048773f10aea96bb95f3474ce86c93f12a736ccbb0068e597d47e2
7
- data.tar.gz: a2e7952731ee46c9896bc562d74926abeb370a80adb8f58f446a8ebfdd7d5d4dd9300e60eda4e536c22db35f844126c0921f716a5b83e0d76594c0b97d1ce165
6
+ metadata.gz: 0f2cf6539f49c45718e4af844d1f75bb92303ede18c9c829a99f87888d0cdc52993209a7cd86e624211dbffa2dc54fb4f76edd93b3d90aca42cf79882d3b9d6f
7
+ data.tar.gz: 1ba85f77edc9a122e4fdeef402ef96f9de6d936d3e58b8ebbba9b65cf755c68588cb59aea55946010480a25bdcf726adc942cc942e135b2ec57ef769045c4335
@@ -48,7 +48,7 @@ module Spree
48
48
  # users should be able to set price when importing orders via api
49
49
  def permitted_line_item_attributes
50
50
  if @current_user_roles.include?("admin")
51
- super << [:price, :variant_id, :sku]
51
+ super + [:price, :variant_id, :sku]
52
52
  else
53
53
  super
54
54
  end
@@ -1,9 +1,17 @@
1
1
  module Spree
2
2
  module Api
3
3
  class LineItemsController < Spree::Api::BaseController
4
+ class_attribute :line_item_options
5
+
6
+ self.line_item_options = []
7
+
4
8
  def create
5
9
  variant = Spree::Variant.find(params[:line_item][:variant_id])
6
- @line_item = order.contents.add(variant, params[:line_item][:quantity] || 1)
10
+ @line_item = order.contents.add(
11
+ variant,
12
+ params[:line_item][:quantity] || 1,
13
+ line_item_params[:options] || {}
14
+ )
7
15
 
8
16
  if @line_item.errors.empty?
9
17
  respond_with(@line_item, status: 201, default_template: :show)
@@ -44,12 +52,17 @@ module Spree
44
52
  def line_items_attributes
45
53
  {line_items_attributes: {
46
54
  id: params[:id],
47
- quantity: params[:line_item][:quantity]
55
+ quantity: params[:line_item][:quantity],
56
+ options: line_item_params[:options] || {}
48
57
  }}
49
58
  end
50
59
 
51
60
  def line_item_params
52
- params.require(:line_item).permit(:quantity, :variant_id)
61
+ params.require(:line_item).permit(
62
+ :quantity,
63
+ :variant_id,
64
+ options: line_item_options
65
+ )
53
66
  end
54
67
  end
55
68
  end
@@ -1,6 +1,17 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  module Spree
4
+ PermittedAttributes.module_eval do
5
+ mattr_writer :line_item_attributes
6
+ end
7
+
8
+ unless PermittedAttributes.line_item_attributes.include? :some_option
9
+ PermittedAttributes.line_item_attributes += [:some_option]
10
+ end
11
+
12
+ # This should go in an initializer
13
+ Spree::Api::LineItemsController.line_item_options += [:some_option]
14
+
4
15
  describe Api::LineItemsController, :type => :controller do
5
16
  render_views
6
17
 
@@ -48,6 +59,17 @@ module Spree
48
59
  expect(json_response["variant"]["name"]).not_to be_blank
49
60
  end
50
61
 
62
+ it "can add a new line item to an existing order with options" do
63
+ expect_any_instance_of(LineItem).to receive(:some_option=).with(4)
64
+ api_post :create,
65
+ line_item: {
66
+ variant_id: product.master.to_param,
67
+ quantity: 1,
68
+ options: { some_option: 4 }
69
+ }
70
+ expect(response.status).to eq(201)
71
+ end
72
+
51
73
  it "default quantity to 1 if none is given" do
52
74
  api_post :create, :line_item => { :variant_id => product.master.to_param }
53
75
  expect(response.status).to eq(201)
@@ -75,6 +97,15 @@ module Spree
75
97
  expect(json_response["quantity"]).to eq(101)
76
98
  end
77
99
 
100
+ it "can update a line item's options on the order" do
101
+ expect_any_instance_of(LineItem).to receive(:some_option=).with(12)
102
+ line_item = order.line_items.first
103
+ api_put :update,
104
+ id: line_item.id,
105
+ line_item: { quantity: 1, options: { some_option: 12 } }
106
+ expect(response.status).to eq(200)
107
+ end
108
+
78
109
  it "can delete a line item on the order" do
79
110
  line_item = order.line_items.first
80
111
  api_delete :destroy, :id => line_item.id
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.4.1
4
+ version: 2.4.2
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-22 00:00:00.000000000 Z
11
+ date: 2014-12-05 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.4.1
19
+ version: 2.4.2
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.4.1
26
+ version: 2.4.2
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rabl
29
29
  requirement: !ruby/object:Gem::Requirement