dry-initializer-rails 2.0.0 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -1
- data/dry-initializer-rails.gemspec +1 -1
- data/lib/dry/initializer/rails.rb +2 -2
- data/spec/dry/initializer/assignment_by_custom_key_spec.rb +6 -31
- data/spec/dry/initializer/assignment_by_id_spec.rb +7 -4
- data/spec/dry/initializer/assignment_by_nil_spec.rb +20 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6c6808d3a56d819ed0d0f450cf8d866e69cdcf0c
|
4
|
+
data.tar.gz: f7f9480365f3b68b1503eafbe8b57ecd6314bc1e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 605829836cc66781e67c0c2d2b4c299d5a4885ab9e9c0facb4f3e29d8c6e8a9c49e312ea661bf189f42d6e9374f4777ccb252f3d3ba1f86f5ef21443620428a9
|
7
|
+
data.tar.gz: e3801f23bddecf3dbb6959ddca18f0b4b52f5de3bb7b11867da5976a700872695e1ae842d885ce79f6cd3c1f62c65cf260b5ca58f4d560db433c36d67b206cd7
|
data/CHANGELOG.md
CHANGED
@@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
|
|
5
5
|
The format is based on [Keep a Changelog](http://keepachangelog.com/)
|
6
6
|
and this project adheres to [Semantic Versioning](http://semver.org/).
|
7
7
|
|
8
|
+
## [3.0.0] [2018-02-01]
|
9
|
+
|
10
|
+
### Changed
|
11
|
+
- take `nil` as is without trying to find a record (nepalez)
|
12
|
+
- raise `ActiveRecord::RecordNotFound` in case of absent key (nepalez)
|
13
|
+
|
8
14
|
## [2.0.0] [2018-02-01]
|
9
15
|
|
10
16
|
Update dependency to [dry-initializer] v2.4+ (nepalez)
|
@@ -30,4 +36,5 @@ First public release
|
|
30
36
|
[0.0.2]: https://github.com/nepalez/dry-initializer-rails/compare/v0.0.1...v0.0.2
|
31
37
|
[0.0.3]: https://github.com/nepalez/dry-initializer-rails/compare/v0.0.2...v0.0.3
|
32
38
|
[1.0.0]: https://github.com/nepalez/dry-initializer-rails/compare/v0.0.3...v1.0.0
|
33
|
-
[0.0
|
39
|
+
[2.0.0]: https://github.com/nepalez/dry-initializer-rails/compare/v1.0.0...v2.0.0
|
40
|
+
[3.0.0]: https://github.com/nepalez/dry-initializer-rails/compare/v2.0.0...v3.0.0
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |gem|
|
2
2
|
gem.name = "dry-initializer-rails"
|
3
|
-
gem.version = "
|
3
|
+
gem.version = "3.0.0"
|
4
4
|
gem.author = ["Vladimir Kochnev (marshall-lee)", "Andrew Kozin (nepalez)"]
|
5
5
|
gem.email = ["andrew.kozin@gmail.com"]
|
6
6
|
gem.homepage = "https://github.com/nepalez/dry-initializer-rails"
|
@@ -7,8 +7,8 @@ rails_dispatcher = lambda do |model: nil, find_by: :id, **options|
|
|
7
7
|
|
8
8
|
model = model.constantize if model.is_a? String
|
9
9
|
coercer = lambda do |value|
|
10
|
-
return value if value.instance_of?
|
11
|
-
model.find_by
|
10
|
+
return value if value.nil? || value.instance_of?(model)
|
11
|
+
model.find_by! find_by => value
|
12
12
|
end
|
13
13
|
|
14
14
|
options.merge(type: coercer)
|
@@ -19,39 +19,14 @@ describe "assignment by custom key" do
|
|
19
19
|
expect(subject.product).to eql item
|
20
20
|
end
|
21
21
|
|
22
|
-
it "
|
23
|
-
|
22
|
+
it "raises when records are absent" do
|
23
|
+
Test::Order.new("Dude", product: "The thing")
|
24
24
|
|
25
|
-
expect(
|
26
|
-
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
context "with container syntax" do
|
31
|
-
before do
|
32
|
-
class Test::Order
|
33
|
-
include Dry::Initializer.define -> do
|
34
|
-
param :user, model: "User", find_by: "name"
|
35
|
-
option :product, model: Item, find_by: :name
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
let!(:user) { User.create name: "Dude" }
|
41
|
-
let!(:item) { Item.create name: "The thing" }
|
42
|
-
|
43
|
-
it "works when records are present" do
|
44
|
-
subject = Test::Order.new("Dude", product: "The thing")
|
45
|
-
|
46
|
-
expect(subject.user).to eql user
|
47
|
-
expect(subject.product).to eql item
|
48
|
-
end
|
49
|
-
|
50
|
-
it "works when records are absent" do
|
51
|
-
subject = Test::Order.new("Man", product: "Something strange")
|
25
|
+
expect { Test::Order.new("Man", product: "The thing") }
|
26
|
+
.to raise_error ActiveRecord::RecordNotFound
|
52
27
|
|
53
|
-
expect(
|
54
|
-
|
28
|
+
expect { Test::Order.new("Dude", product: "Something strange") }
|
29
|
+
.to raise_error ActiveRecord::RecordNotFound
|
55
30
|
end
|
56
31
|
end
|
57
32
|
end
|
@@ -18,10 +18,13 @@ describe "assignment by id" do
|
|
18
18
|
expect(subject.product).to eql item
|
19
19
|
end
|
20
20
|
|
21
|
-
it "
|
22
|
-
|
21
|
+
it "raises when records are absent" do
|
22
|
+
Test::Order.new(user.id, product: item.id)
|
23
23
|
|
24
|
-
expect(
|
25
|
-
|
24
|
+
expect { Test::Order.new(0, product: item) }
|
25
|
+
.to raise_error ActiveRecord::RecordNotFound
|
26
|
+
|
27
|
+
expect { Test::Order.new(user, product: 0) }
|
28
|
+
.to raise_error ActiveRecord::RecordNotFound
|
26
29
|
end
|
27
30
|
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
describe "assignment by model" do
|
2
|
+
before do
|
3
|
+
class Test::Order
|
4
|
+
extend Dry::Initializer
|
5
|
+
|
6
|
+
param :user, model: "User"
|
7
|
+
option :product, model: Item
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
let!(:user) { User.create name: "Dude" }
|
12
|
+
let!(:item) { Item.create name: "The thing" }
|
13
|
+
|
14
|
+
it "works" do
|
15
|
+
subject = Test::Order.new(nil, product: nil)
|
16
|
+
|
17
|
+
expect(subject.user).to be_nil
|
18
|
+
expect(subject.product).to be_nil
|
19
|
+
end
|
20
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dry-initializer-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 3.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Vladimir Kochnev (marshall-lee)
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2018-02-
|
12
|
+
date: 2018-02-03 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -135,6 +135,7 @@ files:
|
|
135
135
|
- spec/dry/initializer/assignment_by_custom_key_spec.rb
|
136
136
|
- spec/dry/initializer/assignment_by_id_spec.rb
|
137
137
|
- spec/dry/initializer/assignment_by_model_spec.rb
|
138
|
+
- spec/dry/initializer/assignment_by_nil_spec.rb
|
138
139
|
- spec/dry/initializer/base_syntax_spec.rb
|
139
140
|
- spec/dummy/Rakefile
|
140
141
|
- spec/dummy/app/models/item.rb
|
@@ -175,6 +176,7 @@ test_files:
|
|
175
176
|
- spec/dry/initializer/assignment_by_custom_key_spec.rb
|
176
177
|
- spec/dry/initializer/assignment_by_id_spec.rb
|
177
178
|
- spec/dry/initializer/assignment_by_model_spec.rb
|
179
|
+
- spec/dry/initializer/assignment_by_nil_spec.rb
|
178
180
|
- spec/dry/initializer/base_syntax_spec.rb
|
179
181
|
- spec/dummy/Rakefile
|
180
182
|
- spec/dummy/app/models/item.rb
|