From dff6827761f3f78a09201e4c1f8d1efc54567741 Mon Sep 17 00:00:00 2001 From: robotscissors Date: Sun, 10 Jun 2018 20:38:43 -0700 Subject: [PATCH 1/5] create rss feed for harvests --- app/controllers/harvests_controller.rb | 2 +- app/views/harvests/index.html.haml | 2 + app/views/harvests/index.rss.haml | 19 ++++++++ spec/views/harvests/index.rss.haml_spec.rb | 53 ++++++++++++++++++++++ 4 files changed, 75 insertions(+), 1 deletion(-) create mode 100644 app/views/harvests/index.rss.haml create mode 100644 spec/views/harvests/index.rss.haml_spec.rb diff --git a/app/controllers/harvests_controller.rb b/app/controllers/harvests_controller.rb index 73aaafd86..f731b1018 100644 --- a/app/controllers/harvests_controller.rb +++ b/app/controllers/harvests_controller.rb @@ -3,7 +3,7 @@ class HarvestsController < ApplicationController after_action :update_crop_medians, only: %i(create update destroy) load_and_authorize_resource respond_to :html, :json - respond_to :csv, only: :index + respond_to :csv, :rss, only: :index responders :flash def index diff --git a/app/views/harvests/index.html.haml b/app/views/harvests/index.html.haml index f743f8ad3..4ef4a427b 100644 --- a/app/views/harvests/index.html.haml +++ b/app/views/harvests/index.html.haml @@ -24,8 +24,10 @@ %ul.list-inline %li The data on this page is available in the following formats: - if @owner + %li= link_to "RSS", harvests_by_owner_path(@owner, format: 'rss') %li= link_to "CSV", harvests_by_owner_path(@owner, format: 'csv') %li= link_to "JSON", harvests_by_owner_path(@owner, format: 'json') - else + %li= link_to "RSS", harvests_path(format: 'rss') %li= link_to "CSV", harvests_path(format: 'csv') %li= link_to "JSON", harvests_path(format: 'json') diff --git a/app/views/harvests/index.rss.haml b/app/views/harvests/index.rss.haml new file mode 100644 index 000000000..f5682edf1 --- /dev/null +++ b/app/views/harvests/index.rss.haml @@ -0,0 +1,19 @@ + +%rss{ version: 2.0 } + %channel + %title + Recent harvests from #{@owner ? @owner : 'all members'} (#{ENV['GROWSTUFF_SITE_NAME']}) + %link= harvests_url + - @harvests.each do |harvest| + %item + %title #{harvest.owner.login_name}'s #{harvest.crop.name} + %pubdate= harvest.harvested_at.to_s(:rfc822) + %description + :escaped +

Crop: #{harvest.crop ? harvest.crop : 'unknown' }

+

Quantity: #{harvest.quantity ? harvest.quantity : 'unknown' }

+

Harvested on: #{harvest.harvested_at ? harvest.harvested_at : 'unknown' }

