gon 5.0.1 → 5.0.2

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of gon might be problematic. Click here for more details.

checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 433e0b5aaba27657199f00d90ee17a9c68a8f319
4
- data.tar.gz: 21e99404fb2852a9f00a0c27bdd5fd8e1794207e
3
+ metadata.gz: 8e6e422d6bc49363eaa72a3d1edf4a45bcffca9d
4
+ data.tar.gz: 37181b539c628bf961165ae89e96dc5d93c9871c
5
5
  SHA512:
6
- metadata.gz: c91f601c056db00171a9fe2db144c0c42e25d03874cb3b2c571edeb64c2550eb282567ec68197681f306ee217d0b32a3f14e872b779db9f14394c777e0a72f66
7
- data.tar.gz: 9beef1f22711018f058160e486f919523868432e579b26cf55e5a4f247ff9ce8b7c05a1259264a0d02772dcf7a5b5c09d467bdf2fb301e3ddf0129d55266ddcd
6
+ metadata.gz: 0e7e96329caa65c2cdb52c86c7258ab8584fb315b497b12aac3bcdc7b19ec90e63078166fdf34465538169d5d175beede8fda51152b07ad7a6b4bc784d7ae571
7
+ data.tar.gz: 7f2003f997c30c86f1ff7863b962e5e5d3a181bd171c04d2d67f881db9f38e0fa7aa52f4c0721be0e17e1f670c419a590a0bc67cce4354c52e989f0f622c5027
@@ -2,6 +2,7 @@ language: ruby
2
2
  rvm:
3
3
  - 1.9.3
4
4
  - 2.0.0
5
+ - 2.1.0
5
6
  - jruby-19mode # JRuby in 1.9 mode
6
7
  - rbx
7
8
  matrix:
