mirror of
https://github.com/Growstuff/growstuff.git
synced 2026-05-19 06:15:44 -04:00
Merge pull request #1646 from robotscissors/issue-565-create-harvests-rss
Issue 565 create harvests RSS
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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')
|
||||
|
||||
19
app/views/harvests/index.rss.haml
Normal file
19
app/views/harvests/index.rss.haml
Normal file
@@ -0,0 +1,19 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
%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
|
||||
<p>Crop: #{harvest.crop ? harvest.crop : 'unknown' }</p>
|
||||
<p>Quantity: #{harvest.quantity ? harvest.quantity : 'unknown' }</p>
|
||||
<p>Harvested on: #{harvest.harvested_at ? harvest.harvested_at : 'unknown' }</p>
|
||||
:escaped_markdown
|
||||
#{ strip_tags harvest.description }
|
||||
%link= harvest_url(harvest)
|
||||
%guid= harvest_url(harvest)
|
||||
42
spec/views/harvests/index.rss.haml_spec.rb
Normal file
42
spec/views/harvests/index.rss.haml_spec.rb
Normal file
@@ -0,0 +1,42 @@
|
||||
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)
|
||||
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
|
||||
|
||||
it 'shows RSS feed title' do
|
||||
rendered.should have_content "Recent harvests from all members"
|
||||
end
|
||||
|
||||
it "displays crop's name in title" do
|
||||
assign(:crop, @tomato)
|
||||
render
|
||||
expect(rendered).to have_content @tomato.name
|
||||
end
|
||||
|
||||
it 'shows formatted content of harvest posts' do
|
||||
expect(rendered).to have_content "<p>Quantity: "
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user