solidus_json_api 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (140) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +15 -0
  3. data/.rspec +2 -0
  4. data/CHANGELOG.md +224 -0
  5. data/Gemfile +6 -0
  6. data/LICENSE +26 -0
  7. data/README.md +94 -0
  8. data/Rakefile +38 -0
  9. data/app/controllers/concerns/spree/api/v2/renderable.rb +63 -0
  10. data/app/controllers/spree/api/v2/base_controller.rb +9 -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 +21 -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/line_item_decorator.rb +3 -0
  27. data/app/models/spree/order_decorator.rb +3 -0
  28. data/app/models/spree/price_decorator.rb +3 -0
  29. data/app/models/spree/state_decorator.rb +3 -0
  30. data/app/serializers/spree/address_serializer.rb +9 -0
  31. data/app/serializers/spree/base_serializer.rb +13 -0
  32. data/app/serializers/spree/country_serializer.rb +7 -0
  33. data/app/serializers/spree/error_serializer.rb +55 -0
  34. data/app/serializers/spree/image_serializer.rb +13 -0
  35. data/app/serializers/spree/line_item_serializer.rb +13 -0
  36. data/app/serializers/spree/option_type_serializer.rb +8 -0
  37. data/app/serializers/spree/option_value_serializer.rb +8 -0
  38. data/app/serializers/spree/order_serializer.rb +20 -0
  39. data/app/serializers/spree/price_serializer.rb +7 -0
  40. data/app/serializers/spree/product_serializer.rb +12 -0
  41. data/app/serializers/spree/role_serializer.rb +5 -0
  42. data/app/serializers/spree/state_serializer.rb +7 -0
  43. data/app/serializers/spree/store_serializer.rb +6 -0
  44. data/app/serializers/spree/taxon_serializer.rb +16 -0
  45. data/app/serializers/spree/taxonomy_serializer.rb +7 -0
  46. data/app/serializers/spree/user_serializer.rb +5 -0
  47. data/app/serializers/spree/variant_serializer.rb +12 -0
  48. data/circle.yml +12 -0
  49. data/config/locales/en.yml +25 -0
  50. data/config/routes.rb +53 -0
  51. data/docs/.nojekyll +0 -0
  52. data/docs/Dockerfile +12 -0
  53. data/docs/Gemfile +14 -0
  54. data/docs/README.md +12 -0
  55. data/docs/Rakefile +9 -0
  56. data/docs/config.rb +39 -0
  57. data/docs/font-selection.json +148 -0
  58. data/docs/source/CNAME +1 -0
  59. data/docs/source/fonts/slate.eot +0 -0
  60. data/docs/source/fonts/slate.svg +14 -0
  61. data/docs/source/fonts/slate.ttf +0 -0
  62. data/docs/source/fonts/slate.woff +0 -0
  63. data/docs/source/fonts/slate.woff2 +0 -0
  64. data/docs/source/images/favicon.ico +0 -0
  65. data/docs/source/images/navbar.png +0 -0
  66. data/docs/source/includes/_countries.md +133 -0
  67. data/docs/source/includes/_errors.md +17 -0
  68. data/docs/source/includes/_filtering.md +11 -0
  69. data/docs/source/includes/_images.md +201 -0
  70. data/docs/source/includes/_line_items.md +143 -0
  71. data/docs/source/includes/_option_types.md +267 -0
  72. data/docs/source/includes/_option_values.md +227 -0
  73. data/docs/source/includes/_orders.md +150 -0
  74. data/docs/source/includes/_pagination.md +10 -0
  75. data/docs/source/includes/_prices.md +188 -0
  76. data/docs/source/includes/_products.md +407 -0
  77. data/docs/source/includes/_states.md +96 -0
  78. data/docs/source/includes/_taxonomies.md +325 -0
  79. data/docs/source/includes/_taxons.md +414 -0
  80. data/docs/source/includes/_variants.md +430 -0
  81. data/docs/source/index.md +51 -0
  82. data/docs/source/javascripts/all.js +4 -0
  83. data/docs/source/javascripts/all_nosearch.js +3 -0
  84. data/docs/source/javascripts/app/_lang.js +162 -0
  85. data/docs/source/javascripts/app/_search.js +74 -0
  86. data/docs/source/javascripts/app/_toc.js +55 -0
  87. data/docs/source/javascripts/lib/_energize.js +169 -0
  88. data/docs/source/javascripts/lib/_imagesloaded.min.js +7 -0
  89. data/docs/source/javascripts/lib/_jquery.highlight.js +108 -0
  90. data/docs/source/javascripts/lib/_jquery.tocify.js +1042 -0
  91. data/docs/source/javascripts/lib/_jquery_ui.js +566 -0
  92. data/docs/source/javascripts/lib/_lunr.js +1910 -0
  93. data/docs/source/layouts/layout.erb +110 -0
  94. data/docs/source/stylesheets/_icon-font.scss +38 -0
  95. data/docs/source/stylesheets/_normalize.css +427 -0
  96. data/docs/source/stylesheets/_syntax.scss.erb +27 -0
  97. data/docs/source/stylesheets/_variables.scss +109 -0
  98. data/docs/source/stylesheets/print.css.scss +142 -0
  99. data/docs/source/stylesheets/screen.css.scss +622 -0
  100. data/lib/solidus_json_api/config.rb +8 -0
  101. data/lib/solidus_json_api/engine.rb +21 -0
  102. data/lib/solidus_json_api.rb +5 -0
  103. data/solidus_json_api.gemspec +36 -0
  104. data/spec/controllers/spree/api/v2/base_controller_spec.rb +46 -0
  105. data/spec/controllers/spree/api/v2/children_controller_spec.rb +28 -0
  106. data/spec/controllers/spree/api/v2/countries_controller_spec.rb +25 -0
  107. data/spec/controllers/spree/api/v2/images_controller_spec.rb +91 -0
  108. data/spec/controllers/spree/api/v2/line_items_controller_spec.rb +101 -0
  109. data/spec/controllers/spree/api/v2/option_types_controller_spec.rb +71 -0
  110. data/spec/controllers/spree/api/v2/option_values_controller_spec.rb +88 -0
  111. data/spec/controllers/spree/api/v2/orders_controller_spec.rb +61 -0
  112. data/spec/controllers/spree/api/v2/prices_controller_spec.rb +55 -0
  113. data/spec/controllers/spree/api/v2/products_controller_spec.rb +99 -0
  114. data/spec/controllers/spree/api/v2/states_controller_spec.rb +42 -0
  115. data/spec/controllers/spree/api/v2/taxonomies_controller_spec.rb +31 -0
  116. data/spec/controllers/spree/api/v2/taxons_controller_spec.rb +54 -0
  117. data/spec/controllers/spree/api/v2/variants_controller_spec.rb +106 -0
  118. data/spec/lib/solidus_json_api/config_spec.rb +10 -0
  119. data/spec/models/spree/base_decorator_spec.rb +9 -0
  120. data/spec/models/spree/price_decorator_spec.rb +3 -0
  121. data/spec/serializers/spree/address_serializer_spec.rb +35 -0
  122. data/spec/serializers/spree/country_serializer_spec.rb +27 -0
  123. data/spec/serializers/spree/error_serializer_spec.rb +141 -0
  124. data/spec/serializers/spree/image_serializer_spec.rb +30 -0
  125. data/spec/serializers/spree/line_item_serializer_spec.rb +40 -0
  126. data/spec/serializers/spree/option_type_serializer_spec.rb +27 -0
  127. data/spec/serializers/spree/option_value_serializer_spec.rb +29 -0
  128. data/spec/serializers/spree/order_serializer_spec.rb +68 -0
  129. data/spec/serializers/spree/price_serializer_spec.rb +28 -0
  130. data/spec/serializers/spree/product_serializer_spec.rb +47 -0
  131. data/spec/serializers/spree/role_serializer_spec.rb +17 -0
  132. data/spec/serializers/spree/state_serializer_spec.rb +25 -0
  133. data/spec/serializers/spree/store_serializer_spec.rb +25 -0
  134. data/spec/serializers/spree/taxon_serializer_spec.rb +44 -0
  135. data/spec/serializers/spree/taxonomy_serializer_spec.rb +27 -0
  136. data/spec/serializers/spree/user_serializer_spec.rb +17 -0
  137. data/spec/serializers/spree/variant_serializer_spec.rb +55 -0
  138. data/spec/spec_helper.rb +57 -0
  139. data/spec/support/shoulda_matchers.rb +6 -0
  140. metadata +442 -0
