From 6fabbfd31af5952f363a8dc573bfa2059e41371d Mon Sep 17 00:00:00 2001 From: Abe Flansburg Date: Tue, 6 Dec 2022 08:58:15 -0600 Subject: =?UTF-8?q?new=20integration=20spec=20for=20rails=207=20exhibiting?= =?UTF-8?q?=20failure=20when=20executing=20de=E2=80=A6=20(#569)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 3 +- spec/integration/rails_7/.rspec | 3 ++ spec/integration/rails_7/Gemfile | 6 +++ spec/integration/rails_7/app.rb | 40 +++++++++++++++++ spec/integration/rails_7/integration_spec.rb | 64 ++++++++++++++++++++++++++++ 5 files changed, 115 insertions(+), 1 deletion(-) create mode 100644 spec/integration/rails_7/.rspec create mode 100644 spec/integration/rails_7/Gemfile create mode 100644 spec/integration/rails_7/app.rb create mode 100644 spec/integration/rails_7/integration_spec.rb diff --git a/CHANGELOG.md b/CHANGELOG.md index bc57ada..5067120 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,12 +12,13 @@ Any violations of this scheme are considered to be bugs. ### Added +* [#569](https://github.com/hashie/hashie/pull/569): Added support for Rails 7 - [@aflansburg](https://github.com/aflansburg). * Your contribution here. ### Changed -* Your contribution here. * [#558](https://github.com/hashie/hashie/pull/558): Test with Ruby 3.1 - [@petergoldstein](https://github.com/petergoldstein). +* Your contribution here. ### Deprecated diff --git a/spec/integration/rails_7/.rspec b/spec/integration/rails_7/.rspec new file mode 100644 index 0000000..a4c51e7 --- /dev/null +++ b/spec/integration/rails_7/.rspec @@ -0,0 +1,3 @@ +--colour +--format=documentation +--pattern=*_spec.rb diff --git a/spec/integration/rails_7/Gemfile b/spec/integration/rails_7/Gemfile new file mode 100644 index 0000000..1b6d630 --- /dev/null +++ b/spec/integration/rails_7/Gemfile @@ -0,0 +1,6 @@ +source 'http://rubygems.org' + +gem 'hashie', path: '../../..' +gem 'rails', '~> 7.0.0' +gem 'rspec', '~> 3.5.0' +gem 'rspec-rails' diff --git a/spec/integration/rails_7/app.rb b/spec/integration/rails_7/app.rb new file mode 100644 index 0000000..1065688 --- /dev/null +++ b/spec/integration/rails_7/app.rb @@ -0,0 +1,40 @@ +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' + + routes.append do + get '/' => 'application#index' + end + end +end + +PAGE = <<-HTML.freeze + + + + TestApp + <%= csrf_meta_tags %> + + +

Hello, world!

+ + +HTML + +class ApplicationController < ActionController::Base + include Rails.application.routes.url_helpers + + def index + render inline: PAGE + end +end + +Bundler.require(:default, Rails.env) + +RailsApp::Application.initialize! diff --git a/spec/integration/rails_7/integration_spec.rb b/spec/integration/rails_7/integration_spec.rb new file mode 100644 index 0000000..0e69880 --- /dev/null +++ b/spec/integration/rails_7/integration_spec.rb @@ -0,0 +1,64 @@ +ENV['RAILS_ENV'] = 'test' + +require 'rspec/core' + +RSpec.describe 'rails', type: :request do + let(:stdout) { StringIO.new } + + around(:each) do |example| + original_stdout = $stdout + $stdout = stdout + require_relative 'app' + require 'rspec/rails' + example.run + $stdout = original_stdout + end + + it 'does not log anything to STDOUT when initializing' do + expect(stdout.string).to eq('') + end + + it 'sets the Hashie logger to the Rails logger' do + expect(Hashie.logger).to eq(Rails.logger) + end + + context '#except' do + subject { Hashie::Mash.new(x: 1, y: 2) } + + it 'returns an instance of the class it was called on' do + class HashieKlass < Hashie::Mash; end + hashie_klass = HashieKlass.new(subject) + expect(hashie_klass.except('x')).to be_a HashieKlass + end + + it 'works with string keys' do + expect(subject.except('x')).to eq Hashie::Mash.new(y: 2) + end + + it 'works with symbol keys' do + expect(subject.except(:x)).to eq Hashie::Mash.new(y: 2) + end + end + + context '#deep_transform_keys' do + let(:klass) do + Class.new(Hashie::Dash) do + property :foo_bar + property :foo_baz, required: true + end + end + + subject(:hash) { klass.new(foo_bar: 'bar', foo_baz: 'baz') } + + it 'sucessfully deep transforms keys' do + pending('https://github.com/hashie/hashie/issues/559') + transformed = hash.deep_transform_keys(&:to_s) + expect(transformed.keys).to all(be_a(String)) + end + end + + it 'works' do + get '/' + assert_select 'h1', 'Hello, world!' + end +end -- cgit v1.2.1