Skip to content

Commit

Permalink
Localization (#61)
Browse files Browse the repository at this point in the history
* Localize application views
* Update system tests to use authentication
* Swap selenium for cuprite
* Upgrade Rails to 7.0.7.2
  • Loading branch information
cmason committed Aug 30, 2023
1 parent ce52f3f commit 368702a
Show file tree
Hide file tree
Showing 23 changed files with 244 additions and 170 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ end
group :test do
# Use system testing [https://guides.rubyonrails.org/testing.html#system-testing]
gem "capybara"
gem "selenium-webdriver", "~> 4.11"
gem "cuprite"
gem "simplecov", require: false
end

Expand Down
129 changes: 66 additions & 63 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -10,67 +10,67 @@ GIT
GEM
remote: https://rubygems.org/
specs:
actioncable (7.0.6)
actionpack (= 7.0.6)
activesupport (= 7.0.6)
actioncable (7.0.7.2)
actionpack (= 7.0.7.2)
activesupport (= 7.0.7.2)
nio4r (~> 2.0)
websocket-driver (>= 0.6.1)
actionmailbox (7.0.6)
actionpack (= 7.0.6)
activejob (= 7.0.6)
activerecord (= 7.0.6)
activestorage (= 7.0.6)
activesupport (= 7.0.6)
actionmailbox (7.0.7.2)
actionpack (= 7.0.7.2)
activejob (= 7.0.7.2)
activerecord (= 7.0.7.2)
activestorage (= 7.0.7.2)
activesupport (= 7.0.7.2)
mail (>= 2.7.1)
net-imap
net-pop
net-smtp
actionmailer (7.0.6)
actionpack (= 7.0.6)
actionview (= 7.0.6)
activejob (= 7.0.6)
activesupport (= 7.0.6)
actionmailer (7.0.7.2)
actionpack (= 7.0.7.2)
actionview (= 7.0.7.2)
activejob (= 7.0.7.2)
activesupport (= 7.0.7.2)
mail (~> 2.5, >= 2.5.4)
net-imap
net-pop
net-smtp
rails-dom-testing (~> 2.0)
actionpack (7.0.6)
actionview (= 7.0.6)
activesupport (= 7.0.6)
actionpack (7.0.7.2)
actionview (= 7.0.7.2)
activesupport (= 7.0.7.2)
rack (~> 2.0, >= 2.2.4)
rack-test (>= 0.6.3)
rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.0, >= 1.2.0)
actiontext (7.0.6)
actionpack (= 7.0.6)
activerecord (= 7.0.6)
activestorage (= 7.0.6)
activesupport (= 7.0.6)
actiontext (7.0.7.2)
actionpack (= 7.0.7.2)
activerecord (= 7.0.7.2)
activestorage (= 7.0.7.2)
activesupport (= 7.0.7.2)
globalid (>= 0.6.0)
nokogiri (>= 1.8.5)
actionview (7.0.6)
activesupport (= 7.0.6)
actionview (7.0.7.2)
activesupport (= 7.0.7.2)
builder (~> 3.1)
erubi (~> 1.4)
rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.1, >= 1.2.0)
activejob (7.0.6)
activesupport (= 7.0.6)
activejob (7.0.7.2)
activesupport (= 7.0.7.2)
globalid (>= 0.3.6)
activemodel (7.0.6)
activesupport (= 7.0.6)
activerecord (7.0.6)
activemodel (= 7.0.6)
activesupport (= 7.0.6)
activestorage (7.0.6)
actionpack (= 7.0.6)
activejob (= 7.0.6)
activerecord (= 7.0.6)
activesupport (= 7.0.6)
activemodel (7.0.7.2)
activesupport (= 7.0.7.2)
activerecord (7.0.7.2)
activemodel (= 7.0.7.2)
activesupport (= 7.0.7.2)
activestorage (7.0.7.2)
actionpack (= 7.0.7.2)
activejob (= 7.0.7.2)
activerecord (= 7.0.7.2)
activesupport (= 7.0.7.2)
marcel (~> 1.0)
mini_mime (>= 1.1.0)
activesupport (7.0.6)
activesupport (7.0.7.2)
concurrent-ruby (~> 1.0, >= 1.0.2)
i18n (>= 1.6, < 2)
minitest (>= 5.1)
Expand Down Expand Up @@ -111,6 +111,9 @@ GEM
crass (1.0.6)
cssbundling-rails (1.2.0)
railties (>= 6.0.0)
cuprite (0.14.3)
capybara (~> 3.0)
ferrum (~> 0.13.0)
date (3.3.3)
debug (1.8.0)
irb (>= 1.5.0)
Expand All @@ -123,6 +126,11 @@ GEM
faraday-net_http (>= 2.0, < 3.1)
ruby2_keywords (>= 0.0.4)
faraday-net_http (3.0.2)
ferrum (0.13)
addressable (~> 2.5)
concurrent-ruby (~> 1.1)
webrick (~> 1.7)
websocket-driver (>= 0.6, < 0.8)
flay (2.13.1)
erubi (~> 1.10)
path_expander (~> 1.0)
Expand Down Expand Up @@ -176,7 +184,7 @@ GEM
marcel (1.0.2)
matrix (0.4.2)
method_source (1.0.0)
mini_mime (1.1.2)
mini_mime (1.1.5)
minitest (5.19.0)
msgpack (1.7.2)
multi_xml (0.6.0)
Expand All @@ -195,9 +203,9 @@ GEM
net-smtp (0.3.3)
net-protocol
nio4r (2.5.9)
nokogiri (1.15.3-x86_64-darwin)
nokogiri (1.15.4-x86_64-darwin)
racc (~> 1.4)
nokogiri (1.15.3-x86_64-linux)
nokogiri (1.15.4-x86_64-linux)
racc (~> 1.4)
oauth2 (2.0.9)
faraday (>= 0.17.3, < 3.0)
Expand All @@ -221,30 +229,30 @@ GEM
rack (>= 1.2.0)
rack-test (2.1.0)
rack (>= 1.3)
rails (7.0.6)
actioncable (= 7.0.6)
actionmailbox (= 7.0.6)
actionmailer (= 7.0.6)
actionpack (= 7.0.6)
actiontext (= 7.0.6)
actionview (= 7.0.6)
activejob (= 7.0.6)
activemodel (= 7.0.6)
activerecord (= 7.0.6)
activestorage (= 7.0.6)
activesupport (= 7.0.6)
rails (7.0.7.2)
actioncable (= 7.0.7.2)
actionmailbox (= 7.0.7.2)
actionmailer (= 7.0.7.2)
actionpack (= 7.0.7.2)
actiontext (= 7.0.7.2)
actionview (= 7.0.7.2)
activejob (= 7.0.7.2)
activemodel (= 7.0.7.2)
activerecord (= 7.0.7.2)
activestorage (= 7.0.7.2)
activesupport (= 7.0.7.2)
bundler (>= 1.15.0)
railties (= 7.0.6)
railties (= 7.0.7.2)
rails-dom-testing (2.2.0)
activesupport (>= 5.0.0)
minitest
nokogiri (>= 1.6)
rails-html-sanitizer (1.6.0)
loofah (~> 2.21)
nokogiri (~> 1.14)
railties (7.0.6)
actionpack (= 7.0.6)
activesupport (= 7.0.6)
railties (7.0.7.2)
actionpack (= 7.0.7.2)
activesupport (= 7.0.7.2)
method_source
rake (>= 12.2)
thor (~> 1.0)
Expand Down Expand Up @@ -295,11 +303,6 @@ GEM
simplecov (>= 0.22.0)
tty-which (~> 0.5.0)
virtus (~> 2.0)
rubyzip (2.3.2)
selenium-webdriver (4.11.0)
rexml (~> 3.2, >= 3.2.5)
rubyzip (>= 1.2.2, < 3.0)
websocket (~> 1.0)
sexp_processor (4.17.0)
simplecov (0.22.0)
docile (~> 1.1)
Expand Down Expand Up @@ -359,7 +362,7 @@ GEM
activemodel (>= 6.0.0)
bindex (>= 0.4.0)
railties (>= 6.0.0)
websocket (1.2.9)
webrick (1.8.1)
websocket-driver (0.7.6)
websocket-extensions (>= 0.1.0)
websocket-extensions (0.1.5)
Expand All @@ -379,6 +382,7 @@ DEPENDENCIES
bundler-leak
capybara
cssbundling-rails
cuprite
debug
jbuilder
jsbundling-rails
Expand All @@ -388,7 +392,6 @@ DEPENDENCIES
rails (~> 7.0.6)
rubocop-minitest
rubycritic
selenium-webdriver (~> 4.11)
simplecov
slack_sign_in!
sprockets-rails
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/sessions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ def create
if slack_authorization.successful?
user = find_or_create_user(slack_authorization.identity)
create_session_for_user(user)
flash[:notice] = t(:signed_in, name: user.name)
flash[:notice] = t(".success", name: user.name)
else
logger.error "Slack authorization failed: #{slack_authorization.inspect}"
flash[:alert] = t(slack_authorization.error)
Expand All @@ -15,7 +15,7 @@ def create

