Cleaned up controller for notifications.

Removed json from notification, since it's a bit risky and we don't really need it.
This commit is contained in:
gnattery committed 2013-04-01 11:44:14 +11:00
1 parent fe895562f5
commit ceef39e846
3 files changed
+3 -24

No files matched your search

+2 -13
View File
@@ -1,18 +1,15 @@
class NotificationsController < ApplicationController
load_and_authorize_resource
# GET /notifications
# GET /notifications.json
def index
@notifications = Notification.find_all_by_recipient_id(current_member)
respond_to do |format|
format.html # index.html.erb
format.json { render json: @notifications }
end
end
# GET /notifications/1
# GET /notifications/1.json
def show
@notification = Notification.find(params[:id])
@notification.read = true
@@ -20,49 +17,41 @@ class NotificationsController < ApplicationController
respond_to do |format|
format.html # show.html.erb
format.json { render json: @notification }
end
end
# GET /notifications/new
# GET /notifications/new.json
def new
@notification = Notification.new
@recipient = Member.find_by_id(params[:recipient_id])
@sender = Member.find_by_id(params[:sender_id])
respond_to do |format|
format.html # new.html.erb
format.json { render json: @notification }
end
end
# DELETE /notifications/1
# DELETE /notifications/1.json
def destroy
@notification = Notification.find(params[:id])
@notification.destroy
respond_to do |format|
format.html { redirect_to notifications_url }
format.json { head :no_content }
end
end
# POST /notifications
# POST /notifications.json
def create
params[:notification][:sender_id] = current_member.id
@notification = Notification.new(params[:notification])
@recipient = Member.find_by_id(params[:notification][:recipient_id])
respond_to do |format|
if @notification.save
format.html { redirect_to @recipient, notice: 'Message was successfully sent.' }
format.json { render json: @notification, status: :created, location: @notification }
else
format.html { render action: "new" }
format.json { render json: @notification.errors, status: :unprocessable_entity }
end
end
end
-1
View File
@@ -8,7 +8,6 @@
.field
= f.hidden_field :recipient_id, :value => @recipient.id
= f.hidden_field :sender_id, :value => @sender.id
%p
To:
@@ -47,13 +47,6 @@ describe NotificationsController do
get :new, {:recipient_id => @recipient.id }
assigns(:recipient).should be_an_instance_of(Member)
end
it "assigns a sender" do
@sender = FactoryGirl.create(:member)
@notification = FactoryGirl.create(:notification, :sender => @sender)
get :new, {:sender_id => @sender.id }
assigns(:sender).should be_an_instance_of(Member)
end
end
describe "DELETE destroy" do
@@ -86,10 +79,8 @@ describe NotificationsController do
end
it "redirects to the recipient's profile" do
@sender = FactoryGirl.create(:member)
@recipient = FactoryGirl.create(:member)
post :create, { :notification => { :recipient_id => @recipient.id,
:sender_id => @sender.id}}
post :create, { :notification => { :recipient_id => @recipient.id}}
response.should redirect_to(@recipient)
end
end