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

Change naming to be aware of plant parts, even if it sounds oddly formal #3684

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
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
11 changes: 5 additions & 6 deletions app/models/harvest.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,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
Expand Down Expand Up @@ -108,7 +107,7 @@ def harvest_slug
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
Expand All @@ -131,13 +130,13 @@ def weight_to_human
"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

Expand Down
4 changes: 4 additions & 0 deletions app/models/plant_part.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
146 changes: 81 additions & 65 deletions spec/models/harvest_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -149,78 +149,94 @@
end

context "stringification" do
let(:crop) { FactoryBot.create(:crop, name: "apricot") }

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(: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") }

let(:apricot) { FactoryBot.create(:crop, name: "apricot") }
let(:lettuce) { FactoryBot.create(:crop, name: "lettuce") }

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 "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
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 "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 "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 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 "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 "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.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 "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 "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 "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 "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:,
quantity: 10,
unit: 'bushel',
weight_quantity: 100,
weight_unit: 'kg')
expect(@h.to_s).to eq "10 bushels of apricots weighing 100 kg"
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

Expand Down
Loading