From ceef39e846ace4ba5e7e3232e98e5ac31191eb2f Mon Sep 17 00:00:00 2001 From: gnattery Date: Mon, 1 Apr 2013 11:44:14 +1100 Subject: [PATCH] Cleaned up controller for notifications. Removed json from notification, since it's a bit risky and we don't really need it. --- app/controllers/notifications_controller.rb | 15 ++------------- app/views/notifications/_form.html.haml | 1 - spec/controllers/notifications_controller_spec.rb | 11 +---------- 3 files changed, 3 insertions(+), 24 deletions(-) diff --git a/app/controllers/notifications_controller.rb b/app/controllers/notifications_controller.rb index 6cc9c13df..7b49c326f 100644 --- a/app/controllers/notifications_controller.rb +++ b/app/controllers/notifications_controller.rb @@ -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 diff --git a/app/views/notifications/_form.html.haml b/app/views/notifications/_form.html.haml index 6eccf0faa..a0b9f6d55 100644 --- a/app/views/notifications/_form.html.haml +++ b/app/views/notifications/_form.html.haml @@ -8,7 +8,6 @@ .field = f.hidden_field :recipient_id, :value => @recipient.id - = f.hidden_field :sender_id, :value => @sender.id %p To: diff --git a/spec/controllers/notifications_controller_spec.rb b/spec/controllers/notifications_controller_spec.rb index a1642b36f..e015c531a 100644 --- a/spec/controllers/notifications_controller_spec.rb +++ b/spec/controllers/notifications_controller_spec.rb @@ -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