From ca3604516b5725b30a290482c219ca55fca5de49 Mon Sep 17 00:00:00 2001 From: Bobby McDonald Date: Wed, 2 Oct 2019 10:48:19 -0400 Subject: Make Hashie play nice with Rails 6 Hash#except method (#479) --- spec/integration/elasticsearch/Gemfile | 2 +- spec/integration/elasticsearch/integration_spec.rb | 2 +- spec/integration/rails/Gemfile | 2 +- spec/integration/rails/app.rb | 17 +++++------------ spec/integration/rails/integration_spec.rb | 18 ++++++++++++++++++ 5 files changed, 26 insertions(+), 15 deletions(-) (limited to 'spec') diff --git a/spec/integration/elasticsearch/Gemfile b/spec/integration/elasticsearch/Gemfile index 318242a..15dc04f 100644 --- a/spec/integration/elasticsearch/Gemfile +++ b/spec/integration/elasticsearch/Gemfile @@ -1,6 +1,6 @@ source 'http://rubygems.org' -gem 'elasticsearch-model' +gem 'elasticsearch-model', '~> 7.0' gem 'hashie', path: '../../..' gem 'rake' gem 'rspec', '~> 3.5.0' diff --git a/spec/integration/elasticsearch/integration_spec.rb b/spec/integration/elasticsearch/integration_spec.rb index 2c4e220..70689fb 100644 --- a/spec/integration/elasticsearch/integration_spec.rb +++ b/spec/integration/elasticsearch/integration_spec.rb @@ -23,7 +23,7 @@ RSpec.describe 'elaasticsearch-model' do object = MyModel.new stub_elasticsearch_client - expect { object.__elasticsearch__.index_document }.to raise_error(NoMethodError) + expect { object.__elasticsearch__.index_document }.to raise_error(NameError) end it 'does not raise an error when the model has an id' do diff --git a/spec/integration/rails/Gemfile b/spec/integration/rails/Gemfile index 32e1749..da94f2f 100644 --- a/spec/integration/rails/Gemfile +++ b/spec/integration/rails/Gemfile @@ -1,6 +1,6 @@ source 'http://rubygems.org' gem 'hashie', path: '../../..' -gem 'rails', '~> 5.0.1' +gem 'rails', '~> 6.0.0' gem 'rspec', '~> 3.5.0' gem 'rspec-rails' diff --git a/spec/integration/rails/app.rb b/spec/integration/rails/app.rb index dee7fe1..1065688 100644 --- a/spec/integration/rails/app.rb +++ b/spec/integration/rails/app.rb @@ -14,7 +14,7 @@ module RailsApp end end -LAYOUT = <<-HTML.freeze +PAGE = <<-HTML.freeze @@ -22,24 +22,17 @@ LAYOUT = <<-HTML.freeze <%= csrf_meta_tags %> -<%= yield %> +

Hello, world!

HTML -INDEX = '

Hello, world!

'.freeze - class ApplicationController < ActionController::Base include Rails.application.routes.url_helpers - layout 'application' - - self.view_paths = [ActionView::FixtureResolver.new( - 'layouts/application.html.erb' => LAYOUT, - 'application/index.html.erb' => INDEX - )] - - def index; end + def index + render inline: PAGE + end end Bundler.require(:default, Rails.env) diff --git a/spec/integration/rails/integration_spec.rb b/spec/integration/rails/integration_spec.rb index 9b150a2..dc1d670 100644 --- a/spec/integration/rails/integration_spec.rb +++ b/spec/integration/rails/integration_spec.rb @@ -19,6 +19,24 @@ RSpec.describe 'rails', type: :request 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 + it 'works' do get '/' assert_select 'h1', 'Hello, world!' -- cgit v1.2.1