Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Allergens to Food #2706

Merged
merged 1 commit into from
Feb 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions doc/default/food.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
Available since version 1.7.0.

```ruby
Faker::Food.allergen #=> "Peanuts"

Faker::Food.description #=> "Three eggs with cilantro, tomatoes, onions, avocados and melted Emmental cheese. With a side of roasted potatoes, and your choice of toast or croissant."

Faker::Food.dish #=> "Caesar Salad"
Expand Down
13 changes: 13 additions & 0 deletions lib/faker/default/food.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,19 @@ class Food < Base
flexible :food

class << self
##
# Retrieves an allergen.
#
# @return [String]
#
# @example
# Faker::Food.allergen #=> "Peanuts"
#
# @faker.version next
def allergen
fetch('food.allergens')
end

##
# Retrieves a typical dish from each country.
#
Expand Down
12 changes: 12 additions & 0 deletions lib/locales/en/food.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
en:
faker:
food:
allergens:
- Eggs
- Milk
- Mustard
- Peanuts
- Crustaceans and molluscs
- Fish
- Sesame seeds
- Soy
- Sulphites
- Tree Nuts
- Wheat and triticale
dish:
- Arepas
- Barbecue Ribs
Expand Down
4 changes: 4 additions & 0 deletions test/faker/default/test_faker_food.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ def test_flexible_key
assert_equal(:food, @tester.flexible_key)
end

def test_allergen
assert_match(/\w+/, @tester.allergen)
end

def test_dish
assert_match(/\w+/, @tester.dish)
end
Expand Down