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

- old
+ new

@@ -1,6 +1,6 @@ -require 'gon' +require 'spec_helper' describe Gon do before(:each) do Gon::Request.env = {} @@ -49,11 +49,11 @@ it 'can be support new push syntax' do Gon.clear Gon.push({ :int => 1, :string => 'string' }) - Gon.all_variables.should == { :int => 1, :string => 'string' } + Gon.all_variables.should == { 'int' => 1, 'string' => 'string' } end it 'push with wrong object' do expect { Gon.clear @@ -77,34 +77,46 @@ @base.request = request end it 'outputs correct js with an integer' do Gon.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;' + + "\n//]]>\n" + '</script>' end it 'outputs correct js with a string' do Gon.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 = {};' + %q(gon.str="a'b\"c";) + + "\n//]]>\n" + '</script>' end it 'outputs correct js with a script string' do Gon.str = %q(</script><script>alert('!')</script>) - @base.include_gon.should == '<script>window.gon = {};' + - %q(gon.str="\\u003C/script><script>alert('!')\\u003C/script>";) + + @base.include_gon.should == '<script type="text/javascript">' + + "\n//<![CDATA[\n" + + 'window.gon = {};' + + %q(gon.str="</script><script>alert('!')</script>";) + + "\n//]]>\n" + '</script>' end it 'outputs correct js with an integer, camel-case and namespace' do Gon.int_cased = 1 @base.include_gon(camel_case: true, namespace: 'camel_cased').should == \ - '<script>window.camel_cased = {};' + + '<script type="text/javascript">' + + "\n//<![CDATA[\n" + + 'window.camel_cased = {};' + 'camel_cased.intCased=1;' + + "\n//]]>\n" + '</script>' end it 'outputs correct js with an integer and without tag' do Gon.int = 1 @@ -134,10 +146,12 @@ end it 'outputs correct js with type text/javascript' do @base.include_gon(need_type: true, init: true).should == \ '<script type="text/javascript">' + + "\n//<![CDATA[\n" + 'window.gon = {};'\ + "\n//]]>\n" + '</script>' end end