active_interaction 1.2.0 → 1.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1c1d5b914798cc9b8b70729d645f8ef4a0d4031f
4
- data.tar.gz: ae3a8b0db8afdd311a44d9c73e1fcb2788d11086
3
+ metadata.gz: 0b77e2393588e6b32887a4a38847e14b8f347191
4
+ data.tar.gz: ef3b09ab34ef2b7937a457f5cab2648f0cb7e8cc
5
5
  SHA512:
6
- metadata.gz: 95496b5a5f1b4d837b7d2e1231c38ae6522aac69fd0bcc5f5c70739f26428299e4aaf89d43791558b97c5f90b5e4e422b9ade2db76aec0371da27fcb078a9fa8
7
- data.tar.gz: 7fcb37ddb4a3bd9beb005401448304314a6996fe99c0b4e6ddcb1f684c456cd861fcfdaddc75aa7a7ff24571f1a52f2783406c6ff8af519d5295d6c1287df61d
6
+ metadata.gz: 5af88c5f9d4b7da0b6e6adc2039d393e0b2fdbac83268b28a8015dce6cf926ec59465201e298e90ce6f4a8f6cd77d5d3641bd787eaaaf0cd2e314646237f66c3
7
+ data.tar.gz: ebdfcf778480fa4874e04551d07cb2495df8845238d1b79868c0905c77e309f5c9130892c888c241786cf6d7d78b3b914d5bdf374ef513fb78b1e3c8dcd2fdba
data/CHANGELOG.md CHANGED
@@ -1,7 +1,13 @@
1
1
  # [Master][]
2
2
 
3
+ # [1.2.1][] (2014-05-02)
4
+
5
+ - Fix a bug that marked model inputs as invalid even if they returned true for
6
+ `object.is_a?(klass)`.
7
+
3
8
  # [1.2.0][] (2014-04-30)
4
9
 
10
+ - Add support for Rails-style date and time parameters like `date(1i)`.
5
11
  - Add a decimal filter.
6
12
  - Add support for disabling and modifying transactions through the
7
13
  `transaction` helper method.
@@ -193,7 +199,8 @@
193
199
 
194
200
  - Initial release.
195
201
 
196
- [master]: https://github.com/orgsync/active_interaction/compare/v1.2.0...master
202
+ [master]: https://github.com/orgsync/active_interaction/compare/v1.2.1...master
203
+ [1.2.1]: https://github.com/orgsync/active_interaction/compare/v1.2.0...v1.2.1
197
204
  [1.2.0]: https://github.com/orgsync/active_interaction/compare/v1.1.7...v1.2.0
198
205
  [1.1.7]: https://github.com/orgsync/active_interaction/compare/v1.1.6...v1.1.7
199
206
  [1.1.6]: https://github.com/orgsync/active_interaction/compare/v1.1.5...v1.1.6
@@ -37,6 +37,8 @@ require 'active_interaction/filters/time_filter'
37
37
 
38
38
  require 'active_interaction/base'
39
39
 
40
+ require 'active_interaction/backports'
41
+
40
42
  I18n.load_path << File.expand_path(
41
43
  File.join(%w[active_interaction locale en.yml]), File.dirname(__FILE__))
42
44
 
