Skip to content

Commit

Permalink
Specs for rabl and jbuilder with global
Browse files Browse the repository at this point in the history
  • Loading branch information
gazay committed Apr 17, 2012
1 parent 7a4f50f commit 7025aca
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 8 deletions.
14 changes: 8 additions & 6 deletions lib/gon/rabl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module Rabl
class << self

def handler(args, global = false)
options = parse_options_from args
options = parse_options_from args, global
if global && !options[:template]
raise 'You should provide :template when use rabl with global variables'
end
Expand All @@ -29,12 +29,14 @@ def parse_rabl(rabl_path, controller)
JSON.parse(output)
end

def parse_options_from(args)
def parse_options_from(args, global)
if old_api? args
text = "[DEPRECATION] view_path argument is now optional. "
text << "If you need to specify it, "
text << "please use gon.rabl(:template => 'path')"
warn text
unless global
text = "[DEPRECATION] view_path argument is now optional. "
text << "If you need to specify it, "
text << "please use gon.rabl(:template => 'path')"
warn text
end

args.extract_options!.merge(:template => args[0])
elsif new_api? args
Expand Down
31 changes: 29 additions & 2 deletions spec/gon/global_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,35 @@
lambda { Gon.global.rabl = 123 }.should raise_error
end

it 'works fine with rabl and jbuilder' do
pending
context 'with jbuilder and rabl' do

before :each do
Gon.global.clear
controller.instance_variable_set('@objects', objects)
end

let(:controller) { ActionController::Base.new }
let(:objects) { [1,2] }

it 'works fine with rabl' do
Gon.global.rabl :template =>'spec/test_data/sample.rabl', :controller => controller
Gon.global.objects.length.should == 2
end

it 'works fine with jbuilder' do
Gon.global.jbuilder :template =>'spec/test_data/sample.json.jbuilder', :controller => controller
Gon.global.objects.length.should == 2
end

it 'should throw exception, if use rabl or jbuilder without :template' do
lambda { Gon.global.rabl }.should raise_error
lambda { Gon.global.jbuilder }.should raise_error
end

end

after(:all) do
Gon.global.clear
end

def request
Expand Down

0 comments on commit 7025aca

Please sign in to comment.