@@ -1,5 +1,10 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 5.0.2
4
+
5
+ * Fix issue when there is no gon object for current thread and
6
+ rendering include_gon (#108 part) (wasn't fixed) (@gregmolnar)
7
+
3
8
  ## 5.0.1
4
9
 
5
10
  * Fix issue when there is no gon object for current thread and
data/Gemfile CHANGED
@@ -2,3 +2,8 @@ source "http://rubygems.org"
2
2
 
3
3
  # Specify your gem's dependencies in gon.gemspec
4
4
  gemspec
5
+
6
+ platforms :rbx do
7
+ gem 'rubysl', '~> 2.0'
8
+ gem 'rubinius-developer_tools'
9
+ end
data/LICENSE ADDED
@@ -0,0 +1,9 @@
1
+ The MIT License
2
+
3
+ Copyright (c) 2011-2014 gazay
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
+
7
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md CHANGED
@@ -186,11 +186,3 @@ Special thanks to @brainopia, @kossnocorp and @ai.
186
186
  ## License
187
187
 
188
188
  The MIT License
189
-
190
- Copyright (c) 2011-2012 gazay
191
-
192
- Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
193
-
194
- The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
195
-
196
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile CHANGED
@@ -4,6 +4,9 @@ require 'bundler'
4
4
  Bundler::GemHelper.install_tasks
5
5
 
6
6
  desc 'Run all tests by default'
7
- task :default do
8
- system('rspec spec')
9
- end
7
+ task :default => :spec
8
+
9
+ require 'rspec/core/rake_task'
10
+ RSpec::Core::RakeTask.new do |t|
11
+ t.rspec_opts = ["--color", '--format doc']
12
+ end
@@ -8,6 +8,7 @@ Gem::Specification.new do |s|
8
8
  s.version = Gon::VERSION
9
9
  s.platform = Gem::Platform::RUBY
10
10
  s.authors = ['gazay']
11
+ s.licenses = ['MIT']
11
12
  s.email = ['alex.gaziev@gmail.com']
12
13
  s.homepage = 'https://github.com/gazay/gon'
13
14
  s.summary = %q{Get your Rails variables in your JS}
@@ -19,11 +20,11 @@ Gem::Specification.new do |s|
19
20
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
20
21
  s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
21
22
  s.require_paths = ['lib']
22
- s.add_dependency 'actionpack', '>= 2.3.0'
23
- s.add_dependency 'json'
24
- s.add_development_dependency 'rabl'
25
- s.add_development_dependency 'rabl-rails'
26
- s.add_development_dependency 'rspec'
27
- s.add_development_dependency 'jbuilder'
28
- s.add_development_dependency 'rake'
23
+ s.add_runtime_dependency 'actionpack', '~> 2.3.0', '>= 2.3.0'
24
+ s.add_runtime_dependency 'json', '~> 0'
25
+ s.add_development_dependency 'rabl', '~> 0'
26
+ s.add_development_dependency 'rabl-rails', '~> 0'
27
+ s.add_development_dependency 'rspec', '~> 0'
28
+ s.add_development_dependency 'jbuilder', '~> 0'
29
+ s.add_development_dependency 'rake', '~> 0'
29
30
  end
data/lib/gon.rb CHANGED
@@ -25,6 +25,9 @@ class Gon
25
25
  if public_method_name?(method)
26
26
  raise 'You can\'t use Gon public methods for storing data'
27
27
  end
28
+ unless current_gon
29
+ raise 'Assign request-specific gon variables only through `gon` helper, not through Gon constant'
30
+ end
28
31
 
29
32
  set_variable(method.to_s.delete('='), args[0])
30
33
  else
@@ -49,11 +52,11 @@ class Gon
49
52
  end
50
53
 
51
54
  def all_variables
52
- current_gon.gon
55
+ current_gon.gon if current_gon
53
56
  end
54
57
 
55
58
  def clear
56
- current_gon.clear
59
+ current_gon.clear if current_gon
57
60
  end
58
61
 
59
62
  def rabl(*args)
@@ -15,10 +15,13 @@ class Gon
15
15
 
16
16
  def get_controller(options = {})
17
17
  options[:controller] ||
18
- current_gon.env['action_controller.instance'] ||
19
- current_gon.env['action_controller.rescue.response'].
20
- instance_variable_get('@template').
21
- instance_variable_get('@controller')
18
+ (
19
+ current_gon &&
20
+ current_gon.env['action_controller.instance'] ||
21
+ current_gon.env['action_controller.rescue.response'].
22
+ instance_variable_get('@template').
23
+ instance_variable_get('@controller')
24
+ )
22
25
  end
23
26
 
24
27
  def get_template_path(options, extension)
@@ -7,7 +7,7 @@ class Gon
7
7
 
8
8
  def escape_unicode(javascript)
9
9
  if javascript
10
- result = javascript.gsub(/\342\200\250/u, '&#x2028;').gsub(/(<\/)/u, '\u003C/')
10
+ result = javascript.gsub(/\\u2028/u, '&#x2028;').gsub(/(<\/)/u, '\u003C/')
11
11
  javascript.html_safe? ? result.html_safe : result
12
12
  end
13
13
  end
@@ -14,7 +14,7 @@ class Gon
14
14
  Gon.clear
15
15
  Gon::Base.render_data(options)
16
16
  elsif options[:init].present?
17
- Gon.clear if Gon.all_variables.present?
17
+ Gon.clear
18
18
  Gon::Base.render_data(options)
19
19
  else
20
20
  ''
@@ -1,3 +1,3 @@
1
1
  class Gon
2
- VERSION = '5.0.1'
2
+ VERSION = '5.0.2'
3
3
  end
@@ -21,7 +21,7 @@ class Gon
21
21
  def set_variable(name, value)
22
22
  if return_variable?(name)
23
23
  return_variable value
24
- else
24
+ elsif Gon.send(:current_gon)
25
25
  variable = {}
26
26
  @watch_variables ||= {}
27
27
  env = Gon.send(:current_gon).env
@@ -11,8 +11,8 @@ describe Gon do
11
11
  Gon.a = 1
12
12
  Gon.b = 2
13
13
  Gon.c = Gon.a + Gon.b
14
- Gon.c.should == 3
15
- Gon.all_variables.should == { 'a' => 1, 'b' => 2, 'c' => 3 }
14
+ expect(Gon.c).to eq(3)
15
+ expect(Gon.all_variables).to eq({ 'a' => 1, 'b' => 2, 'c' => 3 })
16
16
  end
17
17
 
18
18
  it 'supports all data types' do
@@ -35,7 +35,7 @@ describe Gon do
35
35
  check["variable#{i}"] = i
36
36
  end
37
37
 
38
- Gon.all_variables.should == check
38
+ expect(Gon.all_variables).to eq(check)
39
39
  end
40
40
 
41
41
  it 'can set and get variable with dynamic name' do
@@ -43,14 +43,14 @@ describe Gon do
43
43
  var_name = "variable#{rand}"
44
44
 
45
45
  Gon.set_variable(var_name, 1)
46
- Gon.get_variable(var_name).should == 1
46
+ expect(Gon.get_variable(var_name)).to eq(1)
47
47
  end
48
48
 
49
49
  it 'can be support new push syntax' do
50
50
  Gon.clear
51
51
 
52
52
  Gon.push({ :int => 1, :string => 'string' })
53
- Gon.all_variables.should == { 'int' => 1, 'string' => 'string' }
53
+ expect(Gon.all_variables).to eq({ 'int' => 1, 'string' => 'string' })
54
54
  end
55
55
 
56
56
  it 'push with wrong object' do
@@ -68,130 +68,139 @@ describe Gon do
68
68
  Gon.clear
69
69
  Gon::Request.
70
70
  instance_variable_set(:@request_id, request.object_id)
71
- ActionView::Base.
71
+ expect(ActionView::Base.
72
72
  instance_methods.
73
73
  map(&:to_s).
74
- include?('include_gon').should == true
74
+ include?('include_gon')).to eq(true)
75
75
  @base = ActionView::Base.new
76
76
  @base.request = request
77
77
  end
78
78
 
79
79
  it 'outputs correct js with an integer' do
80
80
  Gon.int = 1
81
- @base.include_gon.should == '<script type="text/javascript">' +
81
+ expect(@base.include_gon).to eq('<script type="text/javascript">' +
82
82
  "\n//<![CDATA[\n" +
83
83
  'window.gon={};' +
84
84
  'gon.int=1;' +
85
85
  "\n//]]>\n" +
86
- '</script>'
86
+ '</script>')
87
87
  end
88
88
 
89
89
  it 'outputs correct js with a string' do
90
90
  Gon.str = %q(a'b"c)
91
- @base.include_gon.should == '<script type="text/javascript">' +
91
+ expect(@base.include_gon).to eq('<script type="text/javascript">' +
92
92
  "\n//<![CDATA[\n" +
93
93
  'window.gon={};' +
94
94
  %q(gon.str="a'b\"c";) +
95
95
  "\n//]]>\n" +
96
- '</script>'
96
+ '</script>')
97
97
  end
98
98
 
99
99
  it 'outputs correct js with a script string' do
100
100
  Gon.str = %q(</script><script>alert('!')</script>)
101
- @base.include_gon.should == '<script type="text/javascript">' +
101
+ expect(@base.include_gon).to eq('<script type="text/javascript">' +
102
102
  "\n//<![CDATA[\n" +
103
103
  'window.gon={};' +
104
104
  %q(gon.str="\u003C/script><script>alert('!')\u003C/script>";) +
105
105
  "\n//]]>\n" +
106
- '</script>'
106
+ '</script>')
107
107
  end
108
108
 
109
109
  it 'outputs correct js with an integer, camel-case and namespace' do
110
110
  Gon.int_cased = 1
111
- @base.include_gon(camel_case: true, namespace: 'camel_cased').should == \
111
+ expect(@base.include_gon(camel_case: true, namespace: 'camel_cased')).to eq( \
112
112
  '<script type="text/javascript">' +
113
113
  "\n//<![CDATA[\n" +
114
114
  'window.camel_cased={};' +
115
115
  'camel_cased.intCased=1;' +
116
116
  "\n//]]>\n" +
117
117
  '</script>'
118
+ )
118
119
  end
119
120
 
120
121
  it 'outputs correct js with camel_depth = :recursive' do
121
122
  Gon.test_hash = { test_depth_one: { test_depth_two: 1 } }
122
- @base.include_gon(camel_case: true, camel_depth: :recursive).should == \
123
+ expect(@base.include_gon(camel_case: true, camel_depth: :recursive)).to eq( \
123
124
  '<script type="text/javascript">' +
124
125
  "\n//<![CDATA[\n" +
125
126
  'window.gon={};' +
126
127
  'gon.testHash={"testDepthOne":{"testDepthTwo":1}};' +
127
128
  "\n//]]>\n" +
128
129
  '</script>'
130
+ )
129
131
  end
130
132
 
131
133
  it 'outputs correct js with camel_depth = 2' do
132
134
  Gon.test_hash = { test_depth_one: { test_depth_two: 1 } }
133
- @base.include_gon(camel_case: true, camel_depth: 2).should == \
135
+ expect(@base.include_gon(camel_case: true, camel_depth: 2)).to eq( \
134
136
  '<script type="text/javascript">' +
135
137
  "\n//<![CDATA[\n" +
136
138
  'window.gon={};' +
137
139
  'gon.testHash={"testDepthOne":{"test_depth_two":1}};' +
138
140
  "\n//]]>\n" +
139
141
  '</script>'
142
+ )
140
143
  end
141
144
 
142
145
  it 'outputs correct js with an integer and without tag' do
143
146
  Gon.int = 1
144
- @base.include_gon(need_tag: false).should == \
147
+ expect(@base.include_gon(need_tag: false)).to eq( \
145
148
  'window.gon={};' +
146
149
  'gon.int=1;'
150
+ )
147
151
  end
148
152
 
149
153
  it 'outputs correct js without variables, without tag and gon init if before there was data' do
150
154
  Gon::Request.
151
155
  instance_variable_set(:@request_id, 123)
152
156
  Gon::Request.instance_variable_set(:@request_env, { 'gon' => { :a => 1 } })
153
- @base.include_gon(need_tag: false, init: true).should == \
157
+ expect(@base.include_gon(need_tag: false, init: true)).to eq( \
154
158
  'window.gon={};'
159
+ )
155
160
  end
156
161
 
157
162
  it 'outputs correct js without variables, without tag and gon init' do
158
- @base.include_gon(need_tag: false, init: true).should == \
163
+ expect(@base.include_gon(need_tag: false, init: true)).to eq( \
159
164
  'window.gon={};'
165
+ )
160
166
  end
161
167
 
162
168
  it 'outputs correct js without variables, without tag, gon init and an integer' do
163
169
  Gon.int = 1
164
- @base.include_gon(need_tag: false, init: true).should == \
170
+ expect(@base.include_gon(need_tag: false, init: true)).to eq( \
165
171
  'window.gon={};' +
166
172
  'gon.int=1;'
173
+ )
167
174
  end
168
175
 
169
176
  it 'outputs correct js without cdata, without type, gon init and an integer' do
170
177
  Gon.int = 1
171
- @base.include_gon(cdata: false, type: false).should == \
178
+ expect(@base.include_gon(cdata: false, type: false)).to eq( \
172
179
  '<script>' +
173
180
  "\n" +
174
181
  'window.gon={};' +
175
182
  'gon.int=1;' +
176
183
  "\n" +
177
184
  '</script>'
185
+ )
178
186
  end
179
187
 
180
188
  it 'outputs correct js with type text/javascript' do
181
- @base.include_gon(need_type: true, init: true).should == \
189
+ expect(@base.include_gon(need_type: true, init: true)).to eq( \
182
190
  '<script type="text/javascript">' +
183
191
  "\n//<![CDATA[\n" +
184
192
  'window.gon={};'\
185
193
  "\n//]]>\n" +
186
194
  '</script>'
195
+ )
187
196
  end
188
197
 
189
198
  end
190
199
 
191
200
  it 'returns exception if try to set public method as variable' do
192
201
  Gon.clear
193
- lambda { Gon.all_variables = 123 }.should raise_error
194
- lambda { Gon.rabl = 123 }.should raise_error
202
+ expect { Gon.all_variables = 123 }.to raise_error
203
+ expect { Gon.rabl = 123 }.to raise_error
195
204
  end
196
205
 
197
206
  describe '#check_for_rabl_and_jbuilder' do
@@ -200,16 +209,16 @@ describe Gon do
200
209
 
201
210
  it 'should be able to handle ruby 1.8.7 style constants array (strings)' do
202
211
  constants_as_strings = Gon.constants.map(&:to_s)
203
- Gon.stub(:constants) { constants_as_strings }
204
- lambda { Gon.rabl 'spec/test_data/sample.rabl', :controller => controller }.should_not raise_error
205
- lambda { Gon.jbuilder 'spec/test_data/sample.json.jbuilder', :controller => controller }.should_not raise_error
212
+ allow(Gon).to receive(:constants) { constants_as_strings }
213
+ expect { Gon.rabl 'spec/test_data/sample.rabl', :controller => controller }.not_to raise_error
214
+ expect { Gon.jbuilder 'spec/test_data/sample.json.jbuilder', :controller => controller }.not_to raise_error
206
215
  end
207
216
 
208
217
  it 'should be able to handle ruby 1.9+ style constants array (symbols)' do
209
218
  constants_as_symbols = Gon.constants.map(&:to_sym)
210
- Gon.stub(:constants) { constants_as_symbols }
211
- lambda { Gon.rabl 'spec/test_data/sample.rabl', :controller => controller }.should_not raise_error
212
- lambda { Gon.jbuilder 'spec/test_data/sample.json.jbuilder', :controller => controller }.should_not raise_error
219
+ allow(Gon).to receive(:constants) { constants_as_symbols }
220
+ expect { Gon.rabl 'spec/test_data/sample.rabl', :controller => controller }.not_to raise_error
221
+ expect { Gon.jbuilder 'spec/test_data/sample.json.jbuilder', :controller => controller }.not_to raise_error
213
222
  end
214
223
  end
215
224
 
@@ -13,8 +13,8 @@ describe Gon::Global do
13
13
  Gon.global.a = 1
14
14
  Gon.global.b = 2
15
15
  Gon.global.c = Gon.global.a + Gon.global.b
16
- Gon.global.c.should == 3
17
- Gon.global.all_variables.should == { 'a' => 1, 'b' => 2, 'c' => 3 }
16
+ expect(Gon.global.c).to eq(3)
17
+ expect(Gon.global.all_variables).to eq({ 'a' => 1, 'b' => 2, 'c' => 3 })
18
18
  end
19
19
 
20
20
  it 'supports all data types' do
@@ -35,72 +35,72 @@ describe Gon::Global do
35
35
  before(:each) do
36
36
  Gon.clear
37
37
  Gon.global.clear
38
- ActionView::Base.
38
+ expect(ActionView::Base.
39
39
  instance_methods.
40
40
  map(&:to_s).
41
- include?('include_gon').should == true
41
+ include?('include_gon')).to eq(true)
42
42
  @base = ActionView::Base.new
43
43
  @base.request = request
44
44
  end
45
45
 
46
46
  it 'outputs correct js with an integer' do
47
47
  Gon.global.int = 1
48
- @base.include_gon.should == "<script type=\"text/javascript\">" +
48
+ expect(@base.include_gon).to eq("<script type=\"text/javascript\">" +
49
49
  "\n//<![CDATA[\n" +
50
50
  "window.gon={};" +
51
51
  "gon.global={\"int\":1};" +
52
52
  "\n//]]>\n" +
53
- "</script>"
53
+ "</script>")
54
54
  end
55
55
 
56
56
  it 'outputs correct js with an integer and integer in Gon' do
57
57
  Gon.int = 1
58
58
  Gon.global.int = 1
59
- @base.include_gon.should == "<script type=\"text/javascript\">" +
59
+ expect(@base.include_gon).to eq("<script type=\"text/javascript\">" +
60
60
  "\n//<![CDATA[\n" +
61
61
  "window.gon={};" +
62
62
  "gon.int=1;" +
63
63
  "gon.global={\"int\":1};" +
64
64
  "\n//]]>\n" +
65
- "</script>"
65
+ "</script>")
66
66
  end
67
67
 
68
68
  it 'outputs correct js with a string' do
69
69
  Gon.global.str = %q(a'b"c)
70
- @base.include_gon.should == "<script type=\"text/javascript\">" +
70
+ expect(@base.include_gon).to eq("<script type=\"text/javascript\">" +
71
71
  "\n//<![CDATA[\n" +
72
72
  "window.gon={};" +
73
73
  "gon.global={\"str\":\"a'b\\\"c\"};" +
74
74
  "\n//]]>\n" +
75
- "</script>"
75
+ "</script>")
76
76
  end
77
77
 
78
78
  it 'outputs correct js with a script string' do
79
79
  Gon.global.str = %q(</script><script>alert('!')</script>)
80
- @base.include_gon.should == "<script type=\"text/javascript\">" +
80
+ expect(@base.include_gon).to eq("<script type=\"text/javascript\">" +
81
81
  "\n//<![CDATA[\n" +
82
82
  "window.gon={};" +
83
83
  "gon.global={\"str\":\"\\u003C/script><script>alert('!')\\u003C/script>\"};" +
84
84
  "\n//]]>\n" +
85
- "</script>"
85
+ "</script>")
86
86
  end
87
87
 
88
88
  it 'outputs correct js with a unicode line separator' do
89
89
  Gon.global.str = "\u2028"
90
- @base.include_gon.should == "<script type=\"text/javascript\">" +
90
+ expect(@base.include_gon).to eq("<script type=\"text/javascript\">" +
91
91
  "\n//<![CDATA[\n" +
92
92
  "window.gon={};" +
93
93
  "gon.global={\"str\":\"&#x2028;\"};" +
94
94
  "\n//]]>\n" +
95
- "</script>"
95
+ "</script>")
96
96
  end
97
97
 
98
98
  end
99
99
 
100
100
  it 'returns exception if try to set public method as variable' do
101
101
  Gon.global.clear
102
- lambda { Gon.global.all_variables = 123 }.should raise_error
103
- lambda { Gon.global.rabl = 123 }.should raise_error
102
+ expect { Gon.global.all_variables = 123 }.to raise_error
103
+ expect { Gon.global.rabl = 123 }.to raise_error
104
104
  end
105
105
 
106
106
  context 'with jbuilder and rabl' do
@@ -115,17 +115,17 @@ describe Gon::Global do
115
115
 
116
116
  it 'works fine with rabl' do
117
117
  Gon.global.rabl :template => 'spec/test_data/sample.rabl', :controller => controller
118
- Gon.global.objects.length.should == 2
118
+ expect(Gon.global.objects.length).to eq(2)
119
119
  end
120
120
 
121
121
  it 'works fine with jbuilder' do
122
122
  Gon.global.jbuilder :template => 'spec/test_data/sample.json.jbuilder', :controller => controller
123
- Gon.global.objects.length.should == 2
123
+ expect(Gon.global.objects.length).to eq(2)
124
124
  end
125
125
 
126
126
  it 'should throw exception, if use rabl or jbuilder without :template' do
127
- lambda { Gon.global.rabl }.should raise_error
128
- lambda { Gon.global.jbuilder }.should raise_error
127
+ expect { Gon.global.rabl }.to raise_error
128
+ expect { Gon.global.jbuilder }.to raise_error
129
129
  end
130
130
 
131
131
  end
@@ -15,20 +15,20 @@ describe Gon do
15
15
 
16
16
  it 'render json from jbuilder template' do
17
17
  Gon.jbuilder 'spec/test_data/sample.json.jbuilder', :controller => controller
18
- Gon.objects.length.should == 2
18
+ expect(Gon.objects.length).to eq(2)
19
19
  end
20
20
 
21
21
  it 'render json from jbuilder template with locals' do
22
22
  Gon.jbuilder 'spec/test_data/sample_with_locals.json.jbuilder',
23
23
  :controller => controller,
24
24
  :locals => { :some_local => 1234, :some_complex_local => OpenStruct.new(:id => 1234) }
25
- Gon.some_local.should == 1234
26
- Gon.some_complex_local_id.should == 1234
25
+ expect(Gon.some_local).to eq(1234)
26
+ expect(Gon.some_complex_local_id).to eq(1234)
27
27
  end
28
28
 
29
29
  it 'render json from jbuilder template with locals' do
30
30
  Gon.jbuilder 'spec/test_data/sample_with_helpers.json.jbuilder', :controller => controller
31
- Gon.date.should == 'about 6 hours'
31
+ expect(Gon.date).to eq('about 6 hours')
32
32
  end
33
33
 
34
34
  it 'render json from jbuilder template with controller methods' do
@@ -41,13 +41,13 @@ describe Gon do
41
41
  }
42
42
 
43
43
  Gon.jbuilder 'spec/test_data/sample_with_controller_method.json.jbuilder', :controller => controller
44
- Gon.date.should == 'about 6 hours'
44
+ expect(Gon.date).to eq('about 6 hours')
45
45
  end
46
46
 
47
47
  it 'render json from jbuilder template with a partial' do
48
48
  controller.view_paths << 'spec/test_data'
49
49
  Gon.jbuilder 'spec/test_data/sample_with_partial.json.jbuilder', :controller => controller
50
- Gon.objects.length.should == 2
50
+ expect(Gon.objects.length).to eq(2)
51
51
  end
52
52
 
53
53
  end
@@ -20,7 +20,7 @@ describe Gon do
20
20
  context 'render template with deprecation' do
21
21
  it 'still works' do
22
22
  Gon.rabl 'spec/test_data/sample_rabl_rails.rabl', :controller => controller
23
- Gon.objects.length.should == 2
23
+ expect(Gon.objects.length).to eq(2)
24
24
  end
25
25
  end
26
26
 
@@ -30,7 +30,7 @@ describe Gon do
30
30
  :template =>'spec/test_data/sample_rabl_rails.rabl',
31
31
  :controller => controller
32
32
  )
33
- Gon.objects.map { |it| it['inspect'] }.should == %w(1 2)
33
+ expect(Gon.objects.map { |it| it['inspect'] }).to eq(%w(1 2))
34
34
  end
35
35
 
36
36
  it 'works with different locals object' do
@@ -39,18 +39,18 @@ describe Gon do
39
39
  :controller => controller,
40
40
  :locals => { :objects => [3, 4] }
41
41
  )
