test/twin/twin_test.rb in disposable-0.0.2 vs test/twin/twin_test.rb in disposable-0.0.3
- old
+ new
@@ -65,15 +65,70 @@
end
end
class TwinDecoratorTest < MiniTest::Spec
- subject { TwinTest::Twin::Song.representer_class }
+ subject { TwinTest::Twin::Song.representer_class.new(nil) }
- it { subject.twin_names.must_equal ["album"] }
+ it { subject.twin_names.must_equal [:album] }
end
# from is as close to from_hash as possible
# there should be #to in a perfect API, nothing else.
# should #new create empty associated models?
+
+
+class TwinAsTest < MiniTest::Spec
+ module Model
+ Song = Struct.new(:title, :album)
+ Album = Struct.new(:name)
+ end
+
+
+ module Twin
+ class Album < Disposable::Twin
+ property :name, :as => :record_name
+
+ model Model::Album
+ end
+
+ class Song < Disposable::Twin
+ property :title, :as => :name
+ property :album, :twin => Album, :as => :record
+
+ model Model::Song
+ end
+ end
+
+
+ let (:record) { Twin::Album.new(:record_name => "Veni Vidi Vicous") }
+ subject { Twin::Song.new(:name => "Outsmarted", :record => record) }
+
+
+ describe "::new" do # TODO: this creates a new model!
+ # the Twin exposes the as: API.
+ it { subject.name.must_equal "Outsmarted" }
+ it { subject.record.must_equal record }
+ end
+
+ # DISCUSS: should we test saving without AR? is that worth the hustle?
+ # describe "#save" do
+ # before { subject.send(:model).instance_eval do
+ # def update_attributes(*)
+
+ # end
+ # end
+ # subject.save
+ # }
+
+
+
+ # # before { subject.save }
+
+ # it { subject.name }
+ # end
+end
+
+
+# TODO: test coercion!
\ No newline at end of file