spree_api 3.0.3 → 3.0.4

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: a420ffcea7708290cc00ef92bc229128f71c52f5
4
- data.tar.gz: c448f467f44145e7255784bc73e8596211fff73c
3
+ metadata.gz: 312dad95a36f976a119c7548cb87beb86b496e46
4
+ data.tar.gz: bf74b689033ee0464d019029fc9ef21c9d340c09
5
5
  SHA512:
6
- metadata.gz: 9fa28a7494f1bf6b67f74d8ee1d514251a43a87d2156198dce6a980111b93f980c95fe5b0a8af0c0672ec4e72675b0939d7ead87c1333d83cc1667a6ba4abfc4
7
- data.tar.gz: fdb0759f783dfca6da8c09161745220a5069265f8b6d02cd82a5d58fdbdcc73dc098f8c13920585bbb13c245e60a98ea9c4338b95afc95f6414461e66ce7d511
6
+ metadata.gz: 6c840d1ac0335d2980dbd7802af4a8afbf119f90b897a4a5c48f0f5f8862a96b646548fb1739e657ecceeab94ba5b83b1866195eafc542a1d3e9e413fe8ec890
7
+ data.tar.gz: 7399b407d17c2f90d763f6709ccbd97894dcf9961ad8c85bf5bef0765d4d3a4181f4ad2de172309727173c3e3ad090578c929cfa2f7ed1d8f588b34ebbfdb55d
@@ -85,7 +85,7 @@ module Spree
85
85
 
86
86
  @@payment_attributes = [
87
87
  :id, :source_type, :source_id, :amount, :display_amount,
88
- :payment_method_id, :response_code, :state, :avs_response, :created_at,
88
+ :payment_method_id, :state, :avs_response, :created_at,
89
89
  :updated_at
90
90
  ]
91
91
 
@@ -6,7 +6,7 @@ module Spree
6
6
  let!(:order) { create(:order) }
7
7
  let!(:payment) { create(:payment, :order => order) }
8
8
  let!(:attributes) { [:id, :source_type, :source_id, :amount, :display_amount,
9
- :payment_method_id, :response_code, :state, :avs_response,
9
+ :payment_method_id, :state, :avs_response,
10
10
  :created_at, :updated_at] }
11
11
 
12
12
  let(:resource_scoping) { { :order_id => order.to_param } }
@@ -82,7 +82,7 @@ module Spree
82
82
  end
83
83
 
84
84
  context "multiple payments" do
85
- before { @payment = create(:payment, :order => order, :response_code => '99999') }
85
+ before { @payment = create(:payment, :order => order) }
86
86
 
87
87
  it "can view all payments on an order" do
88
88
  api_get :index
@@ -95,12 +95,6 @@ module Spree
95
95
  expect(json_response['current_page']).to eq(1)
96
96
  expect(json_response['pages']).to eq(2)
97
97
  end
98
-
99
- it 'can query the results through a paramter' do
100
- api_get :index, :q => { :response_code_cont => '999' }
101
- expect(json_response['count']).to eq(1)
102
- expect(json_response['payments'].first['response_code']).to eq @payment.response_code
103
- end
104
98
  end
105
99
 
106
100
  context "for a given payment" do
@@ -0,0 +1,79 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Ransackable Attributes" do
4
+ let(:user) { create(:user).tap(&:generate_spree_api_key!) }
5
+ let(:order) { create(:order_with_line_items, user: user) }
6
+ context "filtering by attributes one association away" do
7
+ it "does not allow the filtering of variants by order attributes" do
8
+ 2.times { create(:variant) }
9
+
10
+ get "/api/variants?q[orders_email_start]=#{order.email}", token: user.spree_api_key
11
+
12
+ variants_response = JSON.parse(response.body)
13
+ expect(variants_response['total_count']).to eq(Spree::Variant.count)
14
+ end
15
+ end
16
+
17
+ context "filtering by attributes two associations away" do
18
+ it "does not allow the filtering of variants by user attributes" do
19
+ 2.times { create(:variant) }
20
+
21
+ get "/api/variants?q[orders_user_email_start]=#{order.user.email}", token: user.spree_api_key
22
+
23
+ variants_response = JSON.parse(response.body)
24
+ expect(variants_response['total_count']).to eq(Spree::Variant.count)
25
+ end
26
+ end
27
+
28
+ context "it maintains desired association behavior" do
29
+ it "allows filtering of variants product name" do
30
+ product = create(:product, name: "Fritos")
31
+ variant = create(:variant, product: product)
32
+ other_variant = create(:variant)
33
+
34
+ get "/api/variants?q[product_name_or_sku_cont]=fritos", token: user.spree_api_key
35
+
36
+ skus = JSON.parse(response.body)['variants'].map { |variant| variant['sku'] }
37
+ expect(skus).to include variant.sku
38
+ expect(skus).not_to include other_variant.sku
39
+ end
40
+ end
41
+
42
+ context "filtering by attributes" do
43
+ it "most attributes are not filterable by default" do
44
+ product = create(:product, description: "special product")
45
+ other_product = create(:product)
46
+
47
+ get "/api/products?q[description_cont]=special", token: user.spree_api_key
48
+
49
+ products_response = JSON.parse(response.body)
50
+ expect(products_response['total_count']).to eq(Spree::Product.count)
51
+ end
52
+
53
+ it "id is filterable by default" do
54
+ product = create(:product)
55
+ other_product = create(:product)
56
+
57
+ get "/api/products?q[id_eq]=#{product.id}", token: user.spree_api_key
58
+
59
+ product_names = JSON.parse(response.body)['products'].map { |product| product['name'] }
60
+ expect(product_names).to include product.name
61
+ expect(product_names).not_to include other_product.name
62
+ end
63
+ end
64
+
65
+ context "filtering by whitelisted attributes" do
66
+ it "filtering is supported for whitelisted attributes" do
67
+ product = create(:product, name: "Fritos")
68
+ other_product = create(:product)
69
+
70
+ get "/api/products?q[name_cont]=fritos", token: user.spree_api_key
71
+
72
+ product_names = JSON.parse(response.body)['products'].map { |product| product['name'] }
73
+ expect(product_names).to include product.name
74
+ expect(product_names).not_to include other_product.name
75
+ end
76
+ end
77
+
78
+
79
+ 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: 3.0.3
4
+ version: 3.0.4
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-07-28 00:00:00.000000000 Z
11
+ date: 2015-08-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: 3.0.3
19
+ version: 3.0.4
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: 3.0.3
26
+ version: 3.0.4
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rabl
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -239,6 +239,7 @@ files:
239
239
  - spec/fixtures/thinking-cat.jpg
240
240
  - spec/models/spree/legacy_user_spec.rb
241
241
  - spec/requests/rabl_cache_spec.rb
242
+ - spec/requests/ransackable_attributes_spec.rb
242
243
  - spec/shared_examples/protect_product_actions.rb
243
244
  - spec/spec_helper.rb
244
245
  - spec/support/controller_hacks.rb
@@ -304,6 +305,7 @@ test_files:
304
305
  - spec/fixtures/thinking-cat.jpg
305
306
  - spec/models/spree/legacy_user_spec.rb
306
307
  - spec/requests/rabl_cache_spec.rb
308
+ - spec/requests/ransackable_attributes_spec.rb
307
309
  - spec/shared_examples/protect_product_actions.rb
308
310
  - spec/spec_helper.rb
309
311
  - spec/support/controller_hacks.rb