openbeautyfacts 0.1.0 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/README.md +15 -9
- data/lib/openbeautyfacts.rb +6 -0
- data/lib/openbeautyfacts/additive.rb +1 -1
- data/lib/openbeautyfacts/allergen.rb +1 -1
- data/lib/openbeautyfacts/brand.rb +1 -1
- data/lib/openbeautyfacts/category.rb +1 -1
- data/lib/openbeautyfacts/city.rb +1 -1
- data/lib/openbeautyfacts/contributor.rb +1 -1
- data/lib/openbeautyfacts/country.rb +1 -1
- data/lib/openbeautyfacts/entry_date.rb +33 -0
- data/lib/openbeautyfacts/faq.rb +1 -1
- data/lib/openbeautyfacts/ingredient.rb +33 -0
- data/lib/openbeautyfacts/ingredient_that_may_be_from_palm_oil.rb +1 -1
- data/lib/openbeautyfacts/label.rb +1 -1
- data/lib/openbeautyfacts/last_edit_date.rb +33 -0
- data/lib/openbeautyfacts/locale.rb +20 -6
- data/lib/openbeautyfacts/manufacturing_place.rb +1 -1
- data/lib/openbeautyfacts/mission.rb +72 -0
- data/lib/openbeautyfacts/number_of_ingredients.rb +33 -0
- data/lib/openbeautyfacts/origin.rb +1 -1
- data/lib/openbeautyfacts/packager_code.rb +1 -1
- data/lib/openbeautyfacts/packaging.rb +1 -1
- data/lib/openbeautyfacts/period_after_opening.rb +33 -0
- data/lib/openbeautyfacts/press.rb +1 -1
- data/lib/openbeautyfacts/product.rb +12 -11
- data/lib/openbeautyfacts/product_state.rb +1 -1
- data/lib/openbeautyfacts/purchase_place.rb +1 -1
- data/lib/openbeautyfacts/store.rb +1 -1
- data/lib/openbeautyfacts/trace.rb +1 -1
- data/lib/openbeautyfacts/user.rb +1 -2
- data/lib/openbeautyfacts/version.rb +1 -1
- data/test/minitest_helper.rb +6 -0
- data/test/test_openbeautyfacts.rb +155 -17
- metadata +35 -41
- data/test/fixtures/additives.yml +0 -1422
- data/test/fixtures/additives_locale.yml +0 -1422
- data/test/fixtures/brands.yml +0 -2144
- data/test/fixtures/brands_locale.yml +0 -2024
- data/test/fixtures/faq.yml +0 -1031
- data/test/fixtures/fetch_product_3600550362626.yml +0 -104
- data/test/fixtures/index.yml +0 -169
- data/test/fixtures/login_user.yml +0 -40
- data/test/fixtures/press.yml +0 -986
- data/test/fixtures/product_3600550362626.yml +0 -104
- data/test/fixtures/product_states.yml +0 -936
- data/test/fixtures/product_states_locale.yml +0 -976
- data/test/fixtures/products_for_brand.yml +0 -1707
- data/test/fixtures/products_for_state.yml +0 -2260
- data/test/fixtures/products_with_additive.yml +0 -1723
- data/test/fixtures/search_doux.yml +0 -538
- data/test/fixtures/search_doux_1_000_000.yml +0 -257
@@ -17,7 +17,7 @@ module Openbeautyfacts
|
|
17
17
|
#
|
18
18
|
def all(locale: DEFAULT_LOCALE, domain: DEFAULT_DOMAIN)
|
19
19
|
if path = LOCALE_PATHS[locale]
|
20
|
-
Product.tags_from_page(self, "
|
20
|
+
Product.tags_from_page(self, "https://#{locale}.#{domain}/#{path}")
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
@@ -17,7 +17,7 @@ module Openbeautyfacts
|
|
17
17
|
#
|
18
18
|
def all(locale: DEFAULT_LOCALE, domain: DEFAULT_DOMAIN)
|
19
19
|
if path = LOCALE_PATHS[locale]
|
20
|
-
Product.tags_from_page(self, "
|
20
|
+
Product.tags_from_page(self, "https://#{locale}.#{domain}/#{path}")
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
@@ -17,7 +17,7 @@ module Openbeautyfacts
|
|
17
17
|
#
|
18
18
|
def all(locale: DEFAULT_LOCALE, domain: DEFAULT_DOMAIN)
|
19
19
|
if path = LOCALE_PATHS[locale]
|
20
|
-
Product.tags_from_page(self, "
|
20
|
+
Product.tags_from_page(self, "https://#{locale}.#{domain}/#{path}")
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'hashie'
|
2
|
+
|
3
|
+
module Openbeautyfacts
|
4
|
+
class PeriodAfterOpening < Hashie::Mash
|
5
|
+
|
6
|
+
# TODO: Add more locales
|
7
|
+
LOCALE_PATHS = {
|
8
|
+
'fr' => 'durees-d-utilisation-apres-ouverture',
|
9
|
+
'uk' => 'periods-after-opening',
|
10
|
+
'us' => 'periods-after-opening',
|
11
|
+
'world' => 'periods-after-opening'
|
12
|
+
}
|
13
|
+
|
14
|
+
class << self
|
15
|
+
|
16
|
+
# Get labels
|
17
|
+
#
|
18
|
+
def all(locale: DEFAULT_LOCALE, domain: DEFAULT_DOMAIN)
|
19
|
+
if path = LOCALE_PATHS[locale]
|
20
|
+
Product.tags_from_page(self, "https://#{locale}.#{domain}/#{path}")
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
|
26
|
+
# Get products with label
|
27
|
+
#
|
28
|
+
def products(page: -1)
|
29
|
+
Product.from_website_page(url, page: page, products_count: products_count) if url
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
end
|
@@ -24,7 +24,7 @@ module Openbeautyfacts
|
|
24
24
|
class << self
|
25
25
|
def items(locale: DEFAULT_LOCALE, domain: DEFAULT_DOMAIN)
|
26
26
|
if path = LOCALE_PATHS[locale]
|
27
|
-
html = open("
|
27
|
+
html = URI.open("https://#{locale}.#{domain}/#{path}").read
|
28
28
|
dom = Nokogiri::HTML.fragment(html)
|
29
29
|
|
30
30
|
titles = dom.css('#main_column li')
|
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'cgi'
|
1
2
|
require 'hashie'
|
2
3
|
require 'net/http'
|
3
4
|
require 'nokogiri'
|
@@ -21,7 +22,7 @@ module Openbeautyfacts
|
|
21
22
|
def get(code, locale: DEFAULT_LOCALE)
|
22
23
|
if code
|
23
24
|
product_url = url(code, locale: locale)
|
24
|
-
json = open(product_url).read
|
25
|
+
json = URI.open(product_url).read
|
25
26
|
hash = JSON.parse(json)
|
26
27
|
|
27
28
|
new(hash["product"]) if !hash["status"].nil? && hash["status"] == 1
|
@@ -34,17 +35,17 @@ module Openbeautyfacts
|
|
34
35
|
def url(code, locale: DEFAULT_LOCALE, domain: DEFAULT_DOMAIN)
|
35
36
|
if code
|
36
37
|
path = "api/v0/produit/#{code}.json"
|
37
|
-
"
|
38
|
+
"https://#{locale}.#{domain}/#{path}"
|
38
39
|
end
|
39
40
|
end
|
40
41
|
|
41
42
|
# Search products
|
42
43
|
#
|
43
44
|
def search(terms, locale: DEFAULT_LOCALE, page: 1, page_size: 20, sort_by: 'unique_scans_n', domain: DEFAULT_DOMAIN)
|
44
|
-
terms =
|
45
|
+
terms = CGI.escape(terms)
|
45
46
|
path = "cgi/search.pl?search_terms=#{terms}&jqm=1&page=#{page}&page_size=#{page_size}&sort_by=#{sort_by}"
|
46
|
-
url = "
|
47
|
-
json = open(url).read
|
47
|
+
url = "https://#{locale}.#{domain}/#{path}"
|
48
|
+
json = URI.open(url).read
|
48
49
|
hash = JSON.parse(json)
|
49
50
|
html = hash["jqm"]
|
50
51
|
|
@@ -78,11 +79,11 @@ module Openbeautyfacts
|
|
78
79
|
end
|
79
80
|
|
80
81
|
def from_jquery_mobile_list(jqm_html)
|
81
|
-
from_html_list(jqm_html, 'ul li:not(#loadmore)', /code=(\d+)\Z/i)
|
82
|
+
from_html_list(jqm_html, 'ul#search_results_list li:not(#loadmore)', /code=(\d+)\Z/i)
|
82
83
|
end
|
83
84
|
|
84
85
|
def from_website_list(html, locale: 'world')
|
85
|
-
from_html_list(html, 'ul.products li', /\/(\d+)
|
86
|
+
from_html_list(html, 'ul.products li', /\/(\d+)\/?/i, locale: 'world')
|
86
87
|
end
|
87
88
|
|
88
89
|
# page -1 to fetch all pages
|
@@ -104,13 +105,13 @@ module Openbeautyfacts
|
|
104
105
|
products
|
105
106
|
end
|
106
107
|
else
|
107
|
-
html = open("#{page_url}/#{page}").read
|
108
|
+
html = URI.open("#{page_url}/#{page}").read
|
108
109
|
from_website_list(html, locale: Locale.locale_from_link(page_url))
|
109
110
|
end
|
110
111
|
end
|
111
112
|
|
112
113
|
def tags_from_page(_klass, page_url, &custom_tag_parsing)
|
113
|
-
html = open(page_url).read
|
114
|
+
html = URI.open(page_url).read
|
114
115
|
dom = Nokogiri::HTML.fragment(html)
|
115
116
|
|
116
117
|
dom.css('table#tagstable tbody tr').map do |tag|
|
@@ -151,7 +152,7 @@ module Openbeautyfacts
|
|
151
152
|
if self.code && self.lc
|
152
153
|
subdomain = self.lc == 'world' ? 'world' : "world-#{self.lc}"
|
153
154
|
path = 'cgi/product_jqm.pl'
|
154
|
-
uri = URI("
|
155
|
+
uri = URI("https://#{subdomain}.#{domain}/#{path}")
|
155
156
|
params = self.to_hash
|
156
157
|
params.merge!("user_id" => user.user_id, "password" => user.password) if user
|
157
158
|
response = Net::HTTP.post_form(uri, params)
|
@@ -177,7 +178,7 @@ module Openbeautyfacts
|
|
177
178
|
|
178
179
|
if self.code && prefix = LOCALE_WEBURL_PREFIXES[locale]
|
179
180
|
path = "#{prefix}/#{self.code}"
|
180
|
-
"
|
181
|
+
"https://#{locale}.#{domain}/#{path}"
|
181
182
|
end
|
182
183
|
end
|
183
184
|
|
@@ -17,7 +17,7 @@ module Openbeautyfacts
|
|
17
17
|
#
|
18
18
|
def all(locale: DEFAULT_LOCALE, domain: DEFAULT_DOMAIN)
|
19
19
|
if path = LOCALE_PATHS[locale]
|
20
|
-
Product.tags_from_page(self, "
|
20
|
+
Product.tags_from_page(self, "https://#{locale}.#{domain}/#{path}")
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
@@ -17,7 +17,7 @@ module Openbeautyfacts
|
|
17
17
|
#
|
18
18
|
def all(locale: DEFAULT_LOCALE, domain: DEFAULT_DOMAIN)
|
19
19
|
if path = LOCALE_PATHS[locale]
|
20
|
-
Product.tags_from_page(self, "
|
20
|
+
Product.tags_from_page(self, "https://#{locale}.#{domain}/#{path}")
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
@@ -17,7 +17,7 @@ module Openbeautyfacts
|
|
17
17
|
#
|
18
18
|
def all(locale: DEFAULT_LOCALE, domain: DEFAULT_DOMAIN)
|
19
19
|
if path = LOCALE_PATHS[locale]
|
20
|
-
Product.tags_from_page(self, "
|
20
|
+
Product.tags_from_page(self, "https://#{locale}.#{domain}/#{path}")
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
@@ -17,7 +17,7 @@ module Openbeautyfacts
|
|
17
17
|
#
|
18
18
|
def all(locale: DEFAULT_LOCALE, domain: DEFAULT_DOMAIN)
|
19
19
|
if path = LOCALE_PATHS[locale]
|
20
|
-
Product.tags_from_page(self, "
|
20
|
+
Product.tags_from_page(self, "https://#{locale}.#{domain}/#{path}")
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
data/lib/openbeautyfacts/user.rb
CHANGED
@@ -6,11 +6,10 @@ module Openbeautyfacts
|
|
6
6
|
class << self
|
7
7
|
|
8
8
|
# Login
|
9
|
-
# WARNING SECURITY: It is not made throught HTTPS Secure so password can be read on the way.
|
10
9
|
#
|
11
10
|
def login(user_id, password, locale: DEFAULT_LOCALE, domain: DEFAULT_DOMAIN)
|
12
11
|
path = 'cgi/session.pl'
|
13
|
-
uri = URI("
|
12
|
+
uri = URI("https://#{locale}.#{domain}/#{path}")
|
14
13
|
params = {
|
15
14
|
"jqm" => "1",
|
16
15
|
"user_id" => user_id,
|
data/test/minitest_helper.rb
CHANGED
@@ -6,6 +6,12 @@ require 'minitest/autorun'
|
|
6
6
|
require 'webmock/minitest'
|
7
7
|
require 'vcr'
|
8
8
|
|
9
|
+
# Avoid OpenSSL certificate verify failed error
|
10
|
+
if ENV.has_key?('APPVEYOR') && Gem::Version.new(RUBY_VERSION) < Gem::Version.new('2.4')
|
11
|
+
require 'openssl'
|
12
|
+
OpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONE
|
13
|
+
end
|
14
|
+
|
9
15
|
VCR.configure do |c|
|
10
16
|
c.cassette_library_dir = "test/fixtures"
|
11
17
|
c.hook_into :webmock
|
@@ -13,9 +13,7 @@ class TestOpenbeautyfacts < Minitest::Test
|
|
13
13
|
def test_it_fetches_locales
|
14
14
|
VCR.use_cassette("index") do
|
15
15
|
locales = ::Openbeautyfacts::Locale.all
|
16
|
-
assert_includes locales, "
|
17
|
-
assert_includes locales, "fr"
|
18
|
-
assert_includes locales, "es-gl"
|
16
|
+
assert_includes locales.map { |locale| locale['code'] }, "gd"
|
19
17
|
end
|
20
18
|
end
|
21
19
|
|
@@ -37,7 +35,7 @@ class TestOpenbeautyfacts < Minitest::Test
|
|
37
35
|
|
38
36
|
def test_it_returns_product_weburl
|
39
37
|
product = ::Openbeautyfacts::Product.new(code: "3600550362626")
|
40
|
-
assert_equal "
|
38
|
+
assert_equal "https://world.openbeautyfacts.org/product/#{product.code}", product.weburl(locale: 'world')
|
41
39
|
end
|
42
40
|
|
43
41
|
def test_it_fetches_product
|
@@ -66,8 +64,8 @@ class TestOpenbeautyfacts < Minitest::Test
|
|
66
64
|
products = ::Openbeautyfacts::Product.search(term, page_size: 24)
|
67
65
|
first_product = products.first
|
68
66
|
|
69
|
-
assert_match
|
70
|
-
assert_match
|
67
|
+
assert_match(/#{term}/i, products.last["product_name"])
|
68
|
+
assert_match(/#{term}/i, ::Openbeautyfacts::Product.search(term).last["product_name"])
|
71
69
|
assert_equal products.size, 24
|
72
70
|
end
|
73
71
|
|
@@ -105,23 +103,24 @@ class TestOpenbeautyfacts < Minitest::Test
|
|
105
103
|
|
106
104
|
def test_it_fetches_additives
|
107
105
|
VCR.use_cassette("additives") do
|
108
|
-
additives = ::Openbeautyfacts::Additive.all
|
109
|
-
|
106
|
+
additives = ::Openbeautyfacts::Additive.all # World to have riskiness
|
107
|
+
assert_includes additives.map { |additive| additive['url'] }, "https://world.openbeautyfacts.org/additive/e508-potassium-chloride"
|
110
108
|
refute_nil additives.detect { |additive| !additive['riskiness'].nil? }
|
111
109
|
end
|
112
110
|
end
|
113
111
|
|
114
112
|
def test_it_fetches_additives_for_locale
|
115
113
|
VCR.use_cassette("additives_locale") do
|
114
|
+
skip("Website have a bug with Additives page on https://fr.openbeautyfacts.org/additifs")
|
116
115
|
additives = ::Openbeautyfacts::Additive.all(locale: 'fr')
|
117
|
-
|
116
|
+
assert_includes additives.map { |additive| additive['url'] }, "https://fr.openbeautyfacts.org/additif/e470-sels-de-sodium-potassium-calcium-d-acides-gras"
|
118
117
|
end
|
119
118
|
end
|
120
119
|
|
121
120
|
def test_it_fetches_products_with_additive
|
122
|
-
additive = ::Openbeautyfacts::Additive.new("url" => "
|
121
|
+
additive = ::Openbeautyfacts::Additive.new("url" => "https://world.openbeautyfacts.org/additive/e539-sodium-thiosulfate")
|
123
122
|
VCR.use_cassette("products_with_additive") do
|
124
|
-
products_with_additive = additive.products(page:
|
123
|
+
products_with_additive = additive.products(page: 1)
|
125
124
|
refute_empty products_with_additive
|
126
125
|
end
|
127
126
|
end
|
@@ -137,15 +136,16 @@ class TestOpenbeautyfacts < Minitest::Test
|
|
137
136
|
|
138
137
|
def test_it_fetches_brands_for_locale
|
139
138
|
VCR.use_cassette("brands_locale") do
|
139
|
+
skip("Website have a bug with Brands page on https://fr.openbeautyfacts.org/marques")
|
140
140
|
brands = ::Openbeautyfacts::Brand.all(locale: 'fr')
|
141
141
|
assert_includes brands.map { |brand| brand['name'] }, "Sedapoux"
|
142
142
|
end
|
143
143
|
end
|
144
144
|
|
145
145
|
def test_it_fetches_products_for_brand
|
146
|
-
brand = ::Openbeautyfacts::Brand.new("url" => "
|
146
|
+
brand = ::Openbeautyfacts::Brand.new("url" => "https://world.openbeautyfacts.org/brand/sedapoux")
|
147
147
|
VCR.use_cassette("products_for_brand") do
|
148
|
-
products_for_brand = brand.products(page:
|
148
|
+
products_for_brand = brand.products(page: 1)
|
149
149
|
refute_empty products_for_brand
|
150
150
|
end
|
151
151
|
end
|
@@ -155,25 +155,163 @@ class TestOpenbeautyfacts < Minitest::Test
|
|
155
155
|
def test_it_fetches_product_states
|
156
156
|
VCR.use_cassette("product_states") do
|
157
157
|
product_states = ::Openbeautyfacts::ProductState.all
|
158
|
-
|
158
|
+
assert_includes product_states.map { |product_state| product_state['url'] }, "https://world.openbeautyfacts.org/state/empty"
|
159
159
|
end
|
160
160
|
end
|
161
161
|
|
162
162
|
def test_it_fetches_product_states_for_locale
|
163
163
|
VCR.use_cassette("product_states_locale") do
|
164
164
|
product_states = ::Openbeautyfacts::ProductState.all(locale: 'fr')
|
165
|
-
|
165
|
+
assert_includes product_states.map { |product_state| product_state['url'] }, "https://fr.openbeautyfacts.org/etat/vide"
|
166
166
|
end
|
167
167
|
end
|
168
168
|
|
169
169
|
def test_it_fetches_products_for_state
|
170
|
-
product_state = ::Openbeautyfacts::ProductState.new("url" => "
|
170
|
+
product_state = ::Openbeautyfacts::ProductState.new("url" => "https://world.openbeautyfacts.org/state/photos-uploaded", "products_count" => 22)
|
171
171
|
VCR.use_cassette("products_for_state") do
|
172
|
-
products_for_state = product_state.products(page:
|
172
|
+
products_for_state = product_state.products(page: 1)
|
173
173
|
refute_empty products_for_state
|
174
174
|
end
|
175
175
|
end
|
176
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
|
+
|
177
315
|
# FAQ
|
178
316
|
|
179
317
|
def test_it_fetches_faq
|