spree_api_v2 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (138) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +15 -0
  3. data/.rspec +2 -0
  4. data/CHANGELOG.md +38 -0
  5. data/Gemfile +13 -0
  6. data/LICENSE +26 -0
  7. data/README.md +98 -0
  8. data/Rakefile +37 -0
  9. data/app/controllers/concerns/spree/api/v2/renderable.rb +51 -0
  10. data/app/controllers/spree/api/v2/base_controller.rb +31 -0
  11. data/app/controllers/spree/api/v2/children_controller.rb +29 -0
  12. data/app/controllers/spree/api/v2/countries_controller.rb +21 -0
  13. data/app/controllers/spree/api/v2/images_controller.rb +29 -0
  14. data/app/controllers/spree/api/v2/line_items_controller.rb +36 -0
  15. data/app/controllers/spree/api/v2/option_types_controller.rb +31 -0
  16. data/app/controllers/spree/api/v2/option_values_controller.rb +29 -0
  17. data/app/controllers/spree/api/v2/orders_controller.rb +11 -0
  18. data/app/controllers/spree/api/v2/prices_controller.rb +27 -0
  19. data/app/controllers/spree/api/v2/products_controller.rb +37 -0
  20. data/app/controllers/spree/api/v2/states_controller.rb +29 -0
  21. data/app/controllers/spree/api/v2/taxonomies_controller.rb +21 -0
  22. data/app/controllers/spree/api/v2/taxons_controller.rb +40 -0
  23. data/app/controllers/spree/api/v2/variants_controller.rb +35 -0
  24. data/app/models/spree/base_decorator.rb +5 -0
  25. data/app/models/spree/image_decorator.rb +3 -0
  26. data/app/models/spree/price_decorator.rb +3 -0
  27. data/app/models/spree/state_decorator.rb +3 -0
  28. data/app/serializers/spree/address_serializer.rb +9 -0
  29. data/app/serializers/spree/base_serializer.rb +13 -0
  30. data/app/serializers/spree/country_serializer.rb +7 -0
  31. data/app/serializers/spree/error_serializer.rb +52 -0
  32. data/app/serializers/spree/image_serializer.rb +13 -0
  33. data/app/serializers/spree/line_item_serializer.rb +13 -0
  34. data/app/serializers/spree/option_type_serializer.rb +8 -0
  35. data/app/serializers/spree/option_value_serializer.rb +8 -0
  36. data/app/serializers/spree/order_serializer.rb +21 -0
  37. data/app/serializers/spree/price_serializer.rb +7 -0
  38. data/app/serializers/spree/product_serializer.rb +12 -0
  39. data/app/serializers/spree/role_serializer.rb +5 -0
  40. data/app/serializers/spree/state_serializer.rb +7 -0
  41. data/app/serializers/spree/store_serializer.rb +6 -0
  42. data/app/serializers/spree/taxon_serializer.rb +16 -0
  43. data/app/serializers/spree/taxonomy_serializer.rb +7 -0
  44. data/app/serializers/spree/user_serializer.rb +5 -0
  45. data/app/serializers/spree/variant_serializer.rb +12 -0
  46. data/bin/rails +7 -0
  47. data/circle.yml +13 -0
  48. data/config/locales/en.yml +25 -0
  49. data/config/routes.rb +53 -0
  50. data/docs/.nojekyll +0 -0
  51. data/docs/Dockerfile +12 -0
  52. data/docs/Gemfile +13 -0
  53. data/docs/README.md +12 -0
  54. data/docs/Rakefile +9 -0
  55. data/docs/config.rb +39 -0
  56. data/docs/font-selection.json +148 -0
  57. data/docs/source/fonts/slate.eot +0 -0
  58. data/docs/source/fonts/slate.svg +14 -0
  59. data/docs/source/fonts/slate.ttf +0 -0
  60. data/docs/source/fonts/slate.woff +0 -0
  61. data/docs/source/fonts/slate.woff2 +0 -0
  62. data/docs/source/images/logo.png +0 -0
  63. data/docs/source/images/navbar.png +0 -0
  64. data/docs/source/includes/_authentication.md +61 -0
  65. data/docs/source/includes/_countries.md +133 -0
  66. data/docs/source/includes/_errors.md +17 -0
  67. data/docs/source/includes/_filtering.md +11 -0
  68. data/docs/source/includes/_images.md +201 -0
  69. data/docs/source/includes/_line_items.md +137 -0
  70. data/docs/source/includes/_option_types.md +267 -0
  71. data/docs/source/includes/_option_values.md +227 -0
  72. data/docs/source/includes/_orders.md +75 -0
  73. data/docs/source/includes/_pagination.md +10 -0
  74. data/docs/source/includes/_prices.md +188 -0
  75. data/docs/source/includes/_products.md +403 -0
  76. data/docs/source/includes/_states.md +96 -0
  77. data/docs/source/includes/_taxonomies.md +325 -0
  78. data/docs/source/includes/_taxons.md +414 -0
  79. data/docs/source/includes/_variants.md +430 -0
  80. data/docs/source/index.md +53 -0
  81. data/docs/source/javascripts/all.js +4 -0
  82. data/docs/source/javascripts/all_nosearch.js +3 -0
  83. data/docs/source/javascripts/app/_lang.js +162 -0
  84. data/docs/source/javascripts/app/_search.js +74 -0
  85. data/docs/source/javascripts/app/_toc.js +55 -0
  86. data/docs/source/javascripts/lib/_energize.js +169 -0
  87. data/docs/source/javascripts/lib/_imagesloaded.min.js +7 -0
  88. data/docs/source/javascripts/lib/_jquery.highlight.js +108 -0
  89. data/docs/source/javascripts/lib/_jquery.tocify.js +1042 -0
  90. data/docs/source/javascripts/lib/_jquery_ui.js +566 -0
  91. data/docs/source/javascripts/lib/_lunr.js +1910 -0
  92. data/docs/source/layouts/layout.erb +102 -0
  93. data/docs/source/stylesheets/_icon-font.scss +38 -0
  94. data/docs/source/stylesheets/_normalize.css +427 -0
  95. data/docs/source/stylesheets/_syntax.scss.erb +27 -0
  96. data/docs/source/stylesheets/_variables.scss +109 -0
  97. data/docs/source/stylesheets/print.css.scss +142 -0
  98. data/docs/source/stylesheets/screen.css.scss +622 -0
  99. data/lib/solidus_api_v2.rb +5 -0
  100. data/lib/spree_api_v2.rb +4 -0
  101. data/lib/spree_api_v2/engine.rb +21 -0
  102. data/solidus_api_v2.gemspec +36 -0
  103. data/spec/controllers/spree/api/v2/children_controller_spec.rb +28 -0
  104. data/spec/controllers/spree/api/v2/countries_controller_spec.rb +25 -0
  105. data/spec/controllers/spree/api/v2/images_controller_spec.rb +93 -0
  106. data/spec/controllers/spree/api/v2/line_items_controller_spec.rb +86 -0
  107. data/spec/controllers/spree/api/v2/option_types_controller_spec.rb +73 -0
  108. data/spec/controllers/spree/api/v2/option_values_controller_spec.rb +88 -0
  109. data/spec/controllers/spree/api/v2/orders_controller_spec.rb +15 -0
  110. data/spec/controllers/spree/api/v2/prices_controller_spec.rb +55 -0
  111. data/spec/controllers/spree/api/v2/products_controller_spec.rb +95 -0
  112. data/spec/controllers/spree/api/v2/states_controller_spec.rb +42 -0
  113. data/spec/controllers/spree/api/v2/taxonomies_controller_spec.rb +31 -0
  114. data/spec/controllers/spree/api/v2/taxons_controller_spec.rb +54 -0
  115. data/spec/controllers/spree/api/v2/variants_controller_spec.rb +108 -0
  116. data/spec/models/spree/base_decorator_spec.rb +9 -0
  117. data/spec/models/spree/price_decorator_spec.rb +3 -0
  118. data/spec/serializers/spree/address_serializer_spec.rb +35 -0
  119. data/spec/serializers/spree/country_serializer_spec.rb +27 -0
  120. data/spec/serializers/spree/error_serializer_spec.rb +116 -0
  121. data/spec/serializers/spree/image_serializer_spec.rb +30 -0
  122. data/spec/serializers/spree/line_item_serializer_spec.rb +40 -0
  123. data/spec/serializers/spree/option_type_serializer_spec.rb +27 -0
  124. data/spec/serializers/spree/option_value_serializer_spec.rb +29 -0
  125. data/spec/serializers/spree/order_serializer_spec.rb +69 -0
  126. data/spec/serializers/spree/price_serializer_spec.rb +28 -0
  127. data/spec/serializers/spree/product_serializer_spec.rb +47 -0
  128. data/spec/serializers/spree/role_serializer_spec.rb +17 -0
  129. data/spec/serializers/spree/state_serializer_spec.rb +25 -0
  130. data/spec/serializers/spree/store_serializer_spec.rb +25 -0
  131. data/spec/serializers/spree/taxon_serializer_spec.rb +44 -0
  132. data/spec/serializers/spree/taxonomy_serializer_spec.rb +27 -0
  133. data/spec/serializers/spree/user_serializer_spec.rb +17 -0
  134. data/spec/serializers/spree/variant_serializer_spec.rb +55 -0
  135. data/spec/spec_helper.rb +51 -0
  136. data/spec/support/shoulda_matchers.rb +6 -0
  137. data/spree_api_v2.gemspec +36 -0
  138. metadata +437 -0
