Sha256: 0ae39d46415d0a4ace6da0d968a3c0641be38a55b9a27886d6346a58673dd926

Contents?: true

Size: 1.07 KB

Versions: 5

Compression:

Stored size: 1.07 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 "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

end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
spark_api-1.3.3 spec/unit/spark_api/models/dirty_spec.rb
spark_api-1.3.1 spec/unit/spark_api/models/dirty_spec.rb
spark_api-1.3.0 spec/unit/spark_api/models/dirty_spec.rb
spark_api-1.2.1 spec/unit/spark_api/models/dirty_spec.rb
spark_api-1.2.0 spec/unit/spark_api/models/dirty_spec.rb