Sha256: 687b3e2e07451c2f86b55d4c0953fcdaf66709089167aad983d4bc8dd1e6e18b

Contents?: true

Size: 1002 Bytes

Versions: 5

Compression:

Stored size: 1002 Bytes

Contents

shared_examples_for "a resource with an update action" do |valid_id, changes|
  describe "#update" do
    it "updates an existing object" do
      model = nil

      VCR.use_cassette("#{subject.endpoint}_show") do
        model = subject.find(valid_id)
      end

      changes.each do |attribute, value|
        expect(model[attribute]).not_to eq value
      end

      original_values = model.to_h.select do |attribute, _|
        changes.keys.include?(attribute)
      end

      VCR.use_cassette("#{subject.endpoint}_update") do
        model.update(changes)
      end

      VCR.use_cassette("#{subject.endpoint}_show_updated") do
        model = subject.find(valid_id)
      end
      changes.each do |attribute, value|
        expect(model[attribute]).to eq value
      end

      revert_changes(model, original_values)
    end
  end

  def revert_changes(model, original_values)
    VCR.use_cassette("#{subject.endpoint}_update_revert") do
      model.update(original_values)
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
namely-0.2.4 spec/shared_examples/a_resource_with_an_update_action.rb
namely-0.2.3 spec/shared_examples/a_resource_with_an_update_action.rb
namely-0.2.2 spec/shared_examples/a_resource_with_an_update_action.rb
namely-0.2.1 spec/shared_examples/a_resource_with_an_update_action.rb
namely-0.1.0 spec/shared_examples/a_resource_with_an_update_action.rb