copy_tuner_client 0.4.3 → 0.4.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 03ba0b085f868890879331c827dc5b536dd7ab60
4
- data.tar.gz: 87fde9370a787494eee210acef172e308d3bd712
3
+ metadata.gz: 0cb55c2bd2d4429781a893a3aab0ad71c0655701
4
+ data.tar.gz: 498fa6bcaad92bd1145f530aa5f2ce9820bd63ef
5
5
  SHA512:
6
- metadata.gz: b7224992276e3886e74346a54b9de1facf6dbf5140b0da2c29ded50534f61e820525cd1dce5ef865213a496bad59f34a17bf71a797f6010620557c3613fda02b
7
- data.tar.gz: 5bc71e6e6643e52038c4065e2dd5357b605875720b141f7dde522caa1dd335f6934bf612840abf805217a7da5584fb1a326d5a5f64c5ffe5339c2a6307015b4c
6
+ metadata.gz: 0bc675e3c354496f98ebd709e2abe80f85681a3eab511a4e2645127c46f112991aac078f62ff0681a484e3a3d1f68f1f54ad606315e527c7db61af8020cb1160
7
+ data.tar.gz: a9a276d4fd2e1c520a0293014648b70d8025ff0b72092a60cd768abcc3b71de98162399c76baeeff3d57a525896cde52720ce07e5f692a18871069259de072df
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## 0.4.4
2
+ - bug fix
3
+ - Don't upload resolved default values.
4
+
1
5
  ## 0.4.3
2
6
  - bug fix
3
7
  - Start poller thread regardless of puma mode. #39
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- copy_tuner_client (0.4.3)
4
+ copy_tuner_client (0.4.4)
5
5
  i18n (>= 0.5.0)
6
6
  json
7
7
 
@@ -78,7 +78,7 @@ GEM
78
78
  activesupport (>= 4.1.0)
79
79
  hashdiff (0.3.2)
80
80
  i18n (0.8.1)
81
- json (2.0.3)
81
+ json (2.1.0)
82
82
  loofah (2.0.3)
83
83
  nokogiri (>= 1.5.9)
84
84
  mail (2.6.4)
@@ -245,7 +245,7 @@ Feature: Using copy_tuner in a rails app
245
245
  When I wait for changes to be synchronized
246
246
  Then the "abc123" project should have the following error blurbs:
247
247
  | key | draft content |
248
- | user.attributes.name.blank | can't be blank |
248
+ | user.attributes.name.blank | |
249
249
 
250
250
  Scenario: ensure keys are synced with short lived processes
251
251
  When I configure the copy_tuner client to have a polling delay of 86400 seconds
@@ -147,10 +147,21 @@ module CopyTunerClient
147
147
  end
148
148
 
149
149
  if changes_to_push
150
- yield changes_to_push
150
+ yield nil_value_to_empty(changes_to_push)
151
151
  end
152
152
  end
153
153
 
154
+ def nil_value_to_empty(hash)
155
+ hash.each do |k, v|
156
+ if v.nil?
157
+ hash[k] = ''.freeze
158
+ elsif v.is_a?(Hash)
159
+ nil_value_to_empty(v)
160
+ end
161
+ end
162
+ hash
163
+ end
164
+
154
165
  def lock(&block)
155
166
  @mutex.synchronize &block
156
167
  end
@@ -62,7 +62,7 @@ module CopyTunerClient
62
62
  parts = I18n.normalize_keys(locale, key, scope, options[:separator])
63
63
  key_with_locale = parts.join('.')
64
64
  content = cache[key_with_locale] || super
65
- cache[key_with_locale] = "" if content.nil?
65
+ cache[key_with_locale] = nil if content.nil?
66
66
  content
67
67
  end
68
68
 
@@ -86,8 +86,11 @@ module CopyTunerClient
86
86
  content = super(locale, object, subject, options)
87
87
  if content.respond_to?(:to_str)
88
88
  parts = I18n.normalize_keys(locale, object, options[:scope], options[:separator])
89
- key = parts.join('.')
90
- cache[key] = content.to_str
89
+ # NOTE: ActionView::Helpers::TranslationHelper#translate wraps default String in an Array
90
+ if subject.is_a?(String) || (subject.is_a?(Array) && subject.size == 1 && subject.first.is_a?(String))
91
+ key = parts.join('.')
92
+ cache[key] = content.to_str
93
+ end
91
94
  end
92
95
  content
93
96
  end
@@ -1,6 +1,6 @@
1
1
  module CopyTunerClient
