spec/unit/form_spec.rb in rom-rails-0.3.0 vs spec/unit/form_spec.rb in rom-rails-0.3.1

- old
+ new

@@ -65,11 +65,11 @@ form_object = form.build(name: 'Jane').save expect(form_object).to be_success expect(rom.relations.users.first).to include(name: 'Jane') - expect(form_object.tasks).to be(rom.command(:tasks)) + expect(form_object.tasks).to_not be(nil) end end describe '.key' do it 'returns default key' do @@ -284,10 +284,27 @@ it 'copies input' do expect(child_form.attributes.attribute_set[:email]).to_not be(nil) expect(child_form.attributes).to_not be(form.attributes) end + it 'expands input' do + child_form = Class.new(form) do + def self.name + "NewUserForm" + end + + input do + attribute :login, String + end + end + + expect(child_form.attributes.attribute_set[:login]).to_not be(nil) + expect(child_form.attributes.attribute_set[:email]).to_not be(nil) + + expect(child_form.attributes).to_not be(form.attributes) + end + it 'copies model' do expect(child_form.model.attribute_set[:email]).to_not be(nil) expect(child_form.model).to_not be(form.model) end @@ -295,7 +312,35 @@ expect(child_form.validator.validators.first).to be_instance_of( ActiveModel::Validations::PresenceValidator ) expect(child_form.validator).to_not be(form.validator) end + + it "expands existing validators" do + child_form = Class.new(form) do + def self.name + "NewUserForm" + end + + input do + attribute :login, String + end + + validations do + validates :login, length: { minimum: 4 } + end + end + + expect(child_form.validator.validators.first).to be_instance_of( + ActiveModel::Validations::PresenceValidator + ) + + expect(child_form.validator.validators.last).to be_instance_of( + ActiveModel::Validations::LengthValidator + ) + + expect(child_form.validator).to_not be(form.validator) + end + + end end