Sha256: c1d34082cb5dec7423cbcacbc42a364041ed08902a9104cebfdf0d65bb6e531e

Contents?: true

Size: 866 Bytes

Versions: 1

Compression:

Stored size: 866 Bytes

Contents

require 'helper'

class Profile < OpenStruct
  def create! attrs; end
  def update_attributes attrs; end
end

class ExampleModelForm < Cave::ModelForm
  model Profile

  field :name, String
end

describe ExampleModelForm do

  it 'checks instance against model' do
    expect { ExampleModelForm.new 1 }.to raise_error TypeError
  end

  context 'when new' do
    subject { ExampleModelForm.new name: 'James' }

    it 'creates' do
      Profile.should_receive :create!
      subject.save!
    end
  end

  context 'pre-existing' do
    let(:instance) { Profile.new name: 'James' }
    subject { ExampleModelForm.new instance, name: 'Jim' }

    it 'updates' do
      instance.should_receive(:update_attributes).with(name: 'Jim')
      subject.save!
    end

    it 'does not create' do
      Profile.should_not_receive :create!
      subject.save!
    end
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
cave-0.0.1 spec/gears/model_form_spec.rb