Skip to content

Commit 76abcd4

Browse files
committed
spec #include_gon how it escapes a string
1 parent 65277b4 commit 76abcd4

File tree

1 file changed

+24
-10
lines changed

1 file changed

+24
-10
lines changed

spec/gon/gon_spec.rb

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,30 @@
2626
Gon.klass = Hash
2727
end
2828

29-
it 'output as js correct' do
30-
Gon.clear
31-
Gon.int = 1
32-
Gon.instance_variable_set(:@request_id, request.object_id)
33-
ActionView::Base.instance_methods.map(&:to_s).include?('include_gon').should == true
34-
base = ActionView::Base.new
35-
base.request = request
36-
base.include_gon.should == "<script>window.gon = {};" +
37-
"gon.int=1;" +
38-
"</script>"
29+
describe '#include_gon' do
30+
31+
before(:each) do
32+
Gon.clear
33+
Gon.instance_variable_set(:@request_id, request.object_id)
34+
ActionView::Base.instance_methods.map(&:to_s).include?('include_gon').should == true
35+
@base = ActionView::Base.new
36+
@base.request = request
37+
end
38+
39+
it 'outputs correct js with an integer' do
40+
Gon.int = 1
41+
@base.include_gon.should == "<script>window.gon = {};" +
42+
"gon.int=1;" +
43+
"</script>"
44+
end
45+
46+
it 'outputs correct js with a string' do
47+
Gon.str = %q(a'b"c)
48+
@base.include_gon.should == '<script>window.gon = {};' +
49+
%q(gon.str="a'b\"c";) +
50+
'</script>'
51+
end
52+
3953
end
4054

4155
it 'returns exception if try to set public method as variable' do

0 commit comments

Comments
 (0)