liveqa 1.4.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +4 -0
  3. data/.rspec +1 -0
  4. data/.rubocop.yml +40 -0
  5. data/.ruby-version +1 -0
  6. data/.travis.yml +10 -0
  7. data/CHANGELOG.md +5 -0
  8. data/Gemfile +12 -0
  9. data/README.md +40 -0
  10. data/Rakefile +4 -0
  11. data/lib/liveqa/api_operation/save.rb +57 -0
  12. data/lib/liveqa/api_resource.rb +123 -0
  13. data/lib/liveqa/async_handlers/base.rb +17 -0
  14. data/lib/liveqa/async_handlers/sidekiq.rb +33 -0
  15. data/lib/liveqa/config.rb +116 -0
  16. data/lib/liveqa/errors.rb +41 -0
  17. data/lib/liveqa/event.rb +22 -0
  18. data/lib/liveqa/library_name.rb +3 -0
  19. data/lib/liveqa/liveqa_object.rb +139 -0
  20. data/lib/liveqa/message.rb +50 -0
  21. data/lib/liveqa/plugins/rack/middleware.rb +121 -0
  22. data/lib/liveqa/plugins/rails/middleware_data.rb +44 -0
  23. data/lib/liveqa/plugins/rails/railtie.rb +23 -0
  24. data/lib/liveqa/plugins/sidekiq/client_middleware.rb +19 -0
  25. data/lib/liveqa/plugins/sidekiq/load.rb +14 -0
  26. data/lib/liveqa/plugins/sidekiq/server_middleware.rb +47 -0
  27. data/lib/liveqa/plugins.rb +16 -0
  28. data/lib/liveqa/request.rb +132 -0
  29. data/lib/liveqa/store.rb +49 -0
  30. data/lib/liveqa/util.rb +148 -0
  31. data/lib/liveqa/version.rb +3 -0
  32. data/lib/liveqa.rb +105 -0
  33. data/liveqa.gemspec +26 -0
  34. data/spec/lib/liveqa/async_handlers/base_spec.rb +19 -0
  35. data/spec/lib/liveqa/async_handlers/sidekiq_spec.rb +40 -0
  36. data/spec/lib/liveqa/config_spec.rb +40 -0
  37. data/spec/lib/liveqa/event_spec.rb +36 -0
  38. data/spec/lib/liveqa/liveqa_object_spec.rb +72 -0
  39. data/spec/lib/liveqa/message_spec.rb +101 -0
  40. data/spec/lib/liveqa/plugins/rack/middleware_spec.rb +25 -0
  41. data/spec/lib/liveqa/plugins/rails/middleware_data_spec.rb +67 -0
  42. data/spec/lib/liveqa/plugins/sidekiq/client_middleware_spec.rb +15 -0
  43. data/spec/lib/liveqa/plugins/sidekiq/server_middleware_spec.rb +63 -0
  44. data/spec/lib/liveqa/store_spec.rb +82 -0
  45. data/spec/lib/liveqa/util_spec.rb +123 -0
  46. data/spec/lib/liveqa_spec.rb +78 -0
  47. data/spec/spec_helper.rb +31 -0
  48. data/spec/support/rack_app.rb +12 -0
  49. metadata +176 -0
