Skip to content

Commit 7025aca

Browse files
committed
Specs for rabl and jbuilder with global
1 parent 7a4f50f commit 7025aca

File tree

2 files changed

+37
-8
lines changed

2 files changed

+37
-8
lines changed

lib/gon/rabl.rb

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ module Rabl
66
class << self
77

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

32-
def parse_options_from(args)
32+
def parse_options_from(args, global)
3333
if old_api? args
34-
text = "[DEPRECATION] view_path argument is now optional. "
35-
text << "If you need to specify it, "
36-
text << "please use gon.rabl(:template => 'path')"
37-
warn text
34+
unless global
35+
text = "[DEPRECATION] view_path argument is now optional. "
36+
text << "If you need to specify it, "
37+
text << "please use gon.rabl(:template => 'path')"
38+
warn text
39+
end
3840

3941
args.extract_options!.merge(:template => args[0])
4042
elsif new_api? args

spec/gon/global_spec.rb

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,35 @@
8282
lambda { Gon.global.rabl = 123 }.should raise_error
8383
end
8484

85-
it 'works fine with rabl and jbuilder' do
86-
pending
85+
context 'with jbuilder and rabl' do
86+
87+
before :each do
88+
Gon.global.clear
89+
controller.instance_variable_set('@objects', objects)
90+
end
91+
92+
let(:controller) { ActionController::Base.new }
93+
let(:objects) { [1,2] }
94+
95+
it 'works fine with rabl' do
96+
Gon.global.rabl :template =>'spec/test_data/sample.rabl', :controller => controller
97+
Gon.global.objects.length.should == 2
98+
end
99+
100+
it 'works fine with jbuilder' do
101+
Gon.global.jbuilder :template =>'spec/test_data/sample.json.jbuilder', :controller => controller
102+
Gon.global.objects.length.should == 2
103+
end
104+
105+
it 'should throw exception, if use rabl or jbuilder without :template' do
106+
lambda { Gon.global.rabl }.should raise_error
107+
lambda { Gon.global.jbuilder }.should raise_error
108+
end
109+
110+
end
111+
112+
after(:all) do
113+
Gon.global.clear
87114
end
88115

89116
def request

0 commit comments

Comments
 (0)