From 368702aa967ebd8630b6ca103bd82af493ab6099 Mon Sep 17 00:00:00 2001 From: Chris Mason <47318+cmason@users.noreply.github.com> Date: Wed, 30 Aug 2023 18:45:01 -0500 Subject: [PATCH] Localization (#61) * Localize application views * Update system tests to use authentication * Swap selenium for cuprite * Upgrade Rails to 7.0.7.2 --- Gemfile | 2 +- Gemfile.lock | 129 ++++++++++--------- app/controllers/sessions_controller.rb | 4 +- app/helpers/application_helper.rb | 13 ++ app/helpers/users_helper.rb | 8 +- app/views/layouts/_navbar.html.erb | 12 +- app/views/layouts/_og_meta.html.erb | 8 +- app/views/layouts/application.html.erb | 2 +- config/environments/test.rb | 1 + config/locales/en.yml | 36 ------ config/locales/globals/en.yml | 5 + config/locales/views/layouts/navbar/en.yml | 5 + config/locales/views/quotes/en.yml | 1 + config/locales/views/sessions/en.yml | 6 + db/seeds.rb | 15 ++- test/application_system_test_case.rb | 4 +- test/controllers/sessions_controller_test.rb | 46 +------ test/helpers/application_helper_test.rb | 18 +++ test/helpers/users_helper_test.rb | 10 ++ test/support/authentication_helpers.rb | 51 ++++++++ test/support/quote_helpers.rb | 8 ++ test/system/nav_bar_test.rb | 19 +++ test/test_helper.rb | 11 +- 23 files changed, 244 insertions(+), 170 deletions(-) delete mode 100644 config/locales/en.yml create mode 100644 config/locales/globals/en.yml create mode 100644 config/locales/views/layouts/navbar/en.yml create mode 100644 config/locales/views/quotes/en.yml create mode 100644 config/locales/views/sessions/en.yml create mode 100644 test/support/authentication_helpers.rb create mode 100644 test/support/quote_helpers.rb create mode 100644 test/system/nav_bar_test.rb diff --git a/Gemfile b/Gemfile index f7371c9..ba45d23 100644 --- a/Gemfile +++ b/Gemfile @@ -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 diff --git a/Gemfile.lock b/Gemfile.lock index bda2619..83fe907 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -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) @@ -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) @@ -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) @@ -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) @@ -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) @@ -221,20 +229,20 @@ 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 @@ -242,9 +250,9 @@ GEM 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) @@ -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) @@ -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) @@ -379,6 +382,7 @@ DEPENDENCIES bundler-leak capybara cssbundling-rails + cuprite debug jbuilder jsbundling-rails @@ -388,7 +392,6 @@ DEPENDENCIES rails (~> 7.0.6) rubocop-minitest rubycritic - selenium-webdriver (~> 4.11) simplecov slack_sign_in! sprockets-rails diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb index 0b1eaae..c48c83d 100644 --- a/app/controllers/sessions_controller.rb +++ b/app/controllers/sessions_controller.rb @@ -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) @@ -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 diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 1ac9d90..2061413 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -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 diff --git a/app/helpers/users_helper.rb b/app/helpers/users_helper.rb index 5b4f409..597e106 100644 --- a/app/helpers/users_helper.rb +++ b/app/helpers/users_helper.rb @@ -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 diff --git a/app/views/layouts/_navbar.html.erb b/app/views/layouts/_navbar.html.erb index f96b75a..74f907f 100644 --- a/app/views/layouts/_navbar.html.erb +++ b/app/views/layouts/_navbar.html.erb @@ -13,12 +13,12 @@