Sha256: 006b6eb32495be48446b72986a1851ec13d04cad2d41dbf134469fb209d9b515

Contents?: true

Size: 1.3 KB

Versions: 6

Compression:

Stored size: 1.3 KB

Contents

describe "Form Persisting" do

  it "works" do
    f = Formotion::Form.persist({
      persist_as: "test_#{rand(255)}",
      sections: [
        rows: [ {
            key: "first",
            type: "string",
            value: "initial value"
          }
        ]
      ]
    })

    r = f.sections[0].rows[0]
    r.value = "new value"

    saved = Formotion::Form.new(f.send(:load_state))
    saved.sections[0].rows[0].value.should == r.value

    f.reset
    r.value.should == "initial value"
  end

  it "works with subforms" do
    f = Formotion::Form.persist({
      persist_as: "test_#{rand(255)}",
      sections: [
        rows: [ {
            key: :subform,
            type: :subform,
            title: "Subform",
            subform: {
              title: "New Page",
              sections: [
                rows: [{
                  key: "second",
                  type: "string",
                  value: "initial value"
                }]
              ]
            }
          }
        ]
      ]
    })

    r = f.sections[0].rows[0].subform.to_form.sections[0].rows[0]
    r.value = "new value"

    saved = Formotion::Form.new(f.send(:load_state))
    saved.sections[0].rows[0].subform.to_form.sections[0].rows[0].value.should == r.value

    f.reset
    r.value.should == "initial value"
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
formotion-1.1.5 spec/form/persist_spec.rb
formotion-1.1.4 spec/form/persist_spec.rb
formotion-1.1.3 spec/form/persist_spec.rb
formotion-1.1.2 spec/form/persist_spec.rb
formotion-1.1.1 spec/form/persist_spec.rb
formotion-1.1 spec/form/persist_spec.rb