Skip to content

Instantly share code, notes, and snippets.

@darrinholst
Created May 5, 2012 02:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save darrinholst/2599138 to your computer and use it in GitHub Desktop.
Save darrinholst/2599138 to your computer and use it in GitHub Desktop.
class FormsController < ApplicationController
def index
respond_to do |format|
format.html {render template: "shared/backbone", locals: {preloaded: {forms: all_forms}}}
format.json {render json: all_forms}
end
end
private
def all_forms
FormRepository.all(current_organization)
end
end
require 'models/form_repository'
require 'controllers/forms_controller'
describe FormsController do
let(:form) {stub}
let(:responder) {stub.as_null_object}
let(:organization) {stub}
let(:controller) do
controller = FormsController.new
controller.stub!(current_organization: organization)
controller
end
describe "#index" do
it "finds all forms and renders them as json when json wanted" do
expect_to_want(:json)
FormRepository.should_receive(:all).with(organization).and_return([form])
controller.should_receive(:render).with(json: [form])
controller.index
end
end
def expect_to_want(type)
controller.should_receive(:respond_to).and_yield(responder)
responder.should_receive(type).and_yield
end
end
class ApplicationController
class << self
def method_missing(meth, *args)
end
end
def params
@params ||= {}
end
def method_missing(meth, *args)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment