Sha256: e2ad9791febedcfa8fccb6ed95f3d732b86a6c4565a86b4fc1c99a59cbbe35b0

Contents?: true

Size: 897 Bytes

Versions: 16

Compression:

Stored size: 897 Bytes

Contents

require 'spec_helper'

describe "Cistern::Model#dirty" do
  class DirtySpec < Sample::Model
    identity :id

    attribute :name
    attribute :properties, type: :array

    def save
      merge_attributes(attributes)
    end
  end

  it "should mark a existing record as dirty" do
    model = DirtySpec.new(id: 1, name: "steve")
    expect(model.changed).to be_empty

    expect {
      model.properties = [1]
    }.to change { model.dirty? }.to(true)

    expect(model.changed).to eq(properties: [nil, [1]])
    expect(model.dirty_attributes).to eq(properties: [1])

    expect {
      model.properties = [2]
    }.to change { model.changed }.to(properties: [nil, [2]])
    expect(model.dirty_attributes).to eq(properties: [2])

    expect {
      model.save
    }.to change { model.dirty? }.to(false)

    expect(model.changed).to eq({})
    expect(model.dirty_attributes).to eq({})
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
cistern-2.2.3 spec/dirty_spec.rb
cistern-2.2.1 spec/dirty_spec.rb
cistern-2.1.0 spec/dirty_spec.rb
cistern-2.0.5 spec/dirty_spec.rb
cistern-2.0.4 spec/dirty_spec.rb
cistern-2.0.3 spec/dirty_spec.rb
cistern-2.0.2 spec/dirty_spec.rb
cistern-2.0.1 spec/dirty_spec.rb
cistern-1.0.1.pre6 spec/dirty_spec.rb
cistern-1.0.1.pre5 spec/dirty_spec.rb
cistern-1.0.1.pre4 spec/dirty_spec.rb
cistern-1.0.1.pre3 spec/dirty_spec.rb
cistern-1.0.1.pre2 spec/dirty_spec.rb
cistern-1.0.1.pre1 spec/dirty_spec.rb
cistern-1.0.0.pre spec/dirty_spec.rb
cistern-0.11.2.pre2 spec/dirty_spec.rb