diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index de96fc4f8..dd52af87e 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -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) diff --git a/app/helpers/plantings_helper.rb b/app/helpers/plantings_helper.rb index 1eb220481..62d96be88 100644 --- a/app/helpers/plantings_helper.rb +++ b/app/helpers/plantings_helper.rb @@ -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 \ No newline at end of file + + 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 diff --git a/app/views/crops/_plantings.html.haml b/app/views/crops/_plantings.html.haml index 026f6f7fb..2f9d04483 100644 --- a/app/views/crops/_plantings.html.haml +++ b/app/views/crops/_plantings.html.haml @@ -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) diff --git a/spec/helpers/plantings_helper_spec.rb b/spec/helpers/plantings_helper_spec.rb new file mode 100644 index 000000000..4cb2c63a7 --- /dev/null +++ b/spec/helpers/plantings_helper_spec.rb @@ -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 \ No newline at end of file