@@ -0,0 +1,82 @@
1
+
2
+ require 'spec_helper'
3
+
4
+ describe LiveQA::Store do
5
+
6
+ subject(:store) { LiveQA::Store }
7
+
8
+ describe '.store' do
9
+ it { expect(store.store).to eq({})}
10
+ end
11
+
12
+ describe '.store' do
13
+ before { store.clear! }
14
+ it { expect(store.store).to eq({})}
15
+
16
+ context 'with values' do
17
+ before { store.set(:test, 'value') }
18
+ before { store.clear! }
19
+
20
+ it { expect(store.store).to eq({}) }
21
+ end
22
+ end
23
+
24
+ describe '.load_from_hash' do
25
+ context 'with hash' do
26
+ before { store.load_from_hash('test' => 'value', another: 'another_value') }
27
+
28
+ it { expect(store.store).to match(test: 'value', another: 'another_value') }
29
+ end
30
+
31
+ it { expect { store.load_from_hash(nil) }.to_not raise_error }
32
+ end
33
+
34
+ describe '.set' do
35
+ before { store.set(:test, 'value') }
36
+
37
+ it { expect(store.store).to eq(test: 'value') }
38
+ end
39
+
40
+ describe '[]=' do
41
+ before { store[:test] = 'value' }
42
+
43
+ it { expect(store.store).to eq(test: 'value') }
44
+ end
45
+
46
+ describe '.get' do
47
+ before { store.set(:test, 'value') }
48
+
49
+ it { expect(store.get(:test)).to eq('value') }
50
+ end
51
+
52
+ describe '[]' do
53
+ before { store[:test] = 'value' }
54
+
55
+ it { expect(store[:test]).to eq('value') }
56
+ end
57
+
58
+ describe '.bulk_set' do
59
+ before { store[:test] = 'value' }
60
+ before { store.bulk_set(new_test: 'value', another: 'another_value') }
61
+
62
+ it { expect(store.store).to match(test: 'value', new_test: 'value', another: 'another_value') }
63
+ end
64
+
65
+ describe '.exist?' do
66
+ before { store.set(:test, 'value') }
67
+
68
+ it { expect(store.exist?(:test)).to be_truthy }
69
+ it { expect(store.exist?(:something)).to be_falsey }
70
+ end
71
+
72
+ describe '.exist?' do
73
+ before { store.set(:test, 'value') }
74
+ before { store.delete(:test)}
75
+
76
+ it { expect(store.exist?(:test)).to be_falsey }
77
+
78
+ context 'value does not exist' do
79
+ it { expect { store.delete(:something) }.to_not raise_error }
80
+ end
81
+ end
82
+ end
@@ -0,0 +1,123 @@
1
+ require 'spec_helper'
2
+
3
+ describe LiveQA::Util do
4
+
5
+ describe '#compact' do
6
+ it { expect(LiveQA::Util.compact(test: nil, other: 'test')).to eq(other: 'test') }
7
+ end
8
+
9
+ describe '#deep_compact' do
10
+ let(:payload) {{
11
+ my_key: 'test',
12
+ empty_key: nil,
13
+ another_key: {
14
+ last_key: 42,
15
+ valid_key: 'test',
16
+ empty_key: nil,
17
+ yet_another_key: {
18
+ empty_key: nil
19
+ }
20
+ }
21
+ }}
22
+
23
+ let(:expected) {{
24
+ my_key: 'test',
25
+ another_key: {
26
+ last_key: 42,
27
+ valid_key: 'test'
28
+ }
29
+ }}
30
+ it { expect(LiveQA::Util.deep_compact(payload)).to eq(expected) }
31
+ end
32
+
33
+ describe '#encode_parameters' do
34
+ it { expect(LiveQA::Util.encode_parameters(id: 42, other: 'test')).to eq("id=42&other=test") }
35
+ end
36
+
37
+ describe '#underscore' do
38
+ it { expect(LiveQA::Util.underscore('Model')).to eq("model") }
39
+ it { expect(LiveQA::Util.underscore('MyModel')).to eq("my_model") }
40
+ end
41
+
42
+ describe '#deep_underscore_key' do
43
+ let(:payload) {{
44
+ 'MyKey' => 'test',
45
+ 'anotherKey' => {
46
+ 'lastKey' => 'test',
47
+ 'valid_key' => 'test'
48
+ }
49
+ }}
50
+
51
+ let(:expected) {{
52
+ my_key: 'test',
53
+ another_key: {
54
+ last_key: 'test',
55
+ valid_key: 'test'
56
+ }
57
+ }}
58
+
59
+ it { expect(LiveQA::Util.deep_underscore_key(payload)).to eq(expected) }
60
+ end
61
+
62
+ describe '#deep_stringify_key' do
63
+ let(:payload) {{
64
+ my_key: 'test',
65
+ another_key: {
66
+ last_key: 'test',
67
+ valid_key: 'test'
68
+ }
69
+ }}
70
+
71
+ let(:expected) {{
72
+ 'my_key' => 'test',
73
+ 'another_key' => {
74
+ 'last_key' => 'test',
75
+ 'valid_key' => 'test'
76
+ }
77
+ }}
78
+
79
+ it { expect(LiveQA::Util.deep_stringify_key(payload)).to eq(expected) }
80
+ end
81
+
82
+ describe '#deep_symbolize_key' do
83
+ let(:payload) {{
84
+ 'my_key' => 'test',
85
+ 'another_key' => {
86
+ 'last_key' => 'test',
87
+ 'valid_key' => 'test'
88
+ }
89
+ }}
90
+
91
+ let(:expected) {{
92
+ my_key: 'test',
93
+ another_key: {
94
+ last_key: 'test',
95
+ valid_key: 'test'
96
+ }
97
+ }}
98
+
99
+ it { expect(LiveQA::Util.deep_symbolize_key(payload)).to eq(expected) }
100
+ end
101
+
102
+ describe '#deep_obfuscate_value' do
103
+ let(:fields) { ['password', 'credit_card'] }
104
+ let(:payload) {{
105
+ password: 'test',
106
+ another_key: {
107
+ credit_card: '41111111',
108
+ valid_key: 'test'
109
+ }
110
+ }}
111
+
112
+ let(:expected) {{
113
+ password: '[HIDDEN]',
114
+ another_key: {
115
+ credit_card: '[HIDDEN]',
116
+ valid_key: 'test'
117
+ }
118
+ }}
119
+
120
+ it { expect(LiveQA::Util.deep_obfuscate_value(payload, fields)).to eq(expected) }
121
+ end
122
+
123
+ end
@@ -0,0 +1,78 @@
1
+ require 'spec_helper'
2
+
3
+ describe LiveQA::Event do
4
+
5
+ describe '.configurations' do
6
+ it { expect(LiveQA.configurations).to be_a(LiveQA::Config) }
7
+ end
8
+
9
+ describe '.track' do
10
+ let(:response) { double('LiveQA::Event', successful?: true) }
11
+ after { LiveQA.track('test', { user_id: 42, properties: { total: 10 }}, { no_ssl: true }) }
12
+
13
+ let(:expected_arg) {{
14
+ user_id: 42,
15
+ type: 'track',
16
+ name: 'test',
17
+ message_id: kind_of(String),
18
+ timestamp: kind_of(String),
19
+ tracker_id: kind_of(String),
20
+ session_tracker_id: kind_of(String),
21
+ properties: {
22
+ total: 10
23
+ },
24
+ library: {
25
+ name: "liveqa",
26
+ language: "ruby",
27
+ version: kind_of(String)
28
+ },
29
+ server: {
30
+ host: kind_of(String),
31
+ pid: kind_of(Numeric)
32
+ }
33
+ }}
34
+
35
+ it { expect(LiveQA::Event).to receive(:create).with(expected_arg, { no_ssl: true }).and_return(response) }
36
+
37
+ context 'not enabled' do
38
+ before { LiveQA.configurations.enabled = false }
39
+
40
+ it { expect(LiveQA::Event).to_not receive(:create) }
41
+ end
42
+ end
43
+
44
+ describe '.identify' do
45
+ let(:response) { double('LiveQA::Event', successful?: true) }
46
+ after { LiveQA.identify(42, { tracker_id: 'xx', properties: { name: 'John Doe' }}, { no_ssl: true }) }
47
+
48
+ let(:expected_arg) {{
49
+ tracker_id: 'xx',
50
+ properties: {
51
+ name: 'John Doe'
52
+ },
53
+ type: 'identify',
54
+ user_id: 42,
55
+ message_id: kind_of(String),
56
+ timestamp: kind_of(String),
57
+ session_tracker_id: kind_of(String),
58
+ library: {
59
+ name: "liveqa",
60
+ language: "ruby",
61
+ version: kind_of(String)
62
+ },
63
+ server: {
64
+ host: kind_of(String),
65
+ pid: kind_of(Numeric)
66
+ }
67
+ }}
68
+
69
+ it { expect(LiveQA::Event).to receive(:create).with(expected_arg, { no_ssl: true }).and_return(response) }
70
+
71
+ context 'not enabled' do
72
+ before { LiveQA.configurations.enabled = false }
73
+
74
+ it { expect(LiveQA::Event).to_not receive(:create) }
75
+ end
76
+ end
77
+
78
+ end
@@ -0,0 +1,31 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+ require 'liveqa'
4
+ require 'rspec'
5
+ require 'pry'
6
+
7
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
8
+
9
+ RSpec.configure do |config|
10
+ config.expect_with :rspec do |c|
11
+ c.syntax = :expect
12
+ end
13
+ config.mock_with :rspec
14
+
15
+ config.before(:each) do
16
+ LiveQA.configure do |config|
17
+ config.api_host = 'localhost:4003'
18
+ config.api_key = 'MVulkyYgAf1Xqc09eLbvONymxZCSwA-yevXRsBHx226lxdwIs5ppG942'
19
+ config.http_secure = false
20
+ end
21
+ end
22
+
23
+ config.after(:each) do
24
+ LiveQA::Store.clear!
25
+ end
26
+
27
+ config.before(:each) do
28
+ LiveQA::Store.clear!
29
+ end
30
+
31
+ end
@@ -0,0 +1,12 @@
1
+ class RackApp
2
+ attr_reader :last_value, :store_active
3
+
4
+ def call(env)
5
+ LiveQA::Store.store[:foo] ||= 0
6
+ LiveQA::Store.store[:foo] += 1
7
+
8
+ @last_value = LiveQA::Store.store[:foo]
9
+
10
+ raise 'ERROR' if env[:error]
11
+ end
12
+ end
metadata ADDED
@@ -0,0 +1,176 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: liveqa
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.4.6
5
+ platform: ruby
6
+ authors:
7
+ - LiveQA
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-12-20 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: faker
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 1.8.4
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 1.8.4
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 0.9.0
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 0.9.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: pry
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.5'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.5'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rubocop
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '='
74
+ - !ruby/object:Gem::Version
75
+ version: 0.49.1
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '='
81
+ - !ruby/object:Gem::Version
82
+ version: 0.49.1
83
+ description: LiveQA ruby integration
84
+ email:
85
+ - support@liveqa.io
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - ".rspec"
92
+ - ".rubocop.yml"
93
+ - ".ruby-version"
94
+ - ".travis.yml"
95
+ - CHANGELOG.md
96
+ - Gemfile
97
+ - README.md
98
+ - Rakefile
99
+ - lib/liveqa.rb
100
+ - lib/liveqa/api_operation/save.rb
101
+ - lib/liveqa/api_resource.rb
102
+ - lib/liveqa/async_handlers/base.rb
103
+ - lib/liveqa/async_handlers/sidekiq.rb
104
+ - lib/liveqa/config.rb
105
+ - lib/liveqa/errors.rb
106
+ - lib/liveqa/event.rb
107
+ - lib/liveqa/library_name.rb
108
+ - lib/liveqa/liveqa_object.rb
109
+ - lib/liveqa/message.rb
110
+ - lib/liveqa/plugins.rb
111
+ - lib/liveqa/plugins/rack/middleware.rb
112
+ - lib/liveqa/plugins/rails/middleware_data.rb
113
+ - lib/liveqa/plugins/rails/railtie.rb
114
+ - lib/liveqa/plugins/sidekiq/client_middleware.rb
115
+ - lib/liveqa/plugins/sidekiq/load.rb
116
+ - lib/liveqa/plugins/sidekiq/server_middleware.rb
117
+ - lib/liveqa/request.rb
118
+ - lib/liveqa/store.rb
119
+ - lib/liveqa/util.rb
120
+ - lib/liveqa/version.rb
121
+ - liveqa.gemspec
122
+ - spec/lib/liveqa/async_handlers/base_spec.rb
123
+ - spec/lib/liveqa/async_handlers/sidekiq_spec.rb
124
+ - spec/lib/liveqa/config_spec.rb
125
+ - spec/lib/liveqa/event_spec.rb
126
+ - spec/lib/liveqa/liveqa_object_spec.rb
127
+ - spec/lib/liveqa/message_spec.rb
128
+ - spec/lib/liveqa/plugins/rack/middleware_spec.rb
129
+ - spec/lib/liveqa/plugins/rails/middleware_data_spec.rb
130
+ - spec/lib/liveqa/plugins/sidekiq/client_middleware_spec.rb
131
+ - spec/lib/liveqa/plugins/sidekiq/server_middleware_spec.rb
132
+ - spec/lib/liveqa/store_spec.rb
133
+ - spec/lib/liveqa/util_spec.rb
134
+ - spec/lib/liveqa_spec.rb
135
+ - spec/spec_helper.rb
136
+ - spec/support/rack_app.rb
137
+ homepage: https://github.com/arkes/liveqa-ruby
138
+ licenses:
139
+ - MIT
140
+ metadata: {}
141
+ post_install_message:
142
+ rdoc_options: []
143
+ require_paths:
144
+ - lib
145
+ required_ruby_version: !ruby/object:Gem::Requirement
146
+ requirements:
147
+ - - ">="
148
+ - !ruby/object:Gem::Version
149
+ version: '0'
150
+ required_rubygems_version: !ruby/object:Gem::Requirement
151
+ requirements:
152
+ - - ">="
153
+ - !ruby/object:Gem::Version
154
+ version: '0'
155
+ requirements: []
156
+ rubyforge_project:
157
+ rubygems_version: 2.5.2
158
+ signing_key:
159
+ specification_version: 4
160
+ summary: LiveQA ruby integration
161
+ test_files:
162
+ - spec/lib/liveqa/async_handlers/base_spec.rb
163
+ - spec/lib/liveqa/async_handlers/sidekiq_spec.rb
164
+ - spec/lib/liveqa/config_spec.rb
165
+ - spec/lib/liveqa/event_spec.rb
166
+ - spec/lib/liveqa/liveqa_object_spec.rb
167
+ - spec/lib/liveqa/message_spec.rb
168
+ - spec/lib/liveqa/plugins/rack/middleware_spec.rb
169
+ - spec/lib/liveqa/plugins/rails/middleware_data_spec.rb
170
+ - spec/lib/liveqa/plugins/sidekiq/client_middleware_spec.rb
171
+ - spec/lib/liveqa/plugins/sidekiq/server_middleware_spec.rb
172
+ - spec/lib/liveqa/store_spec.rb
173
+ - spec/lib/liveqa/util_spec.rb
174
+ - spec/lib/liveqa_spec.rb
175
+ - spec/spec_helper.rb
176
+ - spec/support/rack_app.rb