@@ -47,5 +49,5 @@ I18n.load_path << File.expand_path(
47
49
  #
48
50
  # @since 1.0.0
49
51
  #
50
- # @version 1.2.0
52
+ # @version 1.2.1
51
53
  module ActiveInteraction end
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+
3
+ # rubocop:disable Documentation
4
+ module ActiveInteraction
5
+ class GroupedInput
6
+ # Required for Ruby <= 1.9.3.
7
+ def [](name)
8
+ send(name)
9
+ end unless method_defined?(:[])
10
+
11
+ # Required for Ruby <= 1.9.3.
12
+ def []=(name, value)
13
+ send("#{name}=", value)
14
+ end unless method_defined?(:[]=)
15
+ end
16
+ end
17
+
18
+ # @private
19
+ class Hash
20
+ # Required for Rails <= 4.0.2.
21
+ def transform_keys
22
+ result = {}
23
+ each_key do |key|
24
+ result[yield(key)] = self[key]
25
+ end
26
+ result
27
+ end unless method_defined?(:transform_keys)
28
+ end
@@ -73,14 +73,8 @@ module ActiveInteraction
73
73
  options.fetch(:strip, true)
74
74
  end
75
75
 
76
- # Switch to `transform_keys` once we support only Rails 4.0.2+
77
76
  def stringify_the_symbol_keys(hash)
78
- new_hash = {}
79
- hash.each_key do |key|
80
- new_key = key.is_a?(Symbol) ? key.to_s : key
81
- new_hash[new_key] = hash[key]
82
- end
83
- new_hash
77
+ hash.transform_keys { |key| key.is_a?(Symbol) ? key.to_s : key }
84
78
  end
85
79
  end
86
80
  end
@@ -19,8 +19,9 @@ module ActiveInteraction
19
19
  # @private
20
20
  class ModelFilter < Filter
21
21
  def cast(value, reconstantize = true)
22
- case value
23
- when @klass ||= klass
22
+ @klass ||= klass
23
+
24
+ if matches?(value)
24
25
  value
25
26
  else
26
27
  return super(value) unless reconstantize
@@ -41,5 +42,13 @@ module ActiveInteraction
41
42
  rescue NameError
42
43
  raise InvalidClassError, klass_name.inspect
43
44
  end
45
+
46
+ # @param value [Object]
47
+ #
48
+ # @return [Boolean]
49
+ def matches?(value)
50
+ @klass === value || # rubocop:disable CaseEquality
51
+ value.is_a?(@klass)
52
+ end
44
53
  end
45
54
  end
@@ -9,16 +9,5 @@ module ActiveInteraction
9
9
  #
10
10
  # @private
11
11
  class GroupedInput < OpenStruct
12
- unless method_defined?(:[])
13
- def [](name)
14
- send(name)
15
- end
16
- end
17
-
18
- unless method_defined?(:[]=)
19
- def []=(name, value)
20
- send("#{name}=", value)
21
- end
22
- end
23
12
  end
24
13
  end
@@ -5,5 +5,5 @@ module ActiveInteraction
5
5
  # The version number.
6
6
  #
7
7
  # @return [Gem::Version]
8
- VERSION = Gem::Version.new('1.2.0')
8
+ VERSION = Gem::Version.new('1.2.1')
9
9
  end
@@ -62,6 +62,40 @@ describe ActiveInteraction::ModelFilter, :filter do
62
62
  expect { filter }.to_not raise_error
63
63
  end
64
64
  end
65
+
66
+ context 'with bidirectional class comparisons' do
67
+ let(:case_equality) { false }
68
+ let(:class_equality) { false }
69
+
70
+ before do
71
+ allow(Model).to receive(:===).and_return(case_equality)
72
+ allow(value).to receive(:is_a?).and_return(class_equality)
73
+ end
74
+
75
+ context 'without case or class equality' do
76
+ it 'raises an error' do
77
+ expect do
78
+ result
79
+ end.to raise_error ActiveInteraction::InvalidValueError
80
+ end
81
+ end
82
+
83
+ context 'with case equality' do
84
+ let(:case_equality) { true }
85
+
86
+ it 'returns the instance' do
87
+ expect(result).to eql value
88
+ end
89
+ end
90
+
91
+ context 'with class equality' do
92
+ let(:class_equality) { true }
93
+
94
+ it 'returns the instance' do
95
+ expect(result).to eql value
96
+ end
97
+ end
98
+ end
65
99
  end
66
100
 
67
101
  context 'with class as a superclass' do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_interaction
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aaron Lasseigne
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-04-30 00:00:00.000000000 Z
12
+ date: 2014-05-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activemodel
@@ -155,6 +155,7 @@ files:
155
155
  - LICENSE.txt
156
156
  - README.md
157
157
  - lib/active_interaction.rb
158
+ - lib/active_interaction/backports.rb
158
159
  - lib/active_interaction/base.rb
159
160
  - lib/active_interaction/concerns/active_modelable.rb
160
161
  - lib/active_interaction/concerns/hashable.rb