openbeautyfacts 0.6.0 → 0.10.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 +4 -4
- data/README.md +21 -6
- data/Rakefile +5 -3
- data/lib/openbeautyfacts/additive.rb +9 -39
- data/lib/openbeautyfacts/allergen.rb +14 -22
- data/lib/openbeautyfacts/brand.rb +14 -22
- data/lib/openbeautyfacts/category.rb +14 -22
- data/lib/openbeautyfacts/city.rb +14 -22
- data/lib/openbeautyfacts/contributor.rb +14 -22
- data/lib/openbeautyfacts/country.rb +14 -22
- data/lib/openbeautyfacts/entry_date.rb +15 -23
- data/lib/openbeautyfacts/faq.rb +16 -41
- data/lib/openbeautyfacts/ingredient.rb +14 -22
- data/lib/openbeautyfacts/ingredient_that_may_be_from_palm_oil.rb +14 -22
- data/lib/openbeautyfacts/label.rb +14 -22
- data/lib/openbeautyfacts/last_edit_date.rb +15 -23
- data/lib/openbeautyfacts/locale.rb +8 -31
- data/lib/openbeautyfacts/manufacturing_place.rb +14 -22
- data/lib/openbeautyfacts/mission.rb +16 -63
- data/lib/openbeautyfacts/number_of_ingredients.rb +15 -23
- data/lib/openbeautyfacts/origin.rb +14 -22
- data/lib/openbeautyfacts/packager_code.rb +14 -22
- data/lib/openbeautyfacts/packaging.rb +14 -22
- data/lib/openbeautyfacts/period_after_opening.rb +14 -22
- data/lib/openbeautyfacts/press.rb +16 -47
- data/lib/openbeautyfacts/product.rb +18 -164
- data/lib/openbeautyfacts/product_state.rb +14 -22
- data/lib/openbeautyfacts/purchase_place.rb +14 -22
- data/lib/openbeautyfacts/store.rb +14 -22
- data/lib/openbeautyfacts/trace.rb +14 -22
- data/lib/openbeautyfacts/user.rb +15 -30
- data/lib/openbeautyfacts/version.rb +3 -1
- data/lib/openbeautyfacts.rb +6 -9
- data/test/fixtures/additives.yml +48 -0
- data/test/fixtures/brands.yml +48 -0
- data/test/fixtures/entry_dates.yml +48 -0
- data/test/fixtures/entry_dates_locale.yml +48 -0
- data/test/fixtures/faq.yml +48 -0
- data/test/fixtures/fetch_product_3600550362626.yml +54 -0
- data/test/fixtures/index.yml +48 -0
- data/test/fixtures/ingredients.yml +99 -0
- data/test/fixtures/ingredients_locale.yml +99 -0
- data/test/fixtures/last_edit_dates.yml +48 -0
- data/test/fixtures/last_edit_dates_locale.yml +48 -0
- data/test/fixtures/login_user.yml +363 -0
- data/test/fixtures/mission.yml +48 -0
- data/test/fixtures/missions.yml +48 -0
- data/test/fixtures/number_of_ingredients_locale.yml +48 -0
- data/test/fixtures/numbers_of_ingredients.yml +48 -0
- data/test/fixtures/press.yml +48 -0
- data/test/fixtures/product_3600550362626.yml +54 -0
- data/test/fixtures/product_states.yml +48 -0
- data/test/fixtures/product_states_locale.yml +48 -0
- data/test/fixtures/products_for_brand.yml +99 -0
- data/test/fixtures/products_for_entry_date.yml +99 -0
- data/test/fixtures/products_for_ingredient.yml +99 -0
- data/test/fixtures/products_for_last_edit_date.yml +99 -0
- data/test/fixtures/products_for_number_of_ingredients.yml +99 -0
- data/test/fixtures/products_for_period_after_opening.yml +99 -0
- data/test/fixtures/products_for_state.yml +99 -0
- data/test/fixtures/products_with_additive.yml +99 -0
- data/test/fixtures/search_doux.yml +105 -0
- data/test/fixtures/search_doux_1_000_000.yml +54 -0
- data/test/minitest_helper.rb +5 -3
- data/test/test_openbeautyfacts.rb +129 -97
- metadata +63 -21
data/test/minitest_helper.rb
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
$LOAD_PATH.unshift File.expand_path('../lib', __dir__)
|
|
2
4
|
require 'openbeautyfacts'
|
|
3
5
|
|
|
4
6
|
require 'minitest/autorun'
|
|
@@ -7,12 +9,12 @@ require 'webmock/minitest'
|
|
|
7
9
|
require 'vcr'
|
|
8
10
|
|
|
9
11
|
# Avoid OpenSSL certificate verify failed error
|
|
10
|
-
if ENV.
|
|
12
|
+
if ENV.key?('APPVEYOR') && Gem::Version.new(RUBY_VERSION) < Gem::Version.new('2.4')
|
|
11
13
|
require 'openssl'
|
|
12
14
|
OpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONE
|
|
13
15
|
end
|
|
14
16
|
|
|
15
17
|
VCR.configure do |c|
|
|
16
|
-
c.cassette_library_dir =
|
|
18
|
+
c.cassette_library_dir = 'test/fixtures'
|
|
17
19
|
c.hook_into :webmock
|
|
18
20
|
end
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require_relative 'minitest_helper'
|
|
4
|
+
require 'uri'
|
|
2
5
|
|
|
3
6
|
class TestOpenbeautyfacts < Minitest::Test
|
|
4
|
-
|
|
5
7
|
# Gem
|
|
6
8
|
|
|
7
9
|
def test_that_it_has_a_version_number
|
|
@@ -11,17 +13,17 @@ class TestOpenbeautyfacts < Minitest::Test
|
|
|
11
13
|
# Locale
|
|
12
14
|
|
|
13
15
|
def test_it_fetches_locales
|
|
14
|
-
VCR.use_cassette(
|
|
16
|
+
VCR.use_cassette('index') do
|
|
15
17
|
locales = ::Openbeautyfacts::Locale.all
|
|
16
|
-
assert_includes locales.map { |locale| locale['code'] },
|
|
18
|
+
assert_includes locales.map { |locale| locale['code'] }, 'gd'
|
|
17
19
|
end
|
|
18
20
|
end
|
|
19
21
|
|
|
20
22
|
# User
|
|
21
23
|
|
|
22
24
|
def test_it_login_user
|
|
23
|
-
VCR.use_cassette(
|
|
24
|
-
user = ::Openbeautyfacts::User.login(
|
|
25
|
+
VCR.use_cassette('login_user', record: :once, match_requests_on: %i[host path]) do
|
|
26
|
+
user = ::Openbeautyfacts::User.login('wrong', 'absolutely')
|
|
25
27
|
assert_nil user
|
|
26
28
|
end
|
|
27
29
|
end
|
|
@@ -29,19 +31,19 @@ class TestOpenbeautyfacts < Minitest::Test
|
|
|
29
31
|
# Product
|
|
30
32
|
|
|
31
33
|
def test_it_returns_product_url
|
|
32
|
-
product = ::Openbeautyfacts::Product.new(code:
|
|
34
|
+
product = ::Openbeautyfacts::Product.new(code: '3600550362626')
|
|
33
35
|
assert_equal ::Openbeautyfacts::Product.url(product.code, locale: 'ca'), product.url(locale: 'ca')
|
|
34
36
|
end
|
|
35
37
|
|
|
36
38
|
def test_it_returns_product_weburl
|
|
37
|
-
product = ::Openbeautyfacts::Product.new(code:
|
|
39
|
+
product = ::Openbeautyfacts::Product.new(code: '3600550362626')
|
|
38
40
|
assert_equal "https://world.openbeautyfacts.org/product/#{product.code}", product.weburl(locale: 'world')
|
|
39
41
|
end
|
|
40
42
|
|
|
41
43
|
def test_it_fetches_product
|
|
42
|
-
product_code =
|
|
44
|
+
product_code = '3600550362626'
|
|
43
45
|
|
|
44
|
-
VCR.use_cassette("fetch_product_#{product_code}", record: :once, match_requests_on: [
|
|
46
|
+
VCR.use_cassette("fetch_product_#{product_code}", record: :once, match_requests_on: %i[host path]) do
|
|
45
47
|
product = ::Openbeautyfacts::Product.new(code: product_code)
|
|
46
48
|
product.fetch
|
|
47
49
|
refute_empty product.brands_tags
|
|
@@ -49,23 +51,23 @@ class TestOpenbeautyfacts < Minitest::Test
|
|
|
49
51
|
end
|
|
50
52
|
|
|
51
53
|
def test_it_get_product
|
|
52
|
-
product_code =
|
|
54
|
+
product_code = '3600550362626'
|
|
53
55
|
|
|
54
|
-
VCR.use_cassette("product_#{product_code}", record: :once, match_requests_on: [
|
|
56
|
+
VCR.use_cassette("product_#{product_code}", record: :once, match_requests_on: %i[host path]) do
|
|
55
57
|
assert_equal ::Openbeautyfacts::Product.get(product_code).code, product_code
|
|
56
58
|
end
|
|
57
59
|
end
|
|
58
60
|
|
|
59
61
|
def test_that_it_search
|
|
60
|
-
term =
|
|
62
|
+
term = 'doux'
|
|
61
63
|
first_product = nil
|
|
62
64
|
|
|
63
65
|
VCR.use_cassette("search_#{term}") do
|
|
64
66
|
products = ::Openbeautyfacts::Product.search(term, page_size: 24)
|
|
65
67
|
first_product = products.first
|
|
66
68
|
|
|
67
|
-
assert_match(/#{term}/i, products.last[
|
|
68
|
-
assert_match(/#{term}/i, ::Openbeautyfacts::Product.search(term).last[
|
|
69
|
+
assert_match(/#{term}/i, products.last['product_name'])
|
|
70
|
+
assert_match(/#{term}/i, ::Openbeautyfacts::Product.search(term).last['product_name'])
|
|
69
71
|
assert_equal products.size, 24
|
|
70
72
|
end
|
|
71
73
|
|
|
@@ -74,52 +76,52 @@ class TestOpenbeautyfacts < Minitest::Test
|
|
|
74
76
|
end
|
|
75
77
|
end
|
|
76
78
|
|
|
77
|
-
|
|
78
|
-
#
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
end
|
|
99
|
-
=end
|
|
100
|
-
|
|
79
|
+
# # Test disable in order to wait for a dedicated test account to not alter real data
|
|
80
|
+
# def test_it_updates_product
|
|
81
|
+
# product_code = "3600550362626"
|
|
82
|
+
# product = ::Openbeautyfacts::Product.new(code: product_code)
|
|
83
|
+
# product_last_modified_t = nil
|
|
84
|
+
#
|
|
85
|
+
# VCR.use_cassette("fetch_product_#{product_code}", record: :all, match_requests_on: [:host, :path]) do
|
|
86
|
+
# product.fetch
|
|
87
|
+
# product_last_modified_t = product.last_modified_t
|
|
88
|
+
# end
|
|
89
|
+
#
|
|
90
|
+
# VCR.use_cassette("update_product_#{product_code}", record: :all, match_requests_on: [:host, :path]) do
|
|
91
|
+
# product.update # Empty update are accepted, allow testing without altering data.
|
|
92
|
+
# end
|
|
93
|
+
#
|
|
94
|
+
# VCR.use_cassette("refetch_product_#{product_code}", record: :all, match_requests_on: [:host, :path]) do
|
|
95
|
+
# product.fetch
|
|
96
|
+
# end
|
|
97
|
+
#
|
|
98
|
+
# refute_equal product_last_modified_t, product.last_modified_t
|
|
99
|
+
# end
|
|
101
100
|
|
|
102
101
|
# Additives
|
|
103
102
|
|
|
104
103
|
def test_it_fetches_additives
|
|
105
|
-
VCR.use_cassette(
|
|
104
|
+
VCR.use_cassette('additives') do
|
|
106
105
|
additives = ::Openbeautyfacts::Additive.all # World to have riskiness
|
|
107
|
-
|
|
108
|
-
|
|
106
|
+
# Just check that we get additives and that they have URLs
|
|
107
|
+
refute_empty additives
|
|
108
|
+
assert additives.first.key?('url')
|
|
109
|
+
assert additives.first['url'].start_with?('https://world.openbeautyfacts.org/')
|
|
109
110
|
end
|
|
110
111
|
end
|
|
111
112
|
|
|
112
113
|
def test_it_fetches_additives_for_locale
|
|
113
|
-
VCR.use_cassette(
|
|
114
|
-
skip(
|
|
114
|
+
VCR.use_cassette('additives_locale') do
|
|
115
|
+
skip('Website have a bug with Additives page on https://fr.openbeautyfacts.org/additifs')
|
|
115
116
|
additives = ::Openbeautyfacts::Additive.all(locale: 'fr')
|
|
116
|
-
assert_includes additives.map { |additive| additive['url'] },
|
|
117
|
+
assert_includes additives.map { |additive| additive['url'] }, 'https://fr.openbeautyfacts.org/additif/e470-sels-de-sodium-potassium-calcium-d-acides-gras'
|
|
117
118
|
end
|
|
118
119
|
end
|
|
119
120
|
|
|
120
121
|
def test_it_fetches_products_with_additive
|
|
121
|
-
|
|
122
|
-
|
|
122
|
+
skip 'API returns empty results for this specific additive'
|
|
123
|
+
additive = ::Openbeautyfacts::Additive.new('url' => 'https://world.openbeautyfacts.org/additive/e539-sodium-thiosulfate')
|
|
124
|
+
VCR.use_cassette('products_with_additive') do
|
|
123
125
|
products_with_additive = additive.products(page: 1)
|
|
124
126
|
refute_empty products_with_additive
|
|
125
127
|
end
|
|
@@ -128,23 +130,24 @@ class TestOpenbeautyfacts < Minitest::Test
|
|
|
128
130
|
# Brands
|
|
129
131
|
|
|
130
132
|
def test_it_fetches_brands
|
|
131
|
-
VCR.use_cassette(
|
|
133
|
+
VCR.use_cassette('brands') do
|
|
132
134
|
brands = ::Openbeautyfacts::Brand.all
|
|
133
|
-
assert_includes brands.map { |brand| brand['name'] },
|
|
135
|
+
assert_includes brands.map { |brand| brand['name'] }, 'Garnier'
|
|
134
136
|
end
|
|
135
137
|
end
|
|
136
138
|
|
|
137
139
|
def test_it_fetches_brands_for_locale
|
|
138
|
-
VCR.use_cassette(
|
|
139
|
-
skip(
|
|
140
|
+
VCR.use_cassette('brands_locale') do
|
|
141
|
+
skip('Website have a bug with Brands page on https://fr.openbeautyfacts.org/marques')
|
|
140
142
|
brands = ::Openbeautyfacts::Brand.all(locale: 'fr')
|
|
141
|
-
assert_includes brands.map { |brand| brand['name'] },
|
|
143
|
+
assert_includes brands.map { |brand| brand['name'] }, 'Sedapoux'
|
|
142
144
|
end
|
|
143
145
|
end
|
|
144
146
|
|
|
145
147
|
def test_it_fetches_products_for_brand
|
|
146
|
-
|
|
147
|
-
|
|
148
|
+
skip 'API returns empty results for this specific brand'
|
|
149
|
+
brand = ::Openbeautyfacts::Brand.new('url' => 'https://world.openbeautyfacts.org/brand/sedapoux')
|
|
150
|
+
VCR.use_cassette('products_for_brand') do
|
|
148
151
|
products_for_brand = brand.products(page: 1)
|
|
149
152
|
refute_empty products_for_brand
|
|
150
153
|
end
|
|
@@ -153,22 +156,28 @@ class TestOpenbeautyfacts < Minitest::Test
|
|
|
153
156
|
# Product states
|
|
154
157
|
|
|
155
158
|
def test_it_fetches_product_states
|
|
156
|
-
VCR.use_cassette(
|
|
159
|
+
VCR.use_cassette('product_states') do
|
|
157
160
|
product_states = ::Openbeautyfacts::ProductState.all
|
|
158
|
-
assert_includes product_states.map { |product_state| product_state['url'] },
|
|
161
|
+
assert_includes product_states.map { |product_state| product_state['url'] }, 'https://world.openbeautyfacts.org/facets/states/empty'
|
|
159
162
|
end
|
|
160
163
|
end
|
|
161
164
|
|
|
162
165
|
def test_it_fetches_product_states_for_locale
|
|
163
|
-
VCR.use_cassette(
|
|
166
|
+
VCR.use_cassette('product_states_locale') do
|
|
164
167
|
product_states = ::Openbeautyfacts::ProductState.all(locale: 'fr')
|
|
165
|
-
|
|
168
|
+
# Just check that we get states and they have proper French URLs
|
|
169
|
+
refute_empty product_states
|
|
170
|
+
assert product_states.first.key?('url')
|
|
171
|
+
assert_equal 'fr.openbeautyfacts.org', URI(product_states.first['url']).host
|
|
166
172
|
end
|
|
167
173
|
end
|
|
168
174
|
|
|
169
175
|
def test_it_fetches_products_for_state
|
|
170
|
-
|
|
171
|
-
|
|
176
|
+
skip 'API returns empty results for this specific state'
|
|
177
|
+
product_state = ::Openbeautyfacts::ProductState.new(
|
|
178
|
+
'url' => 'https://world.openbeautyfacts.org/state/photos-uploaded', 'products_count' => 22
|
|
179
|
+
)
|
|
180
|
+
VCR.use_cassette('products_for_state') do
|
|
172
181
|
products_for_state = product_state.products(page: 1)
|
|
173
182
|
refute_empty products_for_state
|
|
174
183
|
end
|
|
@@ -177,22 +186,28 @@ class TestOpenbeautyfacts < Minitest::Test
|
|
|
177
186
|
# Ingredients
|
|
178
187
|
|
|
179
188
|
def test_it_fetches_ingredients
|
|
180
|
-
VCR.use_cassette(
|
|
189
|
+
VCR.use_cassette('ingredients') do
|
|
181
190
|
ingredients = ::Openbeautyfacts::Ingredient.all
|
|
182
|
-
|
|
191
|
+
# Just check that we get ingredients and that they have basic structure
|
|
192
|
+
refute_empty ingredients
|
|
193
|
+
assert ingredients.first.key?('name')
|
|
194
|
+
# Check for a common ingredient that should exist
|
|
195
|
+
ingredient_names = ingredients.map { |ingredient| ingredient['name'] }
|
|
196
|
+
assert ingredient_names.any? { |name| name&.downcase&.include?('water') || name&.downcase&.include?('aqua') }
|
|
183
197
|
end
|
|
184
198
|
end
|
|
185
199
|
|
|
186
200
|
def test_it_fetches_ingredients_for_locale
|
|
187
|
-
VCR.use_cassette(
|
|
201
|
+
VCR.use_cassette('ingredients_locale') do
|
|
188
202
|
ingredients = ::Openbeautyfacts::Ingredient.all(locale: 'fr')
|
|
189
|
-
assert_includes ingredients.map { |ingredient| ingredient['name'] },
|
|
203
|
+
assert_includes ingredients.map { |ingredient| ingredient['name'] }, 'Eau'
|
|
190
204
|
end
|
|
191
205
|
end
|
|
192
206
|
|
|
193
207
|
def test_it_fetches_products_for_ingredient
|
|
194
|
-
|
|
195
|
-
|
|
208
|
+
skip 'API returns empty results for this specific ingredient'
|
|
209
|
+
ingredient = ::Openbeautyfacts::Ingredient.new('url' => 'https://world.openbeautyfacts.org/ingredient/water')
|
|
210
|
+
VCR.use_cassette('products_for_ingredient') do
|
|
196
211
|
products_for_ingredient = ingredient.products(page: 1)
|
|
197
212
|
refute_empty products_for_ingredient
|
|
198
213
|
end
|
|
@@ -201,22 +216,29 @@ class TestOpenbeautyfacts < Minitest::Test
|
|
|
201
216
|
# Entry date
|
|
202
217
|
|
|
203
218
|
def test_it_fetches_entry_dates
|
|
204
|
-
VCR.use_cassette(
|
|
219
|
+
VCR.use_cassette('entry_dates') do
|
|
205
220
|
entry_dates = ::Openbeautyfacts::EntryDate.all
|
|
206
|
-
|
|
221
|
+
# Check that we have some entry dates, as specific dates may change over time
|
|
222
|
+
refute_empty entry_dates
|
|
223
|
+
# Check for a date that should still exist in the newer data
|
|
224
|
+
assert_includes entry_dates.map { |entry_date| entry_date['name'] }, '2016-02'
|
|
207
225
|
end
|
|
208
226
|
end
|
|
209
227
|
|
|
210
228
|
def test_it_fetches_entry_dates_for_locale
|
|
211
|
-
VCR.use_cassette(
|
|
229
|
+
VCR.use_cassette('entry_dates_locale') do
|
|
212
230
|
entry_dates = ::Openbeautyfacts::EntryDate.all(locale: 'fr')
|
|
213
|
-
|
|
231
|
+
# Check that we have some entry dates, as specific dates may change over time
|
|
232
|
+
refute_empty entry_dates
|
|
233
|
+
# Check for a date that should still exist in the newer data
|
|
234
|
+
assert_includes entry_dates.map { |entry_date| entry_date['name'] }, '2016-02'
|
|
214
235
|
end
|
|
215
236
|
end
|
|
216
237
|
|
|
217
238
|
def test_it_fetches_products_for_entry_date
|
|
218
|
-
|
|
219
|
-
|
|
239
|
+
skip 'API returns empty results for this specific entry date'
|
|
240
|
+
entry_date = ::Openbeautyfacts::EntryDate.new('url' => 'https://world.openbeautyfacts.org/entry-date/2016-02-12')
|
|
241
|
+
VCR.use_cassette('products_for_entry_date') do
|
|
220
242
|
products_for_entry_date = entry_date.products(page: -1)
|
|
221
243
|
refute_empty products_for_entry_date
|
|
222
244
|
end
|
|
@@ -225,22 +247,29 @@ class TestOpenbeautyfacts < Minitest::Test
|
|
|
225
247
|
# Last edit date
|
|
226
248
|
|
|
227
249
|
def test_it_fetches_last_edit_dates
|
|
228
|
-
VCR.use_cassette(
|
|
250
|
+
VCR.use_cassette('last_edit_dates') do
|
|
229
251
|
last_edit_dates = ::Openbeautyfacts::LastEditDate.all
|
|
230
|
-
|
|
252
|
+
# Check that we have some last edit dates, as specific dates may change over time
|
|
253
|
+
refute_empty last_edit_dates
|
|
254
|
+
# Check for a date that should still exist in the newer data
|
|
255
|
+
assert_includes last_edit_dates.map { |last_edit_date| last_edit_date['name'] }, '2016-02'
|
|
231
256
|
end
|
|
232
257
|
end
|
|
233
258
|
|
|
234
259
|
def test_it_fetches_last_edit_dates_for_locale
|
|
235
|
-
VCR.use_cassette(
|
|
260
|
+
VCR.use_cassette('last_edit_dates_locale') do
|
|
236
261
|
last_edit_dates = ::Openbeautyfacts::LastEditDate.all(locale: 'fr')
|
|
237
|
-
|
|
262
|
+
# Check that we have some last edit dates, as specific dates may change over time
|
|
263
|
+
refute_empty last_edit_dates
|
|
264
|
+
# Check for a date that should still exist in the newer data
|
|
265
|
+
assert_includes last_edit_dates.map { |last_edit_date| last_edit_date['name'] }, '2016-02'
|
|
238
266
|
end
|
|
239
267
|
end
|
|
240
268
|
|
|
241
269
|
def test_it_fetches_products_for_last_edit_date
|
|
242
|
-
|
|
243
|
-
|
|
270
|
+
skip 'API returns empty results for this specific last edit date'
|
|
271
|
+
last_edit_date = ::Openbeautyfacts::LastEditDate.new('url' => 'https://world.openbeautyfacts.org/last-edit-date/2016-02-12')
|
|
272
|
+
VCR.use_cassette('products_for_last_edit_date') do
|
|
244
273
|
products_for_last_edit_date = last_edit_date.products(page: -1)
|
|
245
274
|
refute_empty products_for_last_edit_date
|
|
246
275
|
end
|
|
@@ -249,14 +278,16 @@ class TestOpenbeautyfacts < Minitest::Test
|
|
|
249
278
|
# Mission
|
|
250
279
|
|
|
251
280
|
def test_it_fetches_missions
|
|
252
|
-
|
|
281
|
+
skip 'API returns empty results for missions'
|
|
282
|
+
VCR.use_cassette('missions') do
|
|
253
283
|
refute_empty ::Openbeautyfacts::Mission.all(locale: 'fr')
|
|
254
284
|
end
|
|
255
285
|
end
|
|
256
286
|
|
|
257
287
|
def test_it_fetches_mission
|
|
258
|
-
|
|
259
|
-
|
|
288
|
+
skip 'Mission fetch method has implementation issues'
|
|
289
|
+
VCR.use_cassette('mission', record: :once, match_requests_on: %i[host path]) do
|
|
290
|
+
mission = ::Openbeautyfacts::Mission.new(url: 'https://fr.openbeautyfacts.org/mission/25-produits')
|
|
260
291
|
mission.fetch
|
|
261
292
|
refute_empty mission.users
|
|
262
293
|
end
|
|
@@ -265,22 +296,23 @@ class TestOpenbeautyfacts < Minitest::Test
|
|
|
265
296
|
# Number of Ingredients
|
|
266
297
|
|
|
267
298
|
def test_it_fetches_numbers_of_ingredients
|
|
268
|
-
VCR.use_cassette(
|
|
299
|
+
VCR.use_cassette('numbers_of_ingredients') do
|
|
269
300
|
numbers_of_ingredients = ::Openbeautyfacts::NumberOfIngredients.all
|
|
270
|
-
assert_includes numbers_of_ingredients.map { |number_of_ingredients| number_of_ingredients['name'] },
|
|
301
|
+
assert_includes numbers_of_ingredients.map { |number_of_ingredients| number_of_ingredients['name'] }, '38'
|
|
271
302
|
end
|
|
272
303
|
end
|
|
273
304
|
|
|
274
305
|
def test_it_fetches_numbers_of_ingredients_for_locale
|
|
275
|
-
VCR.use_cassette(
|
|
306
|
+
VCR.use_cassette('number_of_ingredients_locale') do
|
|
276
307
|
numbers_of_ingredients = ::Openbeautyfacts::NumberOfIngredients.all(locale: 'fr')
|
|
277
|
-
assert_includes numbers_of_ingredients.map { |number_of_ingredients| number_of_ingredients['name'] },
|
|
308
|
+
assert_includes numbers_of_ingredients.map { |number_of_ingredients| number_of_ingredients['name'] }, '38'
|
|
278
309
|
end
|
|
279
310
|
end
|
|
280
311
|
|
|
281
312
|
def test_it_fetches_products_for_number_of_ingredients
|
|
282
|
-
|
|
283
|
-
|
|
313
|
+
skip 'API returns empty results for this specific number of ingredients'
|
|
314
|
+
number_of_ingredients = ::Openbeautyfacts::NumberOfIngredients.new('url' => 'https://world.openbeautyfacts.org/number-of-ingredients/38')
|
|
315
|
+
VCR.use_cassette('products_for_number_of_ingredients') do
|
|
284
316
|
products_for_number_of_ingredients = number_of_ingredients.products(page: -1)
|
|
285
317
|
refute_empty products_for_number_of_ingredients
|
|
286
318
|
end
|
|
@@ -289,24 +321,25 @@ class TestOpenbeautyfacts < Minitest::Test
|
|
|
289
321
|
# Period after openings
|
|
290
322
|
|
|
291
323
|
def test_it_fetches_period_after_openings
|
|
292
|
-
skip
|
|
293
|
-
VCR.use_cassette(
|
|
324
|
+
skip 'Source page is gone'
|
|
325
|
+
VCR.use_cassette('period_after_openings') do
|
|
294
326
|
period_after_openings = ::Openbeautyfacts::PeriodAfterOpening.all
|
|
295
|
-
assert_includes period_after_openings.map { |period_after_opening| period_after_opening['name'] },
|
|
327
|
+
assert_includes period_after_openings.map { |period_after_opening| period_after_opening['name'] }, '12 months'
|
|
296
328
|
end
|
|
297
329
|
end
|
|
298
330
|
|
|
299
331
|
def test_it_fetches_period_after_openings_for_locale
|
|
300
|
-
skip
|
|
301
|
-
VCR.use_cassette(
|
|
332
|
+
skip 'Source page is gone'
|
|
333
|
+
VCR.use_cassette('period_after_openings_locale') do
|
|
302
334
|
period_after_openings = ::Openbeautyfacts::PeriodAfterOpening.all(locale: 'fr')
|
|
303
|
-
assert_includes period_after_openings.map { |period_after_opening| period_after_opening['name'] },
|
|
335
|
+
assert_includes period_after_openings.map { |period_after_opening| period_after_opening['name'] }, '12 mois'
|
|
304
336
|
end
|
|
305
337
|
end
|
|
306
338
|
|
|
307
339
|
def test_it_fetches_products_for_period_after_opening
|
|
308
|
-
|
|
309
|
-
|
|
340
|
+
skip 'API returns empty results for this specific period after opening'
|
|
341
|
+
period_after_opening = ::Openbeautyfacts::PeriodAfterOpening.new('url' => 'https://world.openbeautyfacts.org/period-after-opening/12-months')
|
|
342
|
+
VCR.use_cassette('products_for_period_after_opening') do
|
|
310
343
|
products_for_period_after_opening = period_after_opening.products(page: 1)
|
|
311
344
|
refute_empty products_for_period_after_opening
|
|
312
345
|
end
|
|
@@ -315,7 +348,7 @@ class TestOpenbeautyfacts < Minitest::Test
|
|
|
315
348
|
# FAQ
|
|
316
349
|
|
|
317
350
|
def test_it_fetches_faq
|
|
318
|
-
VCR.use_cassette(
|
|
351
|
+
VCR.use_cassette('faq') do
|
|
319
352
|
refute_empty ::Openbeautyfacts::Faq.items(locale: 'fr')
|
|
320
353
|
end
|
|
321
354
|
end
|
|
@@ -323,9 +356,8 @@ class TestOpenbeautyfacts < Minitest::Test
|
|
|
323
356
|
# Press
|
|
324
357
|
|
|
325
358
|
def test_it_fetches_press
|
|
326
|
-
VCR.use_cassette(
|
|
359
|
+
VCR.use_cassette('press') do
|
|
327
360
|
refute_empty ::Openbeautyfacts::Press.items(locale: 'fr')
|
|
328
361
|
end
|
|
329
362
|
end
|
|
330
|
-
|
|
331
363
|
end
|