From b816d8be946bf26aff61110407a269b644f0bb47 Mon Sep 17 00:00:00 2001 From: Roman Simecek Date: Tue, 17 Jun 2014 15:57:03 +0200 Subject: [PATCH 1/6] Make it rails 3.2.11 compatible. --- lib/rails/secrets/railtie.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/rails/secrets/railtie.rb b/lib/rails/secrets/railtie.rb index 1a0765e..4913d55 100644 --- a/lib/rails/secrets/railtie.rb +++ b/lib/rails/secrets/railtie.rb @@ -29,6 +29,7 @@ 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_token = app.secrets.secret_key_base app.config.secret_key_base = app.secrets.secret_key_base end end From 4b858b3843b1772d6fd7cac5725f5e84ff6b222d Mon Sep 17 00:00:00 2001 From: Roman Simecek Date: Mon, 23 Jun 2014 14:24:25 +0200 Subject: [PATCH 2/6] Extract into test_helper for reuse. --- test/rails_secrets_test.rb | 4 +--- test/test_helper.rb | 3 +++ 2 files changed, 4 insertions(+), 3 deletions(-) create mode 100644 test/test_helper.rb diff --git a/test/rails_secrets_test.rb b/test/rails_secrets_test.rb index 62347f6..ebb9d7b 100644 --- a/test/rails_secrets_test.rb +++ b/test/rails_secrets_test.rb @@ -1,6 +1,4 @@ -ENV["RAILS_ENV"] ||= 'test' -require File.expand_path('../dummy/config/environment', __FILE__) -require 'minitest/autorun' +require 'test_helper' class RailsSecretsTest < ActiveSupport::TestCase diff --git a/test/test_helper.rb b/test/test_helper.rb new file mode 100644 index 0000000..da74613 --- /dev/null +++ b/test/test_helper.rb @@ -0,0 +1,3 @@ +ENV["RAILS_ENV"] ||= 'test' +require File.expand_path('../dummy/config/environment', __FILE__) +require 'minitest/autorun' From b0ef3f238f31b30d083ca4c1c865c77220b417df Mon Sep 17 00:00:00 2001 From: Roman Simecek Date: Mon, 23 Jun 2014 14:24:58 +0200 Subject: [PATCH 3/6] Add newline at eof. --- test/rails_secrets_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/rails_secrets_test.rb b/test/rails_secrets_test.rb index ebb9d7b..ba2c2b6 100644 --- a/test/rails_secrets_test.rb +++ b/test/rails_secrets_test.rb @@ -20,4 +20,4 @@ def app Rails.application end -end \ No newline at end of file +end From 69941678a83183356c3a294bf0be5c40caa92b91 Mon Sep 17 00:00:00 2001 From: Roman Simecek Date: Mon, 23 Jun 2014 15:51:17 +0200 Subject: [PATCH 4/6] Skip active_record so that the dummy app works without a database. --- test/dummy/config/application.rb | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/test/dummy/config/application.rb b/test/dummy/config/application.rb index 60a8916..bd3f2dc 100644 --- a/test/dummy/config/application.rb +++ b/test/dummy/config/application.rb @@ -1,6 +1,12 @@ require File.expand_path('../boot', __FILE__) -require "rails/all" +require "active_model/railtie" +# require "active_record/railtie" +require "action_controller/railtie" +require "action_mailer/railtie" +require "action_view/railtie" +require "sprockets/railtie" +require "rails/test_unit/railtie" Bundler.require(*Rails.groups) From 8302271c7fc7d819c7e87213f3660311df575f00 Mon Sep 17 00:00:00 2001 From: Roman Simecek Date: Mon, 23 Jun 2014 15:52:27 +0200 Subject: [PATCH 5/6] Perpare the dummy app for integrationtest. --- test/dummy/app/controllers/application_controller.rb | 5 +++++ test/dummy/app/controllers/welcome_controller.rb | 7 +++++++ test/dummy/config/routes.rb | 3 +++ 3 files changed, 15 insertions(+) create mode 100644 test/dummy/app/controllers/application_controller.rb create mode 100644 test/dummy/app/controllers/welcome_controller.rb create mode 100644 test/dummy/config/routes.rb diff --git a/test/dummy/app/controllers/application_controller.rb b/test/dummy/app/controllers/application_controller.rb new file mode 100644 index 0000000..d83690e --- /dev/null +++ b/test/dummy/app/controllers/application_controller.rb @@ -0,0 +1,5 @@ +class ApplicationController < ActionController::Base + # Prevent CSRF attacks by raising an exception. + # For APIs, you may want to use :null_session instead. + protect_from_forgery with: :exception +end diff --git a/test/dummy/app/controllers/welcome_controller.rb b/test/dummy/app/controllers/welcome_controller.rb new file mode 100644 index 0000000..818db69 --- /dev/null +++ b/test/dummy/app/controllers/welcome_controller.rb @@ -0,0 +1,7 @@ +class WelcomeController < ApplicationController + + def index + render text: 'Welcome' + end + +end diff --git a/test/dummy/config/routes.rb b/test/dummy/config/routes.rb new file mode 100644 index 0000000..b01b75f --- /dev/null +++ b/test/dummy/config/routes.rb @@ -0,0 +1,3 @@ +Dummy::Application.routes.draw do + root :to => "welcome#index" +end From 6cf856a7cdeb2f90618259fe1dff32c608ddbb59 Mon Sep 17 00:00:00 2001 From: Roman Simecek Date: Mon, 23 Jun 2014 15:53:17 +0200 Subject: [PATCH 6/6] Create a test which calls the root page to ensure the secret_key_base or secret_token is properly set. --- test/rails_secrets_integration_test.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 test/rails_secrets_integration_test.rb diff --git a/test/rails_secrets_integration_test.rb b/test/rails_secrets_integration_test.rb new file mode 100644 index 0000000..99ad2b9 --- /dev/null +++ b/test/rails_secrets_integration_test.rb @@ -0,0 +1,10 @@ +require 'test_helper' + +class RailsSecretsIntegrationTest < ActionDispatch::IntegrationTest + + test "load root page" do + get '/' + assert_response :success + end + +end