copy_tuner_client 0.5.1 → 0.5.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b3cc0c109c21c0ab75746e4e1c589aba3858137c
4
- data.tar.gz: 9ef00204b7dd815fbf10578c53c78940820304b7
3
+ metadata.gz: c72f170af0093637a763c2e02771cfd584d2c522
4
+ data.tar.gz: c4ef0334c658f6c16798467505f7dc73ce0447ea
5
5
  SHA512:
6
- metadata.gz: eea5da6db9d62a3aad0fb45d75d6f0cfb8ae8b7d8b0a8bc03cd4b381ce36a5d5118ca6c54d0c5bd873337b1e8fb4af3d6da5099beb3d5466b9faad7a26803011
7
- data.tar.gz: 52365f67f27781abde7842b9748f294a5f2a224968d564dcdc366ff1f8a05634d531354ae08bb6519e0e2d9455ce34b85c73b67e6a79e35c37c55849876d507c
6
+ metadata.gz: 04645e2ca212fba15311d766e203770e915aeadd19b44d47ddf1828928c94d5a5d4eed5ebf50c40ed1c0590774ff521154ff4b2f55e2e22dd3ea825208ea750a
7
+ data.tar.gz: 8fc97dc1dea41024746490e8bd6e07edd6ec876ee89c79d732c5aa74fa5a99ec0c2c25d011487a9cf10aec1830a91dc5b0c9624c2744c37f039189dc67eed3f8
data/.rubocop.yml ADDED
@@ -0,0 +1,2 @@
1
+ inherit_gem:
2
+ sgcop: ruby/rubocop.yml
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## 0.5.2
2
+
3
+ - Do not upload invalid keys
4
+
1
5
  ## 0.5.1
2
6
 
3
7
  - Do not upload downloaded keys
data/Gemfile CHANGED
@@ -1,3 +1,5 @@
1
1
  source 'http://rubygems.org'
2
2
 
3
3
  gemspec
4
+
5
+ gem 'sgcop', github: 'SonicGarden/sgcop'
data/Gemfile.lock CHANGED
@@ -1,7 +1,20 @@
1
+ GIT
2
+ remote: git://github.com/SonicGarden/sgcop.git
3
+ revision: 7ba086cff0068d231f55f5be788b757383d3ccba
4
+ specs:
5
+ sgcop (0.0.29)
6
+ brakeman
7
+ brakeman_translate_checkstyle_format
8
+ haml_lint (~> 0.32.0)
9
+ rubocop (~> 0.71.0)
10
+ rubocop-performance (~> 1.4.0)
11
+ rubocop-rails (~> 2.0.1)
12
+ rubocop-rspec (~> 1.33.0)
13
+
1
14
  PATH
2
15
  remote: .
3
16
  specs:
4
- copy_tuner_client (0.5.1)
17
+ copy_tuner_client (0.5.2)
5
18
  i18n (>= 0.5.0)
6
19
  json
7
20
 
@@ -53,6 +66,10 @@ GEM
53
66
  childprocess (>= 0.3.6)
54
67
  cucumber (>= 1.1.1)
55
68
  rspec-expectations (>= 2.7.0)
69
+ ast (2.4.0)
70
+ brakeman (4.5.1)
71
+ brakeman_translate_checkstyle_format (0.0.1)
72
+ thor
56
73
  builder (3.2.3)
57
74
  childprocess (0.6.3)
58
75
  ffi (~> 1.0, >= 1.0.11)
@@ -74,8 +91,18 @@ GEM
74
91
  multi_json (~> 1.3)
75
92
  globalid (0.3.7)
76
93
  activesupport (>= 4.1.0)
94
+ haml (5.1.1)
95
+ temple (>= 0.8.0)
96
+ tilt
97
+ haml_lint (0.32.0)
98
+ haml (>= 4.0, < 5.2)
99
+ rainbow
100
+ rake (>= 10, < 13)
101
+ rubocop (>= 0.50.0)
102
+ sysexits (~> 1.1)
77
103
  hashdiff (0.3.2)
78
104
  i18n (0.8.1)
