Sha256: 36a2f122dd10c0717ee2b5326d2c090ee43199e247c95ae03f11993e2e553d24

Contents?: true

Size: 669 Bytes

Versions: 2

Compression:

Stored size: 669 Bytes

Contents

require 'test_helper'

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

  class LocationForm < Reform::Form
    property :country, virtual: true # read_only: true
  end

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

  it { form.country.must_equal "Australia" }
  it do
    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

2 entries across 2 versions & 1 rubygems

Version Path
reform-1.2.0.beta2 test/read_only_test.rb
reform-1.2.0.beta1 test/read_only_test.rb