Sha256: 91f56f2cca69e9a8c91f98cc8b6081933bd22cc472b71331d160737b70695782

Contents?: true

Size: 998 Bytes

Versions: 1

Compression:

Stored size: 998 Bytes

Contents

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

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

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

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

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

      VCR.use_cassette("#{classname}_show_updated") do
        model = described_class.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("#{classname}_update_revert") do
      model.update(original_values)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
namely-0.0.1 spec/shared_examples/a_model_with_an_update_action.rb