openbeautyfacts 0.6.3 → 0.11.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 +19 -1
- 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 -175
- 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
- metadata +29 -19
- data/test/minitest_helper.rb +0 -18
- data/test/test_openbeautyfacts.rb +0 -331
|
@@ -1,331 +0,0 @@
|
|
|
1
|
-
require_relative 'minitest_helper'
|
|
2
|
-
|
|
3
|
-
class TestOpenbeautyfacts < Minitest::Test
|
|
4
|
-
|
|
5
|
-
# Gem
|
|
6
|
-
|
|
7
|
-
def test_that_it_has_a_version_number
|
|
8
|
-
refute_nil ::Openbeautyfacts::VERSION
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
# Locale
|
|
12
|
-
|
|
13
|
-
def test_it_fetches_locales
|
|
14
|
-
VCR.use_cassette("index") do
|
|
15
|
-
locales = ::Openbeautyfacts::Locale.all
|
|
16
|
-
assert_includes locales.map { |locale| locale['code'] }, "gd"
|
|
17
|
-
end
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
# User
|
|
21
|
-
|
|
22
|
-
def test_it_login_user
|
|
23
|
-
VCR.use_cassette("login_user", record: :once, match_requests_on: [:host, :path]) do
|
|
24
|
-
user = ::Openbeautyfacts::User.login("wrong", "absolutely")
|
|
25
|
-
assert_nil user
|
|
26
|
-
end
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
# Product
|
|
30
|
-
|
|
31
|
-
def test_it_returns_product_url
|
|
32
|
-
product = ::Openbeautyfacts::Product.new(code: "3600550362626")
|
|
33
|
-
assert_equal ::Openbeautyfacts::Product.url(product.code, locale: 'ca'), product.url(locale: 'ca')
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
def test_it_returns_product_weburl
|
|
37
|
-
product = ::Openbeautyfacts::Product.new(code: "3600550362626")
|
|
38
|
-
assert_equal "https://world.openbeautyfacts.org/product/#{product.code}", product.weburl(locale: 'world')
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
def test_it_fetches_product
|
|
42
|
-
product_code = "3600550362626"
|
|
43
|
-
|
|
44
|
-
VCR.use_cassette("fetch_product_#{product_code}", record: :once, match_requests_on: [:host, :path]) do
|
|
45
|
-
product = ::Openbeautyfacts::Product.new(code: product_code)
|
|
46
|
-
product.fetch
|
|
47
|
-
refute_empty product.brands_tags
|
|
48
|
-
end
|
|
49
|
-
end
|
|
50
|
-
|
|
51
|
-
def test_it_get_product
|
|
52
|
-
product_code = "3600550362626"
|
|
53
|
-
|
|
54
|
-
VCR.use_cassette("product_#{product_code}", record: :once, match_requests_on: [:host, :path]) do
|
|
55
|
-
assert_equal ::Openbeautyfacts::Product.get(product_code).code, product_code
|
|
56
|
-
end
|
|
57
|
-
end
|
|
58
|
-
|
|
59
|
-
def test_that_it_search
|
|
60
|
-
term = "doux"
|
|
61
|
-
first_product = nil
|
|
62
|
-
|
|
63
|
-
VCR.use_cassette("search_#{term}") do
|
|
64
|
-
products = ::Openbeautyfacts::Product.search(term, page_size: 24)
|
|
65
|
-
first_product = products.first
|
|
66
|
-
|
|
67
|
-
assert_match(/#{term}/i, products.last["product_name"])
|
|
68
|
-
assert_match(/#{term}/i, ::Openbeautyfacts::Product.search(term).last["product_name"])
|
|
69
|
-
assert_equal products.size, 24
|
|
70
|
-
end
|
|
71
|
-
|
|
72
|
-
VCR.use_cassette("search_#{term}_1_000_000") do
|
|
73
|
-
refute_equal ::Openbeautyfacts::Product.search(term, page: 2).first.code, first_product.code
|
|
74
|
-
end
|
|
75
|
-
end
|
|
76
|
-
|
|
77
|
-
=begin
|
|
78
|
-
# Test disable in order to wait for a dedicated test account to not alter real data
|
|
79
|
-
def test_it_updates_product
|
|
80
|
-
product_code = "3600550362626"
|
|
81
|
-
product = ::Openbeautyfacts::Product.new(code: product_code)
|
|
82
|
-
product_last_modified_t = nil
|
|
83
|
-
|
|
84
|
-
VCR.use_cassette("fetch_product_#{product_code}", record: :all, match_requests_on: [:host, :path]) do
|
|
85
|
-
product.fetch
|
|
86
|
-
product_last_modified_t = product.last_modified_t
|
|
87
|
-
end
|
|
88
|
-
|
|
89
|
-
VCR.use_cassette("update_product_#{product_code}", record: :all, match_requests_on: [:host, :path]) do
|
|
90
|
-
product.update # Empty update are accepted, allow testing without altering data.
|
|
91
|
-
end
|
|
92
|
-
|
|
93
|
-
VCR.use_cassette("refetch_product_#{product_code}", record: :all, match_requests_on: [:host, :path]) do
|
|
94
|
-
product.fetch
|
|
95
|
-
end
|
|
96
|
-
|
|
97
|
-
refute_equal product_last_modified_t, product.last_modified_t
|
|
98
|
-
end
|
|
99
|
-
=end
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
# Additives
|
|
103
|
-
|
|
104
|
-
def test_it_fetches_additives
|
|
105
|
-
VCR.use_cassette("additives") do
|
|
106
|
-
additives = ::Openbeautyfacts::Additive.all # World to have riskiness
|
|
107
|
-
assert_includes additives.map { |additive| additive['url'] }, "https://world.openbeautyfacts.org/additive/e470b-magnesium-salts-of-fatty-acids"
|
|
108
|
-
refute_nil additives.detect { |additive| !additive['riskiness'].nil? }
|
|
109
|
-
end
|
|
110
|
-
end
|
|
111
|
-
|
|
112
|
-
def test_it_fetches_additives_for_locale
|
|
113
|
-
VCR.use_cassette("additives_locale") do
|
|
114
|
-
skip("Website have a bug with Additives page on https://fr.openbeautyfacts.org/additifs")
|
|
115
|
-
additives = ::Openbeautyfacts::Additive.all(locale: 'fr')
|
|
116
|
-
assert_includes additives.map { |additive| additive['url'] }, "https://fr.openbeautyfacts.org/additif/e470-sels-de-sodium-potassium-calcium-d-acides-gras"
|
|
117
|
-
end
|
|
118
|
-
end
|
|
119
|
-
|
|
120
|
-
def test_it_fetches_products_with_additive
|
|
121
|
-
additive = ::Openbeautyfacts::Additive.new("url" => "https://world.openbeautyfacts.org/additive/e539-sodium-thiosulfate")
|
|
122
|
-
VCR.use_cassette("products_with_additive") do
|
|
123
|
-
products_with_additive = additive.products(page: 1)
|
|
124
|
-
refute_empty products_with_additive
|
|
125
|
-
end
|
|
126
|
-
end
|
|
127
|
-
|
|
128
|
-
# Brands
|
|
129
|
-
|
|
130
|
-
def test_it_fetches_brands
|
|
131
|
-
VCR.use_cassette("brands") do
|
|
132
|
-
brands = ::Openbeautyfacts::Brand.all
|
|
133
|
-
assert_includes brands.map { |brand| brand['name'] }, "Garnier"
|
|
134
|
-
end
|
|
135
|
-
end
|
|
136
|
-
|
|
137
|
-
def test_it_fetches_brands_for_locale
|
|
138
|
-
VCR.use_cassette("brands_locale") do
|
|
139
|
-
skip("Website have a bug with Brands page on https://fr.openbeautyfacts.org/marques")
|
|
140
|
-
brands = ::Openbeautyfacts::Brand.all(locale: 'fr')
|
|
141
|
-
assert_includes brands.map { |brand| brand['name'] }, "Sedapoux"
|
|
142
|
-
end
|
|
143
|
-
end
|
|
144
|
-
|
|
145
|
-
def test_it_fetches_products_for_brand
|
|
146
|
-
brand = ::Openbeautyfacts::Brand.new("url" => "https://world.openbeautyfacts.org/brand/sedapoux")
|
|
147
|
-
VCR.use_cassette("products_for_brand") do
|
|
148
|
-
products_for_brand = brand.products(page: 1)
|
|
149
|
-
refute_empty products_for_brand
|
|
150
|
-
end
|
|
151
|
-
end
|
|
152
|
-
|
|
153
|
-
# Product states
|
|
154
|
-
|
|
155
|
-
def test_it_fetches_product_states
|
|
156
|
-
VCR.use_cassette("product_states") do
|
|
157
|
-
product_states = ::Openbeautyfacts::ProductState.all
|
|
158
|
-
assert_includes product_states.map { |product_state| product_state['url'] }, "https://world.openbeautyfacts.org/state/empty"
|
|
159
|
-
end
|
|
160
|
-
end
|
|
161
|
-
|
|
162
|
-
def test_it_fetches_product_states_for_locale
|
|
163
|
-
VCR.use_cassette("product_states_locale") do
|
|
164
|
-
product_states = ::Openbeautyfacts::ProductState.all(locale: 'fr')
|
|
165
|
-
assert_includes product_states.map { |product_state| product_state['url'] }, "https://fr.openbeautyfacts.org/etat/vide"
|
|
166
|
-
end
|
|
167
|
-
end
|
|
168
|
-
|
|
169
|
-
def test_it_fetches_products_for_state
|
|
170
|
-
product_state = ::Openbeautyfacts::ProductState.new("url" => "https://world.openbeautyfacts.org/state/photos-uploaded", "products_count" => 22)
|
|
171
|
-
VCR.use_cassette("products_for_state") do
|
|
172
|
-
products_for_state = product_state.products(page: 1)
|
|
173
|
-
refute_empty products_for_state
|
|
174
|
-
end
|
|
175
|
-
end
|
|
176
|
-
|
|
177
|
-
# Ingredients
|
|
178
|
-
|
|
179
|
-
def test_it_fetches_ingredients
|
|
180
|
-
VCR.use_cassette("ingredients") do
|
|
181
|
-
ingredients = ::Openbeautyfacts::Ingredient.all
|
|
182
|
-
assert_includes ingredients.map { |ingredient| ingredient['name'] }, "Water"
|
|
183
|
-
end
|
|
184
|
-
end
|
|
185
|
-
|
|
186
|
-
def test_it_fetches_ingredients_for_locale
|
|
187
|
-
VCR.use_cassette("ingredients_locale") do
|
|
188
|
-
ingredients = ::Openbeautyfacts::Ingredient.all(locale: 'fr')
|
|
189
|
-
assert_includes ingredients.map { |ingredient| ingredient['name'] }, "Eau"
|
|
190
|
-
end
|
|
191
|
-
end
|
|
192
|
-
|
|
193
|
-
def test_it_fetches_products_for_ingredient
|
|
194
|
-
ingredient = ::Openbeautyfacts::Ingredient.new("url" => "https://world.openbeautyfacts.org/ingredient/water")
|
|
195
|
-
VCR.use_cassette("products_for_ingredient") do
|
|
196
|
-
products_for_ingredient = ingredient.products(page: 1)
|
|
197
|
-
refute_empty products_for_ingredient
|
|
198
|
-
end
|
|
199
|
-
end
|
|
200
|
-
|
|
201
|
-
# Entry date
|
|
202
|
-
|
|
203
|
-
def test_it_fetches_entry_dates
|
|
204
|
-
VCR.use_cassette("entry_dates") do
|
|
205
|
-
entry_dates = ::Openbeautyfacts::EntryDate.all
|
|
206
|
-
assert_includes entry_dates.map { |entry_date| entry_date['name'] }, "2017-03-09"
|
|
207
|
-
end
|
|
208
|
-
end
|
|
209
|
-
|
|
210
|
-
def test_it_fetches_entry_dates_for_locale
|
|
211
|
-
VCR.use_cassette("entry_dates_locale") do
|
|
212
|
-
entry_dates = ::Openbeautyfacts::EntryDate.all(locale: 'fr')
|
|
213
|
-
assert_includes entry_dates.map { |entry_date| entry_date['name'] }, "2017-03-09"
|
|
214
|
-
end
|
|
215
|
-
end
|
|
216
|
-
|
|
217
|
-
def test_it_fetches_products_for_entry_date
|
|
218
|
-
entry_date = ::Openbeautyfacts::EntryDate.new("url" => "https://world.openbeautyfacts.org/entry-date/2016-02-12")
|
|
219
|
-
VCR.use_cassette("products_for_entry_date") do
|
|
220
|
-
products_for_entry_date = entry_date.products(page: -1)
|
|
221
|
-
refute_empty products_for_entry_date
|
|
222
|
-
end
|
|
223
|
-
end
|
|
224
|
-
|
|
225
|
-
# Last edit date
|
|
226
|
-
|
|
227
|
-
def test_it_fetches_last_edit_dates
|
|
228
|
-
VCR.use_cassette("last_edit_dates") do
|
|
229
|
-
last_edit_dates = ::Openbeautyfacts::LastEditDate.all
|
|
230
|
-
assert_includes last_edit_dates.map { |last_edit_date| last_edit_date['name'] }, "2017-03-23"
|
|
231
|
-
end
|
|
232
|
-
end
|
|
233
|
-
|
|
234
|
-
def test_it_fetches_last_edit_dates_for_locale
|
|
235
|
-
VCR.use_cassette("last_edit_dates_locale") do
|
|
236
|
-
last_edit_dates = ::Openbeautyfacts::LastEditDate.all(locale: 'fr')
|
|
237
|
-
assert_includes last_edit_dates.map { |last_edit_date| last_edit_date['name'] }, "2017-03-23"
|
|
238
|
-
end
|
|
239
|
-
end
|
|
240
|
-
|
|
241
|
-
def test_it_fetches_products_for_last_edit_date
|
|
242
|
-
last_edit_date = ::Openbeautyfacts::LastEditDate.new("url" => "https://world.openbeautyfacts.org/last-edit-date/2016-02-12")
|
|
243
|
-
VCR.use_cassette("products_for_last_edit_date") do
|
|
244
|
-
products_for_last_edit_date = last_edit_date.products(page: -1)
|
|
245
|
-
refute_empty products_for_last_edit_date
|
|
246
|
-
end
|
|
247
|
-
end
|
|
248
|
-
|
|
249
|
-
# Mission
|
|
250
|
-
|
|
251
|
-
def test_it_fetches_missions
|
|
252
|
-
VCR.use_cassette("missions") do
|
|
253
|
-
refute_empty ::Openbeautyfacts::Mission.all(locale: 'fr')
|
|
254
|
-
end
|
|
255
|
-
end
|
|
256
|
-
|
|
257
|
-
def test_it_fetches_mission
|
|
258
|
-
VCR.use_cassette("mission", record: :once, match_requests_on: [:host, :path]) do
|
|
259
|
-
mission = ::Openbeautyfacts::Mission.new(url: "https://fr.openbeautyfacts.org/mission/25-produits")
|
|
260
|
-
mission.fetch
|
|
261
|
-
refute_empty mission.users
|
|
262
|
-
end
|
|
263
|
-
end
|
|
264
|
-
|
|
265
|
-
# Number of Ingredients
|
|
266
|
-
|
|
267
|
-
def test_it_fetches_numbers_of_ingredients
|
|
268
|
-
VCR.use_cassette("numbers_of_ingredients") do
|
|
269
|
-
numbers_of_ingredients = ::Openbeautyfacts::NumberOfIngredients.all
|
|
270
|
-
assert_includes numbers_of_ingredients.map { |number_of_ingredients| number_of_ingredients['name'] }, "38"
|
|
271
|
-
end
|
|
272
|
-
end
|
|
273
|
-
|
|
274
|
-
def test_it_fetches_numbers_of_ingredients_for_locale
|
|
275
|
-
VCR.use_cassette("number_of_ingredients_locale") do
|
|
276
|
-
numbers_of_ingredients = ::Openbeautyfacts::NumberOfIngredients.all(locale: 'fr')
|
|
277
|
-
assert_includes numbers_of_ingredients.map { |number_of_ingredients| number_of_ingredients['name'] }, "38"
|
|
278
|
-
end
|
|
279
|
-
end
|
|
280
|
-
|
|
281
|
-
def test_it_fetches_products_for_number_of_ingredients
|
|
282
|
-
number_of_ingredients = ::Openbeautyfacts::NumberOfIngredients.new("url" => "https://world.openbeautyfacts.org/number-of-ingredients/38")
|
|
283
|
-
VCR.use_cassette("products_for_number_of_ingredients") do
|
|
284
|
-
products_for_number_of_ingredients = number_of_ingredients.products(page: -1)
|
|
285
|
-
refute_empty products_for_number_of_ingredients
|
|
286
|
-
end
|
|
287
|
-
end
|
|
288
|
-
|
|
289
|
-
# Period after openings
|
|
290
|
-
|
|
291
|
-
def test_it_fetches_period_after_openings
|
|
292
|
-
skip "Source page is gone"
|
|
293
|
-
VCR.use_cassette("period_after_openings") do
|
|
294
|
-
period_after_openings = ::Openbeautyfacts::PeriodAfterOpening.all
|
|
295
|
-
assert_includes period_after_openings.map { |period_after_opening| period_after_opening['name'] }, "12 months"
|
|
296
|
-
end
|
|
297
|
-
end
|
|
298
|
-
|
|
299
|
-
def test_it_fetches_period_after_openings_for_locale
|
|
300
|
-
skip "Source page is gone"
|
|
301
|
-
VCR.use_cassette("period_after_openings_locale") do
|
|
302
|
-
period_after_openings = ::Openbeautyfacts::PeriodAfterOpening.all(locale: 'fr')
|
|
303
|
-
assert_includes period_after_openings.map { |period_after_opening| period_after_opening['name'] }, "12 mois"
|
|
304
|
-
end
|
|
305
|
-
end
|
|
306
|
-
|
|
307
|
-
def test_it_fetches_products_for_period_after_opening
|
|
308
|
-
period_after_opening = ::Openbeautyfacts::PeriodAfterOpening.new("url" => "https://world.openbeautyfacts.org/period-after-opening/12-months")
|
|
309
|
-
VCR.use_cassette("products_for_period_after_opening") do
|
|
310
|
-
products_for_period_after_opening = period_after_opening.products(page: 1)
|
|
311
|
-
refute_empty products_for_period_after_opening
|
|
312
|
-
end
|
|
313
|
-
end
|
|
314
|
-
|
|
315
|
-
# FAQ
|
|
316
|
-
|
|
317
|
-
def test_it_fetches_faq
|
|
318
|
-
VCR.use_cassette("faq") do
|
|
319
|
-
refute_empty ::Openbeautyfacts::Faq.items(locale: 'fr')
|
|
320
|
-
end
|
|
321
|
-
end
|
|
322
|
-
|
|
323
|
-
# Press
|
|
324
|
-
|
|
325
|
-
def test_it_fetches_press
|
|
326
|
-
VCR.use_cassette("press") do
|
|
327
|
-
refute_empty ::Openbeautyfacts::Press.items(locale: 'fr')
|
|
328
|
-
end
|
|
329
|
-
end
|
|
330
|
-
|
|
331
|
-
end
|