spree_api 2.4.6 → 2.4.7

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: a1355738b99bc466e3299757f7f4d293a08ad45c
4
- data.tar.gz: 9a81176332680c7c6802b11c395cd6c944a335c9
3
+ metadata.gz: 99560ebdaf455a59e76c64abf84ae1d2da1adb30
4
+ data.tar.gz: e9d198bf6d7a8a2131a7db49d55c61ae4d231b63
5
5
  SHA512:
6
- metadata.gz: 576d4ca00833617cf383fa6c2c9ef25f5d0f82a1f3c20cbf53e2270c980dbb23aa390fa38b2945acb1aa109e9da1a1599b847fd5a39e417a746f4f8a2869276d
7
- data.tar.gz: ede324c67a8f201a77f43a12b5321fae1a8a8bd72342564ef9e3cd37313c2f74bff53b6a1be2c437c50bc2c86f1d4942ed6334224bddd02054f9b1f2efccb2e9
6
+ metadata.gz: 94c7b6c9613e7ee865c0cc6cc0e0b761d4b077b76d7013677dacab09b032b15dccabdb3b1cb8d746557f6b66c82864bfcfedd688848c7a16da50c94a99375ba5
7
+ data.tar.gz: 1f4b86560857b5170b7566f641ace8b91d58f367d23dcc5bb4dfe8db02de637b19191825f3722ee378c96e02e53279e054d2f054fda207bb072f635acc070466
@@ -52,7 +52,7 @@ module Spree
52
52
  end
53
53
 
54
54
  def nested_params
55
- map_nested_attributes_keys Order, params[:order] || {}
55
+ map_nested_attributes_keys Spree::Order, params[:order] || {}
56
56
  end
57
57
 
58
58
  # Should be overriden if you have areas of your checkout that don't match
@@ -79,7 +79,7 @@ module Spree
79
79
 
80
80
  def after_update_attributes
81
81
  if nested_params && nested_params[:coupon_code].present?
82
- handler = PromotionHandler::Coupon.new(@order).apply
82
+ handler = Spree::PromotionHandler::Coupon.new(@order).apply
83
83
 
84
84
  if handler.error.present?
85
85
  @coupon_message = handler.error
@@ -5,17 +5,17 @@ module Spree
5
5
  skip_before_action :authenticate_user
6
6
 
7
7
  def index
8
- @countries = Country.accessible_by(current_ability, :read).ransack(params[:q]).result.
8
+ @countries = Spree::Country.accessible_by(current_ability, :read).ransack(params[:q]).result.
9
9
  includes(:states).order('name ASC').
10
10
  page(params[:page]).per(params[:per_page])
11
- country = Country.order("updated_at ASC").last
11
+ country = Spree::Country.order("updated_at ASC").last
12
12
  if stale?(country)
13
13
  respond_with(@countries)
14
14
  end
15
15
  end
16
16
 
17
17
  def show
18
- @country = Country.accessible_by(current_ability, :read).find(params[:id])
18
+ @country = Spree::Country.accessible_by(current_ability, :read).find(params[:id])
19
19
  respond_with(@country)
20
20
  end
21
21
  end
@@ -8,12 +8,12 @@ module Spree
8
8
  end
9
9
 
10
10
  def show
11
- @image = Image.accessible_by(current_ability, :read).find(params[:id])
11
+ @image = Spree::Image.accessible_by(current_ability, :read).find(params[:id])
12
12
  respond_with(@image)
13
13
  end
14
14
 
15
15
  def create
16
- authorize! :create, Image
16
+ authorize! :create, Spree::Image
17
17
  @image = scope.images.create(image_params)
18
18
  respond_with(@image, :status => 201, :default_template => :show)
19
19
  end
@@ -24,7 +24,7 @@ module Spree
24
24
  private
25
25
 
26
26
  def inventory_unit
27
- @inventory_unit ||= InventoryUnit.accessible_by(current_ability, :read).find(params[:id])
27
+ @inventory_unit ||= Spree::InventoryUnit.accessible_by(current_ability, :read).find(params[:id])
28
28
  end
29
29
 
30
30
  def prepare_event
@@ -7,7 +7,7 @@ module Spree
7
7
  before_action :find_order, except: [:create, :mine, :current, :index, :update]
8
8
 
9
9
  # Dynamically defines our stores checkout steps to ensure we check authorization on each step.
10
- Order.checkout_steps.keys.each do |step|
10
+ Spree::Order.checkout_steps.keys.each do |step|
11
11
  define_method step do
12
12
  find_order