def destroy
session[:user_id] = nil
redirect_to root_path, notice: t(:signed_out)
redirect_to root_path, notice: t(".success")
end

private
Expand Down
13 changes: 13 additions & 0 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,17 @@ def flash_message(type, message)
message
end
end

def title
return t("letterkenny") unless content_for?(:title)
"#{content_for(:title)} | #{t("letterkenny")}"
end

def og_description
content_for?(:og_description) ? content_for(:og_description) : t("tagline")
end

def og_url
content_for?(:og_url) ? content_for(:og_url) : root_url
end
end
8 changes: 7 additions & 1 deletion app/helpers/users_helper.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
module UsersHelper
def avatar(user)
content_tag :figure, class: "image is-32x32" do
image_tag user.avatar_url, class: "is-rounded", size: 32, alt: user.name
if user.avatar_url
image_tag user.avatar_url, class: "is-rounded", size: 32, alt: user.name
else
content_tag :span, class: "icon" do
tag.i class: "fas fa-user-secret is-size-3"
end
end
end
end
end
12 changes: 6 additions & 6 deletions app/views/layouts/_navbar.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@
<div id="main-nav" class="navbar-menu">
<div class="navbar-start">
<div class="navbar-item">
Letterkenny consists of hicks, skids, hockey players, and Christians. These are their quotes.
<%= t("tagline") %>
</div>
</div>
<div class="navbar-end is-active">
<% if current_user %>
<div class="navbar-item has-dropdown has-dropdown-up is-hoverable">
<div class="navbar-item has-dropdown has-dropdown-up is-hoverable signed-in-user">
<div class="navbar-link">
<span>
<%= avatar(current_user) %>
Expand All @@ -27,17 +27,17 @@
</div>

