Skip to content

support rails 3 secret_token #6

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
6 changes: 5 additions & 1 deletion lib/rails/secrets/railtie.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@ class Railtie < ::Rails::Railtie
if app.secrets.secret_key_base.blank?
raise "Missing `secret_key_base` for '#{Rails.env}' environment, set this value in `config/secrets.yml`"
else
app.config.secret_key_base = app.secrets.secret_key_base
if Rails::VERSION::MAJOR < 4
app.config.secret_token = app.secrets.secret_key_base
else
app.config.secret_key_base = app.secrets.secret_key_base
end
end
end
end
Expand Down
11 changes: 9 additions & 2 deletions test/rails_secrets_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class RailsSecretsTest < ActiveSupport::TestCase
end

test "config.secret_key_base is copied from secrets.secret_key_base" do
assert_equal app.secrets.secret_key_base, app.config.secret_key_base
assert_equal app.secrets.secret_key_base, secret_key_base
end

private
Expand All @@ -22,4 +22,11 @@ def app
Rails.application
end

end
def secret_key_base
if Rails::VERSION::MAJOR < 4
app.config.secret_token
else
app.config.secret_key_base
end
end
end