Sha256: 490fd2aa7a2ffa1ec91ae050305a7ecb422e852d616d1218be001b911f8b060b

Contents?: true

Size: 1.59 KB

Versions: 9

Compression:

Stored size: 1.59 KB

Contents

# encoding: UTF-8

require 'gooddata/helpers/csv_helper'

describe GoodData::Helpers do
  describe '#diff' do

    before :each do

      @old_tomas = { id: 1, name: 'Tomas', age: 28 }
      @new_tomas = { id: 1, name: "Lil'Tomas", age: 28 }
      @patrick = { id: 4, name: 'Patrick', age: 24 }
      @old_korczis = { id: 3, name: 'Korczis', age: 23 }
      @new_korczis = { id: 3, name: "Korczis", age: 22 }
      @petr = { id: 2, name: 'Petr', age: 32 }
      @cvengy = { id: 5, name: 'Petr', age: 30 }

      @old_list = [@cvengy, @old_tomas, @patrick, @old_korczis]
      @new_list = [@cvengy, @new_tomas, @petr, @new_korczis]
    end

    it 'diffs two lists of hashes' do
      diff = GoodData::Helpers.diff(@old_list, @new_list, key: :id)

      expect(diff[:same]).to eq [@cvengy]
      expect(diff[:added]).to eq [@petr]
      expect(diff[:removed]).to eq [@patrick]
      expect(diff[:changed]).to eq([
        {
          old_obj: @old_tomas,
          new_obj: @new_tomas, 
          diff: { name: "Lil'Tomas"}
        },
        {
          old_obj: @old_korczis,
          new_obj: @new_korczis,
          diff: { age: 22 }
        }
      ])
    end

    it 'diffs two lists of hashes on subset of fields' do
      diff = GoodData::Helpers.diff(@old_list, @new_list, key: :id, fields: [:id, :age])

      expect(diff[:same]).to eq [@cvengy, @old_tomas]
      expect(diff[:added]).to eq [@petr]
      expect(diff[:removed]).to eq [@patrick]
      expect(diff[:changed]).to eq([
        {
          old_obj: @old_korczis,
          new_obj: @new_korczis,
          diff: { age: 22 }
        }
      ])
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
gooddata-0.6.20 spec/unit/helpers/global_helpers_spec.rb
gooddata-0.6.19 spec/unit/helpers/global_helpers_spec.rb
gooddata-0.6.18 spec/unit/helpers/global_helpers_spec.rb
gooddata-0.6.17 spec/unit/helpers/global_helpers_spec.rb
gooddata-0.6.16 spec/unit/helpers/global_helpers_spec.rb
gooddata-0.6.15 spec/unit/helpers/global_helpers_spec.rb
gooddata-0.6.14 spec/unit/helpers/global_helpers_spec.rb
gooddata-0.6.13 spec/unit/helpers/global_helpers_spec.rb
gooddata-0.6.12 spec/unit/helpers/global_helpers_spec.rb