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.
Files changed (47) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +7 -1
  3. data/README.md +1 -5
  4. data/lib/gon/base.rb +6 -3
  5. data/lib/gon/compatibility/old_rails.rb +2 -0
  6. data/lib/gon/env_finder.rb +2 -0
  7. data/lib/gon/escaper.rb +2 -0
  8. data/lib/gon/global.rb +2 -0
  9. data/lib/gon/helpers.rb +2 -0
  10. data/lib/gon/jbuilder/parser.rb +6 -4
  11. data/lib/gon/jbuilder.rb +3 -1
  12. data/lib/gon/json_dumper.rb +18 -1
  13. data/lib/gon/rabl.rb +3 -1
  14. data/lib/gon/request.rb +2 -0
  15. data/lib/gon/spec_helpers.rb +3 -1
  16. data/lib/gon/version.rb +3 -1
  17. data/lib/gon/watch.rb +2 -0
  18. data/lib/gon.rb +2 -0
  19. metadata +21 -38
  20. data/.github/FUNDING.yml +0 -1
  21. data/.gitignore +0 -7
  22. data/.travis.yml +0 -12
  23. data/Gemfile +0 -6
  24. data/Rakefile +0 -10
  25. data/doc/logo.png +0 -0
  26. data/doc/logo_small.png +0 -0
  27. data/doc/top_sample.png +0 -0
  28. data/gon.gemspec +0 -30
  29. data/spec/gon/basic_spec.rb +0 -304
  30. data/spec/gon/global_spec.rb +0 -146
  31. data/spec/gon/jbuilder_spec.rb +0 -75
  32. data/spec/gon/rabl_spec.rb +0 -90
  33. data/spec/gon/templates_spec.rb +0 -36
  34. data/spec/gon/thread_spec.rb +0 -39
  35. data/spec/gon/watch_spec.rb +0 -81
  36. data/spec/spec_helper.rb +0 -36
  37. data/spec/test_data/_sample_partial.json.jbuilder +0 -1
  38. data/spec/test_data/sample.json.jbuilder +0 -1
  39. data/spec/test_data/sample.rabl +0 -2
  40. data/spec/test_data/sample_rabl_rails.rabl +0 -2
  41. data/spec/test_data/sample_url_helpers.json.jbuilder +0 -1
  42. data/spec/test_data/sample_with_controller_method.json.jbuilder +0 -2
  43. data/spec/test_data/sample_with_helpers.json.jbuilder +0 -1
  44. data/spec/test_data/sample_with_helpers.rabl +0 -3
  45. data/spec/test_data/sample_with_helpers_rabl_rails.rabl +0 -3
  46. data/spec/test_data/sample_with_locals.json.jbuilder +0 -2
  47. data/spec/test_data/sample_with_partial.json.jbuilder +0 -1
@@ -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
@@ -1,2 +0,0 @@
1
- collection @objects => 'objects'
2
- attributes :inspect
@@ -1,2 +0,0 @@
1
- collection :@objects => 'objects'
2
- attributes :inspect
@@ -1 +0,0 @@
1
- json.url user_path(@user_id)
@@ -1,2 +0,0 @@
1
- json.objects @objects
2
- json.data_from_method private_controller_method
@@ -1 +0,0 @@
1
- json.date distance_of_time_in_words(20000)
@@ -1,3 +0,0 @@
1
- collection @objects => 'objects'
2
- attributes :id
3
- node(:time_ago) { |_| distance_of_time_in_words(20000) }
@@ -1,3 +0,0 @@
1
- collection :@objects => 'objects'
2
- attributes :inspect
3
- node(:time_ago) { distance_of_time_in_words(20000) }
@@ -1,2 +0,0 @@
1
- json.some_local some_local
2
- json.some_complex_local_id some_complex_local.id
@@ -1 +0,0 @@
1
- json.partial! 'spec/test_data/_sample_partial.json.jbuilder', :objects => @objects