42
- Gon.objects.map { |it| it['inspect'] }.should == %w(3 4)
42
+ expect(Gon.objects.map { |it| it['inspect'] }).to eq(%w(3 4))
43
43
  end
44
44
  end
45
45
 
46
46
  it 'works if rabl-rails is included' do
47
47
  Gon.rabl :template => 'spec/test_data/sample_rabl_rails.rabl', :controller => controller
48
- Gon.objects.length.should == 2
48
+ expect(Gon.objects.length).to eq(2)
49
49
  end
50
50
 
51
51
  it 'works with ActionView::Helpers' do
52
52
  Gon.rabl :template =>'spec/test_data/sample_with_helpers_rabl_rails.rabl', :controller => controller
53
- Gon.objects.first['time_ago'].should == 'about 6 hours'
53
+ expect(Gon.objects.first['time_ago']).to eq('about 6 hours')
54
54
  end
55
55
 
56
56
  it 'raise exception if rabl or rabl-rails is not included' do
@@ -19,7 +19,7 @@ describe Gon do
19
19
  context 'render template with deprecation' do
20
20
  it 'still works' do
21
21
  Gon.rabl 'spec/test_data/sample.rabl', :controller => controller
22
- Gon.objects.length.should == 2
22
+ expect(Gon.objects.length).to eq(2)
23
23
  end
