mandrill_batch_mailer 1.0.0 → 1.1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9c6e6c5d426fdfc9462c81098e2c64f2146907a5
4
- data.tar.gz: c2a7696bad891b2479cf370db9ee6753b25cc9dc
3
+ metadata.gz: 62eb5a8ab276e549611894a5e53967bc8ac6bf86
4
+ data.tar.gz: 32d2bd5d65060185e34e078fbdd10a84a66ed57f
5
5
  SHA512:
6
- metadata.gz: 284043167940b1473b76f4eff2b6b2c813a5853c9b50c549914567e76d737134730a12d0caf52e1dadd7bdc6f6254033d3c2393b0acf6fb6b321200a54137d3e
7
- data.tar.gz: 6768a56dfb2d615fef6014f892906ce25eb5325fa12fd8be06b7ffe2f04bf7a6bb1f1776f0dc2eb686f05ad9cc122cfe5926beca256fe8be9adf3927e3cc2a3b
6
+ metadata.gz: 17f92ea6f9071ea26a2a4c23e3bc49d8fbc0364a29f0cc7e1208d67a00fb1ce2d26e4acf2c67c9b63ac48c5086aa0e9eb3166febc507bea639c71edc7cc226fb
7
+ data.tar.gz: 8dfb5eb9852a1bbaa9d27f926ffe8d70c69f9158832d342067b9cb82861248f24f535048da73cb17494cb22fded20525d783e28ba45aa91ddb77564c8d746d2d
@@ -1,6 +1,7 @@
1
1
  require 'active_support'
2
2
  require 'active_support/inflector'
3
3
  require 'active_support/core_ext/object/try'
4
+ require 'active_support/core_ext/hash/deep_merge.rb'
4
5
 
5
6
  module MandrillBatchMailer
6
7
  class BaseMailer
@@ -154,7 +155,23 @@ module MandrillBatchMailer
154
155
  end
155
156
 
156
157
  def translations
157
- I18n.t scope, default: {}
158
+ if I18n.methods.include? :fallbacks
159
+ fallback_translations scope
160
+ else
161
+ I18n.t scope
162
+ end
163
+ end
164
+
165
+ def fallback_translations(scope)
166
+ I18n.fallbacks[I18n.locale].map do |fallback_locale|
167
+ I18n.t scope, locale: fallback_locale
168
+ end.reduce do |orig_translations, fallback_translations|
169
+ if fallback_translations.is_a? Hash
170
+ fallback_translations.deep_merge orig_translations
171
+ else
172
+ orig_translations
173
+ end
174
+ end
158
175
  end
159
176
 
160
177
  def class_name
@@ -162,9 +179,13 @@ module MandrillBatchMailer
162
179
  end
163
180
 
164
181
  def shared_translations
165
- I18n.t(
166
- "#{class_name.deconstantize.underscore}.shared_translations",
167
- default: {})
182
+ shared_scope =
183
+ "#{class_name.deconstantize.underscore}.shared_translations"
184
+ if I18n.methods.include? :fallbacks
185
+ fallback_translations shared_scope
186
+ else
187
+ I18n.t shared_scope
188
+ end
168
189
  end
169
190
 
170
191
  def merge_vars_from(translations)
@@ -1,3 +1,3 @@
1
1
  module MandrillBatchMailer
2
- VERSION = '1.0.0'
2
+ VERSION = '1.1.0'
3
3
  end
@@ -219,10 +219,27 @@ describe MandrillBatchMailer::BaseMailer do
219
219
  end
220
220
 
221
221
  describe '#translations' do
222
- subject { test_mailer.send :translations }
222
+ subject(:translated) { test_mailer.send :translations }
223
223
  it do
224
224
  should eq translations[:test_mailer][:testing]
225
225
  end
226
+
227
+ context 'with de translations and fallbacks on' do
228
+ let(:de_translations) do
229
+ { test_mailer: { testing: { subject: 'Ein Test Betreff' } } }
230
+ end
231
+ before do
232
+ I18n::Backend::Simple.include I18n::Backend::Fallbacks
233
+ I18n.backend.store_translations :de, de_translations
234
+ I18n.locale = :de
235
+ end
236
+ after { I18n.locale = :en }
237
+
238
+ it 'uses fallbacks' do
239
+ expect(translated[:subject]).to eq 'Ein Test Betreff'
240
+ expect(translated[:just_a_test]).to eq 'This is just a test'
241
+ end
242
+ end
226
243
  end
227
244
 
228
245
  describe '#shared_translations' do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mandrill_batch_mailer
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - schasse
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-08-25 00:00:00.000000000 Z
11
+ date: 2015-03-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -190,5 +190,5 @@ signing_key:
190
190
  specification_version: 4
191
191
  summary: Send batched Mails via Mandrill API
192
192
  test_files:
193
- - spec/spec_helper.rb
194
193
  - spec/mandrill_batch_mailer/base_mailer_spec.rb
194
+ - spec/spec_helper.rb