removed unwanted methods from controller

This commit is contained in:
Skud
2013-02-15 23:42:45 +11:00
parent cc2c63b2eb
commit eaa4e9bab9
3 changed files with 9 additions and 175 deletions

View File

@@ -22,54 +22,6 @@ class NotificationsController < ApplicationController
end
end
# GET /notifications/new
# GET /notifications/new.json
def new
@notification = Notification.new
respond_to do |format|
format.html # new.html.erb
format.json { render json: @notification }
end
end
# GET /notifications/1/edit
def edit
@notification = Notification.find(params[:id])
end
# POST /notifications
# POST /notifications.json
def create
@notification = Notification.new(params[:notification])
respond_to do |format|
if @notification.save
format.html { redirect_to @notification, notice: 'Notification was successfully created.' }
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
# PUT /notifications/1
# PUT /notifications/1.json
def update
@notification = Notification.find(params[:id])
respond_to do |format|
if @notification.update_attributes(params[:notification])
format.html { redirect_to @notification, notice: 'Notification was successfully updated.' }
format.json { head :no_content }
else
format.html { render action: "edit" }
format.json { render json: @notification.errors, status: :unprocessable_entity }
end
end
end
# DELETE /notifications/1
# DELETE /notifications/1.json
def destroy

View File

@@ -14,7 +14,7 @@ class Ability
# can read/delete notifications that were sent to them
can :read, Notification, :to_id => member.id
can :delete, Notification, :to_id => member.id
can :destroy, Notification, :to_id => member.id
# note we don't support create/update for notifications
# for now, anyone can create/edit/destroy crops

View File

@@ -1,35 +1,13 @@
require 'spec_helper'
# This spec was generated by rspec-rails when you ran the scaffold generator.
# It demonstrates how one might use RSpec to specify the controller code that
# was generated by Rails when you ran the scaffold generator.
#
# It assumes that the implementation code is generated by the rails scaffold
# generator. If you are using any extension libraries to generate different
# controller code, this generated spec may or may not pass.
#
# It only uses APIs available in rails and/or rspec-rails. There are a number
# of tools you can use to make these specs even more expressive, but we're
# sticking to rails and rspec-rails APIs to keep things simple and stable.
#
# Compared to earlier versions of this generator, there is very limited use of
# stubs and message expectations in this spec. Stubs are only used when there
# is no simpler way to get a handle on the object needed for the example.
# Message expectations are only used when there is no simpler way to specify
# that an instance is receiving a specific message.
describe NotificationsController do
# This should return the minimal set of attributes required to create a valid
# Notification. As you add validations to Notification, be sure to
# update the return value of this method accordingly.
login_member
def valid_attributes
{ "to_id" => "1" }
{ "to_id" => subject.current_member.id }
end
# This should return the minimal set of values that should be in the session
# in order to pass any filters (e.g. authentication) defined in
# NotificationsController. Be sure to keep this updated too.
def valid_session
{}
end
@@ -37,7 +15,7 @@ describe NotificationsController do
describe "GET index" do
it "assigns all notifications as @notifications" do
notification = Notification.create! valid_attributes
get :index, {}, valid_session
get :index, {}
assigns(:notifications).should eq([notification])
end
end
@@ -45,118 +23,22 @@ describe NotificationsController do
describe "GET show" do
it "assigns the requested notification as @notification" do
notification = Notification.create! valid_attributes
get :show, {:id => notification.to_param}, valid_session
get :show, {:id => notification.to_param}
assigns(:notification).should eq(notification)
end
end
describe "GET new" do
it "assigns a new notification as @notification" do
get :new, {}, valid_session
assigns(:notification).should be_a_new(Notification)
end
end
describe "GET edit" do
it "assigns the requested notification as @notification" do
notification = Notification.create! valid_attributes
get :edit, {:id => notification.to_param}, valid_session
assigns(:notification).should eq(notification)
end
end
describe "POST create" do
describe "with valid params" do
it "creates a new Notification" do
expect {
post :create, {:notification => valid_attributes}, valid_session
}.to change(Notification, :count).by(1)
end
it "assigns a newly created notification as @notification" do
post :create, {:notification => valid_attributes}, valid_session
assigns(:notification).should be_a(Notification)
assigns(:notification).should be_persisted
end
it "redirects to the created notification" do
post :create, {:notification => valid_attributes}, valid_session
response.should redirect_to(Notification.last)
end
end
describe "with invalid params" do
it "assigns a newly created but unsaved notification as @notification" do
# Trigger the behavior that occurs when invalid params are submitted
Notification.any_instance.stub(:save).and_return(false)
post :create, {:notification => { "from_id" => "invalid value" }}, valid_session
assigns(:notification).should be_a_new(Notification)
end
it "re-renders the 'new' template" do
# Trigger the behavior that occurs when invalid params are submitted
Notification.any_instance.stub(:save).and_return(false)
post :create, {:notification => { "from_id" => "invalid value" }}, valid_session
response.should render_template("new")
end
end
end
describe "PUT update" do
describe "with valid params" do
it "updates the requested notification" do
notification = Notification.create! valid_attributes
# Assuming there are no other notifications in the database, this
# specifies that the Notification created on the previous line
# receives the :update_attributes message with whatever params are
# submitted in the request.
Notification.any_instance.should_receive(:update_attributes).with({ "from_id" => "1" })
put :update, {:id => notification.to_param, :notification => { "from_id" => "1" }}, valid_session
end
it "assigns the requested notification as @notification" do
notification = Notification.create! valid_attributes
put :update, {:id => notification.to_param, :notification => valid_attributes}, valid_session
assigns(:notification).should eq(notification)
end
it "redirects to the notification" do
notification = Notification.create! valid_attributes
put :update, {:id => notification.to_param, :notification => valid_attributes}, valid_session
response.should redirect_to(notification)
end
end
describe "with invalid params" do
it "assigns the notification as @notification" do
notification = Notification.create! valid_attributes
# Trigger the behavior that occurs when invalid params are submitted
Notification.any_instance.stub(:save).and_return(false)
put :update, {:id => notification.to_param, :notification => { "from_id" => "invalid value" }}, valid_session
assigns(:notification).should eq(notification)
end
it "re-renders the 'edit' template" do
notification = Notification.create! valid_attributes
# Trigger the behavior that occurs when invalid params are submitted
Notification.any_instance.stub(:save).and_return(false)
put :update, {:id => notification.to_param, :notification => { "from_id" => "invalid value" }}, valid_session
response.should render_template("edit")
end
end
end
describe "DELETE destroy" do
it "destroys the requested notification" do
notification = Notification.create! valid_attributes
expect {
delete :destroy, {:id => notification.to_param}, valid_session
delete :destroy, {:id => notification.to_param}
}.to change(Notification, :count).by(-1)
end
it "redirects to the notifications list" do
it "redirects to the notifications page" do
notification = Notification.create! valid_attributes
delete :destroy, {:id => notification.to_param}, valid_session
delete :destroy, {:id => notification.to_param}
response.should redirect_to(notifications_url)
end
end