13
13
  authorize! :update, @order, params[:token]
@@ -21,7 +21,7 @@ module Spree
21
21
  end
22
22
 
23
23
  def create
24
- authorize! :create, Order
24
+ authorize! :create, Spree::Order
25
25
  order_user = if @current_user_roles.include?('admin') && order_params[:user_id]
26
26
  Spree.user_class.find(order_params[:user_id])
27
27
  else
@@ -46,7 +46,7 @@ module Spree
46
46
 
47
47
  def index
48
48
  authorize! :index, Order
49
- @orders = Order.ransack(params[:q]).result.page(params[:page]).per(params[:per_page])
49
+ @orders = Spree::Order.ransack(params[:q]).result.page(params[:page]).per(params[:per_page])
50
50
  respond_with(@orders)
51
51
  end
52
52
 
@@ -99,7 +99,7 @@ module Spree
99
99
  find_order
100
100
  authorize! :update, @order, order_token
101
101
  @order.coupon_code = params[:coupon_code]
102
- @handler = PromotionHandler::Coupon.new(@order).apply
102
+ @handler = Spree::PromotionHandler::Coupon.new(@order).apply
103
103
  status = @handler.successful? ? 200 : 422
104
104
  render "spree/api/promotions/handler", :status => status
105
105
  end
@@ -67,7 +67,7 @@ module Spree
67
67
  end
68
68
 
69
69
  def perform_payment_action(action, *args)
70
- authorize! action, Payment
70
+ authorize! action, Spree::Payment
71
71
  @payment.send("#{action}!", *args)
72
72
  respond_with(@payment, default_template: :show)
73
73
  end
@@ -20,7 +20,7 @@ module Spree
20
20
  end
21
21
 
22
22
  def create
23
- authorize! :create, ProductProperty
23
+ authorize! :create, Spree::ProductProperty
24
24
  @product_property = @product.product_properties.new(product_property_params)
25
25
  if @product_property.save
26
26
  respond_with(@product_property, status: 201, default_template: :show)
@@ -57,12 +57,12 @@ module Spree
57
57
  # }
58
58
  #
59
59
  def create
60
- authorize! :create, Product
60
+ authorize! :create, Spree::Product
61
61
  params[:product][:available_on] ||= Time.now
62
62
  set_up_shipping_category
63
63
 
64
64
  options = { variants_attrs: variants_params, options_attrs: option_types_params }
65
- @product = Core::Importer::Product.new(nil, product_params, options).create
65
+ @product = Spree::Core::Importer::Product.new(nil, product_params, options).create
66
66
 
67
67
  if @product.persisted?
68
68
  respond_with(@product, :status => 201, :default_template => :show)
@@ -76,7 +76,7 @@ module Spree
76
76
  authorize! :update, @product
77
77
 
78
78
  options = { variants_attrs: variants_params, options_attrs: option_types_params }
79
- @product = Core::Importer::Product.new(@product, product_params, options).update
79
+ @product = Spree::Core::Importer::Product.new(@product, product_params, options).update
80
80
 
81
81
  if @product.errors.empty?
82
82
  respond_with(@product.reload, :status => 200, :default_template => :show)
@@ -119,7 +119,7 @@ module Spree
119
119
 
120
120
  def set_up_shipping_category
121
121
  if shipping_category = params[:product].delete(:shipping_category)
122
- id = ShippingCategory.find_or_create_by(name: shipping_category).id
122
+ id = Spree::ShippingCategory.find_or_create_by(name: shipping_category).id
123
123
  params[:product][:shipping_category_id] = id
124
124
  end
125
125
  end
@@ -25,7 +25,7 @@ module Spree
25
25
  end
26
26
 
27
27
  def create
28
- authorize! :create, Property
28
+ authorize! :create, Spree::Property
29
29
  @property = Spree::Property.new(property_params)
30
30
  if @property.save
31
31
  respond_with(@property, status: 201, default_template: :show)
@@ -3,7 +3,7 @@ module Spree
3
3
  class ReturnAuthorizationsController < Spree::Api::BaseController
4
4
 
5
5
  def create
6
- authorize! :create, ReturnAuthorization
6
+ authorize! :create, Spree::ReturnAuthorization
7
7
  @return_authorization = order.return_authorizations.build(return_authorization_params)
8
8
  if @return_authorization.save
9
9
  respond_with(@return_authorization, status: 201, default_template: :show)
@@ -19,7 +19,7 @@ module Spree
19
19
  end
20
20
 
21
21
  def index
