File tree Expand file tree Collapse file tree 2 files changed +14
-6
lines changed
Expand file tree Collapse file tree 2 files changed +14
-6
lines changed Original file line number Diff line number Diff line change @@ -24,7 +24,10 @@ def self.request_env
2424 def self . method_missing ( m , *args , &block )
2525 @request_env [ :gon ] ||= { }
2626
27- if ( m . to_s =~ /=/ )
27+ if ( m . to_s =~ /=$/ )
28+ if self . public_methods . include? m [ 0 ..-2 ] . to_sym
29+ raise "You can't use Gon public methods for storing data"
30+ end
2831 set_variable ( m . to_s . delete ( '=' ) , args [ 0 ] )
2932 else
3033 get_variable ( m . to_s )
Original file line number Diff line number Diff line change 55 before ( :each ) do
66 Gon . request_env = { }
77 end
8-
8+
99 it 'returns all variables in hash' do
1010 Gon . a = 1
1111 Gon . b = 2
1212 Gon . c = Gon . a + Gon . b
1313 Gon . c . should == 3
1414 Gon . all_variables . should == { 'a' => 1 , 'b' => 2 , 'c' => 3 }
1515 end
16-
16+
1717 it 'supports all data types' do
1818 Gon . clear
1919 Gon . int = 1
2020 Gon . float = 1.1
2121 Gon . string = 'string'
2222 Gon . array = [ 1 , 'string' ]
23- Gon . hash = { :a => 1 , :b => '2' }
23+ Gon . hash_var = { :a => 1 , :b => '2' }
2424 Gon . hash_w_array = { :a => [ 2 , 3 ] }
2525 Gon . klass = Hash
2626 end
27-
27+
2828 it 'output as js correct' do
2929 Gon . clear
3030 Gon . int = 1
3434 "gon.int=1;" +
3535 "</script>"
3636 end
37-
37+
38+ it 'returns exception if try to set public method as variable' do
39+ Gon . clear
40+ lambda { Gon . all_variables = 123 } . should raise_error
41+ end
42+
3843 def request
3944 @request ||= double 'request' , :env => { }
4045 end
You can’t perform that action at this time.
0 commit comments