gon 6.3.2 → 6.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +7 -1
- data/README.md +1 -5
- data/lib/gon/base.rb +6 -3
- data/lib/gon/compatibility/old_rails.rb +2 -0
- data/lib/gon/env_finder.rb +2 -0
- data/lib/gon/escaper.rb +2 -0
- data/lib/gon/global.rb +2 -0
- data/lib/gon/helpers.rb +2 -0
- data/lib/gon/jbuilder/parser.rb +6 -4
- data/lib/gon/jbuilder.rb +3 -1
- data/lib/gon/json_dumper.rb +18 -1
- data/lib/gon/rabl.rb +3 -1
- data/lib/gon/request.rb +2 -0
- data/lib/gon/spec_helpers.rb +3 -1
- data/lib/gon/version.rb +3 -1
- data/lib/gon/watch.rb +2 -0
- data/lib/gon.rb +2 -0
- metadata +21 -38
- data/.github/FUNDING.yml +0 -1
- data/.gitignore +0 -7
- data/.travis.yml +0 -12
- data/Gemfile +0 -6
- data/Rakefile +0 -10
- data/doc/logo.png +0 -0
- data/doc/logo_small.png +0 -0
- data/doc/top_sample.png +0 -0
- data/gon.gemspec +0 -30
- data/spec/gon/basic_spec.rb +0 -304
- data/spec/gon/global_spec.rb +0 -146
- data/spec/gon/jbuilder_spec.rb +0 -75
- data/spec/gon/rabl_spec.rb +0 -90
- data/spec/gon/templates_spec.rb +0 -36
- data/spec/gon/thread_spec.rb +0 -39
- data/spec/gon/watch_spec.rb +0 -81
- data/spec/spec_helper.rb +0 -36
- data/spec/test_data/_sample_partial.json.jbuilder +0 -1
- data/spec/test_data/sample.json.jbuilder +0 -1
- data/spec/test_data/sample.rabl +0 -2
- data/spec/test_data/sample_rabl_rails.rabl +0 -2
- data/spec/test_data/sample_url_helpers.json.jbuilder +0 -1
- data/spec/test_data/sample_with_controller_method.json.jbuilder +0 -2
- data/spec/test_data/sample_with_helpers.json.jbuilder +0 -1
- data/spec/test_data/sample_with_helpers.rabl +0 -3
- data/spec/test_data/sample_with_helpers_rabl_rails.rabl +0 -3
- data/spec/test_data/sample_with_locals.json.jbuilder +0 -2
- data/spec/test_data/sample_with_partial.json.jbuilder +0 -1
data/spec/gon/watch_spec.rb
DELETED
@@ -1,81 +0,0 @@
|
|
1
|
-
describe Gon::Watch do
|
2
|
-
|
3
|
-
let(:controller) { ActionController::Base.new }
|
4
|
-
let(:request) { ActionDispatch::Request.new({}) }
|
5
|
-
|
6
|
-
before :each do
|
7
|
-
controller.request = request
|
8
|
-
controller.params = {}
|
9
|
-
env = {}
|
10
|
-
env['ORIGINAL_FULLPATH'] = '/foo'
|
11
|
-
env['REQUEST_METHOD'] = 'GET'
|
12
|
-
|
13
|
-
Gon::Watch.clear
|
14
|
-
Gon.send(:current_gon).instance_variable_set(:@env, env)
|
15
|
-
Gon.send(:current_gon).env['action_controller.instance'] = controller
|
16
|
-
Gon.clear
|
17
|
-
end
|
18
|
-
|
19
|
-
it 'should add variables to Gon#all_variables hash' do
|
20
|
-
Gon.a = 1
|
21
|
-
Gon.watch.b = 2
|
22
|
-
expect(Gon.all_variables).to eq({ 'a' => 1, 'b' => 2 })
|
23
|
-
end
|
24
|
-
|
25
|
-
describe '#all_variables' do
|
26
|
-
|
27
|
-
it 'should generate array with current request url, method type and variable names' do
|
28
|
-
Gon.watch.a = 1
|
29
|
-
expect(Gon.watch.all_variables).to eq({ 'a' => { 'url' => '/foo', 'method' => 'GET', 'name' => 'a' } })
|
30
|
-
end
|
31
|
-
|
32
|
-
end
|
33
|
-
|
34
|
-
describe '#render' do
|
35
|
-
|
36
|
-
it 'should render function with variables in gon namespace' do
|
37
|
-
Gon.watch.a = 1
|
38
|
-
expect(Gon.watch.render).to match(/gon\.watch\s=/)
|
39
|
-
expect(Gon.watch.render).to match(/gon\.watchedVariables/)
|
40
|
-
end
|
41
|
-
|
42
|
-
end
|
43
|
-
|
44
|
-
describe 'Render concrete variable' do
|
45
|
-
before do
|
46
|
-
env = Gon.send(:current_gon).env
|
47
|
-
env['HTTP_X_REQUESTED_WITH'] = 'XMLHttpRequest'
|
48
|
-
|
49
|
-
allow(controller).to receive_messages(request: ActionDispatch::Request.new(env))
|
50
|
-
Gon.send(:current_gon).env['action_controller.instance'] = controller
|
51
|
-
end
|
52
|
-
|
53
|
-
context 'when request variable is json safe content' do
|
54
|
-
before do
|
55
|
-
allow(controller).to receive_messages(params: {
|
56
|
-
gon_return_variable: true,
|
57
|
-
gon_watched_variable: 'safety'})
|
58
|
-
end
|
59
|
-
|
60
|
-
it 'should return value of variable if called right request' do
|
61
|
-
expect(controller).to receive(:render).with(json: '12345')
|
62
|
-
Gon.watch.safety = 12345
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
context 'when request variable is json unsafe content' do
|
67
|
-
let(:expected) { %Q{"\\u003cscript\\u003e'\\"\\u003c/script\\u003e
Dangerous"} }
|
68
|
-
|
69
|
-
before do
|
70
|
-
allow(controller).to receive_messages(params: {
|
71
|
-
gon_return_variable: true,
|
72
|
-
gon_watched_variable: 'danger'})
|
73
|
-
end
|
74
|
-
|
75
|
-
it 'should return value of variable if called right request' do
|
76
|
-
expect(controller).to receive(:render).with(json: expected)
|
77
|
-
Gon.watch.danger = %Q{<script>'"</script>\u2028Dangerous}
|
78
|
-
end
|
79
|
-
end
|
80
|
-
end
|
81
|
-
end
|
data/spec/spec_helper.rb
DELETED
@@ -1,36 +0,0 @@
|
|
1
|
-
require 'rails/railtie'
|
2
|
-
# We don't require rails for specs, but jbuilder works only in rails.
|
3
|
-
# And it checks version of rails. I've decided to configure jbuilder for rails v4
|
4
|
-
module Rails
|
5
|
-
module VERSION
|
6
|
-
MAJOR = 4
|
7
|
-
end
|
8
|
-
|
9
|
-
def self.version
|
10
|
-
'4.2.0'
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
require 'gon'
|
15
|
-
|
16
|
-
require 'jbuilder'
|
17
|
-
|
18
|
-
RSpec.configure do |config|
|
19
|
-
config.before(:each) do
|
20
|
-
RequestStore.store[:gon] = Gon::Request.new({})
|
21
|
-
@request = RequestStore.store[:gon]
|
22
|
-
allow(Gon).to receive(:current_gon).and_return(@request)
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
def request
|
27
|
-
@request ||= double 'request', :env => {}
|
28
|
-
end
|
29
|
-
|
30
|
-
def wrap_script(content, cdata=true)
|
31
|
-
script = "<script>"
|
32
|
-
script << "\n//<![CDATA[\n" if cdata
|
33
|
-
script << content
|
34
|
-
script << "\n//]]>\n" if cdata
|
35
|
-
script << '</script>'
|
36
|
-
end
|
@@ -1 +0,0 @@
|
|
1
|
-
json.objects objects
|
@@ -1 +0,0 @@
|
|
1
|
-
json.objects @objects
|
data/spec/test_data/sample.rabl
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
json.url user_path(@user_id)
|
@@ -1 +0,0 @@
|
|
1
|
-
json.date distance_of_time_in_words(20000)
|
@@ -1 +0,0 @@
|
|
1
|
-
json.partial! 'spec/test_data/_sample_partial.json.jbuilder', :objects => @objects
|