22
- authorize! :admin, ReturnAuthorization
22
+ authorize! :admin, Spree::ReturnAuthorization
23
23
  @return_authorizations = order.return_authorizations.accessible_by(current_ability, :read).
24
24
  ransack(params[:q]).result.
25
25
  page(params[:page]).per(params[:per_page])
@@ -27,11 +27,11 @@ module Spree
27
27
  end
28
28
 
29
29
  def new
30
- authorize! :admin, ReturnAuthorization
30
+ authorize! :admin, Spree::ReturnAuthorization
31
31
  end
32
32
 
33
33
  def show
34
- authorize! :admin, ReturnAuthorization
34
+ authorize! :admin, Spree::ReturnAuthorization
35
35
  @return_authorization = order.return_authorizations.accessible_by(current_ability, :read).find(params[:id])
36
36
  respond_with(@return_authorization)
37
37
  end
@@ -27,10 +27,10 @@ module Spree
27
27
  private
28
28
  def scope
29
29
  if params[:country_id]
30
- @country = Country.accessible_by(current_ability, :read).find(params[:country_id])
30
+ @country = Spree::Country.accessible_by(current_ability, :read).find(params[:country_id])
31
31
  return @country.states.accessible_by(current_ability, :read)
32
32
  else
33
- return State.accessible_by(current_ability, :read)
33
+ return Spree::State.accessible_by(current_ability, :read)
34
34
  end
35
35
  end
36
36
  end
@@ -14,7 +14,7 @@ module Spree
14
14
  end
15
15
 
16
16
  def create
17
- authorize! :create, StockItem
17
+ authorize! :create, Spree::StockItem
18
18
 
19
19
  count_on_hand = 0
20
20
  if params[:stock_item].has_key?(:count_on_hand)
@@ -31,7 +31,7 @@ module Spree
31
31
  end
32
32
 
33
33
  def update
34
- @stock_item = StockItem.accessible_by(current_ability, :update).find(params[:id])
34
+ @stock_item = Spree::StockItem.accessible_by(current_ability, :update).find(params[:id])
35
35
 
36
36
  count_on_hand = 0
37
37
  if params[:stock_item].has_key?(:count_on_hand)
@@ -50,7 +50,7 @@ module Spree
50
50
  end
51
51
 
52
52
  def destroy
53
- @stock_item = StockItem.accessible_by(current_ability, :destroy).find(params[:id])
53
+ @stock_item = Spree::StockItem.accessible_by(current_ability, :destroy).find(params[:id])
54
54
  @stock_item.destroy
55
55
  respond_with(@stock_item, status: 204)
56
56
  end
@@ -59,7 +59,7 @@ module Spree
59
59
 
60
60
  def stock_location
61
61
  render 'spree/api/shared/stock_location_required', status: 422 and return unless params[:stock_location_id]
62
- @stock_location ||= StockLocation.accessible_by(current_ability, :read).find(params[:stock_location_id])
62
+ @stock_location ||= Spree::StockLocation.accessible_by(current_ability, :read).find(params[:stock_location_id])
63
63
  end
64
64
 
65
65
  def scope
@@ -2,8 +2,8 @@ module Spree
2
2
  module Api
3
3
  class StockLocationsController < Spree::Api::BaseController
4
4
  def index
5
- authorize! :read, StockLocation
6
- @stock_locations = StockLocation.accessible_by(current_ability, :read).order('name ASC').ransack(params[:q]).result.page(params[:page]).per(params[:per_page])
5
+ authorize! :read, Spree::StockLocation
6
+ @stock_locations = Spree::StockLocation.accessible_by(current_ability, :read).order('name ASC').ransack(params[:q]).result.page(params[:page]).per(params[:per_page])
7
7
  respond_with(@stock_locations)
8
8
  end
9
9
 
@@ -12,8 +12,8 @@ module Spree
12
12
  end
13
13
 
14
14
  def create
15
- authorize! :create, StockLocation
16
- @stock_location = StockLocation.new(stock_location_params)
15
+ authorize! :create, Spree::StockLocation
16
+ @stock_location = Spree::StockLocation.new(stock_location_params)
17
17
  if @stock_location.save
18
18
  respond_with(@stock_location, status: 201, default_template: :show)
19
19
  else
@@ -39,7 +39,7 @@ module Spree
39
39
  private
40
40
 
41
41
  def stock_location
42
- @stock_location ||= StockLocation.accessible_by(current_ability, :read).find(params[:id])
42
+ @stock_location ||= Spree::StockLocation.accessible_by(current_ability, :read).find(params[:id])
43
43
  end
