active_data 1.1.6 → 1.1.7

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
  SHA256:
3
- metadata.gz: 8fb124e56b71b295485dcfb70315f109b89b4e48793343bd241ef6c70e0d6247
4
- data.tar.gz: 15adc0c5b026993a18a04a6cdc94dba0d76adafcac5aaffc1ec0e22f9a435975
3
+ metadata.gz: 5de412d5036c1e3192c87b9c7c7cc553cccaa5d53dc48adb32d992c3cf9fca25
4
+ data.tar.gz: 52c67fb161d13a2f7b4791f048c662962b2f0355b77fb8f10d434e6e5279692f
5
5
  SHA512:
6
- metadata.gz: 28aaf1fa3d6c7fb6604ae5b6e3bb380f78983aba6626e2b7981c4127f5b92ce991611d20f41f4901183d6e3f6a9b2a2891197f94d7aecef6685befc7afbe56fa
7
- data.tar.gz: 7547903a22f346ca54d5a3cc8227b1bb3bb19256f5966e6610f3a1ca8ea06952beeb16cb687ddfa00bd1f54d6b6b20f1d314eca72b47b213318d6a323aae011d
6
+ metadata.gz: a804cb81e49839e78dbd9de0bd7c670bfde5b34c46651009f15bc70b890edae3a2148d0fd48251179fe83068769c6ddb950969cb2f8eb06b116e1c184d2724e2
7
+ data.tar.gz: 6b8277845088785bb3a4cd95eb2c56882a7ece7c1cb395e04106717a1ec7ace440709b70c7bec9150be2c9b48626cbb458e8c6882ab01ac808067e428f1a55c3
@@ -49,6 +49,7 @@ Metrics/BlockLength:
49
49
  Metrics/ModuleLength:
50
50
  Exclude:
51
51
  - '**/*_spec.rb'
52
+ - 'lib/active_data.rb'
52
53
 
53
54
  Style/Alias:
54
55
  EnforcedStyle: prefer_alias_method
@@ -1,5 +1,9 @@
1
1
  # master
2
2
 
3
+ # Version 1.1.7
4
+
5
+ * Add typecasting from `ActionController::Parameters` to `Hash` (#73)
6
+
3
7
  # Version 1.1.6
4
8
 
5
9
  * Fix Ruby 2.6 deprecations (#72)
@@ -14,6 +14,7 @@ Gem::Specification.new do |gem|
14
14
  gem.require_paths = ['lib']
15
15
  gem.version = ActiveData::VERSION
16
16
 
17
+ gem.add_development_dependency 'actionpack', '>= 4.0'
17
18
  gem.add_development_dependency 'activerecord', '>= 4.0'
18
19
  gem.add_development_dependency 'appraisal'
19
20
  gem.add_development_dependency 'database_cleaner'
@@ -61,6 +61,16 @@ module ActiveData
61
61
  value
62
62
  end
63
63
  end
64
+ ActiveSupport.on_load :action_controller do
65
+ ActiveData.typecaster('Hash') do |value|
66
+ case value
67
+ when ActionController::Parameters
68
+ value.to_h if value.permitted?
69
+ when ::Hash then
70
+ value
71
+ end
72
+ end
73
+ end
64
74
  typecaster('Date') do |value|
65
75
  begin
66
76
  value.to_date
@@ -1,3 +1,3 @@
1
1
  module ActiveData
2
- VERSION = '1.1.6'.freeze
2
+ VERSION = '1.1.7'.freeze
3
3
  end
@@ -58,9 +58,48 @@ describe ActiveData::Model::Attributes::Attribute do
58
58
  end
59
59
 
60
60
  describe '#typecast' do
61
- specify { expect(attribute.typecast(:hello)).to eq(:hello) }
62
- specify { expect(attribute(type: Integer).typecast(42)).to eq(42) }
63
- specify { expect(attribute(type: Integer).typecast('42')).to eq(42) }
61
+ context 'when Object' do
62
+ specify { expect(attribute.typecast(:hello)).to eq(:hello) }
63
+ end
64
+
65
+ context 'when Integer' do
66
+ specify { expect(attribute(type: Integer).typecast(42)).to eq(42) }
67
+ specify { expect(attribute(type: Integer).typecast('42')).to eq(42) }
68
+ end
69
+
70
+ context 'when Hash' do
71
+ let(:to_h) { {'x' => {'foo' => 'bar'}, 'y' => 2} }
72
+ let(:parameters) { ActionController::Parameters.new(to_h) }
73
+
74
+ before(:all) do
75
+ @default_hash_typecaster = ActiveData.typecaster('Hash')
76
+ require 'action_controller'
77
+ Class.new(ActionController::Base)
78
+ @action_controller_hash_typecaster = ActiveData.typecaster('Hash')
79
+ end
80
+
81
+ context 'when ActionController is loaded' do
82
+ before { ActiveData.typecaster('Hash', &@action_controller_hash_typecaster) }
83
+ after { ActiveData.typecaster('Hash', &@default_hash_typecaster) }
84
+
85
+ specify { expect(attribute(type: Hash).typecast(nil)).to be_nil }
86
+ specify { expect(attribute(type: Hash).typecast(to_h)).to eq(to_h) }
87
+ specify { expect(attribute(type: Hash).typecast(parameters)).to be_nil }
88
+ specify { expect(attribute(type: Hash).typecast(parameters.permit(:y, x: [:foo]))).to eq(to_h) }
89
+ end
90
+
91
+ context 'when ActionController is not loaded' do
92
+ before { ActiveData.typecaster('Hash', &@default_hash_typecaster) }
93
+
94
+ specify { expect(attribute(type: Hash).typecast(nil)).to be_nil }
95
+ specify { expect(attribute(type: Hash).typecast(to_h)).to eq(to_h) }
96
+ if ActiveSupport.version > Gem::Version.new('4.3')
97
+ specify { expect(attribute(type: Hash).typecast(parameters.permit(:y, x: [:foo]))).to be_nil }
98
+ else
99
+ specify { expect(attribute(type: Hash).typecast(parameters.permit(:y, x: [:foo]))).to eq(to_h) }
100
+ end
101
+ end
102
+ end
64
103
  end
65
104
 
66
105
  describe '#enum' do
@@ -4,6 +4,8 @@ Bundler.require
4
4
 
5
5
  require 'rspec/its'
6
6
  require 'active_record'
7
+ require 'rack/test'
8
+ require 'action_controller/metal/strong_parameters'
7
9
  require 'database_cleaner'
8
10
 
9
11
  require 'support/model_helpers'
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_data
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.6
4
+ version: 1.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - pyromaniac
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-11-13 00:00:00.000000000 Z
11
+ date: 2020-08-20 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: actionpack
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '4.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '4.0'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: activerecord
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -316,7 +330,7 @@ files:
316
330
  homepage: ''
317
331
  licenses: []
318
332
  metadata: {}
319
- post_install_message:
333
+ post_install_message:
320
334
  rdoc_options: []
321
335
  require_paths:
322
336
  - lib
@@ -331,8 +345,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
331
345
  - !ruby/object:Gem::Version
332
346
  version: '0'
333
347
  requirements: []
334
- rubygems_version: 3.0.6
335
- signing_key:
348
+ rubygems_version: 3.1.2
349
+ signing_key:
336
350
  specification_version: 4
337
351
  summary: Working with hashes in AR style
338
352
  test_files: