Skip to content
This repository has been archived by the owner on Oct 23, 2024. It is now read-only.

Commit

Permalink
Replace Config::Options#delegate to simple method definitions (rubyco…
Browse files Browse the repository at this point in the history
  • Loading branch information
yhatt authored and vencislavdimitrov committed Sep 12, 2018
1 parent 503cf98 commit 2b1f178
Show file tree
Hide file tree
Showing 15 changed files with 99 additions and 25 deletions.
5 changes: 5 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,17 @@ gemfile:
- gemfiles/rails_4.1.gemfile
- gemfiles/rails_4.2.gemfile
- gemfiles/rails_5.gemfile
- gemfiles/sinatra.gemfile
matrix:
exclude:
- rvm: 2.0.0
gemfile: gemfiles/rails_5.gemfile
- rvm: 2.0.0
gemfile: gemfiles/sinatra.gemfile
- rvm: 2.1.10
gemfile: gemfiles/rails_5.gemfile
- rvm: 2.1.10
gemfile: gemfiles/sinatra.gemfile
- rvm: 2.2.6
gemfile: gemfiles/rails_3.gemfile
- rvm: 2.3.3
Expand Down
4 changes: 4 additions & 0 deletions Appraisals
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,7 @@ end
appraise 'rails-5' do
gem 'rails', '5.0.0.1'
end

appraise 'sinatra' do
gem 'sinatra', '2.0.0'
end
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@

### New features

* Fix `key?` and `has_key?`, which raise NoMethodError in non Rails environment, by using ActiveSupport `#delegate` implicitly ([#185](https://github.com/railsconfig/config/pull/185))

## 1.6.0

**New features**

* `Config#fail_on_missing` option (default `false`) to raise a `KeyError` exception when accessing a non-existing key
* Add ability to test if a value was set for a given key with `key?` and `has_key?`

Expand Down
2 changes: 1 addition & 1 deletion gemfiles/rails_3.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ source "https://rubygems.org"

gem "rails", "3.2.22.4"

gemspec :path => "../"
gemspec path: "../"
4 changes: 2 additions & 2 deletions gemfiles/rails_4.1.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
source "https://rubygems.org"

gem "rails", "4.1.16"
gem "tzinfo-data", :platforms => [:mingw, :mswin, :x64_mingw]
gem "tzinfo-data", platforms: [:mingw, :mswin, :x64_mingw]

gemspec :path => "../"
gemspec path: "../"
4 changes: 2 additions & 2 deletions gemfiles/rails_4.2.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
source "https://rubygems.org"

gem "rails", "4.2.7.1"
gem "tzinfo-data", :platforms => [:mingw, :mswin, :x64_mingw]
gem "tzinfo-data", platforms: [:mingw, :mswin, :x64_mingw]

gemspec :path => "../"
gemspec path: "../"
2 changes: 1 addition & 1 deletion gemfiles/rails_4.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ source "https://rubygems.org"

gem "rails", "4.0.13"

gemspec :path => "../"
gemspec path: "../"
2 changes: 1 addition & 1 deletion gemfiles/rails_5.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ source "https://rubygems.org"

gem "rails", "5.0.0.1"

gemspec :path => "../"
gemspec path: "../"
7 changes: 7 additions & 0 deletions gemfiles/sinatra.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# This file was generated by Appraisal

source "https://rubygems.org"

gem "sinatra", "2.0.0"

gemspec path: "../"
8 changes: 7 additions & 1 deletion lib/config/options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,13 @@ def []=(param, value)
end
end

delegate :key?, :has_key?, to: :table
def key?(key)
table.key?(key)
end

def has_key?(key)
table.has_key?(key)
end

def method_missing(method_name, *args)
if Config.fail_on_missing && method_name !~ /.*(?==\z)/m
Expand Down
9 changes: 9 additions & 0 deletions spec/app/sinatra/app.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
require 'sinatra'
require File.expand_path('../../../../lib/config', __FILE__)

set :root, File.dirname(__FILE__)
register Config

get '/' do
'Hello world!'
end
48 changes: 36 additions & 12 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,52 @@
Dir['./spec/support/**/*.rb'].each { |f| require f }

##
# Load Rails dummy application based on gemfile name substituted by Appraisal
# Detect Rails/Sinatra dummy application based on gemfile name substituted by Appraisal
#
if ENV['APPRAISAL_INITIALIZED'] || ENV['TRAVIS']
app_name = Pathname.new(ENV['BUNDLE_GEMFILE']).basename.sub('.gemfile', '')
else
app_name = 'rails_5'
end

require File.expand_path("../../spec/app/#{app_name}/config/environment", __FILE__)

APP_RAKEFILE = File.expand_path("../../spec/app/#{app_name}/Rakefile", __FILE__)
app_framework = %w{rails sinatra}.find { |f| app_name.to_s.include?(f) }

##
# Load Rspec
# Load dummy application and Rspec
#
require 'rspec/rails'
case app_framework
when 'rails'
# Load Rails
require File.expand_path("../app/#{app_name}/config/environment", __FILE__)

# Configure
RSpec.configure do |config|
config.fixture_path = File.join(File.dirname(__FILE__), '/fixtures')
APP_RAKEFILE = File.expand_path("../app/#{app_name}/Rakefile", __FILE__)

# Load Rspec
require 'rspec/rails'

# Configure
RSpec.configure do |config|
config.fixture_path = FixtureHelper::FIXTURE_PATH
end

when 'sinatra'
# Load Sinatra
require File.expand_path("../app/#{app_name}/app", __FILE__)

# Load Rspec
require 'rspec'

# Configure
RSpec.configure do |config|
config.filter_run_excluding :rails
config.include FixtureHelper
end
end

##
# Common Rspec configure
#
RSpec.configure do |config|
# Turn the deprecation warnings into errors, giving you the full backtrace
config.raise_errors_for_deprecations!

Expand All @@ -53,16 +78,15 @@ def self.reset
end
end


##
# Print some debug info
#
puts
puts "Gemfile: #{ENV['BUNDLE_GEMFILE']}"
puts 'Rails version:'
puts 'Version:'

Gem.loaded_specs.each { |name, spec|
puts "\t#{name}-#{spec.version}" if %w{rails activesupport sqlite3 rspec-rails}.include?(name)
puts "\t#{name}-#{spec.version}" if %w{rails activesupport sqlite3 rspec-rails sinatra}.include?(name)
}

puts
12 changes: 12 additions & 0 deletions spec/support/fixture_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
##
# Config Fixture Helpers
#

module FixtureHelper
FIXTURE_PATH = File.expand_path('../../fixtures', __FILE__)

# Provide fixture path as same way as rspec-rails
def fixture_path
FIXTURE_PATH
end
end
9 changes: 5 additions & 4 deletions spec/support/shared_contexts/rake.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
require 'rake'

shared_context 'rake' do

# include rails rake tasks
load 'rails/tasks/engine.rake'
before do
require 'rake'
load 'rails/tasks/engine.rake'
end

end
end
2 changes: 1 addition & 1 deletion spec/tasks/db_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'spec_helper'

describe 'db:create' do
describe 'db:create', :rails do
include_context 'rake'

it 'has access to Settings object and can read databases from settings.yml file' do
Expand Down

0 comments on commit 2b1f178

Please # to comment.