Sha256: 4949d58f311a21594131944de1e2ccb2422a30b15f9702e1de2eae4cb7df57c2
Contents?: true
Size: 1.9 KB
Versions: 3
Compression:
Stored size: 1.9 KB
Contents
# frozen_string_literal: true require 'spec_helper' require 'action_controller' module SearchObject describe Helper do describe '.stringify_keys' do it 'converts hash keys to strings' do hash = described_class.stringify_keys a: 1, b: nil, c: false expect(hash).to eq 'a' => 1, 'b' => nil, 'c' => false end it 'converts ActionController::Parameters to hash' do params = ::ActionController::Parameters.new a: 1, b: nil, c: false hash = described_class.stringify_keys params expect(hash).to eq 'a' => 1, 'b' => nil, 'c' => false end end describe '.slice_keys' do it 'selects only given keys' do hash = described_class.slice_keys({ a: 1, b: 2, c: 3 }, %i[a b]) expect(hash).to eq a: 1, b: 2 end it 'ignores not existing keys' do hash = described_class.slice_keys({}, %i[a b]) expect(hash).to eq({}) end end describe 'camelize' do it "transforms :paging to 'Paging'" do expect(described_class.camelize(:paging)).to eq 'Paging' end end describe 'underscore' do it "transforms 'veryPopular' to 'very_popular'" do expect(described_class.underscore(:veryPopular)).to eq 'very_popular' expect(described_class.underscore('VERY_POPULAR')).to eq 'very_popular' end end describe 'deep_copy' do it 'returns a deep copy on the given object' do original = { array: [1, 2, 3], hash: { key: 'value' }, boolean: true, number: 1, null: nil } deep_copy = described_class.deep_copy(original) original[:array][0] = 42 original[:hash][:key] = 'other value' expect(deep_copy).to eq( array: [1, 2, 3], hash: { key: 'value' }, boolean: true, number: 1, null: nil ) end end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
search_object-1.2.5 | spec/search_object/helper_spec.rb |
search_object-1.2.4 | spec/search_object/helper_spec.rb |
search_object-1.2.3 | spec/search_object/helper_spec.rb |