From 721539469ed94ea4add5c740fa5af9b5a55eeb4d Mon Sep 17 00:00:00 2001 From: Taylor Fausak Date: Sun, 4 May 2014 09:22:08 -0500 Subject: [PATCH 01/27] Create Filter.register --- lib/active_interaction/filter.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lib/active_interaction/filter.rb b/lib/active_interaction/filter.rb index df04e296..6e9d82f4 100644 --- a/lib/active_interaction/filter.rb +++ b/lib/active_interaction/filter.rb @@ -82,6 +82,16 @@ def inherited(klass) rescue InvalidClassError CLASSES[klass.name.to_sym] = klass end + + private + + # @param slug [Symbol] + # @param klass [Class] + # + # @return [Class] + def register(slug, klass = self) + CLASSES[@slug = slug] = klass + end end # @param name [Symbol] From 27ec43c230cf94356dc42f9a4736b2b25e253f32 Mon Sep 17 00:00:00 2001 From: Taylor Fausak Date: Sun, 4 May 2014 09:24:29 -0500 Subject: [PATCH 02/27] Explicitly register filters --- lib/active_interaction/filters/array_filter.rb | 2 ++ lib/active_interaction/filters/boolean_filter.rb | 2 ++ lib/active_interaction/filters/date_filter.rb | 1 + lib/active_interaction/filters/date_time_filter.rb | 2 ++ lib/active_interaction/filters/decimal_filter.rb | 2 ++ lib/active_interaction/filters/file_filter.rb | 2 ++ lib/active_interaction/filters/float_filter.rb | 1 + lib/active_interaction/filters/hash_filter.rb | 2 ++ lib/active_interaction/filters/integer_filter.rb | 1 + lib/active_interaction/filters/model_filter.rb | 2 ++ lib/active_interaction/filters/string_filter.rb | 2 ++ lib/active_interaction/filters/symbol_filter.rb | 2 ++ lib/active_interaction/filters/time_filter.rb | 2 ++ 13 files changed, 23 insertions(+) diff --git a/lib/active_interaction/filters/array_filter.rb b/lib/active_interaction/filters/array_filter.rb index 6da7d698..624166c9 100644 --- a/lib/active_interaction/filters/array_filter.rb +++ b/lib/active_interaction/filters/array_filter.rb @@ -25,6 +25,8 @@ class Base class ArrayFilter < Filter include Missable + register :array + def cast(value) case value when Array diff --git a/lib/active_interaction/filters/boolean_filter.rb b/lib/active_interaction/filters/boolean_filter.rb index 75886a58..bb9c64c1 100644 --- a/lib/active_interaction/filters/boolean_filter.rb +++ b/lib/active_interaction/filters/boolean_filter.rb @@ -16,6 +16,8 @@ class Base # @private class BooleanFilter < Filter + register :boolean + def cast(value) case value when FalseClass, '0', /\Afalse\z/i diff --git a/lib/active_interaction/filters/date_filter.rb b/lib/active_interaction/filters/date_filter.rb index 0e8912ff..86ed8d54 100644 --- a/lib/active_interaction/filters/date_filter.rb +++ b/lib/active_interaction/filters/date_filter.rb @@ -19,5 +19,6 @@ class Base # @private class DateFilter < AbstractDateTimeFilter + register :date end end diff --git a/lib/active_interaction/filters/date_time_filter.rb b/lib/active_interaction/filters/date_time_filter.rb index a96d5b71..38ff752e 100644 --- a/lib/active_interaction/filters/date_time_filter.rb +++ b/lib/active_interaction/filters/date_time_filter.rb @@ -19,6 +19,8 @@ class Base # @private class DateTimeFilter < AbstractDateTimeFilter + register :date_time + def database_column_type :datetime end diff --git a/lib/active_interaction/filters/decimal_filter.rb b/lib/active_interaction/filters/decimal_filter.rb index e86b81d9..c8abfee2 100644 --- a/lib/active_interaction/filters/decimal_filter.rb +++ b/lib/active_interaction/filters/decimal_filter.rb @@ -17,6 +17,8 @@ class Base # @private class DecimalFilter < AbstractNumericFilter + register :decimal + def cast(value) case value when Numeric diff --git a/lib/active_interaction/filters/file_filter.rb b/lib/active_interaction/filters/file_filter.rb index 483341c1..33490218 100644 --- a/lib/active_interaction/filters/file_filter.rb +++ b/lib/active_interaction/filters/file_filter.rb @@ -16,6 +16,8 @@ class Base # @private class FileFilter < Filter + register :file + def cast(value) value = extract_file(value) diff --git a/lib/active_interaction/filters/float_filter.rb b/lib/active_interaction/filters/float_filter.rb index d59deed6..73bf8be3 100644 --- a/lib/active_interaction/filters/float_filter.rb +++ b/lib/active_interaction/filters/float_filter.rb @@ -15,5 +15,6 @@ class Base # @private class FloatFilter < AbstractNumericFilter + register :float end end diff --git a/lib/active_interaction/filters/hash_filter.rb b/lib/active_interaction/filters/hash_filter.rb index 54cc3862..b3135ddb 100644 --- a/lib/active_interaction/filters/hash_filter.rb +++ b/lib/active_interaction/filters/hash_filter.rb @@ -27,6 +27,8 @@ class Base class HashFilter < Filter include Missable + register :hash + def cast(value) case value when Hash diff --git a/lib/active_interaction/filters/integer_filter.rb b/lib/active_interaction/filters/integer_filter.rb index c14a39c6..6272e8f0 100644 --- a/lib/active_interaction/filters/integer_filter.rb +++ b/lib/active_interaction/filters/integer_filter.rb @@ -15,5 +15,6 @@ class Base # @private class IntegerFilter < AbstractNumericFilter + register :integer end end diff --git a/lib/active_interaction/filters/model_filter.rb b/lib/active_interaction/filters/model_filter.rb index dbda155e..a99a6fb4 100644 --- a/lib/active_interaction/filters/model_filter.rb +++ b/lib/active_interaction/filters/model_filter.rb @@ -18,6 +18,8 @@ class Base # @private class ModelFilter < Filter + register :model + def cast(value, reconstantize = true) @klass ||= klass diff --git a/lib/active_interaction/filters/string_filter.rb b/lib/active_interaction/filters/string_filter.rb index 1ad934ad..64f19902 100644 --- a/lib/active_interaction/filters/string_filter.rb +++ b/lib/active_interaction/filters/string_filter.rb @@ -18,6 +18,8 @@ class Base # @private class StringFilter < Filter + register :string + def cast(value) case value when String diff --git a/lib/active_interaction/filters/symbol_filter.rb b/lib/active_interaction/filters/symbol_filter.rb index 7f1ea079..9af040e2 100644 --- a/lib/active_interaction/filters/symbol_filter.rb +++ b/lib/active_interaction/filters/symbol_filter.rb @@ -14,6 +14,8 @@ class Base # @private class SymbolFilter < Filter + register :symbol + def cast(value) case value when Symbol diff --git a/lib/active_interaction/filters/time_filter.rb b/lib/active_interaction/filters/time_filter.rb index bbcbe61a..0f6b30f8 100644 --- a/lib/active_interaction/filters/time_filter.rb +++ b/lib/active_interaction/filters/time_filter.rb @@ -21,6 +21,8 @@ class Base # @private class TimeFilter < AbstractDateTimeFilter + register :time + alias_method :_klass, :klass private :_klass From 860c7f375156b3445a1d008004ab38e0a7c19a31 Mon Sep 17 00:00:00 2001 From: Taylor Fausak Date: Sun, 4 May 2014 09:51:35 -0500 Subject: [PATCH 03/27] Don't rely on inheritance to register filters --- lib/active_interaction/filter.rb | 38 ++------------------------ spec/active_interaction/filter_spec.rb | 34 +++++++++-------------- spec/active_interaction/i18n_spec.rb | 3 -- 3 files changed, 16 insertions(+), 59 deletions(-) diff --git a/lib/active_interaction/filter.rb b/lib/active_interaction/filter.rb index 6e9d82f4..1dbbfe1d 100644 --- a/lib/active_interaction/filter.rb +++ b/lib/active_interaction/filter.rb @@ -12,10 +12,6 @@ module ActiveInteraction # Describes an input filter for an interaction. class Filter - # @return [Regexp] - CLASS_REGEXP = /\AActiveInteraction::([A-Z]\w*)Filter\z/ - private_constant :CLASS_REGEXP - # @return [Hash{Symbol => Class}] CLASSES = {} private_constant :CLASSES @@ -32,6 +28,9 @@ class Filter undef_method :hash class << self + # @return [Symbol] + attr_reader :slug + # Get the filter associated with a symbol. # # @example @@ -52,37 +51,6 @@ def factory(slug) CLASSES.fetch(slug) { fail MissingFilterError, slug.inspect } end - # Convert the class name into a short symbol. - # - # @example - # ActiveInteraction::BooleanFilter.slug - # # => :boolean - # @example - # ActiveInteraction::Filter.slug - # # => ActiveInteraction::InvalidClassError: ActiveInteraction::Filter - # - # @return [Symbol] - # - # @raise [InvalidClassError] If the filter doesn't have a valid slug. - # - # @see .factory - def slug - return @slug if defined?(@slug) - - match = name[CLASS_REGEXP, 1] - fail InvalidClassError, name unless match - @slug = match.underscore.to_sym - end - - # @param klass [Class] - # - # @private - def inherited(klass) - CLASSES[klass.slug] = klass - rescue InvalidClassError - CLASSES[klass.name.to_sym] = klass - end - private # @param slug [Symbol] diff --git a/spec/active_interaction/filter_spec.rb b/spec/active_interaction/filter_spec.rb index 87d9839d..a3f05215 100644 --- a/spec/active_interaction/filter_spec.rb +++ b/spec/active_interaction/filter_spec.rb @@ -2,11 +2,6 @@ require 'spec_helper' -module ActiveInteraction - class AbstractTestFilter < ActiveInteraction::Filter; end -end -class ATestFilter < ActiveInteraction::Filter; end - describe ActiveInteraction::Filter, :filter do include_context 'filters' @@ -16,33 +11,30 @@ class ATestFilter < ActiveInteraction::Filter; end end end - context ActiveInteraction::AbstractTestFilter do - it_behaves_like 'a filter' - - let(:described_class) { ActiveInteraction::AbstractTestFilter } + context 'with an unregistered subclass' do + let(:described_class) { Class.new(ActiveInteraction::Filter) } describe '.slug' do - it 'returns a slug representing the class' do - expect(described_class.slug).to eql :abstract_test + it 'is nil' do + expect(described_class.slug).to be_nil end end end - context ATestFilter do - let(:described_class) { ATestFilter } + context 'with a registered subclass' do + it_behaves_like 'a filter' - describe '.factory' do - it 'returns a Filter' do - expect(described_class.factory(described_class.name.to_sym)) - .to eql described_class + let(:described_class) do + s = slug + Class.new(ActiveInteraction::Filter) do + register s end end + let(:slug) { SecureRandom.hex.to_sym } describe '.slug' do - it 'raises an error' do - expect do - described_class.slug - end.to raise_error ActiveInteraction::InvalidClassError + it 'returns the registered slug' do + expect(described_class.slug).to eql slug end end end diff --git a/spec/active_interaction/i18n_spec.rb b/spec/active_interaction/i18n_spec.rb index def1dd4a..f1f8a04f 100644 --- a/spec/active_interaction/i18n_spec.rb +++ b/spec/active_interaction/i18n_spec.rb @@ -11,11 +11,8 @@ describe I18nInteraction do include_context 'interactions' - pattern = ActiveInteraction::Filter.const_get(:CLASS_REGEXP) TYPES = ActiveInteraction::Filter .const_get(:CLASSES) - .select { |_, filter| filter.name =~ pattern } - .reject { |_, filter| filter.name =~ /\bAbstract[A-Z]/ } .map { |slug, _| slug.to_s } shared_examples 'translation' do From ca7844a068837edfe244991b0e0c7ff26966fb21 Mon Sep 17 00:00:00 2001 From: Taylor Fausak Date: Sun, 4 May 2014 11:49:42 -0500 Subject: [PATCH 04/27] Load all translations Also set the default locale to English. This avoids an I18n deprecation warning. --- lib/active_interaction.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/active_interaction.rb b/lib/active_interaction.rb index 6b42bb42..d73a0069 100644 --- a/lib/active_interaction.rb +++ b/lib/active_interaction.rb @@ -39,8 +39,9 @@ require 'active_interaction/backports' -I18n.load_path << File.expand_path( - File.join(%w[active_interaction locale en.yml]), File.dirname(__FILE__)) +I18n.load_path += Dir[File.expand_path( + File.join(%w[active_interaction locale *.yml]), File.dirname(__FILE__))] +I18n.default_locale = :en # Manage application specific business logic. # From ea893b8d8a9a1e4d514f239b79b50fda9d4c317a Mon Sep 17 00:00:00 2001 From: Taylor Fausak Date: Sun, 4 May 2014 18:28:30 -0500 Subject: [PATCH 05/27] Remove unnecessary klass parameter --- lib/active_interaction/filter.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/active_interaction/filter.rb b/lib/active_interaction/filter.rb index 1dbbfe1d..c450e978 100644 --- a/lib/active_interaction/filter.rb +++ b/lib/active_interaction/filter.rb @@ -57,8 +57,8 @@ def factory(slug) # @param klass [Class] # # @return [Class] - def register(slug, klass = self) - CLASSES[@slug = slug] = klass + def register(slug) + CLASSES[@slug = slug] = self end end From 08d72b7b10607eb638572aa41c6674ffecddecd2 Mon Sep 17 00:00:00 2001 From: Taylor Fausak Date: Sun, 4 May 2014 18:39:39 -0500 Subject: [PATCH 06/27] Fix deprecation warning Warning: Deprecated pattern style '.../tmp/*' in .../.rubocop.yml --- .rubocop.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.rubocop.yml b/.rubocop.yml index 99ca8006..43c5fb3d 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -2,7 +2,7 @@ AlignParameters: EnforcedStyle: with_fixed_indentation AllCops: Exclude: - - tmp/* + - tmp/**/* HandleExceptions: Enabled: false NonNilCheck: From de5b524d947cf8eba5160a7d32f8b02898ab93d9 Mon Sep 17 00:00:00 2001 From: Taylor Fausak Date: Wed, 7 May 2014 13:21:51 -0500 Subject: [PATCH 07/27] Fix name of error in error_args This essentially prevented the :invalid_nested from working. I messed this up in d99504983e24c1a5f6a10066cf39abb2ee026744. --- lib/active_interaction/modules/validation.rb | 2 +- .../modules/validation_spec.rb | 19 ++++++++++++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/lib/active_interaction/modules/validation.rb b/lib/active_interaction/modules/validation.rb index 3e50a321..4cb8b885 100644 --- a/lib/active_interaction/modules/validation.rb +++ b/lib/active_interaction/modules/validation.rb @@ -26,7 +26,7 @@ def error_args(filter, error) case error when InvalidNestedValueError [filter.name, :invalid_nested, nil, - name: e.filter_name.inspect, value: e.input_value.inspect] + name: error.filter_name.inspect, value: error.input_value.inspect] when InvalidValueError [filter.name, :invalid_type, nil, type: type(filter)] when MissingValueError diff --git a/spec/active_interaction/modules/validation_spec.rb b/spec/active_interaction/modules/validation_spec.rb index 90b4f694..7612c5f8 100644 --- a/spec/active_interaction/modules/validation_spec.rb +++ b/spec/active_interaction/modules/validation_spec.rb @@ -49,10 +49,27 @@ context 'MissingValueError' do let(:exception) { ActiveInteraction::MissingValueError } - it 'returns an :msising error' do + it 'returns a :missing error' do expect(result).to eql [[filter.name, :missing]] end end + + context 'InvalidNestedValueError' do + let(:exception) do + ActiveInteraction::InvalidNestedValueError.new(name, value) + end + let(:name) { SecureRandom.hex.to_sym } + let(:value) { double } + + it 'returns an :invalid_nested error' do + expect(result).to eql [[ + filter.name, + :invalid_nested, + nil, + { name: name.inspect, value: value.inspect } + ]] + end + end end end end From 01f4366c24f2fc15fa01b8ed1770e737bb5afbc9 Mon Sep 17 00:00:00 2001 From: Taylor Fausak Date: Wed, 7 May 2014 13:30:37 -0500 Subject: [PATCH 08/27] Update changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index ff214e64..d5d4ae43 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ # [Master][] +- Fix a bug that raised `NameError`s when there were invalid nested hash + errors. - Add missing translation for symbol filters. # [1.2.1][] (2014-05-02) From e209650a895fbc007e7f6a6548e68cbcc33042d6 Mon Sep 17 00:00:00 2001 From: Taylor Fausak Date: Wed, 7 May 2014 13:31:36 -0500 Subject: [PATCH 09/27] Bump version to 1.2.2 --- CHANGELOG.md | 5 ++++- lib/active_interaction.rb | 2 +- lib/active_interaction/version.rb | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d5d4ae43..929c6936 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ # [Master][] +# [1.2.2][] (2014-05-07) + - Fix a bug that raised `NameError`s when there were invalid nested hash errors. - Add missing translation for symbol filters. @@ -203,7 +205,8 @@ - Initial release. - [master]: https://github.com/orgsync/active_interaction/compare/v1.2.1...master + [master]: https://github.com/orgsync/active_interaction/compare/v1.2.2...master + [1.2.2]: https://github.com/orgsync/active_interaction/compare/v1.2.1...v1.2.2 [1.2.1]: https://github.com/orgsync/active_interaction/compare/v1.2.0...v1.2.1 [1.2.0]: https://github.com/orgsync/active_interaction/compare/v1.1.7...v1.2.0 [1.1.7]: https://github.com/orgsync/active_interaction/compare/v1.1.6...v1.1.7 diff --git a/lib/active_interaction.rb b/lib/active_interaction.rb index d73a0069..6a15c4b1 100644 --- a/lib/active_interaction.rb +++ b/lib/active_interaction.rb @@ -50,5 +50,5 @@ # # @since 1.0.0 # -# @version 1.2.1 +# @version 1.2.2 module ActiveInteraction end diff --git a/lib/active_interaction/version.rb b/lib/active_interaction/version.rb index 98904f73..15194530 100644 --- a/lib/active_interaction/version.rb +++ b/lib/active_interaction/version.rb @@ -5,5 +5,5 @@ module ActiveInteraction # The version number. # # @return [Gem::Version] - VERSION = Gem::Version.new('1.2.1') + VERSION = Gem::Version.new('1.2.2') end From b16dcc5e36e7ed7cac323642163fa7f70f9cf584 Mon Sep 17 00:00:00 2001 From: Taylor Fausak Date: Sat, 10 May 2014 09:00:14 -0500 Subject: [PATCH 10/27] Update to Ruby 2.1.2 --- Vagrantfile | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/Vagrantfile b/Vagrantfile index 0f20011f..45a293fc 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -1,4 +1,4 @@ -# Vagrant 1.5.4 +# Vagrant 1.6.1 # VirtualBox 4.3.10 Vagrant.require_version '~> 1.5' @@ -13,14 +13,14 @@ Vagrant.configure('2') do |config| set -e -x apt-get update apt-get install --assume-yes libffi-dev make - if ! ruby --version | grep --fixed-strings 2.1.1p76; then - test -f ruby-2.1.1.tar.bz2 || - wget cache.ruby-lang.org/pub/ruby/2.1/ruby-2.1.1.tar.bz2 - test -f ruby-2.1.1.tar || - bunzip2 --keep ruby-2.1.1.tar.bz2 - test -d ruby-2.1.1 || - tar --extract --file ruby-2.1.1.tar - cd ruby-2.1.1 + if ! ruby --version | grep --fixed-strings 2.1.2; then + test -f ruby-2.1.2.tar.bz2 || + wget cache.ruby-lang.org/pub/ruby/2.1/ruby-2.1.2.tar.bz2 + test -f ruby-2.1.2.tar || + bunzip2 --keep ruby-2.1.2.tar.bz2 + test -d ruby-2.1.2 || + tar --extract --file ruby-2.1.2.tar + cd ruby-2.1.2 ./configure --disable-install-doc make make install From 265c1808cb71b653eb6cd6511eae43a64a8a7cc8 Mon Sep 17 00:00:00 2001 From: Taylor Fausak Date: Mon, 12 May 2014 16:03:59 -0500 Subject: [PATCH 11/27] Fix #192; only roll back if in a transaction --- lib/active_interaction/concerns/runnable.rb | 2 +- .../concerns/runnable_spec.rb | 18 +++++++++++++++--- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/lib/active_interaction/concerns/runnable.rb b/lib/active_interaction/concerns/runnable.rb index a85c4a07..8fb66336 100644 --- a/lib/active_interaction/concerns/runnable.rb +++ b/lib/active_interaction/concerns/runnable.rb @@ -88,7 +88,7 @@ def run rescue Interrupt => interrupt merge_errors_onto_base(interrupt.outcome.errors) - raise ActiveRecord::Rollback + raise ActiveRecord::Rollback if self.class.transaction? end end end diff --git a/spec/active_interaction/concerns/runnable_spec.rb b/spec/active_interaction/concerns/runnable_spec.rb index 5dff01df..1f54973d 100644 --- a/spec/active_interaction/concerns/runnable_spec.rb +++ b/spec/active_interaction/concerns/runnable_spec.rb @@ -179,12 +179,11 @@ context 'with an execute where composition fails' do before do - CompositionFailure = Class.new(ActiveInteraction::Base) do + interaction = Class.new(TestInteraction) do validate { errors.add(:base) } - def execute; end end - klass.send(:define_method, :execute) { compose(CompositionFailure) } + klass.send(:define_method, :execute) { compose(interaction) } end it 'rolls back the transaction' do @@ -195,6 +194,19 @@ def execute; end expect(instance).to have_received(:raise) .with(ActiveRecord::Rollback) end + + context 'without a transaction' do + before { klass.transaction(false) } + + it 'does not roll back' do + instance = klass.new + + allow(instance).to receive(:raise) + instance.send(:run) + expect(instance).to_not have_received(:raise) + .with(ActiveRecord::Rollback) + end + end end context 'with invalid post-execution state' do From de6f85e986217d35b32357cfd0a0dcb597603fa8 Mon Sep 17 00:00:00 2001 From: Taylor Fausak Date: Mon, 12 May 2014 16:08:36 -0500 Subject: [PATCH 12/27] Update changelog --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 929c6936..ac628bd5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # [Master][] +- Fix a bug that raised `ActiveRecord::Rollback` when composing even when not + in a transaction. + # [1.2.2][] (2014-05-07) - Fix a bug that raised `NameError`s when there were invalid nested hash From 46a9b0f0389830fa769c2c33c9fd017965ae83b6 Mon Sep 17 00:00:00 2001 From: Taylor Fausak Date: Mon, 12 May 2014 16:18:13 -0500 Subject: [PATCH 13/27] Bump version to 1.2.3 --- CHANGELOG.md | 5 ++++- lib/active_interaction.rb | 2 +- lib/active_interaction/version.rb | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ac628bd5..47c072cd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ # [Master][] +# [1.2.3][] (2014-05-12) + - Fix a bug that raised `ActiveRecord::Rollback` when composing even when not in a transaction. @@ -208,7 +210,8 @@ - Initial release. - [master]: https://github.com/orgsync/active_interaction/compare/v1.2.2...master + [master]: https://github.com/orgsync/active_interaction/compare/v1.2.3...master + [1.2.3]: https://github.com/orgsync/active_interaction/compare/v1.2.2...v1.2.3 [1.2.2]: https://github.com/orgsync/active_interaction/compare/v1.2.1...v1.2.2 [1.2.1]: https://github.com/orgsync/active_interaction/compare/v1.2.0...v1.2.1 [1.2.0]: https://github.com/orgsync/active_interaction/compare/v1.1.7...v1.2.0 diff --git a/lib/active_interaction.rb b/lib/active_interaction.rb index 6a15c4b1..bd1e0526 100644 --- a/lib/active_interaction.rb +++ b/lib/active_interaction.rb @@ -50,5 +50,5 @@ # # @since 1.0.0 # -# @version 1.2.2 +# @version 1.2.3 module ActiveInteraction end diff --git a/lib/active_interaction/version.rb b/lib/active_interaction/version.rb index 15194530..d075c645 100644 --- a/lib/active_interaction/version.rb +++ b/lib/active_interaction/version.rb @@ -5,5 +5,5 @@ module ActiveInteraction # The version number. # # @return [Gem::Version] - VERSION = Gem::Version.new('1.2.2') + VERSION = Gem::Version.new('1.2.3') end From fdf7536fb835c9faf320d815ac88f5bbeaae3cb2 Mon Sep 17 00:00:00 2001 From: Taylor Fausak Date: Mon, 19 May 2014 08:37:52 -0500 Subject: [PATCH 14/27] Re #190; fix Rubinius build --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index da604e4d..67e86b46 100644 --- a/.travis.yml +++ b/.travis.yml @@ -16,4 +16,4 @@ rvm: - 2.0.0 - 1.9.3 - jruby -- rbx +- rbx-2 From 898047f7d0b45392dc47a221237a0f0a0c8417a5 Mon Sep 17 00:00:00 2001 From: Taylor Fausak Date: Mon, 19 May 2014 08:38:51 -0500 Subject: [PATCH 15/27] Don't specify patch levels for Ruby versions --- .travis.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 67e86b46..76aba087 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,8 +12,8 @@ notifications: ivR5nEELqEsDgDZAcKGJtRgp70d6Geg5iFUfV9aP1ySy2U0AXBM=' rvm: -- 2.1.1 -- 2.0.0 -- 1.9.3 +- 2.1 +- 2.0 +- 1.9 - jruby - rbx-2 From 384d50704b03fb833a5a1d68cafee0dbc7f5635e Mon Sep 17 00:00:00 2001 From: Taylor Fausak Date: Mon, 19 May 2014 08:39:14 -0500 Subject: [PATCH 16/27] Use correct key --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 76aba087..deb9564e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,5 @@ before_install: gem update bundler -gemfiles: +gemfile: - Gemfile - gemfiles/activemodel3.rb language: ruby From 94f049c5ec8043cceee6121e7c0530c8aa1c2eb0 Mon Sep 17 00:00:00 2001 From: Taylor Fausak Date: Mon, 19 May 2014 09:52:40 -0500 Subject: [PATCH 17/27] Include the right thing --- spec/active_interaction/errors_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/active_interaction/errors_spec.rb b/spec/active_interaction/errors_spec.rb index f0969738..599eda1b 100644 --- a/spec/active_interaction/errors_spec.rb +++ b/spec/active_interaction/errors_spec.rb @@ -5,7 +5,7 @@ describe ActiveInteraction::Errors do let(:klass) do Class.new do - include ActiveModel::Model + include ActiveInteraction::ActiveModelable attr_reader :attribute From 61f807016bbd2ac774ba89bc14f1b3ef1b1be5fb Mon Sep 17 00:00:00 2001 From: Taylor Fausak Date: Mon, 19 May 2014 10:20:44 -0500 Subject: [PATCH 18/27] Require BigDecimal This should help with the broken build. https://travis-ci.org/orgsync/active_interaction/jobs/25522400 --- lib/active_interaction/filters/decimal_filter.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/active_interaction/filters/decimal_filter.rb b/lib/active_interaction/filters/decimal_filter.rb index c8abfee2..e547dc20 100644 --- a/lib/active_interaction/filters/decimal_filter.rb +++ b/lib/active_interaction/filters/decimal_filter.rb @@ -1,5 +1,7 @@ # coding: utf-8 +require 'bigdecimal' + module ActiveInteraction class Base # @!method self.decimal(*attributes, options = {}) From f1c82758c19f5801f2b3988e2dd4c7abd6d45617 Mon Sep 17 00:00:00 2001 From: Taylor Fausak Date: Mon, 19 May 2014 14:05:13 -0500 Subject: [PATCH 19/27] Fix Model filter integration test I'm not sure why it was broken with ActiveModel ~> 3.0. This fixes it, though. --- spec/active_interaction/integration/model_interaction_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/active_interaction/integration/model_interaction_spec.rb b/spec/active_interaction/integration/model_interaction_spec.rb index f64bcaf6..d31f0736 100644 --- a/spec/active_interaction/integration/model_interaction_spec.rb +++ b/spec/active_interaction/integration/model_interaction_spec.rb @@ -3,5 +3,5 @@ require 'spec_helper' describe 'ModelInteraction' do - it_behaves_like 'an interaction', :model, -> { Object }, class: Class + it_behaves_like 'an interaction', :model, -> { // }, class: Regexp end From 2d45038af170cfd2dc502b33ffe62a9fdd1b0453 Mon Sep 17 00:00:00 2001 From: Taylor Fausak Date: Mon, 19 May 2014 14:46:26 -0500 Subject: [PATCH 20/27] Use Module.const_get instead of String#constantize This fixes an incompatibility between major versions of Rails. # Rails 3.2 >> ''.constantize => Object # Rails 4.1 >> ''.constantize NameError: wrong constant name --- lib/active_interaction/filters/abstract_filter.rb | 2 +- lib/active_interaction/filters/model_filter.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/active_interaction/filters/abstract_filter.rb b/lib/active_interaction/filters/abstract_filter.rb index 69c4e69a..eb7a9989 100644 --- a/lib/active_interaction/filters/abstract_filter.rb +++ b/lib/active_interaction/filters/abstract_filter.rb @@ -12,7 +12,7 @@ class AbstractFilter < Filter # @return [Class] def klass - @klass ||= self.class.slug.to_s.camelize.constantize + @klass ||= Object.const_get(self.class.slug.to_s.camelize, false) end end end diff --git a/lib/active_interaction/filters/model_filter.rb b/lib/active_interaction/filters/model_filter.rb index a99a6fb4..083c68aa 100644 --- a/lib/active_interaction/filters/model_filter.rb +++ b/lib/active_interaction/filters/model_filter.rb @@ -40,7 +40,7 @@ def cast(value, reconstantize = true) # @raise [InvalidClassError] def klass klass_name = options.fetch(:class, name).to_s.classify - klass_name.constantize + Object.const_get(klass_name) rescue NameError raise InvalidClassError, klass_name.inspect end From 700deee67bcd701261b2e6922efb166a96ed0c2b Mon Sep 17 00:00:00 2001 From: Taylor Fausak Date: Mon, 19 May 2014 15:09:35 -0500 Subject: [PATCH 21/27] Fix version in comment --- lib/active_interaction/backports.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_interaction/backports.rb b/lib/active_interaction/backports.rb index fd57725b..4070298f 100644 --- a/lib/active_interaction/backports.rb +++ b/lib/active_interaction/backports.rb @@ -17,7 +17,7 @@ def []=(name, value) # @private class Hash - # Required for Rails <= 4.0.2. + # Required for Rails < 4.0.0. def transform_keys result = {} each_key do |key| From 900342262ac65d4db4dc7255424ac209f6f24e31 Mon Sep 17 00:00:00 2001 From: Taylor Fausak Date: Mon, 19 May 2014 15:20:13 -0500 Subject: [PATCH 22/27] Fix Error#initialize_dup for Rails < 3.2.13 --- lib/active_interaction/backports.rb | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/active_interaction/backports.rb b/lib/active_interaction/backports.rb index 4070298f..0793a584 100644 --- a/lib/active_interaction/backports.rb +++ b/lib/active_interaction/backports.rb @@ -13,6 +13,11 @@ def []=(name, value) send("#{name}=", value) end unless method_defined?(:[]=) end + + class Errors + # Required for Rails < 3.2.13. + protected :initialize_dup + end end # @private From cd10dc6e233545b101935b045435ff905e776e97 Mon Sep 17 00:00:00 2001 From: Taylor Fausak Date: Mon, 19 May 2014 15:26:24 -0500 Subject: [PATCH 23/27] Require activemodel >= 3.2 --- active_interaction.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/active_interaction.gemspec b/active_interaction.gemspec index ffda5ad4..242d4922 100644 --- a/active_interaction.gemspec +++ b/active_interaction.gemspec @@ -27,7 +27,7 @@ Gem::Specification.new do |spec| # Dependencies spec.required_ruby_version = '>= 1.9.3' - spec.add_dependency 'activemodel', '>= 3', '< 5' + spec.add_dependency 'activemodel', '>= 3.2', '< 5' spec.add_development_dependency 'bundler', '~> 1.6' spec.add_development_dependency 'coveralls', '~> 0.7' From d66d81cda9b667a1259372cf2654874070810b10 Mon Sep 17 00:00:00 2001 From: Taylor Fausak Date: Mon, 19 May 2014 15:28:58 -0500 Subject: [PATCH 24/27] Fix RSpec warnings --- spec/active_interaction/base_spec.rb | 31 ++++++++-------------------- 1 file changed, 9 insertions(+), 22 deletions(-) diff --git a/spec/active_interaction/base_spec.rb b/spec/active_interaction/base_spec.rb index 60d20776..b58ab55d 100644 --- a/spec/active_interaction/base_spec.rb +++ b/spec/active_interaction/base_spec.rb @@ -462,10 +462,8 @@ def filters(klass) end describe '.import_filters' do - shared_context 'import_filters context' do + shared_context 'import_filters context' do |only, except| let(:klass) { AddInteraction } - let(:only) { nil } - let(:except) { nil } let(:described_class) do interaction = klass @@ -477,8 +475,8 @@ def filters(klass) end end - shared_examples 'import_filters examples' do - include_context 'import_filters context' + shared_examples 'import_filters examples' do |only, except| + include_context 'import_filters context', only, except it 'imports the filters' do expect(described_class.filters).to eql klass.filters @@ -504,42 +502,31 @@ def filters(klass) end context 'with neither :only nor :except' do - include_examples 'import_filters examples' + include_examples 'import_filters examples', nil, nil end context 'with :only' do context 'as an Array' do - include_examples 'import_filters examples' - - let(:only) { [:x] } + include_examples 'import_filters examples', [:x], nil end context 'as an Symbol' do - include_examples 'import_filters examples' - - let(:only) { :x } + include_examples 'import_filters examples', :x, nil end end context 'with :except' do context 'as an Array' do - include_examples 'import_filters examples' - - let(:except) { [:x] } + include_examples 'import_filters examples', nil, [:x] end context 'as an Symbol' do - include_examples 'import_filters examples' - - let(:except) { :x } + include_examples 'import_filters examples', nil, :x end end context 'with :only & :except' do - include_examples 'import_filters examples' - - let(:only) { [:x] } - let(:except) { [:x] } + include_examples 'import_filters examples', [:x], [:x] end end end From 7927e86302e250029f0ebf6145761b701929ac5c Mon Sep 17 00:00:00 2001 From: Taylor Fausak Date: Mon, 19 May 2014 15:30:30 -0500 Subject: [PATCH 25/27] Fix I18n warning in the specs --- spec/spec_helper.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index f0a236bc..3bbb7439 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -3,6 +3,9 @@ require 'coveralls' Coveralls.wear! +require 'i18n' +I18n.config.enforce_available_locales = true + require 'active_interaction' Dir['./spec/support/**/*.rb'].each { |f| require f } @@ -12,5 +15,3 @@ config.run_all_when_everything_filtered = true config.filter_run_including :focus end - -I18n.config.enforce_available_locales = true From 72589c7b5662b573fa776b559dec25e675c46479 Mon Sep 17 00:00:00 2001 From: Taylor Fausak Date: Mon, 19 May 2014 16:12:12 -0500 Subject: [PATCH 26/27] Update Vagrant and VirtualBox version hints --- Vagrantfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Vagrantfile b/Vagrantfile index 45a293fc..85efadb8 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -1,5 +1,5 @@ -# Vagrant 1.6.1 -# VirtualBox 4.3.10 +# Vagrant 1.6.2 +# VirtualBox 4.3.12 Vagrant.require_version '~> 1.5' From 28086a8c37da70ed5c0ebdbae01ce8c6a1354d26 Mon Sep 17 00:00:00 2001 From: Taylor Fausak Date: Mon, 19 May 2014 16:12:24 -0500 Subject: [PATCH 27/27] Check for responsiveness before setting flag This is necessary only for Rails 3.2.13. --- spec/spec_helper.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 3bbb7439..a8f6d2db 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -4,7 +4,9 @@ Coveralls.wear! require 'i18n' -I18n.config.enforce_available_locales = true +if I18n.config.respond_to?(:enforce_available_locales) + I18n.config.enforce_available_locales = true +end require 'active_interaction'