24
24
  end
25
25
 
@@ -29,7 +29,7 @@ describe Gon do
29
29
  :template => 'spec/test_data/sample.rabl',
30
30
  :controller => controller
31
31
  )
32
- Gon.objects.map { |it| it['object']['inspect'] }.should == %w(1 2)
32
+ expect(Gon.objects.map { |it| it['object']['inspect'] }).to eq(%w(1 2))
33
33
  end
34
34
 
35
35
  it 'works with different locals object' do
@@ -38,18 +38,18 @@ describe Gon do
38
38
  :controller => controller,
39
39
  :locals => { :objects => [3, 4] }
40
40
  )
41
- Gon.objects.map { |it| it['object']['inspect'] }.should == %w(3 4)
41
+ expect(Gon.objects.map { |it| it['object']['inspect'] }).to eq(%w(3 4))
42
42
  end
43
43
  end
44
44
 
45
45
  it 'works if rabl is included' do
46
46
  Gon.rabl :template => 'spec/test_data/sample.rabl', :controller => controller
47
- Gon.objects.length.should == 2
47
+ expect(Gon.objects.length).to eq(2)
48
48
  end
49
49
 
50
50
  it 'works with ActionView::Helpers' do
51
51
  Gon.rabl :template => 'spec/test_data/sample_with_helpers.rabl', :controller => controller
