disposable 0.4.3 → 0.5.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 +5 -5
- data/.github/workflows/ci.yml +29 -0
- data/.gitignore +1 -0
- data/CHANGES.md +23 -0
- data/Gemfile +5 -12
- data/README.md +2 -2
- data/disposable.gemspec +6 -9
- data/lib/disposable/rescheme.rb +1 -3
- data/lib/disposable/twin.rb +7 -0
- data/lib/disposable/twin/coercion.rb +11 -3
- data/lib/disposable/twin/default.rb +3 -3
- data/lib/disposable/twin/property/struct.rb +3 -1
- data/lib/disposable/twin/setup.rb +1 -1
- data/lib/disposable/twin/sync.rb +1 -1
- data/lib/disposable/version.rb +1 -1
- data/test/callback_group_test.rb +29 -30
- data/test/callbacks_test.rb +49 -49
- data/test/expose_test.rb +16 -16
- data/test/persisted_test.rb +30 -30
- data/test/rescheme_test.rb +22 -22
- data/test/skip_getter_test.rb +14 -14
- data/test/test_helper.rb +9 -6
- data/test/twin/builder_test.rb +3 -3
- data/test/twin/changed_test.rb +38 -38
- data/test/twin/coercion_test.rb +75 -38
- data/test/twin/collection_test.rb +48 -48
- data/test/twin/composition_test.rb +20 -20
- data/test/twin/default_test.rb +15 -15
- data/test/twin/expose_test.rb +15 -15
- data/test/twin/feature_test.rb +10 -10
- data/test/twin/from_collection_test.rb +4 -4
- data/test/twin/from_test.rb +3 -3
- data/test/twin/hash_test.rb +78 -31
- data/test/twin/inherit_test.rb +7 -7
- data/test/twin/inheritance_test.rb +6 -6
- data/test/twin/option_test.rb +1 -1
- data/test/twin/parent_test.rb +6 -6
- data/test/twin/property_processor_test.rb +5 -5
- data/test/twin/readable_test.rb +9 -9
- data/test/twin/save_test.rb +44 -44
- data/test/twin/setup_test.rb +25 -25
- data/test/twin/skip_unchanged_test.rb +6 -6
- data/test/twin/struct/coercion_test.rb +36 -0
- data/test/twin/struct_test.rb +41 -38
- data/test/twin/sync_option_test.rb +2 -2
- data/test/twin/sync_test.rb +29 -29
- data/test/twin/twin_test.rb +25 -15
- data/test/twin/unnest_test.rb +7 -7
- data/test/twin/virtual_test.rb +3 -3
- data/test/twin/writeable_test.rb +8 -8
- metadata +25 -57
- data/.travis.yml +0 -13
- data/gemfiles/Gemfile.rails-2.3 +0 -7
- data/gemfiles/Gemfile.rails-3.0 +0 -7
- data/gemfiles/Gemfile.rails-3.2 +0 -7
- data/gemfiles/Gemfile.rails-4.0 +0 -8
- data/gemfiles/Gemfile.rails-4.1 +0 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 0ee5b2f01534b1e0d6ce0390c3d7b082fcc9cf5ccbaea0bd554dcbb19d092e51
|
4
|
+
data.tar.gz: b905d21be9d1c94809b9de661698e4880a5a77d532473d7eacff000bca15befe
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e6a09f8afd4c405cd9e54f0581622bfdce3b4e5df0e5e958db01cb57a9d035acbb01ad67fb32cbe3ddb6f9dbc94155d08617ef8f77b686aafe0aa367bb887598
|
7
|
+
data.tar.gz: 555906bb352543b9f123cb891f8bfdb58ce98e9888a8b9f12333170cef13b56768c665272727d9f472f545a88f24b0d4561aea261acba18221b9aea31c8b52ea
|
@@ -0,0 +1,29 @@
|
|
1
|
+
name: CI
|
2
|
+
on: [push, pull_request]
|
3
|
+
jobs:
|
4
|
+
test:
|
5
|
+
strategy:
|
6
|
+
fail-fast: false
|
7
|
+
matrix:
|
8
|
+
ruby: [2.5, 2.6]
|
9
|
+
active_record: [5.0, 5.2, 6.0]
|
10
|
+
dry_types: [0.13, 0.14, 0.15, 1.0, 1.1, 1.2]
|
11
|
+
|
12
|
+
include:
|
13
|
+
- ruby: 2.7
|
14
|
+
active_record: 6.1
|
15
|
+
dry_types: 1.5
|
16
|
+
# Due to https://github.com/actions/runner/issues/849, we have to use quotes for '3.0'
|
17
|
+
- ruby: '3.0'
|
18
|
+
active_record: 6.1
|
19
|
+
dry_types: 1.5
|
20
|
+
|
21
|
+
runs-on: ubuntu-latest
|
22
|
+
steps:
|
23
|
+
- uses: actions/checkout@v2
|
24
|
+
- uses: ruby/setup-ruby@v1
|
25
|
+
with:
|
26
|
+
ruby-version: ${{ matrix.ruby }}
|
27
|
+
# bundler-cache: true # runs 'bundle install' and caches installed gems automatically
|
28
|
+
- run: ACTIVERECORD=${{ matrix.active_record}} DRY_TYPES=${{ matrix.dry_types }} bundle install
|
29
|
+
- run: ACTIVERECORD=${{ matrix.active_record}} DRY_TYPES=${{ matrix.dry_types }} bundle exec rake
|
data/.gitignore
CHANGED
data/CHANGES.md
CHANGED
@@ -1,3 +1,26 @@
|
|
1
|
+
# 0.5.0
|
2
|
+
|
3
|
+
* Upgrade `representable` to replace `Declarative::Option` with `Representable::Option` in order to support ruby-3 style of keyword arguments.
|
4
|
+
|
5
|
+
# 0.4.7
|
6
|
+
|
7
|
+
* Deprecation warning for nilify options for dry-v >= 1.x
|
8
|
+
* Fix initializer struct when using `false` as value
|
9
|
+
|
10
|
+
# 0.4.6
|
11
|
+
|
12
|
+
* Remove deprecation warnings for newer versions of dry-types
|
13
|
+
* Fix sqlite3 version to 1.3.x to avoid issue with AR 5.0
|
14
|
+
* Raise an error if class is used as property name
|
15
|
+
|
16
|
+
# 0.4.5
|
17
|
+
|
18
|
+
* Use Gem::Version to detect version for dry-types
|
19
|
+
|
20
|
+
# 0.4.4
|
21
|
+
|
22
|
+
* Add support for Dry::Types version 0.13
|
23
|
+
|
1
24
|
# 0.4.3
|
2
25
|
|
3
26
|
* Fix `NoMethodError: private method `property' called for MyForm:Class in Reform.` by using `class_eval`.
|
data/Gemfile
CHANGED
@@ -1,17 +1,10 @@
|
|
1
1
|
source "https://rubygems.org"
|
2
2
|
gemspec
|
3
|
-
|
4
|
-
# gem "representable", path: "../representable"
|
5
|
-
# gem "representable", "3.0.0"
|
6
|
-
# gem "representable", github: "apotonick/representable"
|
7
|
-
# gem "declarative", path: "../declarative"
|
8
|
-
# gem "declarative", github: "apotonick/declarative"
|
9
3
|
gem "minitest-line"
|
10
4
|
|
11
|
-
|
12
|
-
|
5
|
+
{ "dry-types" => ENV['DRY_TYPES'], "activerecord" => ENV['ACTIVERECORD']}.each do |gem_name, dependency|
|
6
|
+
next if dependency.nil?
|
7
|
+
gem gem_name, dependency
|
8
|
+
end
|
13
9
|
|
14
|
-
|
15
|
-
# gem "declarative-option", path: "../declarative-option"
|
16
|
-
# gem "declarative-builder", path: "../declarative-builder"
|
17
|
-
# gem "representable", path: "../representable"
|
10
|
+
gem "sqlite3", ENV.fetch('ACTIVERECORD', '5.2').to_f >= 6 ? '~> 1.4' : '~> 1.3.0'
|
data/README.md
CHANGED
@@ -181,7 +181,7 @@ property :artist, twin: TwinArtist
|
|
181
181
|
|
182
182
|
## Unnest
|
183
183
|
|
184
|
-
#todo: document
|
184
|
+
# todo: document
|
185
185
|
|
186
186
|
## Features
|
187
187
|
|
@@ -206,7 +206,7 @@ class AlbumTwin < Disposable::Twin
|
|
206
206
|
feature Coercion
|
207
207
|
feature Setup::SkipSetter
|
208
208
|
|
209
|
-
property :id, type: Types::
|
209
|
+
property :id, type: Types::Params::Integer
|
210
210
|
```
|
211
211
|
|
212
212
|
The `:type` option defines the coercion type. You may incluce `Setup::SkipSetter`, too, as otherwise the coercion will happen at initialization time and in the setter.
|
data/disposable.gemspec
CHANGED
@@ -13,21 +13,18 @@ Gem::Specification.new do |spec|
|
|
13
13
|
spec.license = "MIT"
|
14
14
|
|
15
15
|
spec.files = `git ls-files`.split($/)
|
16
|
-
spec.
|
17
|
-
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
16
|
+
spec.test_files = spec.files.grep(%r{^(test)/})
|
18
17
|
spec.require_paths = ["lib"]
|
19
18
|
|
20
19
|
spec.add_dependency "uber", "< 0.2.0"
|
21
20
|
spec.add_dependency "declarative", ">= 0.0.9", "< 1.0.0"
|
22
|
-
spec.add_dependency "declarative-builder", "
|
23
|
-
spec.add_dependency "
|
24
|
-
spec.add_dependency "representable", ">= 2.4.0", "<= 3.1.0"
|
21
|
+
spec.add_dependency "declarative-builder", "~> 0.2.0"
|
22
|
+
spec.add_dependency "representable", ">= 3.1.1", "< 3.2.0"
|
25
23
|
|
26
|
-
spec.add_development_dependency "bundler"
|
24
|
+
spec.add_development_dependency "bundler"#, "~> 1.3"
|
27
25
|
spec.add_development_dependency "rake"
|
28
26
|
spec.add_development_dependency "minitest"
|
29
|
-
spec.add_development_dependency "activerecord"
|
30
|
-
spec.add_development_dependency "
|
31
|
-
spec.add_development_dependency "dry-types", "~> 0.6"
|
27
|
+
spec.add_development_dependency "activerecord"#, "4.2.5"
|
28
|
+
spec.add_development_dependency "dry-types"# "~> 0.6"
|
32
29
|
# spec.add_development_dependency "database_cleaner"
|
33
30
|
end
|
data/lib/disposable/rescheme.rb
CHANGED
@@ -30,9 +30,7 @@ class Disposable::Rescheme
|
|
30
30
|
|
31
31
|
private
|
32
32
|
def build_representer(options)
|
33
|
-
Class.new(options[:superclass])
|
34
|
-
include *options[:include]
|
35
|
-
end
|
33
|
+
Class.new(options[:superclass]) { include(*options[:include]) }
|
36
34
|
end
|
37
35
|
|
38
36
|
def build_definition!(options, source_dfn, representer, &block)
|
data/lib/disposable/twin.rb
CHANGED
@@ -9,6 +9,9 @@ require "representable/decorator"
|
|
9
9
|
|
10
10
|
module Disposable
|
11
11
|
class Twin
|
12
|
+
class InvalidPropertyNameError < StandardError; end
|
13
|
+
INVALID_PROPERTY_NAMES = %i[class].freeze
|
14
|
+
|
12
15
|
extend Declarative::Schema
|
13
16
|
def self.definition_class
|
14
17
|
Definition
|
@@ -32,6 +35,10 @@ module Disposable
|
|
32
35
|
|
33
36
|
# TODO: move to Declarative, as in Representable and Reform.
|
34
37
|
def property(name, options={}, &block)
|
38
|
+
if INVALID_PROPERTY_NAMES.include?(name)
|
39
|
+
raise InvalidPropertyNameError.new("#{name} is used internally and cannot be used as property name")
|
40
|
+
end
|
41
|
+
|
35
42
|
options[:private_name] ||= options.delete(:from) || name
|
36
43
|
is_inherited = options.delete(:_inherited)
|
37
44
|
|
@@ -2,9 +2,14 @@ require "dry-types"
|
|
2
2
|
|
3
3
|
module Disposable::Twin::Coercion
|
4
4
|
module Types
|
5
|
-
|
5
|
+
# NOTE: Use Dry.Types() instead. Beware, it exports strict types by default, for old behavior use Dry.Types(default: :nominal)
|
6
|
+
DRY_MODULE = Gem::Version.new(Dry::Types::VERSION) < Gem::Version.new("0.15.0") ? Dry::Types.module : Dry.Types()
|
7
|
+
include DRY_MODULE
|
6
8
|
end
|
7
9
|
|
10
|
+
DRY_TYPES_VERSION = Gem::Version.new(Dry::Types::VERSION)
|
11
|
+
DRY_TYPES_CONSTANT = DRY_TYPES_VERSION < Gem::Version.new("0.13.0") ? Types::Form : Types::Params
|
12
|
+
|
8
13
|
module ClassMethods
|
9
14
|
def property(name, options={}, &block)
|
10
15
|
super(name, options, &block).tap do
|
@@ -13,11 +18,14 @@ module Disposable::Twin::Coercion
|
|
13
18
|
end
|
14
19
|
|
15
20
|
def coercing_setter!(name, type, nilify=false)
|
16
|
-
|
21
|
+
# TODO: remove nilily with next release (0.5) for new dry-type versions
|
22
|
+
type = type ? (DRY_TYPES_CONSTANT::Nil | type) : DRY_TYPES_CONSTANT::Nil if nilify
|
23
|
+
|
24
|
+
warn "DEPRECATION WARNING [Disposable]: nilify is deprecated and it will be removed with the next release" if nilify && DRY_TYPES_VERSION >= Gem::Version.new("1.0.0")
|
17
25
|
|
18
26
|
mod = Module.new do
|
19
27
|
define_method("#{name}=") do |value|
|
20
|
-
super type.
|
28
|
+
super type.(value)
|
21
29
|
end
|
22
30
|
end
|
23
31
|
include mod
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require "
|
1
|
+
require "representable/option"
|
2
2
|
|
3
3
|
# TODO: allow default: -> for hashes, etc.
|
4
4
|
module Disposable::Twin::Default
|
@@ -12,13 +12,13 @@ module Disposable::Twin::Default
|
|
12
12
|
# TODO: introduce Null object in Declarative::Definition#[].
|
13
13
|
# dfn[:default].(self) # dfn#[] should return a Null object here if empty.
|
14
14
|
return unless dfn[:default]
|
15
|
-
dfn[:default].(self)
|
15
|
+
dfn[:default].(exec_context: self) # Representable::Option#call
|
16
16
|
end
|
17
17
|
|
18
18
|
module ClassMethods
|
19
19
|
private
|
20
20
|
def build_definition(name, options={}, &block)
|
21
|
-
options = options.merge(default:
|
21
|
+
options = options.merge(default: ::Representable::Option(options[:default])) if options.has_key?(:default)
|
22
22
|
super
|
23
23
|
end
|
24
24
|
end
|
@@ -6,7 +6,9 @@ class Disposable::Twin
|
|
6
6
|
module Struct
|
7
7
|
def read_value_for(dfn, options)
|
8
8
|
name = dfn[:name]
|
9
|
-
|
9
|
+
# TODO: test sym vs. str.
|
10
|
+
return unless key_value = model.to_h.find { |k, _| k.to_sym == name.to_sym }
|
11
|
+
key_value.last
|
10
12
|
end
|
11
13
|
|
12
14
|
def sync_hash_representer # TODO: make this without representable, please.
|
data/lib/disposable/twin/sync.rb
CHANGED
@@ -22,7 +22,7 @@ class Disposable::Twin
|
|
22
22
|
def self.hash_representer(twin_class, &block)
|
23
23
|
Disposable::Rescheme.from(twin_class,
|
24
24
|
recursive: false,
|
25
|
-
definitions_from: lambda { |
|
25
|
+
definitions_from: lambda { |twin_klass| twin_klass.definitions },
|
26
26
|
superclass: Representable::Decorator,
|
27
27
|
include: Representable::Hash,
|
28
28
|
exclude_options: [:default], # TODO: TEST IN default_test.
|
data/lib/disposable/version.rb
CHANGED
data/test/callback_group_test.rb
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
require "test_helper"
|
2
2
|
require "disposable/callback"
|
3
|
-
require "pp"
|
4
3
|
|
5
4
|
class CallbackGroupTest < MiniTest::Spec
|
6
5
|
class Group < Disposable::Callback::Group
|
@@ -56,7 +55,7 @@ class CallbackGroupTest < MiniTest::Spec
|
|
56
55
|
album = Album.new(songs: [Song.new(title: "Dead To Me"), Song.new(title: "Diesel Boy")])
|
57
56
|
twin = AlbumTwin.new(album)
|
58
57
|
|
59
|
-
Group.new(twin).().invocations.must_equal [
|
58
|
+
expect(Group.new(twin).().invocations).must_equal [
|
60
59
|
[:on_change, :change!, []],
|
61
60
|
[:on_add, :notify_album!, []],
|
62
61
|
[:on_add, :reset_song!, []],
|
@@ -77,7 +76,7 @@ class CallbackGroupTest < MiniTest::Spec
|
|
77
76
|
|
78
77
|
group = Group.new(twin).(content: content)
|
79
78
|
|
80
|
-
group.invocations.must_equal [
|
79
|
+
expect(group.invocations).must_equal [
|
81
80
|
[:on_change, :change!, [twin]],
|
82
81
|
[:on_add, :notify_album!, [twin.songs[0], twin.songs[1]]],
|
83
82
|
[:on_add, :reset_song!, [twin.songs[0], twin.songs[1]]],
|
@@ -86,8 +85,8 @@ class CallbackGroupTest < MiniTest::Spec
|
|
86
85
|
[:on_update, :expire_cache!, []],
|
87
86
|
]
|
88
87
|
|
89
|
-
content.must_equal "notify_album!notify_album!reset_song!reset_song!"
|
90
|
-
group.output.must_equal "Album has changed!"
|
88
|
+
expect(content).must_equal "notify_album!notify_album!reset_song!reset_song!"
|
89
|
+
expect(group.output).must_equal "Album has changed!"
|
91
90
|
end
|
92
91
|
|
93
92
|
|
@@ -125,12 +124,12 @@ class CallbackGroupTest < MiniTest::Spec
|
|
125
124
|
|
126
125
|
twin.name = "Dear Landlord"
|
127
126
|
|
128
|
-
group = Group.new(twin).(context:
|
127
|
+
group = Group.new(twin).(context: Operation.new, content: content)
|
129
128
|
# Disposable::Callback::Dispatch.new(twin).on_change{ |twin| puts twin;puts }
|
130
129
|
|
131
130
|
# pp group.invocations
|
132
131
|
|
133
|
-
group.invocations.must_equal [
|
132
|
+
expect(group.invocations).must_equal [
|
134
133
|
[:on_change, :change!, [twin]],
|
135
134
|
[:on_add, :notify_album!, [twin.songs[0]]],
|
136
135
|
[:on_add, :reset_song!, [twin.songs[0]]],
|
@@ -139,7 +138,7 @@ class CallbackGroupTest < MiniTest::Spec
|
|
139
138
|
[:on_update, :expire_cache!, []],
|
140
139
|
]
|
141
140
|
|
142
|
-
content.must_equal "Op: changed! [CallbackGroupTest::Operation]Op: notify_album! [CallbackGroupTest::Operation]Op: reset_song! [CallbackGroupTest::Operation]"
|
141
|
+
expect(content).must_equal "Op: changed! [CallbackGroupTest::Operation]Op: notify_album! [CallbackGroupTest::Operation]Op: reset_song! [CallbackGroupTest::Operation]"
|
143
142
|
end
|
144
143
|
end
|
145
144
|
|
@@ -158,12 +157,12 @@ class CallbackGroupInheritanceTest < MiniTest::Spec
|
|
158
157
|
end
|
159
158
|
|
160
159
|
it do
|
161
|
-
Group.hooks.size.must_equal 4
|
162
|
-
Group.hooks[0].to_s.must_equal "[:on_change, :change!, {}]"
|
160
|
+
expect(Group.hooks.size).must_equal 4
|
161
|
+
expect(Group.hooks[0].to_s).must_equal "[:on_change, :change!, {}]"
|
163
162
|
# Group.hooks[1][1][:nested].hooks.to_s.must_equal "[[:on_add, [:notify_album!]],[:on_add, [:reset_song!]]]"
|
164
|
-
Group.hooks[2].to_s.must_equal "[:on_change, :rehash_name!, {:property=>:title}]"
|
163
|
+
expect(Group.hooks[2].to_s).must_equal "[:on_change, :rehash_name!, {:property=>:title}]"
|
165
164
|
|
166
|
-
Group.definitions.get(Group.hooks[3][1])[:nested].hooks.to_s.must_equal "[[:on_change, :sing!, {}]]"
|
165
|
+
expect(Group.definitions.get(Group.hooks[3][1])[:nested].hooks.to_s).must_equal "[[:on_change, :sing!, {}]]"
|
167
166
|
end
|
168
167
|
|
169
168
|
class EmptyGroup < Group
|
@@ -172,7 +171,7 @@ class CallbackGroupInheritanceTest < MiniTest::Spec
|
|
172
171
|
|
173
172
|
|
174
173
|
it do
|
175
|
-
EmptyGroup.hooks.size.must_equal 4
|
174
|
+
expect(EmptyGroup.hooks.size).must_equal 4
|
176
175
|
# TODO:
|
177
176
|
end
|
178
177
|
|
@@ -184,10 +183,10 @@ class CallbackGroupInheritanceTest < MiniTest::Spec
|
|
184
183
|
end
|
185
184
|
|
186
185
|
it do
|
187
|
-
Group.hooks.size.must_equal 4
|
188
|
-
pp EnhancedGroup.hooks
|
189
|
-
EnhancedGroup.hooks.size.must_equal 6
|
190
|
-
EnhancedGroup.definitions.get(EnhancedGroup.hooks[5][1])[:nested].hooks.to_s.must_equal "[[:on_add, :rewind!, {}]]"
|
186
|
+
expect(Group.hooks.size).must_equal 4
|
187
|
+
# pp EnhancedGroup.hooks
|
188
|
+
expect(EnhancedGroup.hooks.size).must_equal 6
|
189
|
+
expect(EnhancedGroup.definitions.get(EnhancedGroup.hooks[5][1])[:nested].hooks.to_s).must_equal "[[:on_add, :rewind!, {}]]"
|
191
190
|
end
|
192
191
|
|
193
192
|
class EnhancedWithInheritGroup < EnhancedGroup
|
@@ -200,13 +199,13 @@ class CallbackGroupInheritanceTest < MiniTest::Spec
|
|
200
199
|
end
|
201
200
|
|
202
201
|
it do
|
203
|
-
Group.hooks.size.must_equal 4
|
204
|
-
EnhancedGroup.hooks.size.must_equal 6
|
202
|
+
expect(Group.hooks.size).must_equal 4
|
203
|
+
expect(EnhancedGroup.hooks.size).must_equal 6
|
205
204
|
|
206
|
-
EnhancedGroup.definitions.get(EnhancedGroup.hooks[5][1])[:nested].hooks.to_s.must_equal "[[:on_add, :rewind!, {}]]"
|
207
|
-
EnhancedWithInheritGroup.hooks.size.must_equal 6
|
208
|
-
EnhancedWithInheritGroup.definitions.get(EnhancedWithInheritGroup.hooks[1][1])[:nested].hooks.to_s.must_equal "[[:on_add, :rewind!, {}], [:on_add, :eat!, {}]]"
|
209
|
-
EnhancedWithInheritGroup.definitions.get(EnhancedWithInheritGroup.hooks[3][1])[:nested].hooks.to_s.must_equal "[[:on_change, :sing!, {}], [:on_delete, :yell!, {}]]"
|
205
|
+
expect(EnhancedGroup.definitions.get(EnhancedGroup.hooks[5][1])[:nested].hooks.to_s).must_equal "[[:on_add, :rewind!, {}]]"
|
206
|
+
expect(EnhancedWithInheritGroup.hooks.size).must_equal 6
|
207
|
+
expect(EnhancedWithInheritGroup.definitions.get(EnhancedWithInheritGroup.hooks[1][1])[:nested].hooks.to_s).must_equal "[[:on_add, :rewind!, {}], [:on_add, :eat!, {}]]"
|
208
|
+
expect(EnhancedWithInheritGroup.definitions.get(EnhancedWithInheritGroup.hooks[3][1])[:nested].hooks.to_s).must_equal "[[:on_change, :sing!, {}], [:on_delete, :yell!, {}]]"
|
210
209
|
end
|
211
210
|
|
212
211
|
class RemovingInheritGroup < Group
|
@@ -227,10 +226,10 @@ class CallbackGroupInheritanceTest < MiniTest::Spec
|
|
227
226
|
# TODO: object_id tests for all nested representers.
|
228
227
|
|
229
228
|
it do
|
230
|
-
Group.hooks.size.must_equal 4
|
231
|
-
RemovingInheritGroup.hooks.size.must_equal 3
|
232
|
-
RemovingInheritGroup.definitions.get(RemovingInheritGroup.hooks[0][1])[:nested].hooks.to_s.must_equal "[[:on_add, :reset_song!, {}]]"
|
233
|
-
RemovingInheritGroup.definitions.get(RemovingInheritGroup.hooks[2][1])[:nested].hooks.to_s.must_equal "[[:on_change, :sing!, {}]]"
|
229
|
+
expect(Group.hooks.size).must_equal 4
|
230
|
+
expect(RemovingInheritGroup.hooks.size).must_equal 3
|
231
|
+
expect(RemovingInheritGroup.definitions.get(RemovingInheritGroup.hooks[0][1])[:nested].hooks.to_s).must_equal "[[:on_add, :reset_song!, {}]]"
|
232
|
+
expect(RemovingInheritGroup.definitions.get(RemovingInheritGroup.hooks[2][1])[:nested].hooks.to_s).must_equal "[[:on_change, :sing!, {}]]"
|
234
233
|
end
|
235
234
|
|
236
235
|
# Group::clone
|
@@ -240,7 +239,7 @@ class CallbackGroupInheritanceTest < MiniTest::Spec
|
|
240
239
|
end
|
241
240
|
|
242
241
|
it do
|
243
|
-
Group.hooks.size.must_equal 4
|
244
|
-
ClonedGroup.hooks.size.must_equal 3
|
242
|
+
expect(Group.hooks.size).must_equal 4
|
243
|
+
expect(ClonedGroup.hooks.size).must_equal 3
|
245
244
|
end
|
246
|
-
end
|
245
|
+
end
|
data/test/callbacks_test.rb
CHANGED
@@ -46,7 +46,7 @@ class CallbacksTest < MiniTest::Spec
|
|
46
46
|
it do
|
47
47
|
invokes = []
|
48
48
|
Callback.new(twin).on_create { |t| invokes << t }
|
49
|
-
invokes.must_equal []
|
49
|
+
expect(invokes).must_equal []
|
50
50
|
end
|
51
51
|
|
52
52
|
# save, without any attributes changed.
|
@@ -55,7 +55,7 @@ class CallbacksTest < MiniTest::Spec
|
|
55
55
|
|
56
56
|
invokes = []
|
57
57
|
Callback.new(twin).on_create { |t| invokes << t }
|
58
|
-
invokes.must_equal [twin]
|
58
|
+
expect(invokes).must_equal [twin]
|
59
59
|
end
|
60
60
|
|
61
61
|
# before and after save, with attributes changed
|
@@ -64,28 +64,28 @@ class CallbacksTest < MiniTest::Spec
|
|
64
64
|
twin.name = "Run For Cover"
|
65
65
|
invokes = []
|
66
66
|
Callback.new(twin).on_create { |t| invokes << t }
|
67
|
-
invokes.must_equal []
|
67
|
+
expect(invokes).must_equal []
|
68
68
|
|
69
69
|
twin.save
|
70
70
|
|
71
71
|
Callback.new(twin).on_create { |t| invokes << t }
|
72
|
-
invokes.must_equal [twin]
|
72
|
+
expect(invokes).must_equal [twin]
|
73
73
|
end
|
74
74
|
|
75
75
|
# for collections.
|
76
76
|
it do
|
77
|
-
album.songs <<
|
77
|
+
album.songs << Song.new
|
78
78
|
album.songs << Song.create(title: "Run For Cover")
|
79
|
-
album.songs <<
|
79
|
+
album.songs << Song.new
|
80
80
|
invokes = []
|
81
81
|
|
82
82
|
Callback.new(twin.songs).on_create { |t| invokes << t }
|
83
|
-
invokes.must_equal []
|
83
|
+
expect(invokes).must_equal []
|
84
84
|
|
85
85
|
twin.save
|
86
86
|
|
87
87
|
Callback.new(twin.songs).on_create { |t| invokes << t }
|
88
|
-
invokes.must_equal [twin.songs[0], twin.songs[2]]
|
88
|
+
expect(invokes).must_equal [twin.songs[0], twin.songs[2]]
|
89
89
|
end
|
90
90
|
end
|
91
91
|
|
@@ -96,7 +96,7 @@ class CallbacksTest < MiniTest::Spec
|
|
96
96
|
it do
|
97
97
|
invokes = []
|
98
98
|
Callback.new(twin).on_update { |t| invokes << t }
|
99
|
-
invokes.must_equal []
|
99
|
+
expect(invokes).must_equal []
|
100
100
|
end
|
101
101
|
|
102
102
|
# single twin.
|
@@ -106,85 +106,85 @@ class CallbacksTest < MiniTest::Spec
|
|
106
106
|
|
107
107
|
invokes = []
|
108
108
|
Callback.new(twin).on_update { |t| invokes << t }
|
109
|
-
invokes.must_equal []
|
109
|
+
expect(invokes).must_equal []
|
110
110
|
|
111
111
|
invokes = []
|
112
112
|
twin.save
|
113
113
|
|
114
114
|
Callback.new(twin).on_update { |t| invokes << t }
|
115
|
-
invokes.must_equal []
|
115
|
+
expect(invokes).must_equal []
|
116
116
|
|
117
117
|
|
118
118
|
# now with the persisted album.
|
119
119
|
twin = AlbumTwin.new(album) # Album is persisted now.
|
120
120
|
|
121
121
|
Callback.new(twin).on_update { |t| invokes << t }
|
122
|
-
invokes.must_equal []
|
122
|
+
expect(invokes).must_equal []
|
123
123
|
|
124
124
|
invokes = []
|
125
125
|
twin.save
|
126
126
|
|
127
127
|
# nothing has changed, yet.
|
128
128
|
Callback.new(twin).on_update { |t| invokes << t }
|
129
|
-
invokes.must_equal []
|
129
|
+
expect(invokes).must_equal []
|
130
130
|
|
131
131
|
twin.name= "Corridors Of Power"
|
132
132
|
|
133
133
|
# this will even trigger on_update before saving.
|
134
134
|
Callback.new(twin).on_update { |t| invokes << t }
|
135
|
-
invokes.must_equal [twin]
|
135
|
+
expect(invokes).must_equal [twin]
|
136
136
|
|
137
137
|
invokes = []
|
138
138
|
twin.save
|
139
139
|
|
140
140
|
# name changed.
|
141
141
|
Callback.new(twin).on_update { |t| invokes << t }
|
142
|
-
invokes.must_equal [twin]
|
142
|
+
expect(invokes).must_equal [twin]
|
143
143
|
end
|
144
144
|
|
145
145
|
# for collections.
|
146
146
|
it do
|
147
|
-
album.songs <<
|
147
|
+
album.songs << Song.new
|
148
148
|
album.songs << Song.create(title: "Run For Cover")
|
149
|
-
album.songs <<
|
149
|
+
album.songs << Song.new
|
150
150
|
|
151
151
|
invokes = []
|
152
152
|
Callback.new(twin.songs).on_update { |t| invokes << t }
|
153
|
-
invokes.must_equal []
|
153
|
+
expect(invokes).must_equal []
|
154
154
|
|
155
155
|
invokes = []
|
156
156
|
twin.save
|
157
157
|
|
158
158
|
# initial save is no update.
|
159
159
|
Callback.new(twin.songs).on_update { |t| invokes << t }
|
160
|
-
invokes.must_equal []
|
160
|
+
expect(invokes).must_equal []
|
161
161
|
|
162
162
|
|
163
163
|
# now with the persisted album.
|
164
164
|
twin = AlbumTwin.new(album) # Album is persisted now.
|
165
165
|
|
166
166
|
Callback.new(twin.songs).on_update { |t| invokes << t }
|
167
|
-
invokes.must_equal []
|
167
|
+
expect(invokes).must_equal []
|
168
168
|
|
169
169
|
invokes = []
|
170
170
|
twin.save
|
171
171
|
|
172
172
|
# nothing has changed, yet.
|
173
173
|
Callback.new(twin.songs).on_update { |t| invokes << t }
|
174
|
-
invokes.must_equal []
|
174
|
+
expect(invokes).must_equal []
|
175
175
|
|
176
176
|
twin.songs[1].title= "After The War"
|
177
177
|
twin.songs[2].title= "Run For Cover"
|
178
178
|
|
179
179
|
# # this will even trigger on_update before saving.
|
180
180
|
Callback.new(twin.songs).on_update { |t| invokes << t }
|
181
|
-
invokes.must_equal [twin.songs[1], twin.songs[2]]
|
181
|
+
expect(invokes).must_equal [twin.songs[1], twin.songs[2]]
|
182
182
|
|
183
183
|
invokes = []
|
184
184
|
twin.save
|
185
185
|
|
186
186
|
Callback.new(twin.songs).on_update { |t| invokes << t }
|
187
|
-
invokes.must_equal [twin.songs[1], twin.songs[2]]
|
187
|
+
expect(invokes).must_equal [twin.songs[1], twin.songs[2]]
|
188
188
|
end
|
189
189
|
# it do
|
190
190
|
# album.songs << song1 = Song.new
|
@@ -210,7 +210,7 @@ class CallbacksTest < MiniTest::Spec
|
|
210
210
|
it do
|
211
211
|
invokes = []
|
212
212
|
Callback.new(twin.songs).on_add { |t| invokes << t }
|
213
|
-
invokes.must_equal []
|
213
|
+
expect(invokes).must_equal []
|
214
214
|
end
|
215
215
|
|
216
216
|
# collection present on initialize are not added.
|
@@ -220,7 +220,7 @@ class CallbacksTest < MiniTest::Spec
|
|
220
220
|
album.songs = [ex_song, song]
|
221
221
|
|
222
222
|
Callback.new(twin.songs).on_add { |t| invokes << t }
|
223
|
-
invokes.must_equal []
|
223
|
+
expect(invokes).must_equal []
|
224
224
|
end
|
225
225
|
|
226
226
|
# items added after initialization are added.
|
@@ -232,14 +232,14 @@ class CallbacksTest < MiniTest::Spec
|
|
232
232
|
twin.songs << song
|
233
233
|
|
234
234
|
Callback.new(twin.songs).on_add { |t| invokes << t }
|
235
|
-
invokes.must_equal [twin.songs[1]]
|
235
|
+
expect(invokes).must_equal [twin.songs[1]]
|
236
236
|
|
237
237
|
twin.save
|
238
238
|
|
239
239
|
# still shows the added after save.
|
240
240
|
invokes = []
|
241
241
|
Callback.new(twin.songs).on_add { |t| invokes << t }
|
242
|
-
invokes.must_equal [twin.songs[1]]
|
242
|
+
expect(invokes).must_equal [twin.songs[1]]
|
243
243
|
end
|
244
244
|
end
|
245
245
|
|
@@ -250,7 +250,7 @@ class CallbacksTest < MiniTest::Spec
|
|
250
250
|
it do
|
251
251
|
invokes = []
|
252
252
|
Callback.new(twin.songs).on_add(:created) { |t| invokes << t }
|
253
|
-
invokes.must_equal []
|
253
|
+
expect(invokes).must_equal []
|
254
254
|
end
|
255
255
|
|
256
256
|
# collection present on initialize are not added.
|
@@ -260,7 +260,7 @@ class CallbacksTest < MiniTest::Spec
|
|
260
260
|
album.songs = [ex_song, song]
|
261
261
|
|
262
262
|
Callback.new(twin.songs).on_add(:created) { |t| invokes << t }
|
263
|
-
invokes.must_equal []
|
263
|
+
expect(invokes).must_equal []
|
264
264
|
end
|
265
265
|
|
266
266
|
# items added after initialization are added.
|
@@ -273,14 +273,14 @@ class CallbacksTest < MiniTest::Spec
|
|
273
273
|
twin.songs << ex_song # already created.
|
274
274
|
|
275
275
|
Callback.new(twin.songs).on_add(:created) { |t| invokes << t }
|
276
|
-
invokes.must_equal []
|
276
|
+
expect(invokes).must_equal []
|
277
277
|
|
278
278
|
twin.save
|
279
279
|
|
280
280
|
# still shows the added after save.
|
281
281
|
invokes = []
|
282
282
|
Callback.new(twin.songs).on_add(:created) { |t| invokes << t }
|
283
|
-
invokes.must_equal [twin.songs[1]] # only the created is invoked.
|
283
|
+
expect(invokes).must_equal [twin.songs[1]] # only the created is invoked.
|
284
284
|
end
|
285
285
|
end
|
286
286
|
|
@@ -291,7 +291,7 @@ class CallbacksTest < MiniTest::Spec
|
|
291
291
|
it do
|
292
292
|
invokes = []
|
293
293
|
Callback.new(twin.songs).on_delete { |t| invokes << t }
|
294
|
-
invokes.must_equal []
|
294
|
+
expect(invokes).must_equal []
|
295
295
|
end
|
296
296
|
|
297
297
|
# collection present but nothing deleted.
|
@@ -301,7 +301,7 @@ class CallbacksTest < MiniTest::Spec
|
|
301
301
|
album.songs = [ex_song, song]
|
302
302
|
|
303
303
|
Callback.new(twin.songs).on_delete { |t| invokes << t }
|
304
|
-
invokes.must_equal []
|
304
|
+
expect(invokes).must_equal []
|
305
305
|
end
|
306
306
|
|
307
307
|
# items deleted.
|
@@ -313,14 +313,14 @@ class CallbacksTest < MiniTest::Spec
|
|
313
313
|
twin.songs.delete(deleted = twin.songs[0])
|
314
314
|
|
315
315
|
Callback.new(twin.songs).on_delete { |t| invokes << t }
|
316
|
-
invokes.must_equal [deleted]
|
316
|
+
expect(invokes).must_equal [deleted]
|
317
317
|
|
318
318
|
twin.save
|
319
319
|
|
320
320
|
# still shows the deleted after save.
|
321
321
|
invokes = []
|
322
322
|
Callback.new(twin.songs).on_delete { |t| invokes << t }
|
323
|
-
invokes.must_equal [deleted]
|
323
|
+
expect(invokes).must_equal [deleted]
|
324
324
|
end
|
325
325
|
end
|
326
326
|
|
@@ -331,7 +331,7 @@ class CallbacksTest < MiniTest::Spec
|
|
331
331
|
it do
|
332
332
|
invokes = []
|
333
333
|
Callback.new(twin.songs).on_destroy { |t| invokes << t }
|
334
|
-
invokes.must_equal []
|
334
|
+
expect(invokes).must_equal []
|
335
335
|
end
|
336
336
|
|
337
337
|
# collection present but nothing deleted.
|
@@ -341,7 +341,7 @@ class CallbacksTest < MiniTest::Spec
|
|
341
341
|
album.songs = [ex_song, song]
|
342
342
|
|
343
343
|
Callback.new(twin.songs).on_destroy { |t| invokes << t }
|
344
|
-
invokes.must_equal []
|
344
|
+
expect(invokes).must_equal []
|
345
345
|
end
|
346
346
|
|
347
347
|
# items deleted, doesn't trigger on_destroy.
|
@@ -350,10 +350,10 @@ class CallbacksTest < MiniTest::Spec
|
|
350
350
|
song = Song.new
|
351
351
|
album.songs = [ex_song, song]
|
352
352
|
|
353
|
-
twin.songs.delete(
|
353
|
+
twin.songs.delete(twin.songs[0])
|
354
354
|
|
355
355
|
Callback.new(twin.songs).on_destroy { |t| invokes << t }
|
356
|
-
invokes.must_equal []
|
356
|
+
expect(invokes).must_equal []
|
357
357
|
end
|
358
358
|
|
359
359
|
# items destroyed.
|
@@ -365,7 +365,7 @@ class CallbacksTest < MiniTest::Spec
|
|
365
365
|
twin.songs.destroy(deleted = twin.songs[0])
|
366
366
|
|
367
367
|
Callback.new(twin.songs).on_destroy { |t| invokes << t }
|
368
|
-
invokes.must_equal []
|
368
|
+
expect(invokes).must_equal []
|
369
369
|
|
370
370
|
twin.extend(Disposable::Twin::Collection::Semantics) # now #save will destroy.
|
371
371
|
twin.save
|
@@ -373,7 +373,7 @@ class CallbacksTest < MiniTest::Spec
|
|
373
373
|
# still shows the deleted after save.
|
374
374
|
invokes = []
|
375
375
|
Callback.new(twin.songs).on_destroy { |t| invokes << t }
|
376
|
-
invokes.must_equal [deleted]
|
376
|
+
expect(invokes).must_equal [deleted]
|
377
377
|
end
|
378
378
|
end
|
379
379
|
|
@@ -384,7 +384,7 @@ class CallbacksTest < MiniTest::Spec
|
|
384
384
|
# after initialization
|
385
385
|
it do
|
386
386
|
Callback.new(twin).on_change { |t| invokes << t }
|
387
|
-
invokes.must_equal []
|
387
|
+
expect(invokes).must_equal []
|
388
388
|
end
|
389
389
|
|
390
390
|
# save, without any attributes changed. unpersisted before.
|
@@ -394,7 +394,7 @@ class CallbacksTest < MiniTest::Spec
|
|
394
394
|
twin.save
|
395
395
|
|
396
396
|
Callback.new(twin).on_change { |t| invokes << t }
|
397
|
-
invokes.must_equal [] # nothing has changed, not even persisted?.
|
397
|
+
expect(invokes).must_equal [] # nothing has changed, not even persisted?.
|
398
398
|
end
|
399
399
|
|
400
400
|
# save, without any attributes changed. persisted before.
|
@@ -402,7 +402,7 @@ class CallbacksTest < MiniTest::Spec
|
|
402
402
|
twin.save
|
403
403
|
|
404
404
|
Callback.new(twin).on_change { |t| invokes << t }
|
405
|
-
invokes.must_equal [twin]
|
405
|
+
expect(invokes).must_equal [twin]
|
406
406
|
end
|
407
407
|
|
408
408
|
# before and after save, with attributes changed
|
@@ -411,24 +411,24 @@ class CallbacksTest < MiniTest::Spec
|
|
411
411
|
twin.name = "Run For Cover"
|
412
412
|
invokes = []
|
413
413
|
Callback.new(twin).on_change { |t| invokes << t }
|
414
|
-
invokes.must_equal [twin]
|
414
|
+
expect(invokes).must_equal [twin]
|
415
415
|
|
416
416
|
twin.save
|
417
417
|
|
418
418
|
invokes = []
|
419
419
|
Callback.new(twin).on_change { |t| invokes << t }
|
420
|
-
invokes.must_equal [twin]
|
420
|
+
expect(invokes).must_equal [twin]
|
421
421
|
end
|
422
422
|
|
423
423
|
# for scalars: on_change(:email).
|
424
424
|
it do
|
425
425
|
Callback.new(twin).on_change(property: :name) { |t| invokes << t }
|
426
|
-
invokes.must_equal []
|
426
|
+
expect(invokes).must_equal []
|
427
427
|
|
428
428
|
twin.name = "Unforgiven"
|
429
429
|
|
430
430
|
Callback.new(twin).on_change(property: :name) { |t| invokes << t }
|
431
|
-
invokes.must_equal [twin]
|
431
|
+
expect(invokes).must_equal [twin]
|
432
432
|
end
|
433
433
|
|
434
434
|
# for collections.
|
@@ -447,4 +447,4 @@ class CallbacksTest < MiniTest::Spec
|
|
447
447
|
# invokes.must_equal [twin.songs[0], twin.songs[2]]
|
448
448
|
# end
|
449
449
|
end
|
450
|
-
end
|
450
|
+
end
|