spree_api_v2 0.2.0
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 +7 -0
- data/.gitignore +15 -0
- data/.rspec +2 -0
- data/CHANGELOG.md +38 -0
- data/Gemfile +13 -0
- data/LICENSE +26 -0
- data/README.md +98 -0
- data/Rakefile +37 -0
- data/app/controllers/concerns/spree/api/v2/renderable.rb +51 -0
- data/app/controllers/spree/api/v2/base_controller.rb +31 -0
- data/app/controllers/spree/api/v2/children_controller.rb +29 -0
- data/app/controllers/spree/api/v2/countries_controller.rb +21 -0
- data/app/controllers/spree/api/v2/images_controller.rb +29 -0
- data/app/controllers/spree/api/v2/line_items_controller.rb +36 -0
- data/app/controllers/spree/api/v2/option_types_controller.rb +31 -0
- data/app/controllers/spree/api/v2/option_values_controller.rb +29 -0
- data/app/controllers/spree/api/v2/orders_controller.rb +11 -0
- data/app/controllers/spree/api/v2/prices_controller.rb +27 -0
- data/app/controllers/spree/api/v2/products_controller.rb +37 -0
- data/app/controllers/spree/api/v2/states_controller.rb +29 -0
- data/app/controllers/spree/api/v2/taxonomies_controller.rb +21 -0
- data/app/controllers/spree/api/v2/taxons_controller.rb +40 -0
- data/app/controllers/spree/api/v2/variants_controller.rb +35 -0
- data/app/models/spree/base_decorator.rb +5 -0
- data/app/models/spree/image_decorator.rb +3 -0
- data/app/models/spree/price_decorator.rb +3 -0
- data/app/models/spree/state_decorator.rb +3 -0
- data/app/serializers/spree/address_serializer.rb +9 -0
- data/app/serializers/spree/base_serializer.rb +13 -0
- data/app/serializers/spree/country_serializer.rb +7 -0
- data/app/serializers/spree/error_serializer.rb +52 -0
- data/app/serializers/spree/image_serializer.rb +13 -0
- data/app/serializers/spree/line_item_serializer.rb +13 -0
- data/app/serializers/spree/option_type_serializer.rb +8 -0
- data/app/serializers/spree/option_value_serializer.rb +8 -0
- data/app/serializers/spree/order_serializer.rb +21 -0
- data/app/serializers/spree/price_serializer.rb +7 -0
- data/app/serializers/spree/product_serializer.rb +12 -0
- data/app/serializers/spree/role_serializer.rb +5 -0
- data/app/serializers/spree/state_serializer.rb +7 -0
- data/app/serializers/spree/store_serializer.rb +6 -0
- data/app/serializers/spree/taxon_serializer.rb +16 -0
- data/app/serializers/spree/taxonomy_serializer.rb +7 -0
- data/app/serializers/spree/user_serializer.rb +5 -0
- data/app/serializers/spree/variant_serializer.rb +12 -0
- data/bin/rails +7 -0
- data/circle.yml +13 -0
- data/config/locales/en.yml +25 -0
- data/config/routes.rb +53 -0
- data/docs/.nojekyll +0 -0
- data/docs/Dockerfile +12 -0
- data/docs/Gemfile +13 -0
- data/docs/README.md +12 -0
- data/docs/Rakefile +9 -0
- data/docs/config.rb +39 -0
- data/docs/font-selection.json +148 -0
- data/docs/source/fonts/slate.eot +0 -0
- data/docs/source/fonts/slate.svg +14 -0
- data/docs/source/fonts/slate.ttf +0 -0
- data/docs/source/fonts/slate.woff +0 -0
- data/docs/source/fonts/slate.woff2 +0 -0
- data/docs/source/images/logo.png +0 -0
- data/docs/source/images/navbar.png +0 -0
- data/docs/source/includes/_authentication.md +61 -0
- data/docs/source/includes/_countries.md +133 -0
- data/docs/source/includes/_errors.md +17 -0
- data/docs/source/includes/_filtering.md +11 -0
- data/docs/source/includes/_images.md +201 -0
- data/docs/source/includes/_line_items.md +137 -0
- data/docs/source/includes/_option_types.md +267 -0
- data/docs/source/includes/_option_values.md +227 -0
- data/docs/source/includes/_orders.md +75 -0
- data/docs/source/includes/_pagination.md +10 -0
- data/docs/source/includes/_prices.md +188 -0
- data/docs/source/includes/_products.md +403 -0
- data/docs/source/includes/_states.md +96 -0
- data/docs/source/includes/_taxonomies.md +325 -0
- data/docs/source/includes/_taxons.md +414 -0
- data/docs/source/includes/_variants.md +430 -0
- data/docs/source/index.md +53 -0
- data/docs/source/javascripts/all.js +4 -0
- data/docs/source/javascripts/all_nosearch.js +3 -0
- data/docs/source/javascripts/app/_lang.js +162 -0
- data/docs/source/javascripts/app/_search.js +74 -0
- data/docs/source/javascripts/app/_toc.js +55 -0
- data/docs/source/javascripts/lib/_energize.js +169 -0
- data/docs/source/javascripts/lib/_imagesloaded.min.js +7 -0
- data/docs/source/javascripts/lib/_jquery.highlight.js +108 -0
- data/docs/source/javascripts/lib/_jquery.tocify.js +1042 -0
- data/docs/source/javascripts/lib/_jquery_ui.js +566 -0
- data/docs/source/javascripts/lib/_lunr.js +1910 -0
- data/docs/source/layouts/layout.erb +102 -0
- data/docs/source/stylesheets/_icon-font.scss +38 -0
- data/docs/source/stylesheets/_normalize.css +427 -0
- data/docs/source/stylesheets/_syntax.scss.erb +27 -0
- data/docs/source/stylesheets/_variables.scss +109 -0
- data/docs/source/stylesheets/print.css.scss +142 -0
- data/docs/source/stylesheets/screen.css.scss +622 -0
- data/lib/solidus_api_v2.rb +5 -0
- data/lib/spree_api_v2.rb +4 -0
- data/lib/spree_api_v2/engine.rb +21 -0
- data/solidus_api_v2.gemspec +36 -0
- data/spec/controllers/spree/api/v2/children_controller_spec.rb +28 -0
- data/spec/controllers/spree/api/v2/countries_controller_spec.rb +25 -0
- data/spec/controllers/spree/api/v2/images_controller_spec.rb +93 -0
- data/spec/controllers/spree/api/v2/line_items_controller_spec.rb +86 -0
- data/spec/controllers/spree/api/v2/option_types_controller_spec.rb +73 -0
- data/spec/controllers/spree/api/v2/option_values_controller_spec.rb +88 -0
- data/spec/controllers/spree/api/v2/orders_controller_spec.rb +15 -0
- data/spec/controllers/spree/api/v2/prices_controller_spec.rb +55 -0
- data/spec/controllers/spree/api/v2/products_controller_spec.rb +95 -0
- data/spec/controllers/spree/api/v2/states_controller_spec.rb +42 -0
- data/spec/controllers/spree/api/v2/taxonomies_controller_spec.rb +31 -0
- data/spec/controllers/spree/api/v2/taxons_controller_spec.rb +54 -0
- data/spec/controllers/spree/api/v2/variants_controller_spec.rb +108 -0
- data/spec/models/spree/base_decorator_spec.rb +9 -0
- data/spec/models/spree/price_decorator_spec.rb +3 -0
- data/spec/serializers/spree/address_serializer_spec.rb +35 -0
- data/spec/serializers/spree/country_serializer_spec.rb +27 -0
- data/spec/serializers/spree/error_serializer_spec.rb +116 -0
- data/spec/serializers/spree/image_serializer_spec.rb +30 -0
- data/spec/serializers/spree/line_item_serializer_spec.rb +40 -0
- data/spec/serializers/spree/option_type_serializer_spec.rb +27 -0
- data/spec/serializers/spree/option_value_serializer_spec.rb +29 -0
- data/spec/serializers/spree/order_serializer_spec.rb +69 -0
- data/spec/serializers/spree/price_serializer_spec.rb +28 -0
- data/spec/serializers/spree/product_serializer_spec.rb +47 -0
- data/spec/serializers/spree/role_serializer_spec.rb +17 -0
- data/spec/serializers/spree/state_serializer_spec.rb +25 -0
- data/spec/serializers/spree/store_serializer_spec.rb +25 -0
- data/spec/serializers/spree/taxon_serializer_spec.rb +44 -0
- data/spec/serializers/spree/taxonomy_serializer_spec.rb +27 -0
- data/spec/serializers/spree/user_serializer_spec.rb +17 -0
- data/spec/serializers/spree/variant_serializer_spec.rb +55 -0
- data/spec/spec_helper.rb +51 -0
- data/spec/support/shoulda_matchers.rb +6 -0
- data/spree_api_v2.gemspec +36 -0
- metadata +437 -0
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
describe Spree::Api::V2::OrdersController do
|
|
2
|
+
routes { Spree::Core::Engine.routes }
|
|
3
|
+
|
|
4
|
+
let(:order) { create :order }
|
|
5
|
+
let(:user) { order.user }
|
|
6
|
+
|
|
7
|
+
before { user.generate_spree_api_key! }
|
|
8
|
+
|
|
9
|
+
describe '#show' do
|
|
10
|
+
it 'will respond with the order' do
|
|
11
|
+
get :show, token: user.spree_api_key, id: order.id
|
|
12
|
+
expect(JSON.parse(response.body)['data']['type']).to eql 'spree_orders'
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
describe Spree::Api::V2::PricesController do
|
|
2
|
+
routes { Spree::Core::Engine.routes }
|
|
3
|
+
|
|
4
|
+
let!(:price) { create :price }
|
|
5
|
+
let(:new_variant) { create :variant }
|
|
6
|
+
|
|
7
|
+
describe '#index' do
|
|
8
|
+
it 'will list all prices' do
|
|
9
|
+
get :index
|
|
10
|
+
price_ids = parse_json(response.body)['data'].map do |price|
|
|
11
|
+
price['id']
|
|
12
|
+
end
|
|
13
|
+
expect(price_ids).to include price.id.to_s
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
context 'by variant id' do
|
|
17
|
+
it 'will list its prices' do
|
|
18
|
+
get :index, variant_id: price.variant.id
|
|
19
|
+
price_ids = parse_json(response.body)['data'].map do |price|
|
|
20
|
+
price['id']
|
|
21
|
+
end
|
|
22
|
+
expect(price_ids).to include price.id.to_s
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
it 'will not list another variants prices' do
|
|
26
|
+
get :index, variant_id: new_variant.id
|
|
27
|
+
price_ids = parse_json(response.body)['data'].map do |price|
|
|
28
|
+
price['id']
|
|
29
|
+
end
|
|
30
|
+
expect(price_ids).to_not include price.id.to_s
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
describe '#show' do
|
|
36
|
+
it 'will show the price' do
|
|
37
|
+
get :show, id: price.id
|
|
38
|
+
price_id = parse_json(response.body)['data']['id']
|
|
39
|
+
expect(price_id).to eql price.id.to_s
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
context 'by variant id' do
|
|
43
|
+
it 'will show its prices' do
|
|
44
|
+
get :show, id: price.id, variant_id: price.variant.id
|
|
45
|
+
price_id = parse_json(response.body)['data']['id']
|
|
46
|
+
expect(price_id).to eql price.id.to_s
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
it 'will not show another variants price' do
|
|
50
|
+
get :show, id: price.id, variant_id: new_variant.id
|
|
51
|
+
expect(response).to have_http_status 404
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
end
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
describe Spree::Api::V2::ProductsController do
|
|
2
|
+
routes { Spree::Core::Engine.routes }
|
|
3
|
+
|
|
4
|
+
let!(:product) { create :product }
|
|
5
|
+
let(:taxon) { create :taxon, products: [product] }
|
|
6
|
+
let(:new_taxon) { create :taxon }
|
|
7
|
+
|
|
8
|
+
describe '#index' do
|
|
9
|
+
it 'will respond with products' do
|
|
10
|
+
get :index
|
|
11
|
+
expect(JSON.parse(response.body)['data'].size).to eql 1
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
context 'by taxon id' do
|
|
15
|
+
it 'will respond with the taxons products' do
|
|
16
|
+
get :index, taxon_id: taxon.id
|
|
17
|
+
product_ids = parse_json(response.body)['data'].map do |products|
|
|
18
|
+
products['id']
|
|
19
|
+
end
|
|
20
|
+
expect(product_ids).to include product.id.to_s
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
it 'will not respond with a product that is not associated to the taxon' do
|
|
24
|
+
get :index, taxon_id: new_taxon.id
|
|
25
|
+
product_ids = parse_json(response.body)['data'].map do |products|
|
|
26
|
+
products['id']
|
|
27
|
+
end
|
|
28
|
+
expect(product_ids).to_not include product.id.to_s
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
describe '#show' do
|
|
34
|
+
it 'will render the selected product' do
|
|
35
|
+
get :show, id: product.id
|
|
36
|
+
expect(parse_json(response.body)['data']['id']).to eql product.id.to_s
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
context 'by taxon id' do
|
|
40
|
+
it 'will respond with the taxons products' do
|
|
41
|
+
get :show, taxon_id: taxon.id, id: product.id
|
|
42
|
+
product_id = parse_json(response.body)['data']['id']
|
|
43
|
+
expect(product_id).to eql product.id.to_s
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
it 'will not respond with a product that is not associated to the taxon' do
|
|
47
|
+
get :show, taxon_id: new_taxon.id, id: product.id
|
|
48
|
+
expect(response).to have_http_status 404
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
context 'by option type' do
|
|
53
|
+
let(:option_type) { create :option_type, products: [product] }
|
|
54
|
+
let(:new_option_type) { create :option_type }
|
|
55
|
+
|
|
56
|
+
it 'will find product' do
|
|
57
|
+
get :show, option_type_id: option_type.id, id: product.id
|
|
58
|
+
product_id = parse_json(response.body)['data']['id']
|
|
59
|
+
expect(product_id).to eql product.id.to_s
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
it 'will not find a product belong to a different option type' do
|
|
63
|
+
get :show, option_type_id: new_option_type.id, id: product.id
|
|
64
|
+
expect(response).to have_http_status 404
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
context 'by variant id' do
|
|
69
|
+
it 'will show its product' do
|
|
70
|
+
get :show, variant_id: product.master.id
|
|
71
|
+
product_id = parse_json(response.body)['data']['id']
|
|
72
|
+
expect(product_id).to eql product.id.to_s
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
context 'by price id' do
|
|
77
|
+
it 'will show its product' do
|
|
78
|
+
get :show, price_id: product.master.prices.first.id
|
|
79
|
+
product_id = parse_json(response.body)['data']['id']
|
|
80
|
+
expect(product_id).to eql product.id.to_s
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
context 'by image id' do
|
|
85
|
+
let(:image) { create :image }
|
|
86
|
+
|
|
87
|
+
it 'will show its product' do
|
|
88
|
+
product.images << image
|
|
89
|
+
get :show, image_id: image.id
|
|
90
|
+
product_id = parse_json(response.body)['data']['id']
|
|
91
|
+
expect(product_id).to eql product.id.to_s
|
|
92
|
+
end
|
|
93
|
+
end
|
|
94
|
+
end
|
|
95
|
+
end
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
describe Spree::Api::V2::StatesController do
|
|
2
|
+
routes { Spree::Core::Engine.routes }
|
|
3
|
+
|
|
4
|
+
let!(:state) { create :state }
|
|
5
|
+
|
|
6
|
+
describe '#index' do
|
|
7
|
+
it 'can list all states' do
|
|
8
|
+
get :index
|
|
9
|
+
expect(JSON.parse(response.body)['data'].length).to eql 1
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
context 'by country id' do
|
|
13
|
+
it 'will list selected states by country' do
|
|
14
|
+
get :index, country_id: state.country.id
|
|
15
|
+
expect(JSON.parse(response.body)['data'].length).to eql 1
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
it 'will not include states belonging to other countries' do
|
|
19
|
+
new_state = create :state
|
|
20
|
+
get :index, country_id: state.country.id
|
|
21
|
+
state_ids = JSON.parse(response.body)['data'].map do |states|
|
|
22
|
+
states['id']
|
|
23
|
+
end
|
|
24
|
+
expect(state_ids).to_not include new_state
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
describe '#show' do
|
|
30
|
+
it 'will find selected state by id' do
|
|
31
|
+
get :show, id: state.id
|
|
32
|
+
state_id = parse_json(response.body)['data']['id']
|
|
33
|
+
expect(state_id).to eql state.id.to_s
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
it 'can find a state by a country' do
|
|
37
|
+
get :show, country_id: state.country.id, id: state.id
|
|
38
|
+
state_id = parse_json(response.body)['data']['id']
|
|
39
|
+
expect(state_id).to eql state.id.to_s
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
describe Spree::Api::V2::TaxonomiesController do
|
|
2
|
+
routes { Spree::Core::Engine.routes }
|
|
3
|
+
|
|
4
|
+
let!(:taxonomy) { create :taxonomy }
|
|
5
|
+
|
|
6
|
+
describe '#index' do
|
|
7
|
+
it 'will list taxonomies' do
|
|
8
|
+
get :index
|
|
9
|
+
taxonomy_ids = parse_json(response.body)['data'].map do |taxonomy|
|
|
10
|
+
taxonomy['id']
|
|
11
|
+
end
|
|
12
|
+
expect(taxonomy_ids).to include taxonomy.id.to_s
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
describe '#show' do
|
|
17
|
+
let(:taxon) { taxonomy.root }
|
|
18
|
+
|
|
19
|
+
it 'will show taxonomy' do
|
|
20
|
+
get :show, id: taxonomy.id
|
|
21
|
+
taxonomy_id = parse_json(response.body)['data']['id']
|
|
22
|
+
expect(taxonomy_id).to eql taxonomy.id.to_s
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
it 'can show taxonomy by taxon_id' do
|
|
26
|
+
get :show, taxon_id: taxon.id
|
|
27
|
+
taxonomy_id = parse_json(response.body)['data']['id']
|
|
28
|
+
expect(taxonomy_id).to eql taxonomy.id.to_s
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
describe Spree::Api::V2::TaxonsController do
|
|
2
|
+
routes { Spree::Core::Engine.routes }
|
|
3
|
+
|
|
4
|
+
let!(:taxon) { create :taxon }
|
|
5
|
+
|
|
6
|
+
describe '#index' do
|
|
7
|
+
it 'will list the taxons' do
|
|
8
|
+
get :index
|
|
9
|
+
taxon_ids = parse_json(response.body)['data'].map do |taxon|
|
|
10
|
+
taxon['id']
|
|
11
|
+
end
|
|
12
|
+
expect(taxon_ids).to include taxon.id.to_s
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
it 'can list the taxons filtered by taxonomy_id' do
|
|
16
|
+
get :index, taxonomy_id: taxon.taxonomy.id
|
|
17
|
+
taxon_ids = parse_json(response.body)['data'].map do |taxon|
|
|
18
|
+
taxon['id']
|
|
19
|
+
end
|
|
20
|
+
expect(taxon_ids).to include taxon.id.to_s
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
describe '#show' do
|
|
25
|
+
it 'will show the selected taxon' do
|
|
26
|
+
get :show, id: taxon.id
|
|
27
|
+
taxon_id = parse_json(response.body)['data']['id']
|
|
28
|
+
expect(taxon_id).to eql taxon.id.to_s
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
context 'by parent' do
|
|
32
|
+
it 'can show a taxons parent' do
|
|
33
|
+
child = create :taxon, parent: taxon
|
|
34
|
+
get :show, taxon_id: child.id
|
|
35
|
+
taxon_id = parse_json(response.body)['data']['id']
|
|
36
|
+
expect(taxon_id).to eql taxon.id.to_s
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
context 'by taxonomy_id' do
|
|
41
|
+
it 'will fetch the selected taxon' do
|
|
42
|
+
get :show, taxonomy_id: taxon.taxonomy.id, id: taxon.id
|
|
43
|
+
taxon_id = parse_json(response.body)['data']['id']
|
|
44
|
+
expect(taxon_id).to eql taxon.id.to_s
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
it 'when taxon does not belong to taxonomy' do
|
|
48
|
+
new_taxonomy = create :taxonomy
|
|
49
|
+
get :show, taxonomy_id: new_taxonomy.id, id: taxon.id
|
|
50
|
+
expect(response).to have_http_status 404
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
end
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
describe Spree::Api::V2::VariantsController do
|
|
2
|
+
routes { Spree::Core::Engine.routes }
|
|
3
|
+
|
|
4
|
+
let!(:variant) { create :variant }
|
|
5
|
+
let(:new_option_value) { create :option_value }
|
|
6
|
+
|
|
7
|
+
describe '#index' do
|
|
8
|
+
it 'will list all variants' do
|
|
9
|
+
get :index
|
|
10
|
+
variant_ids = parse_json(response.body)['data'].map do |variant|
|
|
11
|
+
variant['id']
|
|
12
|
+
end
|
|
13
|
+
expect(variant_ids).to include variant.id.to_s
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
context 'by product id' do
|
|
17
|
+
let(:new_product) { create :product }
|
|
18
|
+
|
|
19
|
+
it 'will list its variants' do
|
|
20
|
+
get :index, product_id: variant.product.id
|
|
21
|
+
variant_ids = parse_json(response.body)['data'].map do |variant|
|
|
22
|
+
variant['id']
|
|
23
|
+
end
|
|
24
|
+
expect(variant_ids).to include variant.id.to_s
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
it 'will not list another products variants' do
|
|
28
|
+
get :index, product_id: new_product.id
|
|
29
|
+
variant_ids = parse_json(response.body)['data'].map do |variant|
|
|
30
|
+
variant['id']
|
|
31
|
+
end
|
|
32
|
+
expect(variant_ids).to_not include variant.id.to_s
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
context 'by option value' do
|
|
37
|
+
it 'will list its variants' do
|
|
38
|
+
get :index, option_value_id: variant.option_values.first.id
|
|
39
|
+
variant_ids = parse_json(response.body)['data'].map do |variant|
|
|
40
|
+
variant['id']
|
|
41
|
+
end
|
|
42
|
+
expect(variant_ids).to include variant.id.to_s
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
it 'will not list another products variants' do
|
|
46
|
+
get :index, option_value_id: new_option_value.id
|
|
47
|
+
variant_ids = parse_json(response.body)['data'].map do |variant|
|
|
48
|
+
variant['id']
|
|
49
|
+
end
|
|
50
|
+
expect(variant_ids).to_not include variant.id.to_s
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
describe '#show' do
|
|
56
|
+
it 'will show the variant' do
|
|
57
|
+
get :show, id: variant.id
|
|
58
|
+
variant_id = parse_json(response.body)['data']['id']
|
|
59
|
+
expect(variant_id).to eql variant.id.to_s
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
context 'by product id' do
|
|
63
|
+
let(:new_product) { create :product }
|
|
64
|
+
|
|
65
|
+
it 'will show its variant' do
|
|
66
|
+
get :show, id: variant.id, product_id: variant.product.id
|
|
67
|
+
variant_id = parse_json(response.body)['data']['id']
|
|
68
|
+
expect(variant_id).to eql variant.id.to_s
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
it 'will not show another products variant' do
|
|
72
|
+
get :show, id: variant.id, product_id: new_product.id
|
|
73
|
+
expect(response).to have_http_status 404
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
context 'by option_value id' do
|
|
78
|
+
it 'will show its variant' do
|
|
79
|
+
get :show, id: variant.id, option_value_id: variant.option_values.first.id
|
|
80
|
+
variant_id = parse_json(response.body)['data']['id']
|
|
81
|
+
expect(variant_id).to eql variant.id.to_s
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
it 'will not show another option_values variant' do
|
|
85
|
+
get :show, id: variant.id, option_value_id: new_option_value.id
|
|
86
|
+
expect(response).to have_http_status 404
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
context 'by price id' do
|
|
91
|
+
it 'will show its variant' do
|
|
92
|
+
get :show, price_id: variant.prices.first.id
|
|
93
|
+
variant_id = parse_json(response.body)['data']['id']
|
|
94
|
+
expect(variant_id).to eql variant.id.to_s
|
|
95
|
+
end
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
context 'by image id' do
|
|
99
|
+
let(:image) { create :image, viewable: variant }
|
|
100
|
+
|
|
101
|
+
it 'will show its variant' do
|
|
102
|
+
get :show, image_id: image.id
|
|
103
|
+
variant_id = parse_json(response.body)['data']['id']
|
|
104
|
+
expect(variant_id).to eql variant.id.to_s
|
|
105
|
+
end
|
|
106
|
+
end
|
|
107
|
+
end
|
|
108
|
+
end
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
describe Spree::Base do
|
|
2
|
+
it '.paginate' do
|
|
3
|
+
# The pagination is concerned onto abstract models. There's not really a way
|
|
4
|
+
# to be able to ensure that the model is paginated, so instead of ensuring
|
|
5
|
+
# that the result is paginated (tested in the Spree::Api::BaseController),
|
|
6
|
+
# this just makes sure it can respond to the +.paginate+ method.
|
|
7
|
+
expect(described_class).to respond_to(:paginate).with(1).argument
|
|
8
|
+
end
|
|
9
|
+
end
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
describe Spree::AddressSerializer do
|
|
2
|
+
let(:address) { create :address }
|
|
3
|
+
subject { ActiveModel::Serializer::Adapter::JsonApi.new(described_class.new address) }
|
|
4
|
+
|
|
5
|
+
its(:to_json) do
|
|
6
|
+
is_expected.to be_json_eql <<-JSON
|
|
7
|
+
{
|
|
8
|
+
"data" : {
|
|
9
|
+
"attributes" : {
|
|
10
|
+
"address1" : "#{address.address1}",
|
|
11
|
+
"address2" : "#{address.address2}",
|
|
12
|
+
"city" : "#{address.city}",
|
|
13
|
+
"first_name" : "#{address.first_name}",
|
|
14
|
+
"last_name" : "#{address.last_name}",
|
|
15
|
+
"phone" : "#{address.phone}",
|
|
16
|
+
"zipcode" : "#{address.zipcode}"
|
|
17
|
+
},
|
|
18
|
+
"relationships" : {
|
|
19
|
+
"country" : {
|
|
20
|
+
"data" : {
|
|
21
|
+
"type" : "spree_countries"
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
"state" : {
|
|
25
|
+
"data" : {
|
|
26
|
+
"type" : "spree_states"
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
"type" : "spree_addresses"
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
JSON
|
|
34
|
+
end
|
|
35
|
+
end
|