openfoodfacts 0.2.2 → 0.3.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.
@@ -35,6 +35,11 @@ class TestOpenfoodfacts < Minitest::Test
35
35
  assert_equal ::Openfoodfacts::Product.url(product.code, locale: 'ca'), product.url(locale: 'ca')
36
36
  end
37
37
 
38
+ def test_it_returns_product_weburl
39
+ product = ::Openfoodfacts::Product.new(code: "3029330003533")
40
+ assert_equal "http://world.openfoodfacts.org/product/#{product.code}", product.weburl(locale: 'world')
41
+ end
42
+
38
43
  def test_it_fetches_product
39
44
  product_code = "3029330003533"
40
45
 
@@ -95,6 +100,56 @@ class TestOpenfoodfacts < Minitest::Test
95
100
  end
96
101
  =end
97
102
 
103
+
104
+ # Additives
105
+
106
+ def test_it_fetches_additives
107
+ VCR.use_cassette("additives") do
108
+ additives = ::Openfoodfacts::Additive.all(locale: 'fr') # FR to have riskiness
109
+ assert_equal "http://fr.openfoodfacts.org/additif/e330-acide-citrique", additives.first.url
110
+ refute_nil additives.detect { |additive| !additive['riskiness'].nil? }
111
+ end
112
+ end
113
+
114
+ def test_it_fetches_additives_for_locale
115
+ VCR.use_cassette("additives_locale") do
116
+ additives = ::Openfoodfacts::Additive.all(locale: 'fr')
117
+ assert_equal "http://fr.openfoodfacts.org/additif/e330-acide-citrique", additives.first.url
118
+ end
119
+ end
120
+
121
+ def test_it_fetches_products_with_additive
122
+ additive = ::Openfoodfacts::Additive.new("url" => "http://world.openfoodfacts.org/additive/e452i-sodium-polyphosphate")
123
+ VCR.use_cassette("products_with_additive") do
124
+ products_with_additive = additive.products(page: -1)
125
+ refute_empty products_with_additive
126
+ end
127
+ end
128
+
129
+ # Brands
130
+
131
+ def test_it_fetches_brands
132
+ VCR.use_cassette("brands") do
133
+ brands = ::Openfoodfacts::Brand.all
134
+ assert_includes brands.map { |brand| brand['name'] }, "Carrefour"
135
+ end
136
+ end
137
+
138
+ def test_it_fetches_brands_for_locale
139
+ VCR.use_cassette("brands_locale") do
140
+ brands = ::Openfoodfacts::Brand.all(locale: 'fr')
141
+ assert_includes brands.map { |brand| brand['name'] }, "Loue"
142
+ end
143
+ end
144
+
145
+ def test_it_fetches_products_for_brand
146
+ brand = ::Openfoodfacts::Brand.new("url" => "http://world.openfoodfacts.org/brand/bel")
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
+
98
153
  # Product states
99
154
 
100
155
  def test_it_fetches_product_states
@@ -104,6 +159,13 @@ class TestOpenfoodfacts < Minitest::Test
104
159
  end
105
160
  end
106
161
 
162
+ def test_it_fetches_product_states_for_locale
163
+ VCR.use_cassette("product_states_locale") do
164
+ product_states = ::Openfoodfacts::ProductState.all(locale: 'fr')
165
+ assert_equal "http://fr.openfoodfacts.org/etat/vide", product_states.last.url
166
+ end
167
+ end
168
+
107
169
  def test_it_fetches_products_for_state
108
170
  product_state = ::Openfoodfacts::ProductState.new("url" => "http://world.openfoodfacts.org/state/photos-uploaded", "products_count" => 22)
109
171
  VCR.use_cassette("products_for_state") do
@@ -112,4 +174,20 @@ class TestOpenfoodfacts < Minitest::Test
112
174
  end
113
175
  end
114
176
 
177
+ # FAQ
178
+
179
+ def test_it_fetches_faq
180
+ VCR.use_cassette("faq") do
181
+ refute_empty ::Openfoodfacts::Faq.items(locale: 'fr')
182
+ end
183
+ end
184
+
185
+ # Press
186
+
187
+ def test_it_fetches_press
188
+ VCR.use_cassette("press") do
189
+ refute_empty ::Openfoodfacts::Press.items(locale: 'fr')
190
+ end
191
+ end
192
+
115
193
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: openfoodfacts
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nicolas Leger
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-05-23 00:00:00.000000000 Z
11
+ date: 2015-06-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: hashie
@@ -119,17 +119,44 @@ files:
119
119
  - README.md
120
120
  - Rakefile
121
121
  - lib/openfoodfacts.rb
122
+ - lib/openfoodfacts/additive.rb
123
+ - lib/openfoodfacts/allergen.rb
124
+ - lib/openfoodfacts/brand.rb
125
+ - lib/openfoodfacts/category.rb
126
+ - lib/openfoodfacts/city.rb
127
+ - lib/openfoodfacts/contributor.rb
128
+ - lib/openfoodfacts/country.rb
129
+ - lib/openfoodfacts/faq.rb
130
+ - lib/openfoodfacts/ingredient_that_may_be_from_palm_oil.rb
131
+ - lib/openfoodfacts/label.rb
122
132
  - lib/openfoodfacts/locale.rb
133
+ - lib/openfoodfacts/manufacturing_place.rb
134
+ - lib/openfoodfacts/origin.rb
135
+ - lib/openfoodfacts/packager_code.rb
136
+ - lib/openfoodfacts/packaging.rb
137
+ - lib/openfoodfacts/press.rb
123
138
  - lib/openfoodfacts/product.rb
124
139
  - lib/openfoodfacts/product_state.rb
140
+ - lib/openfoodfacts/purchase_place.rb
141
+ - lib/openfoodfacts/store.rb
142
+ - lib/openfoodfacts/trace.rb
125
143
  - lib/openfoodfacts/user.rb
126
144
  - lib/openfoodfacts/version.rb
145
+ - test/fixtures/additives.yml
146
+ - test/fixtures/additives_locale.yml
147
+ - test/fixtures/brands.yml
148
+ - test/fixtures/brands_locale.yml
149
+ - test/fixtures/faq.yml
127
150
  - test/fixtures/fetch_product_3029330003533.yml
128
151
  - test/fixtures/index.yml
129
152
  - test/fixtures/login_user.yml
153
+ - test/fixtures/press.yml
130
154
  - test/fixtures/product_3029330003533.yml
131
155
  - test/fixtures/product_states.yml
156
+ - test/fixtures/product_states_locale.yml
157
+ - test/fixtures/products_for_brand.yml
132
158
  - test/fixtures/products_for_state.yml
159
+ - test/fixtures/products_with_additive.yml
133
160
  - test/fixtures/search_Chocolat.yml
134
161
  - test/fixtures/search_Chocolat_1_000_000.yml
135
162
  - test/minitest_helper.rb