i18n-sequel_bitemporal 1.0.2 → 1.0.3

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
  SHA256:
3
- metadata.gz: 17c191652e457d465a3d7951efdf76a432a82690dd7b3f0bae9324b3bbe7a61d
4
- data.tar.gz: 05a1aa9b8d012cced99c152b0700960bbc812e38b753f4f612bdbef635b2b4f0
3
+ metadata.gz: 57e9252a463de8d43116d067cbe849cdf70a9647e8b7a3cb2dcdbc1016d86317
4
+ data.tar.gz: 6d504736bf4b6e300807bd9973049b3dcebcb3799f5ba9c61aa013374f8aa839
5
5
  SHA512:
6
- metadata.gz: 2c147a89f559776c2977e3aad2a8ee38820d79c0c8246f7b77c801b69667d1272d4d55cdd7ca6cc80a7316aba13fd84516490700a6f9bf1ad2fd6313333e9d19
7
- data.tar.gz: e8cfa24c1ea406cd5ae63eba66040c46db6edb63fe30dff280351cff3745c5b5998ade3000f00dac92da59b1a812affc4baba4c52260194bdde893df9ac98c1b
6
+ metadata.gz: 19b6b5aade339b69265e235d812a1d488a3e0494b1816dd248023ac8d1022183ef86c1c8ae8f44cbbc304047917ecece3322c470f64d08398c1216b3c0bcf3df
7
+ data.tar.gz: 93a7efa3a130e5f4ef83ea6bc8804234380aca8df3d6f785b518c0130841a7136db177bc4b81f6e36a2949459d42598b176fce722e1a68c8e103c23bc645b94f
@@ -44,6 +44,7 @@ module I18n
44
44
 
45
45
  def store_translations(locale, data, options = {})
46
46
  escape = options.fetch(:escape, true)
47
+ point_in_time_for_new = options[:point_in_time_for_new]
47
48
  valid_from_for_new = options[:valid_from_for_new]
48
49
  flatten_translations(locale, data, escape, false).each do |key, value|
49
50
  # Invalidate all keys matching current one:
@@ -56,7 +57,13 @@ module I18n
56
57
  Translation.new(:locale => locale.to_s, :key => key.to_s)
57
58
  translation.attributes = {:value => value}
58
59
  translation.attributes[:valid_from] = valid_from_for_new if translation.new?
59
- translation.save
60
+ if point_in_time_for_new && translation.new?
61
+ ::Sequel::Plugins::Bitemporal.as_we_knew_it point_in_time_for_new do
62
+ translation.save
63
+ end
64
+ else
65
+ translation.save
66
+ end
60
67
  end
61
68
  end
62
69
  end
@@ -1,5 +1,5 @@
1
1
  module I18n
2
2
  module SequelBitemporal
3
- VERSION = "1.0.2"
3
+ VERSION = "1.0.3"
4
4
  end
5
5
  end
data/test/sequel_test.rb CHANGED
@@ -67,6 +67,24 @@ class I18nBackendSequelBitemporalTest < I18nBitemporalTest
67
67
  assert_equal valid_from_for_new, translation.current_version.valid_from
68
68
  end
69
69
 
70
+ test "can specify point in time for the new translation" do
71
+ point_in_time_for_new = Time.parse("2001-01-01T12:00:00Z")
72
+ I18n.backend.store_translations(:es, {:"Pagina's" => "Pagina's"}, point_in_time_for_new: point_in_time_for_new )
73
+ translation = I18n::Backend::SequelBitemporal::Translation.locale(:es).lookup("Pagina's").limit(1).all.first
74
+ assert_equal "Pagina's", translation.value
75
+ assert_equal point_in_time_for_new, translation.current_version.created_at
76
+ end
77
+
78
+ test "can specify both point in time and valid_from for the new translation" do
79
+ point_in_time_for_new = Time.parse("2001-01-01T12:00:00Z")
80
+ valid_from_for_new = Date.parse("2001-01-01")
81
+ I18n.backend.store_translations(:es, {:"Pagina's" => "Pagina's"}, point_in_time_for_new: point_in_time_for_new, valid_from_for_new: valid_from_for_new )
82
+ translation = I18n::Backend::SequelBitemporal::Translation.locale(:es).lookup("Pagina's").limit(1).all.first
83
+ assert_equal "Pagina's", translation.value
84
+ assert_equal point_in_time_for_new, translation.current_version.created_at
85
+ assert_equal valid_from_for_new, translation.current_version.valid_from
86
+ end
87
+
70
88
  with_mocha do
71
89
  test "missing translations table does not cause an error in #available_locales" do
72
90
  I18n::Backend::SequelBitemporal::Translation.expects(:available_locales).raises(::Sequel::Error)
data/test/test_helper.rb CHANGED
@@ -1,3 +1,4 @@
1
+ ENV["TZ"] = "UTC"
1
2
  $:.unshift File.expand_path(".", File.dirname(__FILE__))
2
3
 
3
4
  require 'test_setup'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: i18n-sequel_bitemporal
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jonathan Tron
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-07-14 00:00:00.000000000 Z
11
+ date: 2022-07-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: i18n