Skip to content

Commit

Permalink
hashie#559 - #deep_symbolize_keys is inconsistent in Rails 7
Browse files Browse the repository at this point in the history
  • Loading branch information
DerekYu177 committed Mar 24, 2022
1 parent 3e57eb5 commit ffd328e
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 0 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
3 changes: 3 additions & 0 deletions spec/integration/rails7/.rspec
@@ -0,0 +1,3 @@
--colour
--format=documentation
--pattern=*_spec.rb
6 changes: 6 additions & 0 deletions spec/integration/rails7/Gemfile
@@ -0,0 +1,6 @@
source 'http://rubygems.org'

gem 'hashie', path: '../../..'
gem 'rails', '~> 7.0.2.3'
gem 'rspec', '~> 3.11.0'
gem 'rspec-rails'
15 changes: 15 additions & 0 deletions spec/integration/rails7/app.rb
@@ -0,0 +1,15 @@
require 'action_controller/railtie'
require 'action_view/railtie'
require 'action_view/testing/resolvers'
require 'rails/test_unit/railtie'

module RailsApp
class Application < ::Rails::Application
config.eager_load = false
config.secret_key_base = 'hashieintegrationtest'
end
end

Bundler.require(:default, Rails.env)

RailsApp::Application.initialize!
35 changes: 35 additions & 0 deletions spec/integration/rails7/integration_spec.rb
@@ -0,0 +1,35 @@
ENV['RAILS_ENV'] = 'test'

require 'rspec/core'

RSpec.describe 'rails' do
before do
require 'bundler'
require_relative 'app'
require 'rspec/rails'
end

it 'uses rails7' do
expect(Rails.version).to(eq("7.0.2.3"))
end

context '#deep_symbolize_keys' do
let(:mash) do
Hashie::Mash.new("shallow" => 1, "top-level" => { "deep" => 3, "nested" => 4 })
end

subject { mash.deep_symbolize_keys }

it 'symbolizes keys by access' do
expect(mash[:'top-level'][:deep]).to(eq(3))
end

it 'does not play well with #without, which calls each element directly' do
expect(mash[:'top-level'].without(:deep, :nested)).to(be_blank)
end

it 'does play well with #except, which monkey-patches Hash' do
expect(mash[:'top-level'].except(:deep, :nested)).to(be_blank)
end
end
end

0 comments on commit ffd328e

Please sign in to comment.