mirror of
https://github.com/Growstuff/growstuff.git
synced 2026-05-25 17:31:18 -04:00
Compare commits
4 Commits
release85
...
fix-naming
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1511de8a81 | ||
|
|
df15383dd0 | ||
|
|
bcaeaf3688 | ||
|
|
2fc5b63c0e |
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user