spec/gon/global_spec.rb in gon-4.0.3 vs spec/gon/global_spec.rb in gon-4.1.0

- old
+ new

@@ -1,6 +1,6 @@ -require 'gon' +require 'spec_helper' describe Gon::Global do before(:each) do Gon::Global.clear @@ -43,37 +43,59 @@ @base.request = request end it 'outputs correct js with an integer' do Gon.global.int = 1 - @base.include_gon.should == "<script>window.gon = {};" + + @base.include_gon.should == "<script type=\"text/javascript\">" + + "\n//<![CDATA[\n" + + "window.gon = {};" + "gon.global={\"int\":1};" + + "\n//]]>\n" + "</script>" end it 'outputs correct js with an integer and integer in Gon' do Gon::Request. instance_variable_set(:@request_id, request.object_id) Gon::Request.env = {} Gon.int = 1 Gon.global.int = 1 - @base.include_gon.should == "<script>window.gon = {};" + + @base.include_gon.should == "<script type=\"text/javascript\">" + + "\n//<![CDATA[\n" + + "window.gon = {};" + "gon.int=1;" + "gon.global={\"int\":1};" + + "\n//]]>\n" + "</script>" end it 'outputs correct js with a string' do Gon.global.str = %q(a'b"c) - @base.include_gon.should == "<script>window.gon = {};" + + @base.include_gon.should == "<script type=\"text/javascript\">" + + "\n//<![CDATA[\n" + + "window.gon = {};" + "gon.global={\"str\":\"a'b\\\"c\"};" + + "\n//]]>\n" + "</script>" end it 'outputs correct js with a script string' do Gon.global.str = %q(</script><script>alert('!')</script>) - @base.include_gon.should == "<script>window.gon = {};" + - "gon.global={\"str\":\"\\u003C/script><script>alert('!')\\u003C/script>\"};" + + @base.include_gon.should == "<script type=\"text/javascript\">" + + "\n//<![CDATA[\n" + + "window.gon = {};" + + "gon.global={\"str\":\"</script><script>alert('!')</script>\"};" + + "\n//]]>\n" + + "</script>" + end + + it 'outputs correct js with a unicode line separator' do + Gon.global.str = "\u2028" + @base.include_gon.should == "<script type=\"text/javascript\">" + + "\n//<![CDATA[\n" + + "window.gon = {};" + + "gon.global={\"str\":\"&#x2028;\"};" + + "\n//]]>\n" + "</script>" end end