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

- old
+ new

@@ -23,22 +23,26 @@ end end describe '.build' do it 'rejects blank strings from params' do - input = { - 'name' => 'Jane', - 'hash' => { 'one' => '', 'two' => 2 }, - 'array' => [{ 'three' => '', 'four' => 4 }, 5] - } + input = { 'name' => '' } form_object = form.build(input) - expect(form_object.params).to eql( - name: 'Jane', hash: { two: 2 }, array: [{ four: 4 }, 5] - ) + expect(form_object.attributes.to_h).to eql(email: nil) end + + it 'exposes param values' do + params = { 'email' => 'jane@doe.org' } + form_object = form.build(params) + expect(form_object.email).to eql('jane@doe.org') + + params = { email: 'jane@doe.org' } + form_object = form.build(params) + expect(form_object.email).to eql('jane@doe.org') + end end describe '.commands' do it 'builds its own command registry' do form = Class.new(ROM::Model::Form) { @@ -46,11 +50,11 @@ commands users: :create input { attribute :name } validations { validates :name, presence: true } def commit! - users.try { users.create.call(params) } + users.try { users.create.call(attributes) } end } form_object = form.build(name: '').save @@ -92,20 +96,20 @@ expect(form.new({}, { foo_id: 312, bar_id: 132 }).to_key).to eql([312, 132]) end end describe '.model_name' do - it 'delegates to Params.model_name' do - expect(form.model_name).to be(form.params.model_name) + it 'delegates to Attributes.model_name' do + expect(form.model_name).to be(form.attributes.model_name) end end describe 'input DSL' do it 'defines params handler' do - expect(form.const_defined?(:Params)).to be(true) - expect(form.params.attribute_set.map(&:name)).to eql([:email]) - expect(form.params.model_name).to eql('User') + expect(form.const_defined?(:Attributes)).to be(true) + expect(form.attributes.attribute_set.map(&:name)).to eql([:email]) + expect(form.attributes.model_name).to eql('User') end it 'defines a model' do expect(form.const_defined?(:Model)).to be(true) expect(form.model.attribute_set.map(&:name)).to match_array([:id, :email]) @@ -276,11 +280,11 @@ it 'copies model_name' do expect(child_form.model_name.name).to eql(form.model_name.name) end it 'copies input' do - expect(child_form.params.attribute_set[:email]).to_not be(nil) - expect(child_form.params).to_not be(form.params) + 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)