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 +4 -4
- data/.rubocop.yml +1 -0
- data/CHANGELOG.md +4 -0
- data/active_data.gemspec +1 -0
- data/lib/active_data.rb +10 -0
- data/lib/active_data/version.rb +1 -1
- data/spec/lib/active_data/model/attributes/attribute_spec.rb +42 -3
- data/spec/spec_helper.rb +2 -0
- metadata +20 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5de412d5036c1e3192c87b9c7c7cc553cccaa5d53dc48adb32d992c3cf9fca25
|
4
|
+
data.tar.gz: 52c67fb161d13a2f7b4791f048c662962b2f0355b77fb8f10d434e6e5279692f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a804cb81e49839e78dbd9de0bd7c670bfde5b34c46651009f15bc70b890edae3a2148d0fd48251179fe83068769c6ddb950969cb2f8eb06b116e1c184d2724e2
|
7
|
+
data.tar.gz: 6b8277845088785bb3a4cd95eb2c56882a7ece7c1cb395e04106717a1ec7ace440709b70c7bec9150be2c9b48626cbb458e8c6882ab01ac808067e428f1a55c3
|
data/.rubocop.yml
CHANGED
data/CHANGELOG.md
CHANGED
data/active_data.gemspec
CHANGED
@@ -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'
|
data/lib/active_data.rb
CHANGED
@@ -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
|
data/lib/active_data/version.rb
CHANGED
@@ -58,9 +58,48 @@ describe ActiveData::Model::Attributes::Attribute do
|
|
58
58
|
end
|
59
59
|
|
60
60
|
describe '#typecast' do
|
61
|
-
|
62
|
-
|
63
|
-
|
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
|
data/spec/spec_helper.rb
CHANGED
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.
|
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:
|
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.
|
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:
|