diff --git a/CHANGELOG.md b/CHANGELOG.md index 66f34273..94b2890d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Changelog 9.x +- `Sequent.configuration.time_precision` uses the current value of + `ActiveSupport::JSON::Encoding.time_precision` when it is not set, + instead of the value ActiveSupport had when Sequent was loaded. + `Sequent::Configuration::DEFAULT_TIME_PRECISION` is removed. + - A record class that includes `Sequent::Core::ProjectionRecord` can only be written by projectors, unless writing is allowed using `Sequent::Core::ProjectionWrites`. The `have_no_write_callbacks` diff --git a/docs/docs/concepts/configuration.md b/docs/docs/concepts/configuration.md index 7f5c8074..6172cdb9 100644 --- a/docs/docs/concepts/configuration.md +++ b/docs/docs/concepts/configuration.md @@ -135,7 +135,7 @@ For the latest configuration possibilities please check the `Sequent::Configurat | snapshot_record_class | The [class](event_store.html) mapped to the `snapshot_records` table | `Sequent::Core::SnapshotRecord` | | stream_record_class | The [class](event_store.html) mapped to the `stream_records` table | `Sequent::Core::StreamRecord` | | strict_check_attributes_on_apply_events | Whether or not sequent should fail on calling `apply` with invalid attributes. | `false`. Will be enabled by default in the next major release. | -| time_precision | Sets the precision of encoded time values. Defaults to 3 (equivalent to millisecond precision) | `ActiveSupport::JSON::Encoding.time_precision` | +| time_precision | Sets the precision of encoded time values. When not set, the current value of `ActiveSupport::JSON::Encoding.time_precision` is used | `ActiveSupport::JSON::Encoding.time_precision` | | transaction_provider | The transaction provider used by the [CommandService](command-service.html) | `Sequent::Core::Transactions::ActiveRecordTransactionProvider.new` | | uuid_generator | The UUID Generator used. Mainly useful for testing | `Sequent::Core::RandomUuidGenerator` | | versions_table_name | The name of the table in which Sequent checks which [migration version](migrations.html) is currently active | `'sequent_versions'` | diff --git a/lib/sequent/configuration.rb b/lib/sequent/configuration.rb index 45031379..e95a15c6 100644 --- a/lib/sequent/configuration.rb +++ b/lib/sequent/configuration.rb @@ -43,8 +43,6 @@ class Configuration fail Sequent::Core::AggregateInvariantViolationError.new(aggregate, exception, phase), cause: exception end - DEFAULT_TIME_PRECISION = ActiveSupport::JSON::Encoding.time_precision - DEFAULT_AGGREGATE_SNAPSHOT_VERSIONS = proc do |clazz| Sequent::Core::AggregateRoots.snapshot_version_by_type(clazz) end @@ -77,7 +75,6 @@ class Configuration :replay_group_target_size, :event_store_schema_name, :strict_check_attributes_on_apply_events, - :time_precision, :enable_autoregistration, :aggregate_snapshot_versions, :aggregate_invariant_violation_handler, @@ -85,6 +82,8 @@ class Configuration :projectors_replayer_after_activate_hook, :projectors_replayer_total_lock_timeout + attr_writer :time_precision + attr_reader :migrations_class, :versions_table_name @@ -139,8 +138,6 @@ def initialize self.logger = Logger.new(STDOUT).tap { |l| l.level = Logger::INFO } self.error_locale_resolver = DEFAULT_ERROR_LOCALE_RESOLVER - self.time_precision = DEFAULT_TIME_PRECISION - self.enable_autoregistration = false self.aggregate_snapshot_versions = DEFAULT_AGGREGATE_SNAPSHOT_VERSIONS self.aggregate_invariant_violation_handler = DEFAULT_AGGREGATE_INVARIANT_VIOLATION_HANDLER @@ -148,6 +145,10 @@ def initialize self.projectors_replayer_total_lock_timeout = 10.seconds end + def time_precision + @time_precision || ActiveSupport::JSON::Encoding.time_precision + end + def versions_table_name=(table_name) fail ArgumentError, 'table_name can not be nil' unless table_name diff --git a/spec/lib/sequent/configuration_spec.rb b/spec/lib/sequent/configuration_spec.rb index 7dce51d4..39d2e74b 100644 --- a/spec/lib/sequent/configuration_spec.rb +++ b/spec/lib/sequent/configuration_spec.rb @@ -5,6 +5,28 @@ describe Sequent::Configuration do let(:instance) { described_class.instance } + describe '#time_precision' do + around do |example| + precision = ActiveSupport::JSON::Encoding.time_precision + example.run + ensure + ActiveSupport::JSON::Encoding.time_precision = precision + end + + it 'uses the current time precision of ActiveSupport when not set' do + ActiveSupport::JSON::Encoding.time_precision = 6 + + expect(instance.time_precision).to eq 6 + end + + it 'uses the time precision that is set' do + instance.time_precision = 0 + ActiveSupport::JSON::Encoding.time_precision = 6 + + expect(instance.time_precision).to eq 0 + end + end + context Sequent::Core::BaseCommandHandler do class SpecHandler < Sequent::Core::BaseCommandHandler # rubocop:disable-next Lint/UselessMethodDefinition