Skip to content

Commit

Permalink
Add some demo code (incl unteseted ERB)
Browse files Browse the repository at this point in the history
  • Loading branch information
grodowski committed Jan 22, 2024
1 parent c97f595 commit 1678739
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 5 deletions.
3 changes: 3 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down
12 changes: 12 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -226,6 +237,7 @@ DEPENDENCIES
bootsnap
byebug
capybara (>= 2.15)
haml-rails
jbuilder
listen
mocha
Expand Down
10 changes: 9 additions & 1 deletion app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down
8 changes: 8 additions & 0 deletions app/views/home/index.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
%p
Hi! ✅
From:
=controller.class.name
- if controller.class.name == 'WelcomeController'
%p Unreachable element
- else
%p Unreachable element
2 changes: 0 additions & 2 deletions app/views/home/index.html.erb

This file was deleted.

3 changes: 3 additions & 0 deletions app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
</head>

<body>
<% if controller.class.name == "FancyController" %>
<h1>Undercover Agent 🕵️‍♂️</h1>
<% end %>
<%= yield %>
</body>
</html>
2 changes: 1 addition & 1 deletion test/controllers/home_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 2 additions & 1 deletion test/test_helper.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require_relative '../config/environment'

require 'simplecov'
require 'simplecov-lcov'
SimpleCov::Formatter::LcovFormatter.config.report_with_single_file = true
Expand All @@ -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
Expand Down

0 comments on commit 1678739

Please sign in to comment.