Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't "require 'rails'" at require-time laserlemon#205 #1

Merged
merged 1 commit into from
Aug 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions lib/figaro/rails.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
begin
require "rails"
rescue LoadError
else
# at require-time, we need Rails to be defined to initialize the railtie
# and set the default adapter to the Rails::Application adapter
if defined?(Rails)
require "figaro/rails/application"
require "figaro/rails/railtie"

Figaro.adapter = Figaro::Rails::Application
end
6 changes: 6 additions & 0 deletions spec/figaro/rails/application_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
require 'figaro/rails/application'

module Figaro
module Rails
describe Application do
before do
stub_const('Rails', double('Rails'))
end

describe "#default_path" do
let!(:application) { Application.new }

Expand Down
7 changes: 7 additions & 0 deletions spec/figaro_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
describe Figaro do
describe 'require' do
it 'does not load Rails' do
require 'figaro'
expect(defined?(Rails)).to be nil
end
end

describe ".env" do
it "falls through to Figaro::ENV" do
expect(Figaro.env).to eq(Figaro::ENV)
Expand Down