Skip to content

Commit

Permalink
Add donation product category (#848)
Browse files Browse the repository at this point in the history
* Add donation product category

* Fix lint

* Fix enum
  • Loading branch information
wilco375 authored Feb 8, 2023
1 parent a19324f commit 991a71f
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 4 deletions.
2 changes: 1 addition & 1 deletion app/models/product.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class Product < ApplicationRecord
enum category: { beer: 0, craft_beer: 6, non_alcoholic: 1, distilled: 2, wine: 3, food: 4, tobacco: 5 }
enum category: { beer: 0, craft_beer: 6, non_alcoholic: 1, distilled: 2, wine: 3, food: 4, tobacco: 5, donation: 7 }

has_many :product_prices, dependent: :destroy
has_many :price_lists, through: :product_prices, dependent: :restrict_with_error
Expand Down
2 changes: 2 additions & 0 deletions config/locales/nl.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ nl:
wine: 'wijn'
food: 'etenswaren'
tobacco: 'rookwaren'
donation: 'donaties'

open: 'open'
paid: 'betaald'
Expand All @@ -33,6 +34,7 @@ nl:
wine: 8040
food: 8050
tobacco: 8060
donation: 2100
credit_mutation: '0610'
cash: 1000
pin: 2060
Expand Down
7 changes: 6 additions & 1 deletion db/seeds/products.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
def seed_products # rubocop:disable Metrics/AbcSize, Metrics/MethodLength, Metrics/CyclomaticComplexity
def seed_products # rubocop:disable Metrics/AbcSize, Metrics/MethodLength, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
products = []

# rubocop:disable Style/WordArray
Expand All @@ -9,6 +9,7 @@ def seed_products # rubocop:disable Metrics/AbcSize, Metrics/MethodLength, Metri
products_wine = ['Wijn (glas)', 'Wijn (fles)']
products_food = ['Tosti', 'Nootjes', 'Chips']
products_tobacco = ['Sigaar', 'Sigaar (duur)']
products_donation = ['Donatie']
# rubocop:enable Style/WordArray

products_beer.each do |name|
Expand Down Expand Up @@ -39,5 +40,9 @@ def seed_products # rubocop:disable Metrics/AbcSize, Metrics/MethodLength, Metri
products << Product.create(name: name, category: :tobacco)
end

products_donation.each do |name|
products << Product.create(name: name, category: :donation)
end

products
end
2 changes: 1 addition & 1 deletion spec/factories/product.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FactoryBot.define do
factory :product do
name { Faker::Book.title }
category { %i[beer craft_beer non_alcoholic distilled wine food tobacco].sample }
category { %i[beer craft_beer non_alcoholic distilled wine food tobacco donation].sample }
end
end
2 changes: 1 addition & 1 deletion spec/models/product_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
end

context 'when with non requires age category' do
subject(:product) { create(:product, category: %w[food non_alcoholic].sample) }
subject(:product) { create(:product, category: %w[food non_alcoholic donation].sample) }

it { expect(product.requires_age).to be false }
end
Expand Down

0 comments on commit 991a71f

Please sign in to comment.