@@ -0,0 +1,5 @@
1
+ require 'solidus_core'
2
+ require 'active_model_serializers'
3
+
4
+ ENV['SOLIDUS_API'] = 'true'
5
+ require 'spree_api_v2/engine'
@@ -0,0 +1,4 @@
1
+ require 'spree_core'
2
+ require 'active_model_serializers'
3
+
4
+ require 'spree_api_v2/engine'
@@ -0,0 +1,21 @@
1
+ module SpreeApiV2
2
+ class Engine < Rails::Engine
3
+ require 'spree/core'
4
+
5
+ isolate_namespace Spree
6
+ engine_name ENV['SOLIDUS_API'].nil? ? 'spree_api_v2' : 'solidus_api_v2'
7
+
8
+ # use rspec for tests
9
+ config.generators do |g|
10
+ g.test_framework :rspec
11
+ end
12
+
13
+ def self.activate
14
+ Dir.glob(File.join(File.dirname(__FILE__), '../../app/**/*_decorator*.rb')) do |c|
15
+ Rails.configuration.cache_classes ? require(c) : load(c)
16
+ end
17
+ end
18
+
19
+ config.to_prepare &method(:activate).to_proc
20
+ end
21
+ end
@@ -0,0 +1,36 @@
1
+ # encoding: UTF-8
2
+ Gem::Specification.new do |s|
3
+ s.platform = Gem::Platform::RUBY
4
+ s.name = 'solidus_api_v2'
5
+ s.version = '0.2.0'
6
+ s.summary = 'The V2 API for Solidus.'
7
+ s.description = 'Adds an assortment of new api endpoints that are JSON API compatible.'
8
+ s.required_ruby_version = '>= 2.0.0'
9
+
10
+ s.author = 'Ben A. Morgan'
11
+ s.email = 'ben@benmorgan.io'
12
+ s.homepage = 'http://spree-contrib.github.io/spree_api_v2'
13
+
14
+ s.files = `git ls-files`.split("\n")
15
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
16
+ s.require_path = 'lib'
17
+ s.requirements << 'none'
18
+
19
+ s.add_dependency 'solidus_api', '~> 1.0'
20
+ s.add_dependency 'active_model_serializers', '= 0.10.0.rc2'
21
+
22
+ s.add_development_dependency 'capybara', '~> 2.4'
23
+ s.add_development_dependency 'coffee-rails'
24
+ s.add_development_dependency 'database_cleaner'
25
+ s.add_development_dependency 'factory_girl', '~> 4.5'
26
+ s.add_development_dependency 'ffaker'
27
+ s.add_development_dependency 'rspec-rails', '~> 3.3'
28
+ s.add_development_dependency 'rspec-its'
29
+ s.add_development_dependency 'sass-rails', '~> 5.0.0.beta1'
30
+ s.add_development_dependency 'selenium-webdriver'
31
+ s.add_development_dependency 'simplecov'
32
+ s.add_development_dependency 'sqlite3'
33
+ s.add_development_dependency 'pg'
34
+ s.add_development_dependency 'json_spec', '~> 1.1.4'
35
+ s.add_development_dependency 'shoulda-matchers', '~> 3.0.0'
36
+ end
@@ -0,0 +1,28 @@
1
+ describe Spree::Api::V2::ChildrenController do
2
+ routes { Spree::Core::Engine.routes }
3
+
4
+ let(:taxon) { create :taxon }
5
+ let!(:child) { create :taxon, parent: taxon, taxonomy: taxon.taxonomy }
6
+
7
+ describe '#index' do
8
+ context 'by taxon' do
9
+ it 'can list all the children' do
10
+ get :index, taxon_id: taxon.id
11
+ taxon_ids = parse_json(response.body)['data'].map do |taxon|
12
+ taxon['id']
13
+ end
14
+ expect(taxon_ids).to include child.id.to_s
15
+ end
16
+ end
17
+ end
18
+
19
+ describe '#show' do
20
+ context 'by taxon' do
21
+ it 'will fetch the selected child' do
22
+ get :show, taxon_id: taxon.id, id: child.id
23
+ child_id = parse_json(response.body)['data']['id']
24
+ expect(child_id).to eql child.id.to_s
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,25 @@
1
+ describe Spree::Api::V2::CountriesController do
2
+ routes { Spree::Core::Engine.routes }
3
+
4
+ let!(:country) { create :country }
5
+ let(:state) { create :state, country: country }
6
+
7
+ describe '#index' do
8
+ it 'will list all countries' do
9
+ get :index
10
+ expect(JSON.parse(response.body)['data'].length).to eql 1
11
+ end
12
+ end
13
+
14
+ describe '#show' do
15
+ it 'will list the selected country' do
16
+ get :show, id: country.id
17
+ expect(JSON.parse(response.body)['data']['id']).to eql country.id.to_s
18
+ end
19
+
20
+ it 'will the country via a state' do
21
+ get :show, state_id: state.id
22
+ expect(JSON.parse(response.body)['data']['id']).to eql country.id.to_s
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,93 @@
1
+ describe Spree::Api::V2::ImagesController do
2
+ routes { Spree::Core::Engine.routes }
3
+
4
+ let!(:image) { create :image }
5
+
6
+ let(:product) { create :product }
7
+ let(:new_product) { create :product }
8
+
9
+ let(:variant) { create :variant, images: [image] }
10
+ let(:new_variant) { create :variant, images: [create(:image)] }
11
+
12
+ describe '#index' do
13
+ it 'will list the images' do
14
+ get :index
15
+ image_ids = parse_json(response.body)['data'].map do |image|
16
+ image['id']
17
+ end
18
+ expect(image_ids).to include image.id.to_s
19
+ end
20
+
21
+ context 'by product id' do
22
+ it 'will list its images' do
23
+ product.images << image
24
+ get :index, product_id: product.id
25
+ image_ids = parse_json(response.body)['data'].map do |image|
26
+ image['id']
27
+ end
28
+ expect(image_ids).to include image.id.to_s
29
+ end
30
+
31
+ it 'will not list another products images' do
32
+ get :index, product_id: new_product.id
33
+ image_ids = parse_json(response.body)['data'].map do |image|
34
+ image['id']
35
+ end
36
+ expect(image_ids).to_not include image.id.to_s
37
+ end
38
+ end
39
+
40
+ context 'by variant id' do
41
+ it 'will list its images' do
42
+ get :index, variant_id: variant.id
43
+ image_ids = parse_json(response.body)['data'].map do |image|
44
+ image['id']
45
+ end
46
+ expect(image_ids).to include image.id.to_s
47
+ end
48
+
49
+ it 'will not list another variants images' do
50
+ get :index, variant_id: new_variant.id
51
+ image_ids = parse_json(response.body)['data'].map do |image|
52
+ image['id']
53
+ end
54
+ expect(image_ids).to_not include image.id.to_s
55
+ end
56
+ end
57
+ end
58
+
59
+ describe '#show' do
60
+ it 'will show the image' do
61
+ get :show, id: image.id
62
+ image_id = parse_json(response.body)['data']['id']
63
+ expect(image_id).to eql image.id.to_s
64
+ end
65
+
66
+ context 'by product id' do
67
+ it 'will show its image' do
68
+ product.images << image
69
+ get :show, id: image.id, product_id: product.id
70
+ image_id = parse_json(response.body)['data']['id']
71
+ expect(image_id).to eql image.id.to_s
72
+ end
73
+
74
+ it 'will not show another products image' do
75
+ get :show, id: image.id, product_id: new_product.id
76
+ expect(response).to have_http_status 404
77
+ end
78
+ end
79
+
80
+ context 'by variant id' do
81
+ it 'will show its image' do
82
+ get :show, id: image.id, variant_id: variant.id
83
+ image_id = parse_json(response.body)['data']['id']
84
+ expect(image_id).to eql image.id.to_s
85
+ end
86
+
87
+ it 'will not show another products image' do
88
+ get :show, id: image.id, variant_id: new_variant.id
89
+ expect(response).to have_http_status 404
90
+ end
91
+ end
92
+ end
93
+ end
@@ -0,0 +1,86 @@
1
+ describe Spree::Api::V2::LineItemsController do
2
+ routes { Spree::Core::Engine.routes }
3
+
4
+ let(:order) { create :order }
5
+ let(:user) { order.user }
6
+ let(:variant) { create :variant }
7
+
8
+ before { user.generate_spree_api_key! }
9
+
10
+ describe '#create' do
11
+ let(:line_item_params) { { order_id: order.id, variant_id: variant.id, quantity: 1 } }
12
+
13
+ context 'on success' do
14
+ it 'will respond with line item' do
15
+ post :create, token: user.spree_api_key, line_item: line_item_params
16
+ expect(JSON.parse(response.body)['data']['type']).to eql 'spree_line_items'
17
+ end
18
+ end
19
+
20
+ context 'when out of range' do
21
+ before do
22
+ post :create, token: user.spree_api_key,
23
+ line_item: line_item_params.merge(quantity: 123_123_123_123)
24
+ end
25
+
26
+ it 'will respond with quantity too high error' do
27
+ expect(response.body).to be_json_eql <<-JSON
28
+ {
29
+ "errors" : [
30
+ {
31
+ "detail" : #{Spree.t('api.errors.quantity_too_high.detail').gsub("\n", '').to_json},
32
+ "meta" : {},
33
+ "title" : #{Spree.t('api.errors.quantity_too_high.title').titleize.to_json}
34
+ }
35
+ ]
36
+ }
37
+ JSON
38
+ end
39
+ end
40
+
41
+ context 'when record not found' do
42
+ before do
43
+ post :create, token: user.spree_api_key, line_item: line_item_params.merge(order_id: 0)
44
+ end
45
+
46
+ it 'will respond with record not found error' do
47
+ expect(response.body).to be_json_eql <<-JSON
48
+ {
49
+ "errors" : [
50
+ {
51
+ "detail" : #{Spree.t('api.errors.record_not_found.detail').gsub("\n", '').to_json},
52
+ "meta" : {},
53
+ "title" : #{Spree.t('api.errors.record_not_found.title').to_json}
54
+ }
55
+ ]
56
+ }
57
+ JSON
58
+ end
59
+ end
60
+
61
+ context 'when record is invalid' do
62
+ let(:stock_item) { variant.stock_items.first }
63
+
64
+ before do
65
+ quantity = stock_item.count_on_hand + 1
66
+ stock_item.update(backorderable: false)
67
+ post :create, token: user.spree_api_key,
68
+ line_item: line_item_params.merge(quantity: quantity)
69
+ end
70
+
71
+ it 'will respond with product out of stock' do
72
+ expect(response.body).to be_json_eql <<-JSON
73
+ {
74
+ "errors" : [
75
+ {
76
+ "detail" : "#{Spree.t('api.errors.product_out_of_stock.detail').gsub("\n", '')}",
77
+ "meta" : {},
78
+ "title" : #{Spree.t('api.errors.product_out_of_stock.title').titleize.to_json}
79
+ }
80
+ ]
81
+ }
82
+ JSON
83
+ end
84
+ end
85
+ end
86
+ end
@@ -0,0 +1,73 @@
1
+ describe Spree::Api::V2::OptionTypesController do
2
+ routes { Spree::Core::Engine.routes }
3
+
4
+ let!(:option_type) { create :option_type }
5
+ let(:product) { create :product, option_types: [option_type] }
6
+ let(:new_product) { create :product }
7
+
8
+ describe '#index' do
9
+ it 'will list all option types' do
10
+ get :index
11
+ option_type_ids = parse_json(response.body)['data'].map do |option_type|
12
+ option_type['id']
13
+ end
14
+ expect(option_type_ids).to include option_type.id.to_s
15
+ end
16
+
17
+ context 'by product' do
18
+ it 'will list option types' do
19
+ get :index, product_id: product.id
20
+ option_type_ids = parse_json(response.body)['data'].map do |option_type|
21
+ option_type['id']
22
+ end
23
+ expect(option_type_ids).to include option_type.id.to_s
24
+ end
25
+
26
+ it 'will not list option types belonging to a different product' do
27
+ get :index, product_id: new_product.id
28
+ option_type_ids = parse_json(response.body)['data'].map do |option_type|
29
+ option_type['id']
30
+ end
31
+ expect(option_type_ids).to_not include option_type.id.to_s
32
+ end
33
+ end
34
+ end
35
+
36
+ describe '#show' do
37
+ it 'will find selected option_type by id' do
38
+ get :show, id: option_type.id
39
+ option_type_id = parse_json(response.body)['data']['id']
40
+ expect(option_type_id).to eql option_type.id.to_s
41
+ end
42
+
43
+ context 'by product' do
44
+ it 'will list option types' do
45
+ get :show, id: option_type.id, product_id: product.id
46
+ option_type_id = parse_json(response.body)['data']['id']
47
+ expect(option_type_id).to eql option_type.id.to_s
48
+ end
49
+
50
+ it 'will not list option types belonging to a different product' do
51
+ get :show, id: option_type.id, product_id: new_product.id
52
+ expect(response).to have_http_status 404
53
+ end
54
+ end
55
+
56
+ context 'by option value' do
57
+ let(:option_value) { create :option_value, option_type: option_type }
58
+ let(:new_option_value) { create :option_value }
59
+
60
+ it 'will list option types' do
61
+ get :show, option_value_id: option_value.id
62
+ option_type_id = parse_json(response.body)['data']['id']
63
+ expect(option_type_id).to eql option_type.id.to_s
64
+ end
65
+
66
+ it 'will not list option types belonging to a different option value' do
67
+ get :show, option_value_id: new_option_value.id
68
+ option_type_id = parse_json(response.body)['data']['id']
69
+ expect(option_type_id).to_not eql option_type.id.to_s
70
+ end
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,88 @@
1
+ describe Spree::Api::V2::OptionValuesController do
2
+ routes { Spree::Core::Engine.routes }
3
+
4
+ let!(:option_value) { create :option_value }
5
+ let(:new_option_value) { create :option_value }
6
+ let(:variant) { create :variant, option_values: [option_value] }
7
+ let(:new_variant) { create :variant }
8
+
9
+ describe '#index' do
10
+ it 'will list all option values' do
11
+ get :index
12
+ option_value_ids = parse_json(response.body)['data'].map do |option_value|
13
+ option_value['id']
14
+ end
15
+ expect(option_value_ids).to include option_value.id.to_s
16
+ end
17
+
18
+ context 'by option type' do
19
+ it 'will list all option values' do
20
+ get :index, option_type_id: option_value.option_type.id
21
+ option_value_ids = parse_json(response.body)['data'].map do |option_value|
22
+ option_value['id']
23
+ end
24
+ expect(option_value_ids).to include option_value.id.to_s
25
+ end
26
+
27
+ it 'will not list option value belonging to a different option type' do
28
+ get :index, option_type_id: new_option_value.option_type.id
29
+ option_value_ids = parse_json(response.body)['data'].map do |option_value|
30
+ option_value['id']
31
+ end
32
+ expect(option_value_ids).to_not include option_value.id.to_s
33
+ end
34
+ end
35
+
36
+ context 'by variant' do
37
+ it 'will list all option values' do
38
+ get :index, variant_id: variant.id
39
+ option_value_ids = parse_json(response.body)['data'].map do |option_value|
40
+ option_value['id']
41
+ end
42
+ expect(option_value_ids).to include option_value.id.to_s
43
+ end
44
+
45
+ it 'will not list option value belonging to a different variant' do
46
+ get :index, variant_id: new_variant.id
47
+ option_value_ids = parse_json(response.body)['data'].map do |option_value|
48
+ option_value['id']
49
+ end
50
+ expect(option_value_ids).to_not include option_value.id.to_s
51
+ end
52
+ end
53
+ end
54
+
55
+ describe '#show' do
56
+ it 'will find selected option value by id' do
57
+ get :show, id: option_value.id
58
+ option_value_id = parse_json(response.body)['data']['id']
59
+ expect(option_value_id).to eql option_value.id.to_s
60
+ end
61
+
62
+ context 'by option type' do
63
+ it 'will find option value by option type' do
64
+ get :show, option_type_id: option_value.option_type.id, id: option_value.id
65
+ option_value_id = parse_json(response.body)['data']['id']
66
+ expect(option_value_id).to eql option_value.id.to_s
67
+ end
68
+
69
+ it 'will not find option value belonging to a different option type' do
70
+ get :show, option_type_id: new_option_value.option_type.id, id: option_value.id
71
+ expect(response).to have_http_status 404
72
+ end
73
+ end
74
+
75
+ context 'by variant' do
76
+ it 'will find option value by option type' do
77
+ get :show, variant_id: variant.id, id: option_value.id
78
+ option_value_id = parse_json(response.body)['data']['id']
79
+ expect(option_value_id).to eql option_value.id.to_s
80
+ end
81
+
82
+ it 'will not find option value belonging to a different option type' do
83
+ get :show, variant_id: new_variant.id, id: option_value.id
84
+ expect(response).to have_http_status 404
85
+ end
86
+ end
87
+ end
88
+ end