From 6e80ae52f3f0dc252be8e2d8a526173571bee453 Mon Sep 17 00:00:00 2001 From: Nikita Sokolov Date: Fri, 16 Jun 2017 13:17:51 +0300 Subject: [PATCH] Expose Disposable::Twin#build_twin via Disposable::Twin::Collection#new --- lib/disposable/twin/collection.rb | 5 +++++ test/twin/collection_test.rb | 9 +++++++++ 2 files changed, 14 insertions(+) diff --git a/lib/disposable/twin/collection.rb b/lib/disposable/twin/collection.rb index cbdd9bc..3081739 100644 --- a/lib/disposable/twin/collection.rb +++ b/lib/disposable/twin/collection.rb @@ -55,6 +55,11 @@ def save # only gets called when Collection::Semantics mixed in. destroy! end + # Twins a model + def new(model) + @twinner.(model) + end + module Changed # FIXME: this should not be included automatically, as Changed is a feature. def changed? diff --git a/test/twin/collection_test.rb b/test/twin/collection_test.rb index 2cd7f35..6452daf 100644 --- a/test/twin/collection_test.rb +++ b/test/twin/collection_test.rb @@ -201,6 +201,15 @@ class Album < Disposable::Twin twin.songs.deleted.must_equal [] end end + + describe "#new" do + let (:album) { Album.create() } + + it do + twin = Twin::Album.new(album) + twin.songs.new(Song.new).must_be_instance_of Twin::Song + end + end end