added RSS feed for seeds

This commit is contained in:
Skud
2013-08-05 11:40:53 +10:00
parent e77c402ad9
commit 128c76bca3
3 changed files with 74 additions and 0 deletions

View File

@@ -12,6 +12,7 @@ class SeedsController < ApplicationController
respond_to do |format|
format.html # index.html.erb
format.json { render json: @seeds }
format.rss { render :layout => false } #index.rss.builder
end
end

View File

@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
%rss{:version => 2.0}
%channel
%title
#{Growstuff::Application.config.site_name} - Recent seeds from #{ @owner ? @owner : 'all members' }
%link= seeds_url
- @seeds.each do |seed|
%item
%author= seed.owner.login_name
%title #{seed.owner}'s #{seed.crop} seeds
%pubDate= seed.created_at.to_s(:rfc822)
%description
:escaped
<p>Quantity: #{seed.quantity ? seed.quantity : 'unknown' }</p>
<p>Plant before: #{seed.plant_before ? seed.plant_before : 'unknown' }</p>
- if seed.tradable?
:escaped
<p>Will trade #{seed.tradable_to} from #{seed.owner.location ? seed.owner.location : 'unknown location'}</p>
:escaped_markdown
#{ strip_tags seed.description }
%link= seed_url(seed)
%guid= seed_url(seed)

View File

@@ -0,0 +1,50 @@
require 'spec_helper'
describe 'seeds/index.rss.haml' do
before(:each) do
controller.stub(:current_user) { nil }
end
context 'all seeds' do
before(:each) do
@seed = FactoryGirl.create(:seed)
@tradable = FactoryGirl.create(:tradable_seed)
assign(:seeds, [ @seed, @tradable ])
render
end
it 'shows RSS feed title' do
rendered.should contain "Recent seeds from all members"
end
it 'has a useful item title' do
rendered.should contain "#{@seed.owner}'s #{@seed.crop} seeds"
end
it 'shows the seed count' do
rendered.should contain "Quantity: #{@seed.quantity}"
end
it 'shows the plant_before date' do
rendered.should contain "Plant before: #{@seed.plant_before.to_s}"
end
it 'mentions that one seed is tradable' do
rendered.should contain "Will trade #{@tradable.tradable_to} from #{@tradable.owner.location}"
end
end
context "one member's seeds" do
before(:each) do
@seed = FactoryGirl.create(:seed)
assign(:seeds, [ @seed ])
assign(:owner, @seed.owner)
render
end
it 'shows RSS feed title' do
rendered.should contain "Recent seeds from #{@seed.owner}"
end
end
end