Sha256: d117c52ccd5dc24777873e22dba6b118d07111a22c1c4f292573dd086aa116a1

Contents?: true

Size: 1.99 KB

Versions: 59

Compression:

Stored size: 1.99 KB

Contents

# frozen_string_literal: true

require 'rails_helper'

describe LHS::Record do
  context 'merge' do

    before do
      class Change < LHS::Record
        endpoint 'https://onboarding/places/{id}/change'
      end
    end

    it 'merges a given hash' do
      stub_request(:get, "https://onboarding/places/1/change")
        .to_return(body: { entry: { name: 'Steve', address: 'Zurich' }, products: ['LBP'] }.to_json)
      record = Change.find(1)
      record.merge!(entry: { name: 'Paul' })
      expect(record.entry.name).to eq 'Paul'
      expect(record.entry.address).to eq nil
      expect(record.products.to_a).to eq ['LBP']
    end

    it 'merges! a given hash' do
      stub_request(:get, "https://onboarding/places/1/change")
        .to_return(body: { entry: { name: 'Steve', address: 'Zurich' }, products: ['LBP'] }.to_json)
      record = Change.find(1)
      new_record = record.merge(entry: { name: 'Paul' })
      expect(new_record.entry.name).to eq 'Paul'
      expect(new_record.entry.address).to eq nil
      expect(new_record.products.to_a).to eq ['LBP']
      expect(record.entry.name).to eq 'Steve'
      expect(record.entry.address).to eq 'Zurich'
      expect(record.products.to_a).to eq ['LBP']
    end

    it 'deep_merge! a given hash' do
      stub_request(:get, "https://onboarding/places/1/change")
        .to_return(body: { entry: { name: 'Steve', address: 'Zurich' } }.to_json)
      record = Change.find(1)
      record.deep_merge!(entry: { name: 'Paul' })
      expect(record.entry.name).to eq 'Paul'
      expect(record.entry.address).to eq 'Zurich'
    end

    it 'deep_merge a given hash' do
      stub_request(:get, "https://onboarding/places/1/change")
        .to_return(body: { entry: { name: 'Steve', address: 'Zurich' } }.to_json)
      record = Change.find(1)
      new_record = record.deep_merge(entry: { name: 'Paul' })
      expect(new_record.entry.name).to eq 'Paul'
      expect(new_record.entry.address).to eq 'Zurich'
      expect(record.entry.name).to eq 'Steve'
    end
  end
end

Version data entries

59 entries across 59 versions & 1 rubygems

Version Path
lhs-22.1.1.pre spec/record/force_merge_spec.rb
lhs-22.1.0 spec/record/force_merge_spec.rb
lhs-22.0.0 spec/record/force_merge_spec.rb
lhs-21.3.1 spec/record/force_merge_spec.rb
lhs-21.3.0 spec/record/force_merge_spec.rb
lhs-21.3.0.pre.autoauth.1 spec/record/force_merge_spec.rb
lhs-21.2.4 spec/record/force_merge_spec.rb
lhs-21.2.3 spec/record/force_merge_spec.rb
lhs-21.2.3.pre.preload.pre.providers.pre.too.1 spec/record/force_merge_spec.rb
lhs-21.2.2 spec/record/force_merge_spec.rb
lhs-21.2.1 spec/record/force_merge_spec.rb
lhs-21.2.0 spec/record/force_merge_spec.rb
lhs-21.1.4 spec/record/force_merge_spec.rb
lhs-21.1.3 spec/record/force_merge_spec.rb
lhs-21.1.2 spec/record/force_merge_spec.rb
lhs-21.1.2.pre.keyfix.2 spec/record/force_merge_spec.rb
lhs-21.1.2.pre.keyfix.1 spec/record/force_merge_spec.rb
lhs-21.1.2.pre.fix.pre.cant.pre.add.pre.new.pre.key.pre.during.pre.iteration.1 spec/record/force_merge_spec.rb
lhs-21.1.1.pre.pre.fix.pre.cant.pre.add.pre.new.pre.key.pre.during.pre.iteration.1 spec/record/force_merge_spec.rb
lhs-21.1.0 spec/record/force_merge_spec.rb