2
2
  # Client version
3
- VERSION = '0.4.3'.freeze
3
+ VERSION = '0.4.4'.freeze
4
4
 
5
5
  # API version being used to communicate with the server
6
6
  API_VERSION = '2.0'.freeze
@@ -46,6 +46,15 @@ describe CopyTunerClient::Cache do
46
46
  expect(client.uploaded).to eq({ 'test.key' => 'test value' })
47
47
  end
48
48
 
49
+ it "uploads empties when nil is assigned" do
50
+ cache = build_cache
51
+ cache['test.key'] = nil
52
+
53
+ cache.flush
54
+
55
+ expect(client.uploaded).to eq({ 'test.key' => '' })
56
+ end
57
+
49
58
  it 'upload without locale filter' do
50
59
  cache = build_cache
51
60
  cache['en.test.key'] = 'uploaded en'
@@ -58,11 +58,20 @@ describe CopyTunerClient::I18nBackend do
58
58
  expect(cache['en.test.key']).to eq(default)
59
59
  end
60
60
 
61
+ it "queues missing keys with default string in an array" do
62
+ default = 'default value'
63
+
64
+ expect(subject.translate('en', 'test.key', :default => [default])).to eq(default)
65
+
66
+ expect(cache['en.test.key']).to eq(default)
67
+ end
68
+
61
69
  it "queues missing keys without default" do
62
70
  expect { subject.translate('en', 'test.key') }.
63
71
  to throw_symbol(:exception)
64
72
 
65
- expect(cache['en.test.key']).to eq("")
73
+ expect(cache).to have_key 'en.test.key'
74
+ expect(cache['en.test.key']).to be_nil
66
75
  end
67
76
 
68
77
  it "queues missing keys with scope" do
@@ -74,6 +83,36 @@ describe CopyTunerClient::I18nBackend do
74
83
  expect(cache['en.test.key']).to eq(default)
75
84
  end
76
85
 
86
+ it "does not queues missing keys with a symbol of default" do
87
+ cache['en.key.one'] = "Expected"
88
+
89
+ expect(subject.translate('en', 'key.three', :default => :"key.one")).to eq 'Expected'
90
+
91
+ expect(cache).to have_key 'en.key.three'
92
+ expect(cache['en.key.three']).to be_nil
93
+
94
+ expect(subject.translate('en', 'key.three', :default => :"key.one")).to eq 'Expected'
95
+ end
96
+
97
+ it "does not queues missing keys with an array of default" do
98
+ cache['en.key.one'] = "Expected"
99
+
100
+ expect(subject.translate('en', 'key.three', :default => [:"key.two", :"key.one"])).to eq 'Expected'
101
+
102
+ expect(cache).to have_key 'en.key.three'
103
+ expect(cache['en.key.three']).to be_nil
104
+
105
+ expect(subject.translate('en', 'key.three', :default => [:"key.two", :"key.one"])).to eq 'Expected'
106
+ end
107
+
108
+ it "queues missing keys with interpolation" do
109
+ default = 'default %{interpolate}'
110
+
111
+ expect(subject.translate('en', 'test.key', :default => default, :interpolate => 'interpolated')).to eq 'default interpolated'
112
+
113
+ expect(cache['en.test.key']).to eq 'default %{interpolate}'
114
+ end
115
+
77
116
  it "marks strings as html safe" do
78
117
  cache['en.test.key'] = FakeHtmlSafeString.new("Hello")
79
118
  backend = build_backend
@@ -152,7 +191,8 @@ describe CopyTunerClient::I18nBackend do
152
191
 
153
192
  # default と Fallbacks を併用した場合、キャッシュにデフォルト値は入らない仕様に変えた
154
193
  # その仕様にしないと、うまく Fallbacks の処理が動かないため
155
- expect(cache['en.test.key']).to eq('')
194
+ expect(cache).to have_key 'en.test.key'
195
+ expect(cache['en.test.key']).to be_nil
156
196
  end
157
197
  end
158
198
  end
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.4.3
4
+ version: 0.4.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - SonicGarden
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-08-25 00:00:00.000000000 Z
11
+ date: 2017-09-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: i18n
@@ -319,7 +319,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
319
319
  version: '0'
320
320
  requirements: []
321
321
  rubyforge_project:
322
- rubygems_version: 2.5.2
322
+ rubygems_version: 2.6.13
323
323
  signing_key:
324
324
  specification_version: 4
325
325
  summary: Client for the CopyTuner copy management service