Sha256: 3f8b08e398db75ef05412273f525c66ca20ad531f65da616a797f042fb71e70e

Contents?: true

Size: 1.51 KB

Versions: 24

Compression:

Stored size: 1.51 KB

Contents

require 'test_helper'

class ReadableTest < MiniTest::Spec
  Credentials = Struct.new(:password, :credit_card) do
    def password
      raise "don't call me!"
    end
  end

  CreditCard = Struct.new(:name, :number) do
    def number
      raise "don't call me!"
    end
  end

  class PasswordForm < Disposable::Twin
    feature Setup
    feature Sync

    property :password, readable: false

    property :credit_card do
      property :name
      property :number, readable: false
    end
  end

  let (:cred) { Credentials.new("secret", CreditCard.new("Jonny", "0987654321")) }

  let (:twin) { PasswordForm.new(cred) }

  it {
    twin.password.must_equal nil            # not readable.
    twin.credit_card.name.must_equal "Jonny"
    twin.credit_card.number.must_equal nil  # not readable.

    # 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

    # it writes, but does not read.
    cred.inspect.must_equal '#<struct ReadableTest::Credentials password="123", credit_card=#<struct ReadableTest::CreditCard name="Jonny", number="456">>'

    # test sync{}.
    hash = {}
    twin.sync do |nested|
      hash = nested
    end

    hash.must_equal("password"=> "123", "credit_card"=>{"name"=>"Jonny", "number"=>"456"})
  }

  # allow passing non-readable value as option.
  it do
    twin = PasswordForm.new(cred, password: "open sesame!")
    twin.password.must_equal "open sesame!"
  end
end

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
disposable-0.1.11 test/twin/readable_test.rb
disposable-0.1.9 test/twin/readable_test.rb
disposable-0.1.8 test/twin/readable_test.rb
disposable-0.1.7 test/twin/readable_test.rb