Sha256: a3b99875958a1a4a4dc959c077c6f1270743abbbe13c1b0ebf1d95d40de8bcc9
Contents?: true
Size: 1.93 KB
Versions: 124
Compression:
Stored size: 1.93 KB
Contents
# frozen_string_literal: true RSpec.describe :transform_keys do link :transform_keys, from: :ree_hash context "deep" do it { hash = {id: 1, name: 'John', array: [1,2,3], hash: {id: 1, name: 'Doe'}} result = transform_keys(hash) { _1.to_s } expect(result).to eq( {'id' => 1, 'name' => 'John', 'array' => [1,2,3], 'hash' => {'id' => 1, 'name' => 'Doe'}} ) } end context "deep = false" do it { hash = {id: 1, name: 'John', array: [1,2,3], hash: {id: 1, name: 'Doe'}} result = transform_keys(hash, deep: false) { _1.to_s } expect(result).to eq( {'id' => 1, 'name' => 'John', 'array' => [1,2,3], 'hash' => {id: 1, name: 'Doe'}} ) } end context "default" do it { hash = {id: 1, name: 'John', array: [1,2,3], hash: {id: 1, name: 'Doe'}} hash.default = 1 result = transform_keys(hash, deep: false) { _1.to_s } expect(result.default).to eq(1) expect(result['hash'].default).to eq(nil) } it { hash = {id: 1, name: 'John', array: [1,2,3], hash: {id: 1, name: 'Doe'}} hash.default_proc = Proc.new { 1 } result = transform_keys(hash, deep: false) { _1.to_s } expect(result.default_proc).to eq(hash.default_proc) expect(result['hash'].default).to eq(nil) } it { obj = {id: 1, name: 'Doe'} obj.default = 2 hash = {id: 1, name: 'John', array: [1,2,3], hash: obj} hash.default = 1 result = transform_keys(hash, deep: false) { _1.to_s } expect(result.default).to eq(1) expect(result['hash'].default).to eq(2) } it { obj = {id: 1, name: 'Doe'} obj.default_proc = Proc.new { 2 } hash = {id: 1, name: 'John', array: [1,2,3], hash: obj} hash.default = 1 result = transform_keys(hash, deep: false) { _1.to_s } expect(result.default).to eq(1) expect(result['hash'].default_proc).to eq(obj.default_proc) } end end
Version data entries
124 entries across 124 versions & 1 rubygems