From 16787391d412718e1885df9dc8a5240a5025bf8a Mon Sep 17 00:00:00 2001 From: Jan Grodowski Date: Sun, 30 Jul 2023 11:32:28 +0200 Subject: [PATCH] Add some demo code (incl unteseted ERB) --- Gemfile | 3 +++ Gemfile.lock | 12 ++++++++++++ app/controllers/application_controller.rb | 10 +++++++++- app/views/home/index.haml | 8 ++++++++ app/views/home/index.html.erb | 2 -- app/views/layouts/application.html.erb | 3 +++ test/controllers/home_controller_test.rb | 2 +- test/test_helper.rb | 3 ++- 8 files changed, 38 insertions(+), 5 deletions(-) create mode 100644 app/views/home/index.haml delete mode 100644 app/views/home/index.html.erb diff --git a/Gemfile b/Gemfile index ab10196..16db30c 100644 --- a/Gemfile +++ b/Gemfile @@ -20,6 +20,9 @@ gem 'jbuilder' # Use Active Model has_secure_password # gem 'bcrypt', '~> 3.1.7' +# Try out haml coverage +gem 'haml-rails' + # Use Active Storage variant # gem 'image_processing', '~> 1.2' diff --git a/Gemfile.lock b/Gemfile.lock index a0a1793..b4fb576 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -90,6 +90,15 @@ GEM ffi (1.15.5) globalid (1.1.0) activesupport (>= 5.0) + haml (6.1.1) + temple (>= 0.8.2) + thor + tilt + haml-rails (2.1.0) + actionpack (>= 5.1) + activesupport (>= 5.1) + haml (>= 4.0.6) + railties (>= 5.1) i18n (1.14.1) concurrent-ruby (~> 1.0) jbuilder (2.11.5) @@ -195,7 +204,9 @@ GEM sprockets (>= 3.0.0) sqlite3 (1.6.3) mini_portile2 (~> 2.8.0) + temple (0.10.2) thor (1.2.2) + tilt (2.2.0) timeout (0.4.0) turbolinks (5.2.1) turbolinks-source (~> 5.2) @@ -226,6 +237,7 @@ DEPENDENCIES bootsnap byebug capybara (>= 2.15) + haml-rails jbuilder listen mocha diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 62fb35b..a6aa874 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1,8 +1,16 @@ class ApplicationController < ActionController::Base private + def check_cookie + if params[:x] != ENV.fetch("CODE", "beta") + redirect_to(bounce_home_index_url) and return + end + + cookies[:beta_sign_in] = { value: 1, expires: 1.year } + end + def check_beta_cookie - redirect_to(bounce_home_index_url) and return if params[:x] != ENV.fetch("BETA_CODE", "beta") + redirect_to(bounce_home_index_url) and return if params[:x] != ENV.fetch("CODE", "beta") cookies[:beta_sign_in] = { value: 1, expires: 1.year } end diff --git a/app/views/home/index.haml b/app/views/home/index.haml new file mode 100644 index 0000000..36b6772 --- /dev/null +++ b/app/views/home/index.haml @@ -0,0 +1,8 @@ +%p + Hi! ✅ + From: + =controller.class.name +- if controller.class.name == 'WelcomeController' + %p Unreachable element +- else + %p Unreachable element \ No newline at end of file diff --git a/app/views/home/index.html.erb b/app/views/home/index.html.erb deleted file mode 100644 index 4bfe424..0000000 --- a/app/views/home/index.html.erb +++ /dev/null @@ -1,2 +0,0 @@ -Hi! ✅ -From: <%= controller.class.name %> \ No newline at end of file diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index c8034e2..135f9c8 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -10,6 +10,9 @@ + <% if controller.class.name == "FancyController" %> +

Undercover Agent 🕵️‍♂️

+ <% end %> <%= yield %> diff --git a/test/controllers/home_controller_test.rb b/test/controllers/home_controller_test.rb index 929e84f..bb849e3 100644 --- a/test/controllers/home_controller_test.rb +++ b/test/controllers/home_controller_test.rb @@ -3,7 +3,7 @@ class HomeControllerTest < ActionDispatch::IntegrationTest test "the truth" do ApplicationController.any_instance.stubs(:current_user).returns(nil) - ENV['BETA_CODE'] = 'false' + ENV['CODE'] = 'false' get "/home?x=falsey" assert_equal 302, status diff --git a/test/test_helper.rb b/test/test_helper.rb index 431094d..7787c58 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -1,3 +1,5 @@ +require_relative '../config/environment' + require 'simplecov' require 'simplecov-lcov' SimpleCov::Formatter::LcovFormatter.config.report_with_single_file = true @@ -10,7 +12,6 @@ ENV['RAILS_ENV'] ||= 'test' require 'mocha/minitest' -require_relative '../config/environment' require 'rails/test_help' class ActiveSupport::TestCase # Run tests in parallel with specified workers