105
+ jaro_winkler (1.5.3)
79
106
  json (2.2.0)
80
107
  loofah (2.0.3)
81
108
  nokogiri (>= 1.5.9)
@@ -90,6 +117,9 @@ GEM
90
117
  multi_test (0.1.2)
91
118
  nokogiri (1.8.2)
92
119
  mini_portile2 (~> 2.3.0)
120
+ parallel (1.17.0)
121
+ parser (2.6.3.0)
122
+ ast (~> 2.4.0)
93
123
  public_suffix (2.0.5)
94
124
  rack (1.6.5)
95
125
  rack-protection (1.5.3)
@@ -120,6 +150,7 @@ GEM
120
150
  activesupport (= 4.2.8)
121
151
  rake (>= 0.8.7)
122
152
  thor (>= 0.18.1, < 2.0)
153
+ rainbow (3.0.0)
123
154
  rake (12.0.0)
124
155
  rspec (3.5.0)
125
156
  rspec-core (~> 3.5.0)
@@ -134,6 +165,21 @@ GEM
134
165
  diff-lcs (>= 1.2.0, < 2.0)
135
166
  rspec-support (~> 3.5.0)
136
167
  rspec-support (3.5.0)
168
+ rubocop (0.71.0)
169
+ jaro_winkler (~> 1.5.1)
170
+ parallel (~> 1.10)
171
+ parser (>= 2.6)
172
+ rainbow (>= 2.2.2, < 4.0)
173
+ ruby-progressbar (~> 1.7)
174
+ unicode-display_width (>= 1.4.0, < 1.7)
175
+ rubocop-performance (1.4.0)
176
+ rubocop (>= 0.71.0)
177
+ rubocop-rails (2.0.1)
178
+ rack (>= 1.1)
179
+ rubocop (>= 0.70.0)
180
+ rubocop-rspec (1.33.0)
181
+ rubocop (>= 0.60.0)
182
+ ruby-progressbar (1.10.1)
137
183
  safe_yaml (1.0.4)
138
184
  sham_rack (1.4.0)
139
185
  rack
@@ -149,6 +195,8 @@ GEM
149
195
  activesupport (>= 4.0)
150
196
  sprockets (>= 3.0.0)
151
197
  sqlite3 (1.3.13)
198
+ sysexits (1.2.0)
199
+ temple (0.8.1)
152
200
  thin (1.7.0)
153
201
  daemons (~> 1.0, >= 1.0.9)
154
202
  eventmachine (~> 1.0, >= 1.0.4)
@@ -158,6 +206,7 @@ GEM
158
206
  tilt (2.0.7)
159
207
  tzinfo (1.2.3)
160
208
  thread_safe (~> 0.1)
209
+ unicode-display_width (1.6.0)
161
210
  webmock (2.3.2)
162
211
  addressable (>= 2.3.6)
163
212
  crack (>= 0.3.2)
@@ -175,6 +224,7 @@ DEPENDENCIES
175
224
  rails (~> 4.2.6)
176
225
  rake
177
226
  rspec
227
+ sgcop!
178
228
  sham_rack
179
229
  sinatra
180
230
  sqlite3
data/Rakefile CHANGED
@@ -4,16 +4,16 @@ require 'cucumber/rake/task'
4
4
  require 'rspec/core/rake_task'
5
5
  require 'yard'
6
6
 
7
- desc 'Default: run the specs and features.'
8
- task :default => [:spec, :cucumber]
7
+ desc 'Default: run the specs.'
8
+ task default: [:spec]
9
9
 
10
10
  desc 'Test the copy_tuner_client plugin.'
11
11
  RSpec::Core::RakeTask.new do |t|
12
- t.rspec_opts = ['--color', "--format progress"]
12
+ t.rspec_opts = ['--color', '--format progress']
13
13
  t.pattern = 'spec/copy_tuner_client/**/*_spec.rb'
14
14
  end
15
15
 
16
- desc "Run cucumber features"
16
+ desc 'Run cucumber features'
17
17
  Cucumber::Rake::Task.new do |t|
