mirror of
https://github.com/Growstuff/growstuff.git
synced 2026-05-24 08:52:14 -04:00
Merge remote-tracking branch 'upstream/pr/698' into dev
This commit is contained in:
@@ -60,3 +60,4 @@ submit the change with your pull request.
|
||||
- Gabriel Sandoval / [gabrielsandoval](https://github.com/gabrielsandoval)
|
||||
- Cjay Billones / [CjayBillones](https://github.com/CjayBillones)
|
||||
- Katy Ereira / [maccath](https://github.com/maccath)
|
||||
- Gabrielle DeWitt / [gabrielle27](https://github.com/gabrielle27)
|
||||
|
||||
@@ -21,7 +21,7 @@ module PlantingsHelper
|
||||
"(no date specified)"
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def display_sunniness(planting)
|
||||
!planting.sunniness.blank? ? planting.sunniness : "not specified"
|
||||
end
|
||||
@@ -33,4 +33,17 @@ module PlantingsHelper
|
||||
def display_planting_quantity(planting)
|
||||
!planting.quantity.blank? ? planting.quantity : "not specified"
|
||||
end
|
||||
end
|
||||
|
||||
def display_planting(planting)
|
||||
if planting.quantity.to_i > 0 && planting.planted_from.present?
|
||||
return "#{planting.owner} planted #{pluralize(planting.quantity, planting.planted_from)}."
|
||||
elsif planting.quantity.to_i > 0
|
||||
return "#{planting.owner} planted #{pluralize(planting.quantity, 'unit')}."
|
||||
elsif planting.planted_from.present?
|
||||
return "#{planting.owner} planted #{planting.planted_from.pluralize}."
|
||||
else
|
||||
return "#{planting.owner}."
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
%ul
|
||||
- crop.plantings.take(3).each do |planting|
|
||||
%li
|
||||
= link_to "#{planting.owner} planted #{planting.quantity} #{planting.planted_from}.", planting_path(planting)
|
||||
= link_to display_planting(planting), planting_path(planting)
|
||||
= render :partial => 'members/location', :locals => { :member => planting.owner }
|
||||
%small
|
||||
= distance_of_time_in_words(planting.created_at, Time.zone.now)
|
||||
|
||||
74
spec/helpers/plantings_helper_spec.rb
Normal file
74
spec/helpers/plantings_helper_spec.rb
Normal file
@@ -0,0 +1,74 @@
|
||||
require 'rails_helper'
|
||||
|
||||
describe PlantingsHelper do
|
||||
describe "display_planting" do
|
||||
|
||||
let!(:member) { FactoryGirl.build(:member, :login_name => 'crop_lady') }
|
||||
|
||||
it "does not have a quantity nor a planted from value provided" do
|
||||
planting = FactoryGirl.build(:planting,
|
||||
:quantity => nil,
|
||||
:planted_from => '',
|
||||
:owner => member
|
||||
)
|
||||
result = helper.display_planting(planting)
|
||||
expect(result).to eq "crop_lady."
|
||||
end
|
||||
|
||||
it "does not have a quantity provided" do
|
||||
planting = FactoryGirl.build(:planting,
|
||||
:quantity => nil,
|
||||
:planted_from => 'seed',
|
||||
:owner => member
|
||||
)
|
||||
result = helper.display_planting(planting)
|
||||
expect(result).to eq "crop_lady planted seeds."
|
||||
end
|
||||
|
||||
context "when quantity is greater than 1" do
|
||||
it "does not have a planted from value provided" do
|
||||
planting = FactoryGirl.build(:planting,
|
||||
:quantity => 10,
|
||||
:planted_from => '',
|
||||
:owner => member
|
||||
)
|
||||
result = helper.display_planting(planting)
|
||||
expect(result).to eq "crop_lady planted 10 units."
|
||||
end
|
||||
|
||||
it "does have a planted from value provided" do
|
||||
planting = FactoryGirl.build(:planting,
|
||||
:quantity => 5,
|
||||
:planted_from => 'seed',
|
||||
:owner => member
|
||||
)
|
||||
result = helper.display_planting(planting)
|
||||
expect(result).to eq "crop_lady planted 5 seeds."
|
||||
end
|
||||
end
|
||||
|
||||
context "when quantity is 1" do
|
||||
it "does not have a planted from value provided" do
|
||||
planting = FactoryGirl.build(:planting,
|
||||
:quantity => 1,
|
||||
:planted_from => '',
|
||||
:owner => member
|
||||
)
|
||||
result = helper.display_planting(planting)
|
||||
expect(result).to eq "crop_lady planted 1 unit."
|
||||
end
|
||||
|
||||
it "does have a planted from value provided" do
|
||||
planting = FactoryGirl.build(:planting,
|
||||
:quantity => 1,
|
||||
:planted_from => 'seed',
|
||||
:owner => member
|
||||
)
|
||||
result = helper.display_planting(planting)
|
||||
expect(result).to eq "crop_lady planted 1 seed."
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user