Sha256: 97b58b85935bc38926d47cd3640e153cbc1764e3d81930e410b3f06cfc0a1b8d

Contents?: true

Size: 1.07 KB

Versions: 1

Compression:

Stored size: 1.07 KB

Contents

require 'spec_helper'

describe 'Resource' do
  before(:all) do
    class Person
      include CurrencyCloud::Resource
      resource :people
      actions :update, :delete
    end
  end

  describe "#save" do
    it "only updates changed records" do
      person = Person.new(id: 1, name: 'Richard', surname: 'Nienaber')
      allow(Person.client).to receive(:post).with(1, name: 'John').and_return(id: 1, name: 'John', surname: 'Nienaber')
      person.name = 'John'

      expect(person.save).to eq(person)
      expect(person.changed_attributes).to eq(Set.new)
    end

    it "does nothing if nothing has changed" do
      person = Person.new(id: 1, name: 'Richard', surname: 'Nienaber')

      expect(person.save).to eq(person)
      expect(person.changed_attributes).to eq(Set.new)
    end
  end

  describe "#delete" do
    it 'removes resource' do
      person = Person.new(id: 1, name: 'Richard', surname: 'Nienaber')
      # Uses the class method to perform the deletion
      allow(Person).to receive(:delete).with(1)

      expect(person.delete).to eq(person)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
currency_cloud-0.7.2 spec/currency_cloud/resource_spec.rb