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

Commit untested Ruby and ERB code #56

Open
wants to merge 2 commits 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
10 changes: 5 additions & 5 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
name: Rails Unit Tests
on: [push, pull_request]
on: [push]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
Expand All @@ -20,6 +20,6 @@ jobs:
bundle exec rails db:migrate
bundle exec rails test
ruby -e "$(curl -s https://undercover-ci.com/uploader.rb)" -- \
--repo twitchy-tortoise/undercover-test \
--commit $GITHUB_SHA \
--lcov coverage/lcov/undercover-test.lcov
--repo twitchy-tortoise/undercover-test \
--commit {{ github.event.pull_request.head.sha || github.sha }} \
--lcov coverage/lcov/undercover-test.lcov
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 %>
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

View coverage analysis is coming soon! ⏰

<%= 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
4 changes: 2 additions & 2 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
require_relative '../config/environment'

require 'simplecov'
require 'simplecov-lcov'
SimpleCov::Formatter::LcovFormatter.config.report_with_single_file = true
SimpleCov.formatter = SimpleCov::Formatter::LcovFormatter
SimpleCov.start do
add_filter(/^\/test\//)
enable_coverage(:branch)
enable_coverage_for_eval
end

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
Loading