<div class="navbar-dropdown">
<%= link_to root_path, title: "Admin", class: "navbar-item" do %>
<%= link_to root_path, title: t(".admin"), class: "navbar-item" do %>
<span class="icon">
<i class="fas fa-screwdriver-wrench"></i>
</span>
<span>Admin</span>
<span><%= t(".admin") %></span>
<% end %>
<%= link_to destroy_session_path, title: "Sign out", class: "navbar-item" do %>
<%= link_to destroy_session_path, title: t(".signout"), class: "navbar-item" do %>
<span class="icon">
<i class="fas fa-sign-out-alt"></i>
</span>
<span>Sign Out</span>
<span><%= t(".signout") %></span>
<% end %>
</div>
</div>
Expand Down
8 changes: 4 additions & 4 deletions app/views/layouts/_og_meta.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<meta property="og:type" content="website" />
<meta property="og:url" content="<%= content_for?(:og_url) ? yield(:og_url) : root_url %>" />
<meta property="og:title" content="Letterkenny Quotes" />
<meta property="og:description" content="<%= content_for?(:og_description) ? yield(:og_description) : "Random Letterkenny Quotes" %>" />
<meta property="og:url" content="<%= og_url %>" />
<meta property="og:title" content="<%=t("letterkenny")%>" />
<meta property="og:description" content="<%= og_description %>" />
<meta property="og:image" content="<%= image_url "letterkenny_logo.jpg" %>" />
<meta name="description" content="<%= content_for?(:og_description) ? yield(:og_description) : "Random Letterkenny Quotes" %>" />
<meta name="description" content="<%= og_description %>" />
2 changes: 1 addition & 1 deletion app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<!DOCTYPE html>
<html lang="en">
<head>
<title>LetterKenny Quotes</title>
<title><%= title %></title>
<meta name="viewport" content="width=device-width,initial-scale=1">
<%= csrf_meta_tags %>
<%= csp_meta_tag %>
Expand Down
1 change: 1 addition & 0 deletions config/environments/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,5 @@

# Annotate rendered view with file names.
# config.action_view.annotate_rendered_view_with_filenames = true
config.slack_sign_in.client = SlackSignIn::TestClient
end
36 changes: 0 additions & 36 deletions config/locales/en.yml

This file was deleted.

5 changes: 5 additions & 0 deletions config/locales/globals/en.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
en:
letterkenny: "LetterKenny Quotes"
tagline: "Letterkenny consists of hicks, skids, hockey players, and Christians. These are their quotes."
description: "Random Letterkenny Quotes"
invalid_scope_requested: "Permission to access Slack denied. Unable to authenticate."
Loading

0 comments on commit 368702a

Please sign in to comment.