Merge pull request #1607 from Br3nda/fix/plants-parts-dupe

Don't allow duplicate plant parts names
This commit is contained in:
Brenda Wallace
2018-06-17 10:42:14 +12:00
committed by GitHub
3 changed files with 4 additions and 2 deletions

View File

@@ -5,6 +5,8 @@ class PlantPart < ActiveRecord::Base
has_many :harvests
has_many :crops, -> { uniq }, through: :harvests
validates :name, presence: true, uniqueness: true
def to_s
name
end

View File

@@ -3,7 +3,7 @@
FactoryBot.define do
factory :harvest do
crop { planting.present? ? planting.crop : FactoryBot.create(:crop) }
plant_part
plant_part { FactoryBot.create :plant_part }
planting nil
owner { planting.present? ? planting.owner : FactoryBot.create(:member) }
harvested_at { Time.zone.local(2015, 9, 17) }

View File

@@ -2,6 +2,6 @@
FactoryBot.define do
factory :plant_part do
name "pollen"
name { "#{Faker::Book.title}_#{rand(100..999)}" }
end
end