Sha256: 4a45b10263375d1523145440df25f638690e209a2a2aed2833d4c43cc0e54780

Contents?: true

Size: 1.99 KB

Versions: 12

Compression:

Stored size: 1.99 KB

Contents

# frozen_string_literal: true

require 'rails_helper'

describe DHS::Record do
  context 'merge' do
    before do
      class Change < DHS::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

12 entries across 12 versions & 1 rubygems

Version Path
dhs-1.6.0 spec/record/force_merge_spec.rb
dhs-1.5.0 spec/record/force_merge_spec.rb
dhs-1.4.2 spec/record/force_merge_spec.rb
dhs-1.4.1 spec/record/force_merge_spec.rb
dhs-1.4.0 spec/record/force_merge_spec.rb
dhs-1.3.0 spec/record/force_merge_spec.rb
dhs-1.2.0 spec/record/force_merge_spec.rb
dhs-1.1.0 spec/record/force_merge_spec.rb
dhs-1.0.3 spec/record/force_merge_spec.rb
dhs-1.0.2 spec/record/force_merge_spec.rb
dhs-1.0.1 spec/record/force_merge_spec.rb
dhs-1.0.0 spec/record/force_merge_spec.rb