44
44
 
45
45
  def stock_location_params
@@ -4,7 +4,7 @@ module Spree
4
4
  before_action :stock_location, except: [:update, :destroy]
5
5
 
6
6
  def index
7
- authorize! :read, StockMovement
7
+ authorize! :read, Spree::StockMovement
8
8
  @stock_movements = scope.ransack(params[:q]).result.page(params[:page]).per(params[:per_page])
9
9
  respond_with(@stock_movements)
10
10
  end
@@ -15,7 +15,7 @@ module Spree
15
15
  end
16
16
 
17
17
  def create
18
- authorize! :create, StockMovement
18
+ authorize! :create, Spree::StockMovement
19
19
  @stock_movement = scope.new(stock_movement_params)
20
20
  if @stock_movement.save
21
21
  respond_with(@stock_movement, status: 201, default_template: :show)
@@ -28,7 +28,7 @@ module Spree
28
28
 
29
29
  def stock_location
30
30
  render 'spree/api/shared/stock_location_required', status: 422 and return unless params[:stock_location_id]
31
- @stock_location ||= StockLocation.accessible_by(current_ability, :read).find(params[:stock_location_id])
31
+ @stock_location ||= Spree::StockLocation.accessible_by(current_ability, :read).find(params[:stock_location_id])
32
32
  end
33
33
 
34
34
  def scope
@@ -5,14 +5,14 @@ module Spree
5
5
  before_filter :get_store, except: [:index, :create]
6
6
 
7
7
  def index
8
- authorize! :read, Store
9
- @stores = Store.accessible_by(current_ability, :read).all
8
+ authorize! :read, Spree::Store
9
+ @stores = Spree::Store.accessible_by(current_ability, :read).all
10
10
  respond_with(@stores)
11
11
  end
12
12
 
13
13
  def create
14
- authorize! :create, Store
15
- @store = Store.new(store_params)
14
+ authorize! :create, Spree::Store
15
+ @store = Spree::Store.new(store_params)
16
16
  @store.code = params[:store][:code]
17
17
  if @store.save
18
18
  respond_with(@store, status: 201, default_template: :show)
@@ -44,7 +44,7 @@ module Spree
44
44
  private
45
45
 
46
46
  def get_store
47
- @store = Store.find(params[:id])
47
+ @store = Spree::Store.find(params[:id])
48
48
  end
49
49
 
50
50
  def store_params
@@ -16,8 +16,8 @@ module Spree
16
16
  end
17
17
 
18
18
  def create
19
- authorize! :create, Taxonomy
20
- @taxonomy = Taxonomy.new(taxonomy_params)
19
+ authorize! :create, Spree::Taxonomy
20
+ @taxonomy = Spree::Taxonomy.new(taxonomy_params)
21
21
  if @taxonomy.save
22
22
  respond_with(@taxonomy, :status => 201, :default_template => :show)
23
23
  else
@@ -43,13 +43,13 @@ module Spree
43
43
  private
44
44
 
45
45
  def taxonomies
46
- @taxonomies = Taxonomy.accessible_by(current_ability, :read).order('name').includes(:root => :children).
46
+ @taxonomies = Spree::Taxonomy.accessible_by(current_ability, :read).order('name').includes(:root => :children).
47
47
  ransack(params[:q]).result.
48
48
  page(params[:page]).per(params[:per_page])
49
49
  end
50
50
 
51
51
  def taxonomy
52
- @taxonomy ||= Taxonomy.accessible_by(current_ability, :read).find(params[:id])
52
+ @taxonomy ||= Spree::Taxonomy.accessible_by(current_ability, :read).find(params[:id])
53
53
  end
54
54
 
55
55
  def taxonomy_params
@@ -26,7 +26,7 @@ module Spree
26
26
  end
27
27
 
28
28
  def create
29
- authorize! :create, Taxon
29
+ authorize! :create, Spree::Taxon
30
30
  @taxon = Spree::Taxon.new(taxon_params)
31
31
  @taxon.taxonomy_id = params[:taxonomy_id]
32
32
  taxonomy = Spree::Taxonomy.find_by(id: params[:taxonomy_id])
@@ -4,7 +4,7 @@ module Spree
4
4
  before_action :product
5
5
 
6
6
  def create
7
- authorize! :create, Variant
7
+ authorize! :create, Spree::Variant
8
8
  @variant = scope.new(variant_params)
9
9
  if @variant.save
10
10
  respond_with(@variant, status: 201, default_template: :show)
