Created
May 5, 2012 02:20
-
-
Save darrinholst/2599138 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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