+ :escaped_markdown + #{ strip_tags harvest.description } + %link= harvest_url(harvest) + %guid= harvest_url(harvest) diff --git a/spec/views/harvests/index.rss.haml_spec.rb b/spec/views/harvests/index.rss.haml_spec.rb new file mode 100644 index 000000000..c3faecdaf --- /dev/null +++ b/spec/views/harvests/index.rss.haml_spec.rb @@ -0,0 +1,53 @@ +require 'rails_helper' + +describe 'harvests/index.rss.haml' do + before(:each) do + controller.stub(:current_user) { nil } + @member = FactoryBot.create(:member) + @tomato = FactoryBot.create(:tomato) + @maize = FactoryBot.create(:maize) + @pp = FactoryBot.create(:plant_part) + assign(:harvests, harvests) + render + end + + context 'all harvests' do + before(:each) do + #assign(:harvest, FactoryBot.create(:harvest)) + render + end + + it 'shows RSS feed title' do + rendered.should have_content "Recent harvests from all members" + end + + it 'item title shows owner and crop' do + rendered.should have_content "#{@harvest.crop}" + end + + # it 'shows formatted content of posts' do + # rendered.should have_content "This is a really good plant." + # end + # + # it 'shows sunniness' do + # rendered.should have_content 'Sunniness: sun' + # end + # + # it 'shows propagation method' do + # rendered.should have_content 'Planted from: seedling' + # end + end + + # context "one person's plantings" do + # before :each do + # @planting = FactoryBot.create(:planting) + # assign(:plantings, [@planting]) + # assign(:owner, @planting.owner) + # render + # end + # + # it 'shows title for single member' do + # rendered.should have_content "Recent plantings from #{@planting.owner}" + # end + # end +end From f9bdae77d3fc670711de293aedc1beb19fd16f1c Mon Sep 17 00:00:00 2001 From: robotscissors Date: Mon, 11 Jun 2018 10:38:26 -0700 Subject: [PATCH 2/5] add tests for harvests/index.rss --- spec/views/harvests/index.rss.haml_spec.rb | 63 +++++++++------------- 1 file changed, 26 insertions(+), 37 deletions(-) diff --git a/spec/views/harvests/index.rss.haml_spec.rb b/spec/views/harvests/index.rss.haml_spec.rb index c3faecdaf..b36fdd4a4 100644 --- a/spec/views/harvests/index.rss.haml_spec.rb +++ b/spec/views/harvests/index.rss.haml_spec.rb @@ -7,47 +7,36 @@ describe 'harvests/index.rss.haml' do @tomato = FactoryBot.create(:tomato) @maize = FactoryBot.create(:maize) @pp = FactoryBot.create(:plant_part) + page = 1 + per_page = 2 + total_entries = 2 + harvests = WillPaginate::Collection.create(page, per_page, total_entries) do |pager| + pager.replace([ + FactoryBot.create(:harvest, + crop: @tomato, + owner: @member), + FactoryBot.create(:harvest, + crop: @maize, + plant_part: @pp, + owner: @member, + quantity: 2) + ]) + end assign(:harvests, harvests) render end - context 'all harvests' do - before(:each) do - #assign(:harvest, FactoryBot.create(:harvest)) - render - end - - it 'shows RSS feed title' do - rendered.should have_content "Recent harvests from all members" - end - - it 'item title shows owner and crop' do - rendered.should have_content "#{@harvest.crop}" - end - - # it 'shows formatted content of posts' do - # rendered.should have_content "This is a really good plant." - # end - # - # it 'shows sunniness' do - # rendered.should have_content 'Sunniness: sun' - # end - # - # it 'shows propagation method' do - # rendered.should have_content 'Planted from: seedling' - # end + it 'shows RSS feed title' do + rendered.should have_content "Recent harvests from all members" end - # context "one person's plantings" do - # before :each do - # @planting = FactoryBot.create(:planting) - # assign(:plantings, [@planting]) - # assign(:owner, @planting.owner) - # render - # end - # - # it 'shows title for single member' do - # rendered.should have_content "Recent plantings from #{@planting.owner}" - # end - # end + it "displays crop's name in title" do + assign(:crop, @tomato) + render + rendered.should have_content "#{@tomato.name}" + end + + it 'shows formatted content of harvest posts' do + rendered.should have_content "

Quantity: " + end end From e784790e19d0659427f371aad98079aced84605c Mon Sep 17 00:00:00 2001 From: robotscissors Date: Mon, 11 Jun 2018 11:16:47 -0700 Subject: [PATCH 3/5] add .to_s to accomodate hound --- spec/views/harvests/index.rss.haml_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/views/harvests/index.rss.haml_spec.rb b/spec/views/harvests/index.rss.haml_spec.rb index b36fdd4a4..b36d63867 100644 --- a/spec/views/harvests/index.rss.haml_spec.rb +++ b/spec/views/harvests/index.rss.haml_spec.rb @@ -33,7 +33,7 @@ describe 'harvests/index.rss.haml' do it "displays crop's name in title" do assign(:crop, @tomato) render - rendered.should have_content "#{@tomato.name}" + rendered.should have_content "#{@tomato.name.to_s}" end it 'shows formatted content of harvest posts' do From 82b83ca7a4ca4168a2a837c63e01b95e59656554 Mon Sep 17 00:00:00 2001 From: robotscissors Date: Tue, 12 Jun 2018 10:00:45 -0700 Subject: [PATCH 4/5] Fix linter issues --- spec/views/harvests/index.rss.haml_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/views/harvests/index.rss.haml_spec.rb b/spec/views/harvests/index.rss.haml_spec.rb index b36d63867..aea1f7bc5 100644 --- a/spec/views/harvests/index.rss.haml_spec.rb +++ b/spec/views/harvests/index.rss.haml_spec.rb @@ -33,10 +33,10 @@ describe 'harvests/index.rss.haml' do it "displays crop's name in title" do assign(:crop, @tomato) render - rendered.should have_content "#{@tomato.name.to_s}" + expect(rendered).to have_content @tomato.name end it 'shows formatted content of harvest posts' do - rendered.should have_content "

Quantity: " + expect(rendered).to have_content "

Quantity: " end end From 605e2e1392c861ad15a16ff96a1da53749fc0ec4 Mon Sep 17 00:00:00 2001 From: robotscissors Date: Mon, 18 Jun 2018 15:22:27 -0700 Subject: [PATCH 5/5] Add to contributors file --- CONTRIBUTORS.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index 87b153b17..e2fee563a 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -84,6 +84,7 @@ submit the change with your pull request. - Logan Gingerich / [logangingerich](https://github.com/logangingerich) - Mark Taffman / [mftaff](https://github.com/mftaff) - Jennifer Kruse / [jenkr55](https://github.com/jenkr55) +- Christopher Bazin / [RobotScissors](https://github.com/robotscissors) ## Bots