@@ -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,106 @@
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 variant' do
46
+ get :index, option_value_id: new_option_value.id
47
+ data = parse_json(response.body)['data']
48
+ expect(data).to be_empty
49
+ end
50
+ end
51
+ end
52
+
53
+ describe '#show' do
54
+ it 'will show the variant' do
55
+ get :show, id: variant.id
56
+ variant_id = parse_json(response.body)['data']['id']
57
+ expect(variant_id).to eql variant.id.to_s
58
+ end
59
+
60
+ context 'by product id' do
61
+ let(:new_product) { create :product }
62
+
63
+ it 'will show its variant' do
64
+ get :show, id: variant.id, product_id: variant.product.id
65
+ variant_id = parse_json(response.body)['data']['id']
66
+ expect(variant_id).to eql variant.id.to_s
67
+ end
68
+
69
+ it 'will not show another products variant' do
70
+ get :show, id: variant.id, product_id: new_product.id
71
+ expect(response).to have_http_status 404
72
+ end
73
+ end
74
+
75
+ context 'by option_value id' do
76
+ it 'will show its variant' do
77
+ get :show, id: variant.id, option_value_id: variant.option_values.first.id
78
+ variant_id = parse_json(response.body)['data']['id']
79
+ expect(variant_id).to eql variant.id.to_s
80
+ end
81
+
82
+ it 'will not show another option_values variant' do
83
+ get :show, id: variant.id, option_value_id: new_option_value.id
84
+ expect(response).to have_http_status 404
85
+ end
86
+ end
87
+
88
+ context 'by price id' do
89
+ it 'will show its variant' do
90
+ get :show, price_id: variant.prices.first.id
91
+ variant_id = parse_json(response.body)['data']['id']
92
+ expect(variant_id).to eql variant.id.to_s
93
+ end
94
+ end
95
+
96
+ context 'by image id' do
97
+ let(:image) { create :image, viewable: variant }
98
+
99
+ it 'will show its variant' do
100
+ get :show, image_id: image.id
101
+ variant_id = parse_json(response.body)['data']['id']
102
+ expect(variant_id).to eql variant.id.to_s
103
+ end
104
+ end
105
+ end
106
+ end
@@ -0,0 +1,10 @@
1
+ describe SolidusJsonApi do
2
+ describe '.setup' do
3
+ it 'can set the parent serializer' do
4
+ class DescendantOfAMS < ActiveModel::Serializer; end
5
+
6
+ described_class.setup { |c| c.parent_serializer = DescendantOfAMS }
7
+ expect(described_class.parent_serializer).to eql DescendantOfAMS
8
+ end
9
+ end
10
+ 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,3 @@
1
+ describe Spree::Price do
2
+ it { is_expected.to delegate_method(:product).to :variant }
3
+ 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
@@ -0,0 +1,27 @@
1
+ describe Spree::CountrySerializer do
2
+ let(:country) { create :country }
3
+ subject { ActiveModel::Serializer::Adapter::JsonApi.new(described_class.new country) }
4
+
5
+ its(:to_json) do
6
+ is_expected.to be_json_eql <<-JSON
7
+ {
8
+ "data" : {
9
+ "attributes" : {
10
+ "iso" : "#{country.iso}",
11
+ "iso3" : "#{country.iso3}",
12
+ "iso_name" : "#{country.iso_name}",
13
+ "name" : "#{country.name}",
14
+ "numcode" : #{country.numcode},
15
+ "states_required" : #{country.states_required}
16
+ },
17
+ "relationships" : {
18
+ "states" : {
19
+ "data" : []
20
+ }
21
+ },
22
+ "type" : "spree_countries"
23
+ }
24
+ }
25
+ JSON
26
+ end
27
+ end
@@ -0,0 +1,141 @@
1
+ describe Spree::ErrorSerializer do
2
+ let(:address_errors) do
3
+ [
4
+ {
5
+ "ship_address.firstname": ["can't be blank"],
6
+ "ship_address.lastname": ["can't be blank"]
7
+ },
8
+ {
9
+ "bill_address.firstname": ["can't be blank"],
10
+ "bill_address.lastname": ["can't be blank"]
11
+ }
12
+ ]
13
+ end
14
+
15
+ subject { described_class }
16
+
17
+ describe '#as_json' do
18
+ before do
19
+ @store = build(:store, code: nil, mail_from_address: nil)
20
+ @store.save
21
+ end
22
+
23
+ it 'will format json to json api spec' do
24
+ expect(described_class.new(@store).as_json).to be_json_eql <<-JSON
25
+ {
26
+ "errors": [
27
+ {
28
+ "title": "Code",
29
+ "meta": {},
30
+ "pointer": "data/attributes/code",
31
+ "detail": "can't be blank"
32
+ },
33
+ {
34
+ "title": "Mail From Address",
35
+ "meta": {},
36
+ "pointer": "data/attributes/mail_from_address",
37
+ "detail": "can't be blank"
38
+ }
39
+ ]
40
+ }
41
+ JSON
42
+ end
43
+
44
+ it 'will format options as meta' do
45
+ expect(described_class.new(@store, example: :content).as_json).to be_json_eql <<-JSON
46
+ {
47
+ "errors": [
48
+ {
49
+ "detail": "can't be blank",
50
+ "meta": {
51
+ "example": "content"
52
+ },
53
+ "pointer": "data/attributes/code",
54
+ "title": "Code"
55
+ },
56
+ {
57
+ "detail": "can't be blank",
58
+ "meta": {
59
+ "example": "content"
60
+ },
61
+ "pointer": "data/attributes/mail_from_address",
62
+ "title": "Mail From Address"
63
+ }
64
+ ]
65
+ }
66
+ JSON
67
+ end
68
+
69
+ it 'will format a symbol' do
70
+ expect(described_class.new(:invalid_token).as_json).to be_json_eql <<-JSON
71
+ {
72
+ "errors": [
73
+ {
74
+ "detail": "#{Spree.t('api.errors.invalid_token.detail')}",
75
+ "meta": {},
76
+ "title": "#{Spree.t('api.errors.invalid_token.title')}"
77
+ }
78
+ ]
79
+ }
80
+ JSON
81
+ end
82
+
83
+ it 'will format an array of errors' do
84
+ expect(described_class.new(address_errors).as_json).to be_json_eql <<-JSON
85
+ {
86
+ "errors" : [
87
+ {
88
+ "detail" : "can't be blank",
89
+ "meta" : {},
90
+ "pointer" : "data/attributes/ship_address/firstname",
91
+ "title" : "Ship Address Firstname"
92
+ },
93
+ {
94
+ "detail" : "can't be blank",
95
+ "meta" : {},
96
+ "pointer" : "data/attributes/ship_address/lastname",
97
+ "title" : "Ship Address Lastname"
98
+ },
99
+ {
100
+ "detail" : "can't be blank",
101
+ "meta" : {},
102
+ "pointer" : "data/attributes/bill_address/firstname",
103
+ "title" : "Bill Address Firstname"
104
+ },
105
+ {
106
+ "detail" : "can't be blank",
107
+ "meta" : {},
108
+ "pointer" : "data/attributes/bill_address/lastname",
109
+ "title" : "Bill Address Lastname"
110
+ }
111
+ ]
112
+ }
113
+ JSON
114
+ end
115
+
116
+ context 'can set a response when it is present' do
117
+ let(:response) do
118
+ Response ||= Struct.new(:status_message, :code)
119
+ Response.new('OK', 200)
120
+ end
121
+
122
+ subject { described_class.new(:test, response: response).as_json }
123
+
124
+ it do
125
+ should be_json_eql <<-JSON
126
+ {
127
+ "errors" : [
128
+ {
129
+ "code" : 200,
130
+ "detail" : #{Spree.t('api.errors.test.detail').to_json},
131
+ "meta" : {},
132
+ "status" : "OK",
133
+ "title" : #{Spree.t('api.errors.test.title').titleize.to_json}
134
+ }
135
+ ]
136
+ }
137
+ JSON
138
+ end
139
+ end
140
+ end
141
+ end
@@ -0,0 +1,30 @@
1
+ describe Spree::ImageSerializer do
2
+ let(:image) { create :image }
3
+ subject { ActiveModel::Serializer::Adapter::JsonApi.new(described_class.new image) }
4
+
5
+ its(:to_json) do
6
+ is_expected.to be_json_eql <<-JSON
7
+ {
8
+ "data" : {
9
+ "attributes" : {
10
+ "alt" : null,
11
+ "links" : {
12
+ "large" : "#{image.attachment.url(:large)}",
13
+ "mini" : "#{image.attachment.url(:mini)}",
14
+ "original" : "#{image.attachment.url(:original)}",
15
+ "product" : "#{image.attachment.url(:product)}",
16
+ "small" : "#{image.attachment.url(:small)}"
17
+ },
18
+ "position" : 1
19
+ },
20
+ "relationships" : {
21
+ "viewable" : {
22
+ "data" : null
23
+ }
24
+ },
25
+ "type" : "spree_images"
26
+ }
27
+ }
28
+ JSON
29
+ end
30
+ end
@@ -0,0 +1,40 @@
1
+ describe Spree::LineItemSerializer do
2
+ let(:line_item) { create :line_item }
3
+ subject { ActiveModel::Serializer::Adapter::JsonApi.new(described_class.new line_item) }
4
+
5
+ its(:to_json) do
6
+ is_expected.to be_json_eql <<-JSON
7
+ {
8
+ "data" : {
9
+ "attributes" : {
10
+ "additional_tax_total" : "0.0",
11
+ "adjustment_total" : "0.0",
12
+ "amount" : "10.0",
13
+ "cost_price" : "17.0",
14
+ "currency" : "USD",
15
+ "display_amount" : "$10.00",
16
+ "display_total" : "$10.00",
17
+ "order_id" : #{line_item.order_id},
18
+ "price" : "10.0",
19
+ "quantity" : 1,
20
+ "total" : "10.0",
21
+ "variant_id" : #{line_item.variant_id}
22
+ },
23
+ "relationships" : {
24
+ "order" : {
25
+ "data" : {
26
+ "type" : "spree_orders"
27
+ }
28
+ },
29
+ "variant" : {
30
+ "data" : {
31
+ "type" : "spree_variants"
32
+ }
33
+ }
34
+ },
35
+ "type" : "spree_line_items"
36
+ }
37
+ }
38
+ JSON
39
+ end
40
+ end
@@ -0,0 +1,27 @@
1
+ describe Spree::OptionTypeSerializer do
2
+ let(:option_type) { create :option_type }
3
+ subject { ActiveModel::Serializer::Adapter::JsonApi.new(described_class.new option_type) }
4
+
5
+ its(:to_json) do
6
+ is_expected.to be_json_eql <<-JSON
7
+ {
8
+ "data" : {
9
+ "attributes" : {
10
+ "name" : "#{option_type.name}",
11
+ "position" : #{option_type.position},
12
+ "presentation" : "#{option_type.presentation}"
13
+ },
14
+ "relationships" : {
15
+ "option_values" : {
16
+ "data" : []
17
+ },
18
+ "products" : {
19
+ "data" : []
20
+ }
21
+ },
22
+ "type" : "spree_option_types"
23
+ }
24
+ }
25
+ JSON
26
+ end
27
+ end
@@ -0,0 +1,29 @@
1
+ describe Spree::OptionValueSerializer do
2
+ let(:option_value) { create :option_value }
3
+ subject { ActiveModel::Serializer::Adapter::JsonApi.new(described_class.new option_value) }
4
+
5
+ its(:to_json) do
6
+ is_expected.to be_json_eql <<-JSON
7
+ {
8
+ "data" : {
9
+ "attributes" : {
10
+ "name" : "#{option_value.name}",
11
+ "position" : #{option_value.position},
12
+ "presentation" : "#{option_value.presentation}"
13
+ },
14
+ "relationships" : {
15
+ "option_type" : {
16
+ "data" : {
17
+ "type" : "spree_option_types"
18
+ }
19
+ },
20
+ "variants" : {
21
+ "data" : []
22
+ }
23
+ },
24
+ "type" : "spree_option_values"
25
+ }
26
+ }
27
+ JSON
28
+ end
29
+ end
@@ -0,0 +1,68 @@
1
+ describe Spree::OrderSerializer do
2
+ let(:order) { create :completed_order_with_totals }
3
+ subject { ActiveModel::Serializer::Adapter::JsonApi.new(described_class.new order) }
4
+
5
+ its(:to_json) do
6
+ is_expected.to be_json_eql <<-JSON
7
+ {
8
+ "data" : {
9
+ "attributes" : {
10
+ "additional_tax_total" : "0.0",
11
+ "adjustment_total" : "0.0",
12
+ "approved_at" : null,
13
+ "canceled_at" : null,
14
+ "channel" : "spree",
15
+ "completed_at" : "#{order.completed_at.iso8601(3)}",
16
+ "confirmation_delivered" : false,
17
+ "currency" : "USD",
18
+ "display_additional_tax_total" : "$0.00",
19
+ "display_adjustment_total" : "$0.00",
20
+ "display_included_tax_total" : "$0.00",
21
+ "display_item_total" : "$10.00",
22
+ "display_promo_total" : "$0.00",
23
+ "display_shipment_total" : "$100.00",
24
+ "display_total" : "$110.00",
25
+ "email" : "#{order.email}",
26
+ "included_tax_total" : "0.0",
27
+ "item_count" : 1,
28
+ "item_total" : "10.0",
29
+ "number" : "#{order.number}",
30
+ "payment_state" : null,
31
+ "payment_total" : "0.0",
32
+ "promo_total" : "0.0",
33
+ "shipment_state" : null,
34
+ "shipment_total" : "100.0",
35
+ "special_instructions" : null,
36
+ "state" : "complete",
37
+ "total" : "110.0"
38
+ },
39
+ "relationships" : {
40
+ "bill_address" : {
41
+ "data" : {
42
+ "type" : "spree_addresses"
43
+ }
44
+ },
45
+ "line_items" : {
46
+ "data" : [
47
+ {
48
+ "type" : "spree_line_items"
49
+ }
50
+ ]
51
+ },
52
+ "ship_address" : {
53
+ "data" : {
54
+ "type" : "spree_addresses"
55
+ }
56
+ },
57
+ "user" : {
58
+ "data" : {
59
+ "type" : "spree_users"
60
+ }
61
+ }
62
+ },
63
+ "type" : "spree_orders"
64
+ }
65
+ }
66
+ JSON
67
+ end
68
+ end