Sha256: ae925b1274dc33123ba4533fba7c835d93a525ebcc0852b9d32f6809e2fa4aed

Contents?: true

Size: 1.69 KB

Versions: 49

Compression:

Stored size: 1.69 KB

Contents

require 'spec_helper'

class MyExampleModel < Base
  include Concerns::Savable
  self.prefix = "/test/"
  self.element_name = "example"
end

describe Dirty do

  before :each do
    stub_auth_request
    @model = MyExampleModel.new(:Name => "some old name")
    @model.Name = "a new name"
  end

  it "lets you know if you've changed any attributes" do
    @model.changed?.should be true
  end

  it "should return an array of the attributes that have been changed" do
    @model.changed.should eq(["Name"])
  end

  it "should return a hash diff of current changes on a model" do
    @model.changes.should eq({
      "Name" => ["some old name", "a new name"]
    })
  end

  it "should return previously changed attributes after save" do
    stub_api_post('/test/example', { :MyExampleModels => [ @model.attributes ] }, 'base.json')
    @model.save
    @model.previous_changes.should eq({
    })
  end

  it "should return changed attributes with old values" do
    @model.changed_attributes.should eq({
      "Name" => "some old name"
    })
  end

  it "should return changed attributes with new values" do
    @model.dirty_attributes.should eq({
      "Name" => "a new name"
    })
  end

  it "does not mark attributes dirty when initialized" do
    @model = MyExampleModel.new(:Name => "some sort of name")
    @model.attributes.size.should eq(1)
    @model.changed_attributes.should eq({})
    @model.dirty_attributes.should eq({})
  end

  it "marks attributes dirty that are loaded later" do
    @model.load(:Name => "some sort of name")
    @model.attributes.size.should eq(1)
    @model.changed_attributes.should eq({"Name"=>"some old name"})
    @model.dirty_attributes.should eq({"Name"=>"some sort of name"})
  end

end

Version data entries

49 entries across 49 versions & 1 rubygems

Version Path
spark_api-1.4.34 spec/unit/spark_api/models/dirty_spec.rb
spark_api-1.4.32 spec/unit/spark_api/models/dirty_spec.rb
spark_api-1.4.31 spec/unit/spark_api/models/dirty_spec.rb
spark_api-1.4.29 spec/unit/spark_api/models/dirty_spec.rb
spark_api-1.4.28 spec/unit/spark_api/models/dirty_spec.rb
spark_api-1.4.27 spec/unit/spark_api/models/dirty_spec.rb
spark_api-1.4.26 spec/unit/spark_api/models/dirty_spec.rb
spark_api-1.4.25 spec/unit/spark_api/models/dirty_spec.rb
spark_api-1.4.24 spec/unit/spark_api/models/dirty_spec.rb
spark_api-1.4.23 spec/unit/spark_api/models/dirty_spec.rb
spark_api-1.4.22 spec/unit/spark_api/models/dirty_spec.rb
spark_api-1.4.21 spec/unit/spark_api/models/dirty_spec.rb
spark_api-1.4.20 spec/unit/spark_api/models/dirty_spec.rb
spark_api-1.4.19 spec/unit/spark_api/models/dirty_spec.rb
spark_api-1.4.18 spec/unit/spark_api/models/dirty_spec.rb
spark_api-1.4.17 spec/unit/spark_api/models/dirty_spec.rb
spark_api-1.4.16 spec/unit/spark_api/models/dirty_spec.rb
spark_api-1.4.15 spec/unit/spark_api/models/dirty_spec.rb
spark_api-1.4.14 spec/unit/spark_api/models/dirty_spec.rb
spark_api-1.4.13 spec/unit/spark_api/models/dirty_spec.rb