52
- Gon.objects.first['object']['time_ago'].should == 'about 6 hours'
52
+ expect(Gon.objects.first['object']['time_ago']).to eq('about 6 hours')
53
53
  end
54
54
 
55
55
  it 'raise exception if rabl is not included' do
@@ -63,11 +63,11 @@ describe Gon do
63
63
  context 'template is specified' do
64
64
 
65
65
  it 'add the extension if not included in the template name' do
66
- Gon::Base.send(:get_template_path, { :template => 'spec/test_data/sample' }, 'rabl').should eql('spec/test_data/sample.rabl')
66
+ expect(Gon::Base.send(:get_template_path, { :template => 'spec/test_data/sample' }, 'rabl')).to eql('spec/test_data/sample.rabl')
67
67
  end
68
68
 
69
69
  it 'return the specified template' do
70
- Gon::Base.send(:get_template_path, { :template => 'spec/test_data/sample.rabl' }, 'rabl').should eql('spec/test_data/sample.rabl')
70
+ expect(Gon::Base.send(:get_template_path, { :template => 'spec/test_data/sample.rabl' }, 'rabl')).to eql('spec/test_data/sample.rabl')
71
71
  end
72
72
 
73
73
  end
@@ -85,7 +85,7 @@ describe Gon do
85
85
 
