diff --git a/lib/treasury/fields/base.rb b/lib/treasury/fields/base.rb index 4742748..a59afea 100644 --- a/lib/treasury/fields/base.rb +++ b/lib/treasury/fields/base.rb @@ -7,8 +7,6 @@ class Base include ActiveSupport::Callbacks extend Apress::Sources::Accessors - DEFAULT_BATCH_SIZE = 1000 - # пауза после обработки батча данных # позволяет снизить нагрузку на БД при инициализации, # за счет увеличения времени инициализации @@ -21,6 +19,8 @@ class Base class_attribute :_instance class_attribute :initialize_method + class_attribute :default_batch_size + self.default_batch_size = 1000 self.initialize_method = :offset @@ -69,7 +69,7 @@ def initialize(field_model) end def init_params - @batch_size = DEFAULT_BATCH_SIZE + @batch_size = field_params.fetch(:batch_size, self.class.default_batch_size) @batch_pause = DEFAULT_BATCH_PAUSE end @@ -543,7 +543,7 @@ def cached_state # Returns Hash. def field_params - field_model.params.with_indifferent_access || {} + (field_model.params || {}).with_indifferent_access end # Private: Возвращает префикс хранения для полей. diff --git a/lib/treasury/fields/company/base.rb b/lib/treasury/fields/company/base.rb index 12a53e2..191855d 100644 --- a/lib/treasury/fields/company/base.rb +++ b/lib/treasury/fields/company/base.rb @@ -9,18 +9,7 @@ class Base < Treasury::Fields::Base extract_attribute_name :company - BATCH_SIZE = 10_000 - - protected - - # Protected: Инициализирует параметры поля. - # - # Returns nothing. - - def init_params - super - self.batch_size = BATCH_SIZE - end + self.default_batch_size = 10_000 end end end diff --git a/lib/treasury/fields/product/base.rb b/lib/treasury/fields/product/base.rb index c82b7a2..0c6f643 100644 --- a/lib/treasury/fields/product/base.rb +++ b/lib/treasury/fields/product/base.rb @@ -9,18 +9,7 @@ class Base < Treasury::Fields::Base extract_attribute_name :product - BATCH_SIZE = 50_000 - - protected - - # Protected: Инициализирует параметры поля. - # - # Returns nothing. - - def init_params - super - self.batch_size = BATCH_SIZE - end + self.default_batch_size = 50_000 end end end diff --git a/lib/treasury/fields/user/base.rb b/lib/treasury/fields/user/base.rb index cb60dd1..0b79d16 100644 --- a/lib/treasury/fields/user/base.rb +++ b/lib/treasury/fields/user/base.rb @@ -9,18 +9,7 @@ class Base < Treasury::Fields::Base extract_attribute_name :user - BATCH_SIZE = 25_000 - - protected - - # Protected: Инициализирует параметры поля. - # - # Returns nothing. - - def init_params - super - self.batch_size = BATCH_SIZE - end + self.default_batch_size = 25_000 end end end diff --git a/spec/lib/treasury/fields/base_spec.rb b/spec/lib/treasury/fields/base_spec.rb index 7b2ffb0..f72fc4c 100644 --- a/spec/lib/treasury/fields/base_spec.rb +++ b/spec/lib/treasury/fields/base_spec.rb @@ -19,7 +19,7 @@ def self.value_as_integer(params) end describe TreasuryFieldsBase do - subject { described_class.new(nil) } + subject { described_class.new(build_stubbed(:'denormalization/field')) } context '#data_changed' do let(:chaged_objects) { [1, 2, 3] } diff --git a/treasury.gemspec b/treasury.gemspec index c8ccd29..7cd5d2b 100644 --- a/treasury.gemspec +++ b/treasury.gemspec @@ -32,7 +32,7 @@ Gem::Specification.new do |spec| spec.add_runtime_dependency 'oj', '>= 2.9.9' spec.add_development_dependency 'rspec-rails' - spec.add_development_dependency 'factory_girl_rails' + spec.add_development_dependency 'factory_girl_rails', '<= 4.8.0' spec.add_development_dependency 'apress-rspec' spec.add_development_dependency 'simplecov' spec.add_development_dependency 'combustion', '>= 0.5.3'