diff --git a/app/models/plant.rb b/app/models/plant.rb index 32c66bd..09348d0 100644 --- a/app/models/plant.rb +++ b/app/models/plant.rb @@ -17,11 +17,11 @@ def trefle_data class << self def dead - Plant.where(status_id: Status.find_by(name: 'Dead')) + Plant.where(status_id: Status.dead) end def alive - Plant.where(status_id: Status.find_by(name: 'Alive')) + Plant.where(status_id: Status.alive) end end end diff --git a/app/models/status.rb b/app/models/status.rb index f26f779..d307885 100644 --- a/app/models/status.rb +++ b/app/models/status.rb @@ -1,3 +1,19 @@ class Status < ApplicationRecord has_many :plants + + DEAD = 'Dead'.freeze + + ALIVE = 'Alive'.freeze + + class << self + # @return [Status] + def dead + find_by(name: DEAD) + end + + # @return [Status] + def alive + find_by(name: ALIVE) + end + end end diff --git a/spec/models/status_spec.rb b/spec/models/status_spec.rb index 3cb6281..612250b 100644 --- a/spec/models/status_spec.rb +++ b/spec/models/status_spec.rb @@ -6,4 +6,22 @@ expect(subject).to all(be_instance_of(Plant)) end end + + describe '.dead' do + subject { Status.dead } + + it do + expect(subject).to be_instance_of(Status) + expect(subject.name).to eql('Dead') + end + end + + describe '.alive' do + subject { Status.alive } + + it do + expect(subject).to be_instance_of(Status) + expect(subject.name).to eql('Alive') + end + end end \ No newline at end of file