Sha256: f168f6711fa11a9d6069debd1e6e69711c9b2196c6e69af9e8826c83e7ba3174

Contents?: true

Size: 984 Bytes

Versions: 2

Compression:

Stored size: 984 Bytes

Contents

require 'spec_helper'

describe 'Resource' do
  before(:all) do
    class Person < 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).to receive(:post).with(1, name: 'John')
      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')
      allow(Person).to receive(:post).with('1/delete')

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

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
currency_cloud-0.7.1 spec/currency_cloud/resource_spec.rb
currency_cloud-0.7 spec/currency_cloud/resource_spec.rb