86
86
  context 'the action doesn as a template at a different format' do
87
87
  it 'return the same template as the action with rabl extension' do
88
- Gon::Base.send(:get_template_path, { :controller => controller }, 'rabl').should eql('app/views/action_controller/base/show.json.rabl')
88
+ expect(Gon::Base.send(:get_template_path, { :controller => controller }, 'rabl')).to eql('app/views/action_controller/base/show.json.rabl')
89
89
  end
90
90
  end
91
91
 
@@ -6,11 +6,11 @@ describe Gon do
6
6
  context 'template is specified' do
7
7
 
8
8
  it 'add the extension if not included in the template name' do
9
- Gon::Base.send(:get_template_path, { :template => 'spec/test_data/sample' }, 'jbuilder').should eql('spec/test_data/sample.jbuilder')
9
+ expect(Gon::Base.send(:get_template_path, { :template => 'spec/test_data/sample' }, 'jbuilder')).to eql('spec/test_data/sample.jbuilder')
10
10
  end
11
11
 
12
12
  it 'return the specified template' do
13
- Gon::Base.send(:get_template_path, { :template => 'spec/test_data/sample.jbuilder' }, 'jbuilder').should eql('spec/test_data/sample.jbuilder')
13
+ expect(Gon::Base.send(:get_template_path, { :template => 'spec/test_data/sample.jbuilder' }, 'jbuilder')).to eql('spec/test_data/sample.jbuilder')
14
14
  end