@@ -55,10 +55,10 @@ module Spree
55
55
  if @product
56
56
  variants = @product.variants_including_master
57
57
  else
58
- variants = Variant
58
+ variants = Spree::Variant
59
59
  end
60
60
 
61
- if current_ability.can?(:manage, Variant) && params[:show_deleted]
61
+ if current_ability.can?(:manage, Spree::Variant) && params[:show_deleted]
62
62
  variants = variants.with_deleted
63
63
  end
64
64
 
@@ -3,8 +3,8 @@ module Spree
3
3
  class ZonesController < Spree::Api::BaseController
4
4
 
5
5
  def create
6
- authorize! :create, Zone
7
- @zone = Zone.new(map_nested_attributes_keys(Spree::Zone, params[:zone]))
6
+ authorize! :create, Spree::Zone
7
+ @zone = Spree::Zone.new(map_nested_attributes_keys(Spree::Zone, params[:zone]))
8
8
  if @zone.save
9
9
  respond_with(@zone, :status => 201, :default_template => :show)
10
10
  else
@@ -19,7 +19,7 @@ module Spree
19
19
  end
20
20
 
21
21
  def index
22
- @zones = Zone.accessible_by(current_ability, :read).order('name ASC').ransack(params[:q]).result.page(params[:page]).per(params[:per_page])
22
+ @zones = Spree::Zone.accessible_by(current_ability, :read).order('name ASC').ransack(params[:q]).result.page(params[:page]).per(params[:per_page])
23
23
  respond_with(@zones)
24
24
  end
25
25
 
@@ -1,15 +1,9 @@
1
1
  object @variant
2
- attributes *variant_attributes
3
2
 
4
3
  cache [I18n.locale, @current_user_roles.include?('admin'), 'big_variant', root_object]
5
4
 
6
5
  extends "spree/api/variants/small"
7
6
 
8
- node :total_on_hand do
9
- root_object.total_on_hand
10
- end
11
-
12
-
13
7
  child(:stock_items => :stock_items) do
14
8
  attributes :id, :count_on_hand, :stock_location_id, :backorderable
15
9
  attribute :available? => :available
@@ -315,6 +315,13 @@ module Spree
315
315
  expect(json_response['option_types'].count).to eq(2)
316
316
  end
317
317
 
318
+ it "creates product with option_types ids" do
319
+ option_type = create(:option_type)
320
+ product_data.merge!(option_type_ids: [option_type.id])
321
+ api_post :create, product: product_data
322
+ expect(json_response['option_types'].first['id']).to eq option_type.id
323
+ end
324
+
318
325
  it "creates with shipping categories" do
319
326
  hash = { :name => "The Other Product",
320
327
  :price => 19.99,
@@ -4,7 +4,7 @@ module Spree
4
4
  describe Api::UsersController, :type => :controller do
5
5
  render_views
6
6
 
7
- let(:user) { create(:user, spree_api_key: rand) }
7
+ let(:user) { create(:user, spree_api_key: rand.to_s) }
8
8
  let(:stranger) { create(:user, :email => 'stranger@example.com') }
9
9
  let(:attributes) { [:id, :email, :created_at, :updated_at] }
10
10
 
@@ -4,10 +4,11 @@ module Spree
4
4
  describe Api::VariantsController, :type => :controller do
5
5
  render_views
6
6
 
7
+ let(:option_value) { create(:option_value) }
7
8
  let!(:product) { create(:product) }
8
9
  let!(:variant) do
9
10
  variant = product.master
10
- variant.option_values << create(:option_value)
11
+ variant.option_values << option_value
11
12
  variant
12
13
  end
13
14
 
@@ -166,10 +167,12 @@ module Spree
166
167
  end
167
168
 
168
169
  it "can create a new variant" do
169
- api_post :create, :variant => { :sku => "12345" }
170
+ api_post :create, variant: { sku: "12345", option_value_ids: [option_value.id] }
171
+
170
172
  expect(json_response).to have_attributes(new_attributes)
171
173
  expect(response.status).to eq(201)
172
174
  expect(json_response["sku"]).to eq("12345")
175
+ expect(json_response["option_values"].first["id"]).to eq option_value.id
173
176
 
174
177
  expect(variant.product.variants.count).to eq(1)
175
178
  end
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.6
4
+ version: 2.4.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: 2015-03-10 00:00:00.000000000 Z
11
+ date: 2015-05-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.6
19
+ version: 2.4.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.4.6
26
+ version: 2.4.7
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rabl
29
29
  requirement: !ruby/object:Gem::Requirement