Sha256: 164ed1f63fa545327f5f1d933ac3346b9a3209ac84e15189d018b47f79527dd3

Contents?: true

Size: 1.27 KB

Versions: 3

Compression:

Stored size: 1.27 KB

Contents

require "test_helper"

class WriteableTest < MiniTest::Spec
  Location = Struct.new(:country)

  class LocationForm < TestForm
    property :country, writeable: false
  end

  let(:loc) { Location.new("Australia") }
  let(:form) { LocationForm.new(loc) }

  it do
    form.country.must_equal "Australia"

    form.validate("country" => "Germany") # this usually won't change when submitting.
    form.country.must_equal "Germany"

    form.sync
    loc.country.must_equal "Australia" # the writer wasn't called.

    hash = {}
    form.save do |nested|
      hash = nested
    end

    hash.must_equal("country" => "Germany")
  end
end

# writable option is alias of writeable option.
class WritableTest < MiniTest::Spec
  Location = Struct.new(:country)

  class LocationForm < TestForm
    property :country, writable: false
  end

  let(:loc) { Location.new("Australia") }
  let(:form) { LocationForm.new(loc) }

  it do
    form.country.must_equal "Australia"

    form.validate("country" => "Germany") # this usually won't change when submitting.
    form.country.must_equal "Germany"

    form.sync
    loc.country.must_equal "Australia" # the writer wasn't called.

    hash = {}
    form.save do |nested|
      hash = nested
    end

    hash.must_equal("country" => "Germany")
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
reform-2.3.2 test/writeable_test.rb
reform-2.3.1 test/writeable_test.rb
reform-2.3.0.rc2 test/writeable_test.rb