15
15
 
16
16
  end
@@ -28,7 +28,7 @@ describe Gon do
28
28
 
29
29
  context 'the action doesn as a template at a different format' do
30
30
  it 'return the same template as the action with rabl extension' do
31
- Gon::Base.send(:get_template_path, { :controller => controller }, 'jbuilder').should eql('app/views/action_controller/base/show.json.jbuilder')
31
+ expect(Gon::Base.send(:get_template_path, { :controller => controller }, 'jbuilder')).to eql('app/views/action_controller/base/show.json.jbuilder')
32
32
  end
33
33
  end
34
34
 
@@ -1,17 +1,41 @@
1
1
  require 'spec_helper'
2
2
 
3
+ class GonTestWorker
4
+ include Gon::GonHelpers
5
+
6
+ def request
7
+ @request ||= ActionDispatch::TestRequest.new
8
+ end
9
+
10
+ def env
11
+ request.env
12
+ end
13
+
14
+ def execute
15
+ gon.clear
16
+ gon.a ||= 1
17
+ gon.a += 1
18
+ end
19
+
20
+ def value
21
+ gon.a
22
+ end
23
+ end
24
+
3
25
  describe 'threading behaviour' do
26
+ before do
27
+ Gon.unstub(:current_gon)
28
+ end
29
+
4
30
  it 'is threadsafe' do
5
31
  threads = []
6
32
  10.times do
7
33
  threads << Thread.new do
8
- Gon.clear
9
- Gon.a ||= 1
10
- Gon.a += 1
11
- expect(Gon.a).to eq 2
34
+ gtw = GonTestWorker.new
35
+ gtw.execute
36
+ expect(gtw.value).to eq 2
12
37
  end
13
38
  end
14
39
  threads.each(&:join)
15
- expect(Gon.a).to eq 2
16
40
  end
17
41
  end
@@ -21,14 +21,14 @@ describe Gon::Watch do
21
21
  it 'should add variables to Gon#all_variables hash' do
22
22
  Gon.a = 1
23
23
  Gon.watch.b = 2
24
- Gon.all_variables.should == { 'a' => 1, 'b' => 2 }
24
+ expect(Gon.all_variables).to eq({ 'a' => 1, 'b' => 2 })
25
25
  end
26
26
 
27
27
  describe '#all_variables' do
28
28
 
29
29
  it 'should generate array with current request url, method type and variable names' do
30
30
  Gon.watch.a = 1
31
- Gon.watch.all_variables.should == { 'a' => { 'url' => '/foo', 'method' => 'GET', 'name' => 'a' } }
31
+ expect(Gon.watch.all_variables).to eq({ 'a' => { 'url' => '/foo', 'method' => 'GET', 'name' => 'a' } })
32
32
  end
33
33
 
34
34
  end
@@ -37,8 +37,8 @@ describe Gon::Watch do
37
37
 
38
38
  it 'should render function with variables in gon namespace' do
39
39
  Gon.watch.a = 1
40
- Gon.watch.render.should =~ /gon\.watch\s=/
41
- Gon.watch.render.should =~ /gon\.watchedVariables/
40
+ expect(Gon.watch.render).to match(/gon\.watch\s=/)
41
+ expect(Gon.watch.render).to match(/gon\.watchedVariables/)
42
42
  end
43
43
 
44
44
  end
@@ -54,7 +54,7 @@ describe Gon::Watch do
54
54
  controller.params = params
55
55
  Gon.send(:current_gon).env['action_controller.instance'] = controller
56
56
 
57
- controller.should_receive('render').with(:json => 1)
57
+ expect(controller).to receive('render').with(:json => 1)
58
58
 
59
59
  Gon.watch.a = 1
60
60
  end
@@ -41,6 +41,6 @@ end
41
41
  RSpec.configure do |config|
42
42
  config.before(:each) do
43
43
  @request = Thread.current['gon'] = Gon::Request.new({})
44
- Gon.stub(:current_gon).and_return(@request)
44
+ allow(Gon).to receive(:current_gon).and_return(@request)
45
45
  end
