require File.expand_path(File.dirname(__FILE__) + '/../spec_helper.rb') describe ApplicationController, :type => :controller do render_views include ActionController::Testing describe "#render_jelly_ops" do attr_reader :response before do @response = Struct.new(:body, :content_type).new @controller.instance_variable_set(:@_response, response) end it "have the method included" do @controller.respond_to?(:render_jelly_ops).should be_true end context "when given a format" do describe "json" do it "responds with a json array of arrays, even if the request is not xhr" do stub(request).xhr? {false} @controller.send(:render_jelly_ops, :format => :json) do jelly_notify("foo", "grape") end ops = JSON.parse(response.body) ops.should == [ ["notify", "foo", "grape"] ] end end describe "jsonp" do it "responds with a jsonp callback based on the callback param" do @controller.params[:callback] = "Jelly.run" @controller.send(:render_jelly_ops, :format => :jsonp) do jelly_notify("foo", "grape") end json = Regexp.new( 'Jelly\.run\((.*)\);').match(response.body)[1] ops = JSON.parse(json) ops.should == [ ["notify", "foo", "grape"] ] end end describe "iframe" do it "responds with a the json in a textarea tag" do @controller.send(:render_jelly_ops, :format => :iframe) do jelly_notify("foo", "grape") end body = response.body body.should =~ /^ *