spec/gon/gon_spec.rb in gon-2.1.0 vs spec/gon/gon_spec.rb in gon-2.1.2
- old
+ new
@@ -24,17 +24,40 @@
Gon.hash_var = { :a => 1, :b => '2'}
Gon.hash_w_array = { :a => [ 2, 3 ] }
Gon.klass = Hash
end
- it 'output as js correct' do
- Gon.clear
- Gon.int = 1
- ActionView::Base.instance_methods.map(&:to_s).include?('include_gon').should == true
- base = ActionView::Base.new
- base.include_gon.should == "<script>window.gon = {};" +
- "gon.int=1;" +
- "</script>"
+ describe '#include_gon' do
+
+ before(:each) do
+ Gon.clear
+ Gon.instance_variable_set(:@request_id, request.object_id)
+ ActionView::Base.instance_methods.map(&:to_s).include?('include_gon').should == true
+ @base = ActionView::Base.new
+ @base.request = request
+ end
+
+ it 'outputs correct js with an integer' do
+ Gon.int = 1
+ @base.include_gon.should == '<script>window.gon = {};' +
+ 'gon.int=1;' +
+ '</script>'
+ end
+
+ it 'outputs correct js with a string' do
+ Gon.str = %q(a'b"c)
+ @base.include_gon.should == '<script>window.gon = {};' +
+ %q(gon.str="a'b\"c";) +
+ '</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="<\\/script><script>alert('!')<\\/script>";) +
+ '</script>'
+ end
+
end
it 'returns exception if try to set public method as variable' do
Gon.clear
lambda { Gon.all_variables = 123 }.should raise_error