Permalink
Browse files

watch later button on presentation show changes to _watched_ if in us…

…ers watch list
  • Loading branch information...
1 parent 5b6285e commit dd7b6676b611a2b867907c1a936316faa1a39017 @mattpolito committed Mar 8, 2011
@@ -1,4 +1,18 @@
module PresentationsHelper
+ def queue_button_for(presentation, user)
+ return unless user_signed_in?
+ if user && presentation.queued_by?(user)
+ button_to('Watched',
+ save_presentation_path(presentation.event, presentation),
+ :method => :delete
+ )
+ else
+ button_to('Watch Later',
+ save_presentation_path(presentation.event, presentation)
+ )
+ end
+ end
+
def shorten_url_for(url, presentation)
unless presentation.short_url?
presentation.set_short_url(url)
@@ -18,7 +32,9 @@ def bitly_url(url)
def tweet_text_for(presentation)
speakers = presentation.speakers
- twitter_handles = speakers.collect{ |s| "@#{s.twitter}" if s.twitter? }.compact
+ twitter_handles = speakers.collect do |s|
+ "@#{s.twitter}" if s.twitter?
+ end.compact
speaker_msg = "#{twitter_handles.join(" & ")} talk about " if twitter_handles.present?
"Watching #{speaker_msg}#{presentation.title} - #{presentation.event.name}"
end
@@ -37,6 +37,7 @@ class Presentation < ActiveRecord::Base
accepts_nested_attributes_for :videos, :reject_if => :all_blank
has_many :slideshows
accepts_nested_attributes_for :slideshows, :reject_if => :all_blank
+ has_many :saved_presentations
# Scopes
scope :released, :conditions => { :released => true }
@@ -53,6 +54,10 @@ def build_extras
slideshows.build unless slideshows.present?
end
+ def queued_by?(user)
+ saved_presentations.exists?(:user_id => user.id)
+ end
+
def set_short_url(url)
bitly = Bitly.new(AppConfig.bitly.user, AppConfig.bitly.api_key)
short_url = bitly.shorten(url).try(:short_url)
@@ -46,4 +46,4 @@
= tweet_button :text => tweet_text_for(@presentation),
:url => shorten_url_for(request.url, @presentation)
%dd
- = button_to 'Watch Later', save_presentation_path(@presentation.event, @presentation) if user_signed_in?
+ = queue_button_for(@presentation, current_user)
View
@@ -8,6 +8,7 @@
end
post "events/:event_id/presentations/:presentation_id/watch-later", :to => "saved_presentations#create", :as => "save_presentation"
+ delete "events/:event_id/presentations/:presentation_id/watch-later", :to => "saved_presentations#destroy", :as => "save_presentation"
resources :presentations, :only => [:index]
resources :speakers, :only => [:index, :show]
@@ -11,3 +11,5 @@ Feature: Add presentation to queue
And I press "Watch Later"
Then I should have 1 saved presentation
And I should see "Presentation Saved"
+ And I should not see the "Watch Later" button
+ And I should see the "Watched" button
@@ -45,3 +45,10 @@
assert_equal title, page.find(:css, 'title').text
end
+Then /^I should see the "([^"]*)" button$/ do |text|
+ page.should have_button(text)
+end
+
+Then /^I should not see the "([^"]*)" button$/ do |text|
+ page.should_not have_button(text)
+end
@@ -1,4 +1,3 @@
Then /^I should see "([^"]*)" within watch list$/ do |title|
And %{I should see "#{title}" within "aside"}
end
-
View
@@ -0,0 +1,4 @@
+Factory.define :user do |f|
+ f.email "matt.polito@example.net"
+ f.password "password"
+end
@@ -15,6 +15,7 @@
it { should have_and_belong_to_many(:speakers) }
it { should have_many(:videos) }
it { should have_many(:slideshows) }
+ it { should have_many(:saved_presentations) }
let(:valid_attributes) do
{
@@ -164,4 +165,18 @@
subject.short_url.should == "short_url"
end
end
+
+ describe "#queued_by?(current_user)" do
+ subject { Factory(:presentation) }
+ let(:user) { Factory(:user) }
+
+ it "returns true if current_user has presentation in watch list" do
+ user.watch_list.create(:presentation => subject)
+ subject.queued_by?(user).should be_true
+ end
+
+ it "returns false unless current_user has presentation in watch list" do
+ subject.queued_by?(user).should be_false
+ end
+ end
end

0 comments on commit dd7b667

Please sign in to comment.