test/reform_test.rb in reform-2.2.4 vs test/reform_test.rb in reform-2.3.0.rc1

- old
+ new

@@ -4,32 +4,32 @@ class ReformTest < Minitest::Spec let (:comp) { OpenStruct.new(:name => "Duran Duran", :title => "Rio") } let (:form) { SongForm.new(comp) } - class SongForm < Reform::Form + class SongForm < TestForm property :name property :title validation do - key(:name).required + required(:name).filled end end describe "(new) form with empty models" do let (:comp) { OpenStruct.new } it "returns empty fields" do - form.title.must_equal nil + assert_nil form.title form.name.must_equal nil end describe "and submitted values" do it "returns filled-out fields" do form.validate("name" => "Duran Duran") - form.title.must_equal nil + assert_nil form.title form.name.must_equal "Duran Duran" end end end @@ -61,74 +61,59 @@ end it "doesn't change model properties" do form.validate("name" => "Duran Duran") - comp.name.must_equal nil # don't touch model, yet. + assert_nil comp.name # don't touch model, yet. end # TODO: test errors. test valid. describe "invalid input" do - class ValidatingForm < Reform::Form + class ValidatingForm < TestForm property :name property :title validation do - key(:name).required - key(:title).required + required(:name).filled + required(:title).filled end end let (:form) { ValidatingForm.new(comp) } it "returns false when invalid" do form.validate({}).must_equal false end it "populates errors" do form.validate({}) - form.errors.messages.must_equal({:name=>["is missing"], :title=>["is missing"]}) + form.errors.messages.must_equal({:name=>["must be filled"], :title=>["must be filled"]}) end end end - # FIXME: add this test to reform-rails. - describe "#errors" do - before { form.validate({})} - - it { form.errors.must_be_kind_of Reform::Contract::Errors } - - it { form.errors.messages.must_equal({}) } - - it do - form.validate({"name"=>""}) - form.errors.messages.must_equal({:name=>["must be filled"]}) - end - end - - describe "#save" do let (:comp) { OpenStruct.new } let (:form) { SongForm.new(comp) } before { form.validate("name" => "Diesel Boy") } it "xxpushes data to models" do form.save comp.name.must_equal "Diesel Boy" - comp.title.must_equal nil + assert_nil comp.title end describe "#save with block" do it do hash = {} form.save do |map| hash = map end - hash.must_equal({"name"=>"Diesel Boy"}) + hash.must_equal({"name"=>"Diesel Boy", "title" => nil}) end end end @@ -139,27 +124,27 @@ describe "inheritance" do class HitForm < SongForm property :position validation do - key(:position).required + required(:position).filled end end let (:form) { HitForm.new(OpenStruct.new()) } it do form.validate({"title" => "The Body"}) form.title.must_equal "The Body" - form.position.must_equal nil - form.errors.messages.must_equal({:name=>["is missing"], :position=>["is missing"]}) + assert_nil form.position + form.errors.messages.must_equal({:name=>["must be filled"], :position=>["must be filled"]}) end end end class OverridingAccessorsTest < BaseTest - class SongForm < Reform::Form + class SongForm < TestForm property :title def title=(v) # used in #validate. super v*2 end @@ -198,10 +183,10 @@ end end class MethodInFormTest < MiniTest::Spec - class AlbumForm < Reform::Form + class AlbumForm < TestForm property :title def title "The Suffer And The Witness" end