Skip to content

Commit

Permalink
Added current subcription UI.
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul committed Feb 9, 2011
1 parent 2abd31e commit 6699417
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 2 deletions.
27 changes: 27 additions & 0 deletions app/controllers/currents_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,33 @@ def page_title
end
end

def change_subscription(enabled)
@current = current_object
if enabled
@current.subscribers << current_user
else
@current.subscribers.delete current_user
end

respond_to do |format|
format.html do
flash[:info] = 'You are no longer subscribed to notifications of new ideas on this current.' if !enabled
redirect_to :action => 'show'
end
format.js do
render :partial => 'subscription'
end
end
end

def subscribe
change_subscription(true)
end

def unsubscribe
change_subscription(false)
end

include ApplicationHelper

end
1 change: 1 addition & 0 deletions app/models/user_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ def idea_in_current_notification(user, idea)
set_up_email(user)
@body[:idea] = idea
@body[:url] = idea_url(idea)
@body[:unsubscribe_url] = unsubscribe_current_url(idea.current)
@subject += "New idea in current \"#{strip_funkies(idea.current.title)}\""
end

Expand Down
13 changes: 13 additions & 0 deletions app/views/currents/_subscription.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
-if logged_in?
%li.subscription
-if current_user.subscribed_currents.include?(@current)
You will receive email notifications for new ideas in this current.
= link_to_remote 'Stop watching',
:url => unsubscribe_current_path(@current),
:update => 'subscription',
:complete => visual_effect(:highlight, 'subscription', :duration => 0.8)
-else
= link_to_remote 'Watch this current',
:url => subscribe_current_path(@current),
:update => 'subscription',
:complete => visual_effect(:highlight, 'subscription', :duration => 0.8)
2 changes: 2 additions & 0 deletions app/views/currents/show.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
%h3 About This Current
%ul.entry-meta
%li.ideas= render :partial => 'idea_count', :locals => { :current_ideas => @current_ideas }
#subscription
= render :partial => 'subscription'
%li.sharethis= render :partial => 'ideas/sharethis'
.group.slate
- if @current_ideas.empty?
Expand Down
2 changes: 1 addition & 1 deletion app/views/ideas/_subscription.html.haml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
-if logged_in?
%li
%li.subscription
-if @idea.inventor == current_user && current_user.notify_on_comments?
You will receive email notifications for new comments on your idea.
= link_to 'Account settings', edit_user_path
Expand Down
4 changes: 3 additions & 1 deletion app/views/user_mailer/idea_in_current_notification.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@
<%= h @idea.description %>
<%= @url %>
<%= @url %>

To stop receiving these notifications: <%= @unsubscribe_url %>
17 changes: 17 additions & 0 deletions test/functional/currents_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,5 +89,22 @@ def test_subscriber_notification_delivered_when_user_activated
Delayed::Worker.new(:quiet => true).work_off
assert_email_sent @sally, /ideas\/#{new_idea.id}/
end

def test_subscribe
login_as @quentin
put :subscribe, :id => @walrus_attack_current.id
assert_redirected_to :action => :show
@walrus_attack_current.reload
assert_equal_unordered [@sally, @quentin], @walrus_attack_current.subscribers
end

def test_unsubscribe
login_as @sally
get :unsubscribe, :id => @walrus_attack_current.id
assert_redirected_to :action => :show
assert flash[:info] =~ /no longer subscribed/
@walrus_attack_current.reload
assert_equal [], @walrus_attack_current.subscribers
end

end

0 comments on commit 6699417

Please sign in to comment.