Sha256: abb31340f370378821eed2f8d7142e768ca6761be459751d123230a4bbab098b
Contents?: true
Size: 1.3 KB
Versions: 34
Compression:
Stored size: 1.3 KB
Contents
require 'test_helper' class WriteableTest < MiniTest::Spec Credentials = Struct.new(:password, :credit_card) do def password=(v) raise "don't call me!" end end CreditCard = Struct.new(:name, :number) do def number=(v) raise "don't call me!" end end class PasswordForm < Disposable::Twin feature Setup feature Sync property :password, writeable: false property :credit_card do property :name property :number, writeable: false end end let (:cred) { Credentials.new("secret", CreditCard.new("Jonny", "0987654321")) } let (:twin) { PasswordForm.new(cred) } it { twin.password.must_equal "secret" twin.credit_card.name.must_equal "Jonny" twin.credit_card.number.must_equal "0987654321" # manual setting on the twin works. twin.password = "123" twin.password.must_equal "123" twin.credit_card.number = "456" twin.credit_card.number.must_equal "456" twin.sync cred.inspect.must_equal '#<struct WriteableTest::Credentials password="secret", credit_card=#<struct WriteableTest::CreditCard name="Jonny", number="0987654321">>' # test sync{}. hash = {} twin.sync do |nested| hash = nested end hash.must_equal("password"=> "123", "credit_card"=>{"name"=>"Jonny", "number"=>"456"}) } end
Version data entries
34 entries across 34 versions & 1 rubygems