18
18
  t.cucumber_opts = [
19
19
  '--tags', '~@wip',
@@ -22,5 +22,5 @@ Cucumber::Rake::Task.new do |t|
22
22
  end
23
23
 
24
24
  YARD::Rake::YardocTask.new do |t|
25
- t.files = ['lib/**/*.rb']
25
+ t.files = ['lib/**/*.rb']
26
26
  end
@@ -1,4 +1,3 @@
1
- require 'thread'
2
1
  require 'copy_tuner_client/client'
3
2
  require 'copy_tuner_client/dotted_hash'
4
3
 
@@ -40,9 +39,12 @@ module CopyTunerClient
40
39
  # @param value [String] the new contents of the blurb
41
40
  def []=(key, value)
42
41
  return if @exclude_key_regexp && key.match?(@exclude_key_regexp)
42
+ return unless key.include?('.')
43
43
  return if @locales.present? && !@locales.member?(key.split('.').first)
44
+
44
45
  lock do
45
46
  return if @blank_keys.member?(key) || @blurbs.key?(key)
47
+
46
48
  @queued[key] = value
47
49
  end
48
50
  end
@@ -61,17 +63,15 @@ module CopyTunerClient
61
63
 
62
64
  # Waits until the first download has finished.
63
65
  def wait_for_download
64
- if pending?
65
- logger.info 'Waiting for first download'
66
+ return unless pending?
66
67
 
67
- if logger.respond_to? :flush
68
- logger.flush
69
- end
68
+ logger.info 'Waiting for first download'
70
69
 
71
- while pending?
72
- sleep 0.1
73
- end
70
+ if logger.respond_to? :flush
71
+ logger.flush
74
72
  end
73
+
74
+ sleep 0.1 while pending?
75
75
  end
76
76
 
77
77
  def flush
@@ -82,8 +82,8 @@ module CopyTunerClient
82
82
  @last_uploaded_at = Time.now.utc
83
83
 
84
84
  res
85
- rescue ConnectionError => error
86
- logger.error error.message
85
+ rescue ConnectionError => e
86
+ logger.error e.message
87
87
  end
88
88
 
89
89
  def download
@@ -100,8 +100,8 @@ module CopyTunerClient
100
100
  @last_downloaded_at = Time.now.utc
101
101
 
102
102
  res
103
- rescue ConnectionError => error
104
- logger.error error.message
103
+ rescue ConnectionError => e
104
+ logger.error e.message
105
105
  ensure
106
106
  @downloaded = true
107
107
  end
@@ -1,6 +1,6 @@
1
1
  module CopyTunerClient
2
2
  # Client version
3
- VERSION = '0.5.1'.freeze
3
+ VERSION = '0.5.2'.freeze
4
4
 
5
5
  # API version being used to communicate with the server
6
6
  API_VERSION = '2.0'.freeze
@@ -9,7 +9,7 @@ describe CopyTunerClient::Cache do
9
9
  CopyTunerClient::Cache.new(client, default_config.update(config))
10
10
  end
11
11
 
12
- it "provides access to downloaded data" do
12
+ it 'provides access to downloaded data' do
13
13
  client['en.test.key'] = 'expected'
14
14
  client['en.test.other_key'] = 'expected'
15
15
 
@@ -18,17 +18,17 @@ describe CopyTunerClient::Cache do
18
18
  cache.download
19
19
 
20
20
  expect(cache['en.test.key']).to eq('expected')
21
- expect(cache.keys).to match_array(%w(en.test.key en.test.other_key))
21
+ expect(cache.keys).to match_array(%w[en.test.key en.test.other_key])
22
22
  end
23
23
 
24
- it "exclude data if exclude_key_regexp is set" do
24
+ it 'exclude data if exclude_key_regexp is set' do
25
25
  cache = build_cache(exclude_key_regexp: /^en\.test\.other_key$/)
26
26
  cache['en.test.key'] = 'expected'
27
27
  cache['en.test.other_key'] = 'expected'
28
28
 
29
29
  cache.download
30
30
 
31
- expect(cache.queued.keys).to match_array(%w(en.test.key))
31
+ expect(cache.queued.keys).to match_array(%w[en.test.key])
32
32
  end
33
33
 
34
34
  it "doesn't upload without changes" do
@@ -37,7 +37,15 @@ describe CopyTunerClient::Cache do
37
37
  expect(client).not_to be_uploaded
38
38
  end
39
39
 
40
- it "uploads changes when flushed" do
40
+ it "Don't upload incorrect key" do
41
+ cache = build_cache
42
+ cache['ja'] = 'incorrect key'
43
+
44
+ cache.flush
45
+ expect(client).not_to be_uploaded
46
+ end
47
+
48
+ it 'uploads changes when flushed' do
41
49
  cache = build_cache
42
50
  cache['test.key'] = 'test value'
43
51
 
@@ -46,7 +54,7 @@ describe CopyTunerClient::Cache do
46
54
  expect(client.uploaded).to eq({ 'test.key' => 'test value' })
47
55
  end
48
56
 
49
- it "uploads empties when nil is assigned" do
57
+ it 'uploads empties when nil is assigned' do
50
58
  cache = build_cache
51
59
  cache['test.key'] = nil
52
60
 
@@ -62,7 +70,7 @@ describe CopyTunerClient::Cache do
62
70
 
63
71
  cache.flush
64
72
 
65
- expect(client.uploaded).to eq({'en.test.key' => 'uploaded en', 'ja.test.key' => 'uploaded ja'})
73
+ expect(client.uploaded).to eq({ 'en.test.key' => 'uploaded en', 'ja.test.key' => 'uploaded ja' })
66
74
  end
67
75
 
68
76
  it 'upload with locale filter' do
@@ -72,10 +80,10 @@ describe CopyTunerClient::Cache do
72
80
 
73
81
  cache.flush
74
82
 
75
- expect(client.uploaded).to eq({'en.test.key' => 'uploaded'})
83
+ expect(client.uploaded).to eq({ 'en.test.key' => 'uploaded' })
76
84
  end
77
85
 
78
- it "downloads changes" do
86
+ it 'downloads changes' do
79
87
  client['test.key'] = 'test value'
80
88
  cache = build_cache
81
89
 
@@ -84,7 +92,7 @@ describe CopyTunerClient::Cache do
84
92
  expect(cache['test.key']).to eq('test value')
85
93
  end
86
94
 
87
- it "downloads and uploads when synced" do
95
+ it 'downloads and uploads when synced' do
88
96
  cache = build_cache
89
97
  client['test.key'] = 'test value'
90
98
  cache['other.key'] = 'other value'
@@ -95,7 +103,7 @@ describe CopyTunerClient::Cache do
95
103
  expect(cache['test.key']).to eq('test value')
96
104
  end
97
105
 
98
- it "download included empty keys" do
106
+ it 'download included empty keys' do
99
107
  client['en.test.key'] = 'test value'
100
108
  client['en.test.empty'] = ''
101
109
  cache = build_cache
@@ -109,7 +117,7 @@ describe CopyTunerClient::Cache do
109
117
  expect(cache.queued).to be_empty
110
118
  end
111
119
 
112
- it "Do not upload downloaded keys" do
120
+ it 'Do not upload downloaded keys' do
113
121
  client['en.test.key'] = 'test value'
114
122
  cache = build_cache
115
123
 
@@ -119,11 +127,11 @@ describe CopyTunerClient::Cache do
119
127
  expect(cache.queued).to be_empty
120
128
  end
121
129
 
122
- it "handles connection errors when flushing" do
123
- failure = "server is napping"
130
+ it 'handles connection errors when flushing' do
131
+ failure = 'server is napping'
124
132
  logger = FakeLogger.new
125
133
  expect(client).to receive(:upload).and_raise(CopyTunerClient::ConnectionError.new(failure))
126
- cache = build_cache(:logger => logger)
134
+ cache = build_cache(logger: logger)
127
135
  cache['upload.key'] = 'upload'
128
136
 
129
137
  cache.flush
@@ -131,22 +139,22 @@ describe CopyTunerClient::Cache do
131
139
  expect(logger).to have_entry(:error, failure)
132
140
  end
133
141
 
134
- it "handles connection errors when downloading" do
135
- failure = "server is napping"
142
+ it 'handles connection errors when downloading' do
143
+ failure = 'server is napping'
136
144
  logger = FakeLogger.new
137
145
  expect(client).to receive(:download).and_raise(CopyTunerClient::ConnectionError.new(failure))
138
- cache = build_cache(:logger => logger)
146
+ cache = build_cache(logger: logger)
139
147
 
140
148
  cache.download
141
149
 
142
150
  expect(logger).to have_entry(:error, failure)
143
151
  end
144
152
 
145
- it "blocks until the first download is complete" do
153
+ it 'blocks until the first download is complete' do
146
154
  logger = FakeLogger.new
147
155
  expect(logger).to receive(:flush)
148
156
  client.delay = true
149
- cache = build_cache(:logger => logger)
157
+ cache = build_cache(logger: logger)
150
158
 
151
159
  t_download = Thread.new { cache.download }
152
160
  sleep 0.1 until cache.pending?
@@ -154,7 +162,7 @@ describe CopyTunerClient::Cache do
154
162
  t_wait = Thread.new do
155
163
  cache.wait_for_download
156
164
  end
157
- sleep 0.1 until logger.has_entry?(:info, "Waiting for first download")
165
+ sleep 0.1 until logger.has_entry?(:info, 'Waiting for first download')
158
166
  client.go
159
167
  expect(t_download.join(1)).not_to be_nil
160
168
  expect(cache.pending?).to be_falsey
@@ -163,7 +171,7 @@ describe CopyTunerClient::Cache do
163
171
 
164
172
  it "doesn't block if the first download fails" do
165
173
  client.delay = true
166
- client.error = StandardError.new("Failure")
174
+ client.error = StandardError.new('Failure')
167
175
  cache = build_cache
168
176
 
169
177
  error = nil
@@ -183,12 +191,12 @@ describe CopyTunerClient::Cache do
183
191
  expect(t_download.join(1)).not_to be_nil
184
192
  expect(error).to be_kind_of(StandardError)
185
193
  expect(t_wait.join(1)).not_to be_nil
186
- expect { cache.download }.to raise_error(StandardError, "Failure")
194
+ expect { cache.download }.to raise_error(StandardError, 'Failure')
187
195
  end
188
196
 
189
197
  it "doesn't block before downloading" do
190
198
  logger = FakeLogger.new
191
- cache = build_cache(:logger => logger)
199
+ cache = build_cache(logger: logger)
192
200
 
193
201
  finished = false
194
202
  Thread.new do
@@ -199,7 +207,7 @@ describe CopyTunerClient::Cache do
199
207
  sleep(1)
200
208
 
201
209
  expect(finished).to eq(true)
202
- expect(logger).not_to have_entry(:info, "Waiting for first download")
210
+ expect(logger).not_to have_entry(:info, 'Waiting for first download')
203
211
  end
204
212
 
205
213
  it "doesn't return blank copy" do
@@ -211,13 +219,13 @@ describe CopyTunerClient::Cache do
211
219
  expect(cache['en.test.key']).to be_nil
212
220
  end
213
221
 
214
- describe "given locked mutex" do
222
+ describe 'given locked mutex' do
215
223
  RSpec::Matchers.define :finish_after_unlocking do |mutex|
216
224
  match do |thread|
217
225
  sleep(0.1)
218
226
 
219
227
  if thread.status === false
220
- violated("finished before unlocking")
228
+ violated('finished before unlocking')
221
229
  else
222
230
  mutex.unlock
223
231
  sleep(0.1)
@@ -225,7 +233,7 @@ describe CopyTunerClient::Cache do
225
233
  if thread.status === false
226
234
  true
227
235
  else
228
- violated("still running after unlocking")
236
+ violated('still running after unlocking')
229
237
  end
230
238
  end
231
239
  end
@@ -248,20 +256,20 @@ describe CopyTunerClient::Cache do
248
256
  allow(Mutex).to receive(:new).and_return(mutex)
249
257
  end
250
258
 
251
- it "synchronizes read access to keys between threads" do
259
+ it 'synchronizes read access to keys between threads' do
252
260
  expect(Thread.new { cache['test.key'] }).to finish_after_unlocking(mutex)
253
261
  end
254
262
 
255
- it "synchronizes read access to the key list between threads" do
263
+ it 'synchronizes read access to the key list between threads' do
256
264
  expect(Thread.new { cache.keys }).to finish_after_unlocking(mutex)
257
265
  end
258
266
 
259
- it "synchronizes write access to keys between threads" do
267
+ it 'synchronizes write access to keys between threads' do
260
268
  expect(Thread.new { cache['test.key'] = 'value' }).to finish_after_unlocking(mutex)
261
269
  end
262
270
  end
263
271
 
264
- it "flushes from the top level" do
272
+ it 'flushes from the top level' do
265
273
  cache = build_cache
266
274
  CopyTunerClient.configure do |config|
267
275
  config.cache = cache
@@ -271,7 +279,7 @@ describe CopyTunerClient::Cache do
271
279
  CopyTunerClient.flush
272
280
  end
273
281
 
274
- describe "#export" do
282
+ describe '#export' do
275
283
  subject { cache.export }
276
284
 
277
285
  let(:cache) do
@@ -280,7 +288,7 @@ describe CopyTunerClient::Cache do
280
288
  cache
281
289
  end
282
290
 
283
- it "can be invoked from the top-level constant" do
291
+ it 'can be invoked from the top-level constant' do
284
292
  CopyTunerClient.configure do |config|
285
293
  config.cache = cache
286
294
  end
@@ -292,7 +300,7 @@ describe CopyTunerClient::Cache do
292
300
  is_expected.to eq nil
293
301
  end
294
302
 
295
- context "with single-level blurb keys" do
303
+ context 'with single-level blurb keys' do
296
304
  before do
297
305
  client['key'] = 'test value'
298
306
  client['other_key'] = 'other test value'
@@ -5,7 +5,8 @@ describe CopyTunerClient do
5
5
  config[:logger] ||= FakeLogger.new
6
6
  default_config = CopyTunerClient::Configuration.new.to_hash
7
7
  default_config[:s3_host] = 'copy-tuner.com'
8
- CopyTunerClient::Client.new(default_config.update(config))
8
+ client = CopyTunerClient::Client.new(default_config.update(config))
9
+ client
9
10
  end
10
11
 
11
12
  def add_project
@@ -197,6 +198,7 @@ describe CopyTunerClient do
197
198
 
198
199
  it "deploys from the top-level constant" do
199
200
  client = build_client
201
+ allow(client).to receive(:download)
200
202
  CopyTunerClient.configure do |config|
201
203
  config.client = client
202
204
  end
@@ -16,6 +16,7 @@ describe CopyTunerClient::Copyray do
16
16
  before do
17
17
  CopyTunerClient.configure do |configuration|
18
18
  configuration.html_escape = false
19
+ configuration.client = FakeClient.new
19
20
  end
20
21
  end
21
22
 
@@ -36,6 +37,7 @@ describe CopyTunerClient::Copyray do
36
37
  before do
37
38
  CopyTunerClient.configure do |configuration|
38
39
  configuration.html_escape = true
40
+ configuration.client = FakeClient.new
39
41
  end
40
42
  end
41
43
 
@@ -128,6 +128,7 @@ describe CopyTunerClient::I18nBackend do
128
128
  before do
129
129
  CopyTunerClient.configure do |configuration|
130
130
  configuration.html_escape = true
131
+ configuration.client = FakeClient.new
131
132
  end
132
133
  end
133
134
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: copy_tuner_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.1
4
+ version: 0.5.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - SonicGarden
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-06-24 00:00:00.000000000 Z
11
+ date: 2019-08-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: i18n
@@ -216,6 +216,7 @@ files:
216
216
  - ".eslintrc"
217
217
  - ".gitignore"
218
218
  - ".rspec"
219
+ - ".rubocop.yml"
219
220
  - ".ruby-version"
220
221
  - ".travis.yml"
221
222
  - Appraisals