summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Doubrovkine (dB.) @dblockdotorg <dblock@dblock.org>2017-02-11 11:48:57 -0500
committerGitHub <noreply@github.com>2017-02-11 11:48:57 -0500
commit876813a372e4b32e1a1d998be9f6841a292141b5 (patch)
tree2231a3869ec53ee582c0b7c00f02eef9eb814ee6
parentaef1b46e3a4bb7dfa5465160fcb356eebe729269 (diff)
parent7742133ffed9443dca581da597d44fb7dc0dd96d (diff)
downloadhashie-876813a372e4b32e1a1d998be9f6841a292141b5.tar.gz
Merge pull request #406 from michaelherold/fix-propagation-of-disable-warnings
Fix propagation of disable warnings
-rw-r--r--.rubocop_todo.yml17
-rw-r--r--CHANGELOG.md1
-rw-r--r--lib/hashie/mash.rb9
-rw-r--r--spec/hashie/mash_spec.rb11
-rw-r--r--spec/integration/omniauth-oauth2/Gemfile2
-rw-r--r--spec/integration/omniauth-oauth2/app.rb53
-rw-r--r--spec/integration/omniauth-oauth2/integration_spec.rb80
-rw-r--r--spec/integration/omniauth/Gemfile2
-rw-r--r--spec/integration/omniauth/app.rb11
-rw-r--r--spec/integration/omniauth/integration_spec.rb33
-rw-r--r--spec/integration/rails/Gemfile1
-rw-r--r--spec/integration/rails/app.rb48
-rw-r--r--spec/integration/rails/integration_spec.rb74
13 files changed, 190 insertions, 152 deletions
diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml
index 63464d3..d7d21a5 100644
--- a/.rubocop_todo.yml
+++ b/.rubocop_todo.yml
@@ -1,6 +1,6 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
-# on 2017-02-01 08:14:39 -0600 using RuboCop version 0.34.2.
+# on 2017-02-10 18:48:03 -0600 using RuboCop version 0.34.2.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
@@ -18,13 +18,13 @@ Metrics/AbcSize:
# Offense count: 2
# Configuration parameters: CountComments.
Metrics/ClassLength:
- Max: 200
+ Max: 204
# Offense count: 8
Metrics/CyclomaticComplexity:
Max: 11
-# Offense count: 239
+# Offense count: 242
# Configuration parameters: AllowURI, URISchemes.
Metrics/LineLength:
Max: 170
@@ -43,7 +43,7 @@ Style/CaseEquality:
Exclude:
- 'lib/hashie/hash.rb'
-# Offense count: 34
+# Offense count: 36
# Configuration parameters: Exclude.
Style/Documentation:
Enabled: false
@@ -57,15 +57,8 @@ Style/DoubleNegation:
- 'lib/hashie/mash.rb'
- 'spec/hashie/extensions/coercion_spec.rb'
-# Offense count: 5
+# Offense count: 7
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles, UseHashRocketsWithSymbolValues.
Style/HashSyntax:
Enabled: false
-
-# Offense count: 2
-# Cop supports --auto-correct.
-# Configuration parameters: EnforcedStyle, SupportedStyles, AllowInnerSlashes.
-Style/RegexpLiteral:
- Exclude:
- - 'Guardfile'
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 0cd0b48..67a4c10 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -29,6 +29,7 @@ scheme are considered to be bugs.
### Fixed
* [#402](https://github.com/intridea/hashie/pull/402): Use a Railtie to set Hashie.logger on rails boot - [@matthewrudy](https://github.com/matthewrudy).
+* [#406](https://github.com/intridea/hashie/pull/406): Ensure that subclasses that disable warnings propagate that setting to grandchild classes - [@michaelherold](https://github.com/michaelherold).
* Your contribution here.
### Security
diff --git a/lib/hashie/mash.rb b/lib/hashie/mash.rb
index d6b0aed..4008feb 100644
--- a/lib/hashie/mash.rb
+++ b/lib/hashie/mash.rb
@@ -86,6 +86,15 @@ module Hashie
!!@disable_warnings
end
+ # Inheritance hook that sets class configuration when inherited.
+ #
+ # @api semipublic
+ # @return [void]
+ def self.inherited(subclass)
+ super
+ subclass.disable_warnings if disable_warnings?
+ end
+
def self.load(path, options = {})
@_mashes ||= new
diff --git a/spec/hashie/mash_spec.rb b/spec/hashie/mash_spec.rb
index b66b9ba..6b9882b 100644
--- a/spec/hashie/mash_spec.rb
+++ b/spec/hashie/mash_spec.rb
@@ -155,6 +155,17 @@ describe Hashie::Mash do
it 'cannot disable logging on the base Mash' do
expect { Hashie::Mash.disable_warnings }.to raise_error(Hashie::Mash::CannotDisableMashWarnings)
end
+
+ it 'carries over the disable for warnings on grandchild classes' do
+ child_class = Class.new(Hashie::Mash) do
+ disable_warnings
+ end
+ grandchild_class = Class.new(child_class)
+
+ grandchild_class.new('trust' => { 'two' => 2 })
+
+ expect(logger_output).to be_blank
+ end
end
context 'updating' do
diff --git a/spec/integration/omniauth-oauth2/Gemfile b/spec/integration/omniauth-oauth2/Gemfile
index c2f9159..5e2bdee 100644
--- a/spec/integration/omniauth-oauth2/Gemfile
+++ b/spec/integration/omniauth-oauth2/Gemfile
@@ -4,4 +4,4 @@ gem 'hashie', path: '../../..'
gem 'omniauth-oauth2', '~> 1.4.0'
gem 'rails', '~> 5.0.1'
gem 'rspec', '~> 3.5.0'
-gem 'rack-test', '~> 0.6.3'
+gem 'rspec-rails'
diff --git a/spec/integration/omniauth-oauth2/app.rb b/spec/integration/omniauth-oauth2/app.rb
new file mode 100644
index 0000000..3784148
--- /dev/null
+++ b/spec/integration/omniauth-oauth2/app.rb
@@ -0,0 +1,53 @@
+require 'action_controller/railtie'
+require 'action_view/railtie'
+require 'action_view/testing/resolvers'
+require 'rails/test_unit/railtie'
+require_relative 'some_site'
+
+module RailsApp
+ class Application < ::Rails::Application
+ config.eager_load = false
+ config.secret_key_base = 'hashieintegrationtest'
+
+ config.middleware.use OmniAuth::Builder do
+ provider :some_site
+ end
+
+ routes.append do
+ get '/' => 'application#index'
+ end
+ end
+end
+
+LAYOUT = <<-HTML
+<!DOCTYPE html>
+<html>
+<head>
+ <title>TestApp</title>
+ <%= csrf_meta_tags %>
+</head>
+<body>
+<%= yield %>
+</body>
+</html>
+HTML
+
+INDEX = '<h1>Hello, world!</h1>'
+
+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
+end
+
+Bundler.require(:default, Rails.env)
+
+RailsApp::Application.initialize!
diff --git a/spec/integration/omniauth-oauth2/integration_spec.rb b/spec/integration/omniauth-oauth2/integration_spec.rb
index 3f3df8f..a7c912e 100644
--- a/spec/integration/omniauth-oauth2/integration_spec.rb
+++ b/spec/integration/omniauth-oauth2/integration_spec.rb
@@ -1,74 +1,26 @@
-$LOAD_PATH.unshift File.dirname(__FILE__)
-
-ENV['RACK_ENV'] = 'test'
+ENV['RAILS_ENV'] = 'test'
require 'rspec/core'
-require 'rails'
-require 'rails/all'
-require 'action_view/testing/resolvers'
-require 'some_site'
-
-module RailsApp
- class Application < ::Rails::Application
- config.action_dispatch.show_exceptions = false
- config.active_support.deprecation = :stderr
- config.eager_load = false
- config.root = __dir__
- config.secret_key_base = 'hashieintegrationtest'
- routes.append do
- get '/' => 'application#index'
- end
+RSpec.describe 'omniauth-oauth2 inside of rails', type: :request do
+ let(:stdout) { StringIO.new }
- config.assets.paths << File.join(__dir__, 'assets/javascripts')
- config.assets.debug = true
+ around(:each) do |example|
+ original_stdout = $stdout
+ $stdout = stdout
+ require_relative 'app'
+ require 'rspec/rails'
+ example.run
+ $stdout = original_stdout
end
-end
-
-LAYOUT = <<-HTML
-<!DOCTYPE html>
-<html>
-<head>
- <title>TestApp</title>
- <%= stylesheet_link_tag "application", :media => "all" %>
- <%= javascript_include_tag "application" %>
- <%= csrf_meta_tags %>
-</head>
-<body>
-<%= yield %>
-</body>
-</html>
-HTML
-
-INDEX = <<-HTML
-<h1>Hello, world!</h1>
-HTML
-
-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
+ it 'does not log anything to STDOUT when initializing a Rails app and is set to Rails logger' do
+ expect(stdout.string).to eq('')
+ expect(Hashie.logger).to eq(Rails.logger)
end
-end
-Rails.application.config.middleware.use OmniAuth::Builder do
- provider :some_site
-end
-
-# the order is important
-# hashie must be loaded first to register the railtie
-require 'hashie'
-RailsApp::Application.initialize!
-
-RSpec.describe 'the Hashie logger' do
- it 'is set to the Rails logger' do
- expect(Hashie.logger).to eq(Rails.logger)
+ it 'works' do
+ get '/'
+ assert_select 'h1', 'Hello, world!'
end
end
diff --git a/spec/integration/omniauth/Gemfile b/spec/integration/omniauth/Gemfile
index 5e656f8..cbb4b87 100644
--- a/spec/integration/omniauth/Gemfile
+++ b/spec/integration/omniauth/Gemfile
@@ -1,7 +1,7 @@
source 'http://rubygems.org'
gem 'hashie', path: '../../..'
-gem 'omniauth', '~> 1.3.2'
+gem 'omniauth', '~> 1.4.1'
gem 'sinatra'
gem 'rspec', '~> 3.5.0'
gem 'rack-test', '~> 0.6.3'
diff --git a/spec/integration/omniauth/app.rb b/spec/integration/omniauth/app.rb
new file mode 100644
index 0000000..dc0a260
--- /dev/null
+++ b/spec/integration/omniauth/app.rb
@@ -0,0 +1,11 @@
+require 'sinatra'
+require 'omniauth'
+
+class MyApplication < Sinatra::Base
+ use Rack::Session::Cookie, secret: 'hashie integration tests'
+ use OmniAuth::Strategies::Developer
+
+ get '/' do
+ 'Hello World'
+ end
+end
diff --git a/spec/integration/omniauth/integration_spec.rb b/spec/integration/omniauth/integration_spec.rb
index 848a61b..a1298dd 100644
--- a/spec/integration/omniauth/integration_spec.rb
+++ b/spec/integration/omniauth/integration_spec.rb
@@ -2,33 +2,34 @@ ENV['RACK_ENV'] = 'test'
require 'rspec/core'
require 'rack/test'
-require 'sinatra'
-require 'omniauth'
-class MyApplication < Sinatra::Base
- use Rack::Session::Cookie, secret: 'hashie integration tests'
- use OmniAuth::Strategies::Developer
-
- get '/' do
- 'Hello World'
+RSpec.configure do |config|
+ config.expect_with :rspec do |expect|
+ expect.syntax = :expect
end
end
-module RSpecMixin
+RSpec.describe 'omniauth' do
include Rack::Test::Methods
+
def app
MyApplication
end
-end
-RSpec.configure do |config|
- config.include RSpecMixin
- config.expect_with :rspec do |expect|
- expect.syntax = :expect
+ let(:stdout) { StringIO.new }
+
+ around(:each) do |example|
+ original_stdout = $stdout
+ $stdout = stdout
+ require_relative 'app'
+ example.run
+ $stdout = original_stdout
+ end
+
+ it 'does not log anything to STDOUT when initializing' do
+ expect(stdout.string).to eq('')
end
-end
-describe 'omniauth' do
it 'works' do
get '/'
expect(last_response).to be_ok
diff --git a/spec/integration/rails/Gemfile b/spec/integration/rails/Gemfile
index 87bc758..32e1749 100644
--- a/spec/integration/rails/Gemfile
+++ b/spec/integration/rails/Gemfile
@@ -3,3 +3,4 @@ source 'http://rubygems.org'
gem 'hashie', path: '../../..'
gem 'rails', '~> 5.0.1'
gem 'rspec', '~> 3.5.0'
+gem 'rspec-rails'
diff --git a/spec/integration/rails/app.rb b/spec/integration/rails/app.rb
new file mode 100644
index 0000000..9eed330
--- /dev/null
+++ b/spec/integration/rails/app.rb
@@ -0,0 +1,48 @@
+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
+
+LAYOUT = <<-HTML
+<!DOCTYPE html>
+<html>
+<head>
+ <title>TestApp</title>
+ <%= csrf_meta_tags %>
+</head>
+<body>
+<%= yield %>
+</body>
+</html>
+HTML
+
+INDEX = '<h1>Hello, world!</h1>'
+
+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
+end
+
+Bundler.require(:default, Rails.env)
+
+RailsApp::Application.initialize!
diff --git a/spec/integration/rails/integration_spec.rb b/spec/integration/rails/integration_spec.rb
index 6c00b86..9b150a2 100644
--- a/spec/integration/rails/integration_spec.rb
+++ b/spec/integration/rails/integration_spec.rb
@@ -1,68 +1,26 @@
-ENV['RACK_ENV'] = 'test'
+ENV['RAILS_ENV'] = 'test'
require 'rspec/core'
-require 'rails'
-require 'rails/all'
-require 'action_view/testing/resolvers'
-module RailsApp
- class Application < ::Rails::Application
- config.action_dispatch.show_exceptions = false
- config.active_support.deprecation = :stderr
- config.eager_load = false
- config.root = __dir__
- config.secret_key_base = 'hashieintegrationtest'
+RSpec.describe 'rails', type: :request do
+ let(:stdout) { StringIO.new }
- routes.append do
- get '/' => 'application#index'
- end
-
- config.assets.paths << File.join(__dir__, 'assets/javascripts')
- config.assets.debug = true
+ around(:each) do |example|
+ original_stdout = $stdout
+ $stdout = stdout
+ require_relative 'app'
+ require 'rspec/rails'
+ example.run
+ $stdout = original_stdout
end
-end
-
-LAYOUT = <<-HTML
-<!DOCTYPE html>
-<html>
-<head>
- <title>TestApp</title>
- <%= stylesheet_link_tag "application", :media => "all" %>
- <%= javascript_include_tag "application" %>
- <%= csrf_meta_tags %>
-</head>
-<body>
-<%= yield %>
-</body>
-</html>
-HTML
-
-INDEX = <<-HTML
-<h1>Hello, world!</h1>
-HTML
-
-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
+ it 'does not log anything to STDOUT when initializing and sets the Hashie logger to the Rails logger' do
+ expect(stdout.string).to eq('')
+ expect(Hashie.logger).to eq(Rails.logger)
end
-end
-# the order is important
-# hashie must be loaded first to register the railtie
-# then we can initialize
-require 'hashie'
-RailsApp::Application.initialize!
-
-RSpec.describe 'the Hashie logger' do
- it 'is set to the Rails logger' do
- expect(Hashie.logger).to eq(Rails.logger)
+ it 'works' do
+ get '/'
+ assert_select 'h1', 'Hello, world!'
end
end