Compare commits

...

4 Commits

Author SHA1 Message Date
Daniel O'Connor
1511de8a81 Merge branch 'dev' into fix-naming 2025-09-02 08:41:12 +09:30
Daniel O'Connor
df15383dd0 Merge branch 'dev' into fix-naming 2025-03-29 14:24:31 +10:30
Daniel O'Connor
bcaeaf3688 Merge branch 'dev' into fix-naming 2024-07-13 13:29:09 +09:30
Daniel O'Connor
2fc5b63c0e Change naming to be aware of plant parts, even if it sounds oddly format 2024-03-23 06:57:11 +00:00
3 changed files with 89 additions and 70 deletions

View File

@@ -53,7 +53,6 @@ class Harvest < ApplicationRecord
delegate :name, :slug, to: :crop, prefix: true
delegate :login_name, :slug, to: :owner, prefix: true
delegate :name, to: :plant_part, prefix: true
##
## Validations
@@ -109,7 +108,7 @@ class Harvest < ApplicationRecord
def to_s
# 50 individual apples, weighing 3lb
# 2 buckets of apricots, weighing 10kg
"#{quantity_to_human} #{unit_to_human} #{crop_name_to_human} #{weight_to_human}".strip
"#{quantity_to_human} #{unit_to_human} #{plant_part_name_to_human} of #{crop_name} #{weight_to_human}".strip
end
def quantity_to_human
@@ -132,13 +131,13 @@ class Harvest < ApplicationRecord
"weighing #{number_to_human(weight_quantity, strip_insignificant_zeros: true)} #{weight_unit}"
end
def crop_name_to_human
def plant_part_name_to_human
if unit != 'individual' # buckets of apricot*s*
crop.name.pluralize
plant_part.name.pluralize
elsif quantity == 1
crop.name
plant_part.name
else
crop.name.pluralize
plant_part.name.pluralize
end.to_s
end

View File

@@ -11,6 +11,10 @@ class PlantPart < ApplicationRecord
scope :joins_members, -> { joins("INNER JOIN members ON members.id = harvests.owner_id") }
def whole_plant?
name == 'whole plant'
end
def to_s
name
end

View File

@@ -149,78 +149,94 @@ describe Harvest do
end
context "stringification" do
let(:crop) { FactoryBot.create(:crop, name: "apricot") }
let(:whole_plant) { FactoryBot.create(:plant_part, name: "whole plant") }
let(:leaf) { FactoryBot.create(:plant_part, name: "leaf") }
let(:fruit) { FactoryBot.create(:plant_part, name: "fruit") }
let(:other) { FactoryBot.create(:plant_part, name: "other") }
it "apricots" do
@h = FactoryBot.create(:harvest, crop:,
quantity: nil,
unit: nil,
weight_quantity: nil,
weight_unit: nil)
expect(@h.to_s).to eq "apricots"
end
let(:apricot) { FactoryBot.create(:crop, name: "apricot") }
let(:lettuce) { FactoryBot.create(:crop, name: "lettuce") }
it "1 individual apricot" do
@h = FactoryBot.create(:harvest, crop:,
quantity: 1,
unit: 'individual',
weight_quantity: nil,
weight_unit: nil)
expect(@h.to_s).to eq "1 individual apricot"
end
context "apricots" do
it "apricots" do
@h = FactoryBot.create(:harvest, crop: apricot,
plant_part: fruit,
quantity: nil,
unit: nil,
weight_quantity: nil,
weight_unit: nil)
expect(@h.to_s).to eq "fruits of apricot"
end
it "10 individual apricots" do
@h = FactoryBot.create(:harvest, crop:,
quantity: 10,
unit: 'individual',
weight_quantity: nil,
weight_unit: nil)
expect(@h.to_s).to eq "10 individual apricots"
end
it "1 individual apricot" do
@h = FactoryBot.create(:harvest, crop: apricot,
plant_part: fruit,
quantity: 1,
unit: 'individual',
weight_quantity: nil,
weight_unit: nil)
expect(@h.to_s).to eq "1 individual fruit of apricot"
end
it "1 bushel of apricots" do
@h = FactoryBot.create(:harvest, crop:,
quantity: 1,
unit: 'bushel',
weight_quantity: nil,
weight_unit: nil)
expect(@h.to_s).to eq "1 bushel of apricots"
end
it "10 individual apricots" do
@h = FactoryBot.create(:harvest, crop: apricot,
plant_part: fruit,
quantity: 10,
unit: 'individual',
weight_quantity: nil,
weight_unit: nil)
expect(@h.to_s).to eq "10 individual fruits of apricot"
end
it "1.5 bushels of apricots" do
@h = FactoryBot.create(:harvest, crop:,
quantity: 1.5,
unit: 'bushel',
weight_quantity: nil,
weight_unit: nil)
expect(@h.to_s).to eq "1.5 bushels of apricots"
end
it "1 bushel of apricots" do
@h = FactoryBot.create(:harvest, crop: apricot,
plant_part: fruit,
quantity: 1,
unit: 'bushel',
weight_quantity: nil,
weight_unit: nil)
expect(@h.to_s).to eq "1 bushel of fruits of apricot"
end
it "10 bushels of apricots" do
@h = FactoryBot.create(:harvest, crop:,
quantity: 10,
unit: 'bushel',
weight_quantity: nil,
weight_unit: nil)
expect(@h.to_s).to eq "10 bushels of apricots"
end
it "1.5 bushels of apricots" do
@h = FactoryBot.create(:harvest, crop: apricot,
plant_part: fruit,
quantity: 1.5,
unit: 'bushel',
weight_quantity: nil,
weight_unit: nil)
expect(@h.to_s).to eq "1.5 bushels of fruits of apricot"
end
it "apricots weighing 1.2 kg" do
@h = FactoryBot.create(:harvest, crop:,
quantity: nil,
unit: nil,
weight_quantity: 1.2,
weight_unit: 'kg')
expect(@h.to_s).to eq "apricots weighing 1.2 kg"
end
it "10 bushels of apricots" do
@h = FactoryBot.create(:harvest, crop: apricot,
plant_part: fruit,
quantity: 10,
unit: 'bushel',
weight_quantity: nil,
weight_unit: nil)
expect(@h.to_s).to eq "10 bushels of fruits of apricot"
end
it "10 bushels of apricots weighing 100 kg" do
@h = FactoryBot.create(:harvest, crop:,
quantity: 10,
unit: 'bushel',
weight_quantity: 100,
weight_unit: 'kg')
expect(@h.to_s).to eq "10 bushels of apricots weighing 100 kg"
it "apricots weighing 1.2 kg" do
@h = FactoryBot.create(:harvest, crop: apricot,
plant_part: fruit,
quantity: nil,
unit: nil,
weight_quantity: 1.2,
weight_unit: 'kg')
expect(@h.to_s).to eq "fruits of apricot weighing 1.2 kg"
end
it "10 bushels of apricots weighing 100 kg" do
@h = FactoryBot.create(:harvest, crop: apricot,
plant_part: fruit,
quantity: 10,
unit: 'bushel',
weight_quantity: 100,
weight_unit: 'kg')
expect(@h.to_s).to eq "10 bushels of fruits of apricot weighing 100 kg"
end
end
end