46
46
  end
metadata CHANGED
@@ -1,19 +1,22 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gon
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.0.1
4
+ version: 5.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - gazay
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-12-31 00:00:00.000000000 Z
11
+ date: 2014-02-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionpack
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: 2.3.0
17
20
  - - '>='
18
21
  - !ruby/object:Gem::Version
19
22
  version: 2.3.0
@@ -21,6 +24,9 @@ dependencies:
21
24
  prerelease: false
22
25
  version_requirements: !ruby/object:Gem::Requirement
23
26
  requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: 2.3.0
24
30
  - - '>='
25
31
  - !ruby/object:Gem::Version
26
32
  version: 2.3.0
@@ -28,84 +34,84 @@ dependencies:
28
34
  name: json
29
35
  requirement: !ruby/object:Gem::Requirement
30
36
  requirements:
31
- - - '>='
37
+ - - ~>
32
38
  - !ruby/object:Gem::Version
33
39
  version: '0'
34
40
  type: :runtime
35
41
  prerelease: false
36
42
  version_requirements: !ruby/object:Gem::Requirement
37
43
  requirements:
38
- - - '>='
44
+ - - ~>
39
45
  - !ruby/object:Gem::Version
40
46
  version: '0'
41
47
  - !ruby/object:Gem::Dependency
42
48
  name: rabl
43
49
  requirement: !ruby/object:Gem::Requirement
44
50
  requirements:
45
- - - '>='
51
+ - - ~>
46
52
  - !ruby/object:Gem::Version
47
53
  version: '0'
48
54
  type: :development
49
55
  prerelease: false
50
56
  version_requirements: !ruby/object:Gem::Requirement
51
57
  requirements:
52
- - - '>='
58
+ - - ~>
53
59
  - !ruby/object:Gem::Version
54
60
  version: '0'
55
61
  - !ruby/object:Gem::Dependency
56
62
  name: rabl-rails
57
63
  requirement: !ruby/object:Gem::Requirement
58
64
  requirements:
59
- - - '>='
65
+ - - ~>
60
66
  - !ruby/object:Gem::Version
61
67
  version: '0'
62
68
  type: :development
63
69
  prerelease: false
64
70
  version_requirements: !ruby/object:Gem::Requirement
65
71
  requirements:
66
- - - '>='
72
+ - - ~>
67
73
  - !ruby/object:Gem::Version
68
74
  version: '0'
69
75
  - !ruby/object:Gem::Dependency
70
76
  name: rspec
71
77
  requirement: !ruby/object:Gem::Requirement
72
78
  requirements:
73
- - - '>='
79
+ - - ~>
74
80
  - !ruby/object:Gem::Version
75
81
  version: '0'
76
82
  type: :development
77
83
  prerelease: false
78
84
  version_requirements: !ruby/object:Gem::Requirement
79
85
  requirements:
80
- - - '>='
86
+ - - ~>
81
87
  - !ruby/object:Gem::Version
82
88
  version: '0'
83
89
  - !ruby/object:Gem::Dependency
84
90
  name: jbuilder
85
91
  requirement: !ruby/object:Gem::Requirement
86
92
  requirements:
87
- - - '>='
93
+ - - ~>
88
94
  - !ruby/object:Gem::Version
89
95
  version: '0'
90
96
  type: :development
91
97
  prerelease: false
92
98
  version_requirements: !ruby/object:Gem::Requirement
93
99
  requirements:
94
- - - '>='
100
+ - - ~>
95
101
  - !ruby/object:Gem::Version
96
102
  version: '0'
97
103
  - !ruby/object:Gem::Dependency
98
104
  name: rake
99
105
  requirement: !ruby/object:Gem::Requirement
100
106
  requirements:
101
- - - '>='
107
+ - - ~>
102
108
  - !ruby/object:Gem::Version
103
109
  version: '0'
104
110
  type: :development
105
111
  prerelease: false
106
112
  version_requirements: !ruby/object:Gem::Requirement
107
113
  requirements:
108
- - - '>='
114
+ - - ~>
109
115
  - !ruby/object:Gem::Version
110
116
  version: '0'
111
117
  description: If you need to send some data to your js files and you don't want to
@@ -120,6 +126,7 @@ files:
120
126
  - .travis.yml
121
127
  - CHANGELOG.md
122
128
  - Gemfile
129
+ - LICENSE
123
130
  - README.md
124
131
  - README_old.md
125
132
  - Rakefile
@@ -158,7 +165,8 @@ files:
158
165
  - spec/test_data/sample_with_locals.json.jbuilder
159
166
  - spec/test_data/sample_with_partial.json.jbuilder
160
167
  homepage: https://github.com/gazay/gon
161
- licenses: []
168
+ licenses:
169
+ - MIT
162
170
  metadata: {}
163
171
  post_install_message:
164
172
  rdoc_options: []
@@ -176,7 +184,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
176
184
  version: '0'
177
185
  requirements: []
178
186
  rubyforge_project: gon
179
- rubygems_version: 2.0.14
187
+ rubygems_version: 2.2.0
180
188
  signing_key:
181
189
  specification_version: 4
182
190
  summary: Get your Rails variables in your JS