Skip to content

Instantly share code, notes, and snippets.

@miguelperez
Created June 5, 2012 18:46
Show Gist options
  • Save miguelperez/2876874 to your computer and use it in GitHub Desktop.
Save miguelperez/2876874 to your computer and use it in GitHub Desktop.
Controller conventions
Given a controller file, with some actions in it... This gist defines how I like to organize the rspec controller file.
class PersonsController < ApplicationController
def index
#some code here
end
def new
#some code here
end
def edit
#some code here
end
def update
#some code here
end
def destroy
#some code here
end
def create
#some code here
end
end
require 'spec_helper'
describe PersonsController, "Routing" do
it { {get: "/persons"}.should route_to(controller: "persons", action: "index") }
it { {get: "/persons/new"}.should route_to(controller: "persons", action: "new") }
it { {post: "/persons"}.should route_to(controller: "persons", action: "create") }
it { {delete: "/persons/1"}.should route_to(controller: "persons", action: "destroy", id: "1") }
it { {put: "/persons/1"}.should route_to(controller: "persons", action: "update",id: "1") }
it { {get: "/persons/1/edit"}.should route_to(controller: "persons", action: "edit", id: "1") }
it { {get: "/persons/all"}.should route_to(controller: "persons", action: "all") }
end
describe PersonsController, "Actions" do
render_views
describe "on HTTP_VERB to #action" do
# spec cases usually the possible scenarios that could happen here.
end
describe "on GET to #index" do
#spec cases usually the possible scenarios that could happen here.
it "should set the variable used for the view" do
...
end
it "should render template" do
...
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment