Permalink
Browse files

GH#5 add RSS video feed

  • Loading branch information...
1 parent fea9db9 commit efd17adf0df3b81a92c85d46f62b043a724a6120 @tardate committed Jan 8, 2012
@@ -0,0 +1,13 @@
+class VideosController < InheritedResources::Base
+ defaults :resource_class => Note
+ belongs_to :show, :finder => :find_by_number!, :optional => true
+ respond_to :rss
+
+ protected
+ def begin_of_association_chain
+ resource_class.videos unless parent?
+ end
+ def collection
+ @videos ||= end_of_association_chain.show_meme_note_order
+ end
+end
View
@@ -121,6 +121,8 @@ def normalize_name(value)
'Vaccine$'
when /vagina/i
'Vagina'
+ when /video/i
+ 'VIDEO'
when /we.+can.+wait/i
"We Can't Wait!"
when /word.+matter/i
View
@@ -2,7 +2,6 @@ class Note < ActiveRecord::Base
belongs_to :show
belongs_to :meme
- default_scope order('notes.name')
scope :show_meme_note_order, includes(:show).includes(:meme).reorder('shows.number desc, memes.name asc, notes.name asc')
-
+ scope :videos, includes(:show).includes(:meme).where(:'memes.name' => 'VIDEO')
end
View
@@ -1,5 +1,6 @@
class Show < ActiveRecord::Base
has_many :notes, :dependent => :destroy
+ delegate :videos, :to => :notes
has_many :memes, :through => :notes, :uniq => true, :order => :name
default_scope order('shows.number desc')
@@ -46,6 +47,10 @@ def short_title
"#{number} - #{published_date.to_s}"
end
+ def short_id
+ "NA#{number}"
+ end
+
def full_title
"#{number} - #{published_date.to_s} #{name}"
end
@@ -0,0 +1,23 @@
+xml.instruct! :xml, :version => "1.0"
+xml.rss :version => "2.0" do
+ xml.channel do
+ if parent?
+ xml.title "NoAgenda Videos for Show ##{parent.number}"
+ xml.link parent_url
+ else
+ xml.title "NoAgenda Videos"
+ xml.link root_url
+ end
+ xml.description "this is a feed of all videos linked in the show notes"
+
+ for note in collection
+ xml.item do
+ xml.title h( note.name )
+ xml.description h( note.description )
+ xml.category note.show.short_id
+ xml.pubDate note.show.published_date.rfc822
+ xml.link note.url
+ end
+ end
+ end
+end
View
@@ -17,7 +17,9 @@
resources :shows, :only => [:index,:show] do
resources :notes, :only => [:index,:show]
resources :memes, :only => [:index,:show]
+ resources :videos, :only => [:index]
get :mediawidget, :on => :member
get :stat, :on => :member
end
+ resources :videos, :only => [:index]
end
@@ -0,0 +1,23 @@
+require 'spec_helper'
+
+describe VideosController do
+ render_views
+ let!(:video_meme) { Factory(:meme, :name => 'VIDEO') }
+ let!(:show) { Factory(:show) }
+ let!(:resource) { Factory(:note, :show => show, :meme => video_meme) }
+
+ context "RSS" do
+ describe "GET :index.rss" do
+ subject { get :index, :format => 'rss' }
+ it { should be_success }
+ end
+
+ context "nested under show" do
+ describe "GET :index.rss" do
+ subject { get :index, :format => 'rss', :show_id => show.number }
+ it { should be_success }
+ end
+ end
+ end
+
+end
@@ -1,4 +1,5 @@
Factory.define :show do |f|
f.sequence(:number)
f.sequence(:name) { |n| "show_#{n}" }
+ f.published_date Date.today
end
@@ -20,4 +20,13 @@
expect { subject }.not_to change { Meme.count }
end
end
+
+ describe "##videos" do
+ let!(:video_meme) { Factory(:meme, :name => 'VIDEO') }
+ let!(:video_note) { Factory(:note, :meme => video_meme) }
+ let!(:nonvideo_note) { Factory(:note) }
+ subject { Note.videos }
+ it { should include(video_note) }
+ it { should_not include(nonvideo_note) }
+ end
end
@@ -60,6 +60,12 @@
its(:short_title) { should eql(expected) }
end
+ describe "#short_id" do
+ let(:expected) { "NA33" }
+ subject { resource }
+ its(:short_id) { should eql(expected) }
+ end
+
describe "#full_title" do
let(:expected) { "33 - #{published_date} #{resource.name}" }
subject { resource }
@@ -104,4 +110,13 @@
expect { subject }.not_to change { Meme.count }
end
end
+
+ describe "#videos" do
+ let!(:video_meme) { Factory(:meme, :name => 'VIDEO') }
+ let!(:video_note) { Factory(:note, :show => resource, :meme => video_meme) }
+ let!(:nonvideo_note) { Factory(:note, :show => resource) }
+ subject { resource.videos }
+ it { should include(video_note) }
+ it { should_not include(nonvideo_note) }
+ end
end

0 comments on commit efd17ad

Please sign in to comment.