+
+ # trying to subscribe when already subscribed
+ post :subscribe, { :id => diary_entry.id, :display_name => diary_entry.user.display_name }, { :user => other_user }
+ assert_no_difference "diary_entry.subscribers.count" do
+ post :subscribe, { :id => diary_entry.id, :display_name => diary_entry.user.display_name }, { :user => other_user }
+ end
+ end
+
+ def test_unsubscribe_success
+ user = create(:user)
+ other_user = create(:user)
+
+ diary_entry = create(:diary_entry, :user => user)
+
+ post :subscribe, { :id => diary_entry.id, :display_name => diary_entry.user.display_name }, { :user => other_user }
+ assert_difference "diary_entry.subscribers.count", -1 do
+ post :unsubscribe, { :id => diary_entry.id, :display_name => diary_entry.user.display_name }, { :user => other_user }
+ end
+ assert_response :redirect
+ end
+
+ def test_unsubscribe_fail
+ user = create(:user)
+ other_user = create(:user)
+
+ diary_entry = create(:diary_entry, :user => user)
+
+ # not signed in
+ assert_no_difference "diary_entry.subscribers.count" do
+ post :unsubscribe, :id => diary_entry.id, :display_name => diary_entry.user.display_name
+ end
+ assert_response :forbidden
+
+ # bad diary id
+ post :unsubscribe, { :id => 999111, :display_name => "username" }, { :user => other_user }
+ assert_response :not_found
+
+ # trying to unsubscribe when not subscribed
+ assert_no_difference "diary_entry.subscribers.count" do
+ post :unsubscribe, { :id => diary_entry.id, :display_name => diary_entry.user.display_name }, { :user => other_user }
+ end