- Letterkenny consists of hicks, skids, hockey players, and Christians. These are their quotes.
+ <%= t("tagline") %>
<% if current_user %>
-
+
diff --git a/app/views/layouts/_og_meta.html.erb b/app/views/layouts/_og_meta.html.erb
index 029c174..a9903be 100644
--- a/app/views/layouts/_og_meta.html.erb
+++ b/app/views/layouts/_og_meta.html.erb
@@ -1,6 +1,6 @@
-
-
-" />
+
+" />
+
" />
-" />
+
diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb
index 3869aa4..a37e400 100644
--- a/app/views/layouts/application.html.erb
+++ b/app/views/layouts/application.html.erb
@@ -1,7 +1,7 @@
- LetterKenny Quotes
+ <%= title %>
<%= csrf_meta_tags %>
<%= csp_meta_tag %>
diff --git a/config/environments/test.rb b/config/environments/test.rb
index 9de8427..b0e75c7 100644
--- a/config/environments/test.rb
+++ b/config/environments/test.rb
@@ -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
diff --git a/config/locales/en.yml b/config/locales/en.yml
deleted file mode 100644
index 7affb2a..0000000
--- a/config/locales/en.yml
+++ /dev/null
@@ -1,36 +0,0 @@
-# Files in the config/locales directory are used for internationalization
-# and are automatically loaded by Rails. If you want to use locales other
-# than English, add the necessary files in this directory.
-#
-# To use the locales, use `I18n.t`:
-#
-# I18n.t "hello"
-#
-# In views, this is aliased to just `t`:
-#
-# <%= t("hello") %>
-#
-# To use a different locale, set it with `I18n.locale`:
-#
-# I18n.locale = :es
-#
-# This would use the information in config/locales/es.yml.
-#
-# The following keys must be escaped otherwise they will not be retrieved by
-# the default I18n backend:
-#
-# true, false, on, off, yes, no
-#
-# Instead, surround them with single quotes.
-#
-# en:
-# "true": "foo"
-#
-# To learn more, please read the Rails Internationalization guide
-# available at https://guides.rubyonrails.org/i18n.html.
-
-en:
- hello: "Hello world"
- signed_in: "How are ya now %{name}!"
- signed_out: "We hate to see you pull a Letterkenny Leave"
- invalid_scope_requested: "Permission to access Slack denied. Unable to authenticate."
diff --git a/config/locales/globals/en.yml b/config/locales/globals/en.yml
new file mode 100644
index 0000000..46f96c8
--- /dev/null
+++ b/config/locales/globals/en.yml
@@ -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."
diff --git a/config/locales/views/layouts/navbar/en.yml b/config/locales/views/layouts/navbar/en.yml
new file mode 100644
index 0000000..1a6cba8
--- /dev/null
+++ b/config/locales/views/layouts/navbar/en.yml
@@ -0,0 +1,5 @@
+en:
+ layouts:
+ navbar:
+ admin: "Admin"
+ signout: "Sign Out"
diff --git a/config/locales/views/quotes/en.yml b/config/locales/views/quotes/en.yml
new file mode 100644
index 0000000..63f1c3e
--- /dev/null
+++ b/config/locales/views/quotes/en.yml
@@ -0,0 +1 @@
+en:
diff --git a/config/locales/views/sessions/en.yml b/config/locales/views/sessions/en.yml
new file mode 100644
index 0000000..dbea7a8
--- /dev/null
+++ b/config/locales/views/sessions/en.yml
@@ -0,0 +1,6 @@
+en:
+ sessions:
+ create:
+ success: "How are ya now %{name}!"
+ destroy:
+ success: "Maybe this calls for a Letterkenny Leave"
diff --git a/db/seeds.rb b/db/seeds.rb
index 79e0433..d468d7c 100644
--- a/db/seeds.rb
+++ b/db/seeds.rb
@@ -46,7 +46,8 @@
{text: "Real men finish what they started."},
{text: "It's a hard life pickin stones and pullin teets, but sure as gods got sandals, it sure beats fightin dudes with treasure trails."},
{text: "Do you guys do CrossFit? You can CrossFuck off!"},
- {text: "What’s up with your fuckin body hair big shoots? You look like a 12-year-old dutch girl."}
+ {text: "What’s up with your fuckin body hair big shoots? You look like a 12-year-old dutch girl."},
+ {text: "It sure is nice to be back in the comfort zone."}
])
daryl.quotes.create([
@@ -55,7 +56,8 @@
{text: "How're we going to fuck this pig?"},
{text: "Your neighbor put a Corvette engine in a Ford Ranger. Like, what a fuckin' basic."},
{text: "Closest you’re gettin’ to any action this weekend is givin’ the dairy cow’s teets a good scrubbin’."},
- {text: "Can't help gettin' a semi while bouncing around in a semi truck."}
+ {text: "Can't help gettin' a semi while bouncing around in a semi truck."},
+ {text: "Oh, bother."}
])
katy.quotes.create([
@@ -86,7 +88,8 @@
{text: "Out of the way I’m growing a tail!"},
{text: "Youse guys ever take the dirt road home?"},
{text: "That's what I appreciates about you."},
- {text: "I'm so upset about my perennials."}
+ {text: "I'm so upset about my perennials."},
+ {text: "You are obliged to partakes in some socials stimulations from times to time, lest the young lady becomes rastless."}
])
gail.quotes.create([
@@ -94,13 +97,15 @@
{text: "You wanna 68? That's when you go down on me... And I'll owe ya one"},
{text: "How many planets are there? Only seven after I destroy Uranus"},
{text: "I was flicking more bean than a Starbucks barista!"},
- {text: "Something about that old goat just really grinds my pepper."}
+ {text: "Something about that old goat just really grinds my pepper."},
+ {text: "No tushy play unless I ask for it - and I will ask for it."}
])
stewart.quotes.create([
{text: "Shirt tucker!"},
{text: "Wonderous!"},
- {text: "One does not simply hop on or off the Anabolia Express. No. You ride that juice train all the way to the end of the line."}
+ {text: "One does not simply hop on or off the Anabolia Express. No. You ride that juice train all the way to the end of the line."},
+ {text: "Ah, sweet hubris."}
])
glen.quotes.create([
diff --git a/test/application_system_test_case.rb b/test/application_system_test_case.rb
index 33264b9..62c618a 100644
--- a/test/application_system_test_case.rb
+++ b/test/application_system_test_case.rb
@@ -1,5 +1,7 @@
require "test_helper"
+require "capybara/cuprite"
class ApplicationSystemTestCase < ActionDispatch::SystemTestCase
- driven_by :selenium, using: :headless_chrome, screen_size: [1400, 1400]
+ driven_by :cuprite, screen_size: [1400, 1400], options:
+ {js_errors: true, inspector: true}
end
diff --git a/test/controllers/sessions_controller_test.rb b/test/controllers/sessions_controller_test.rb
index 9f2b1ae..62f12cf 100644
--- a/test/controllers/sessions_controller_test.rb
+++ b/test/controllers/sessions_controller_test.rb
@@ -10,7 +10,7 @@ def setup
test "should login user from slack" do
get create_session_url, env: slack_successful_authentication(@user)
- assert_equal t(:signed_in, name: @user.name), flash[:notice]
+ assert_equal t("sessions.create.success", name: @user.name), flash[:notice]
assert_equal @user.id, session[:user_id]
assert_redirected_to root_path
end
@@ -25,7 +25,7 @@ def setup
test "should be able to log out" do
get destroy_session_url
assert_nil session[:user_id]
- assert_equal t(:signed_out), flash[:notice]
+ assert_equal t("sessions.destroy.success"), flash[:notice]
assert_redirected_to root_path
end
@@ -33,51 +33,11 @@ def setup
assert_difference("User.count") do
get create_session_url, env: slack_successful_authentication(new_user)
end
- assert_equal t(:signed_in, name: new_user.name), flash[:notice]
+ assert_equal t("sessions.create.success", name: new_user.name), flash[:notice]
assert_not_nil session[:user_id]
assert_redirected_to root_path
end
- # The slack_sign_in gem passes the results of the slack sign in flow to the
- # controller as a flash message. We can simulate failed or successful authentication
- # attempts by crafting the flash message, avoiding having to do the oauth dance
- # during testing.
-
- def slack_successful_authentication(user)
- {
- ActionDispatch::Flash::KEY => ActionDispatch::Flash::FlashHash.new(
- slack_sign_in: {"success" => {
- "ok" => true,
- "scope" => "identity.basic,identity.email,identity.avatar,identity.team",
- "user_id" => user.slack_user_id,
- "team_id" => user.slack_team_id,
- "enterprise_id" => nil,
- "user" => {
- "name" => user.name,
- "id" => user.slack_user_id,
- "image_24" => "https://example.com/24.png",
- "image_32" => "https://example.com/32.png",
- "image_48" => "https://example.com/48.png",
- "image_72" => "https://example.com/72.png",
- "image_192" => "https://example.com/192.png",
- "image_512" => "https://example.com/512.png"
- },
- "team" => {
- "id" => user.slack_team_id
- }
- }}
- )
- }
- end
-
- def slack_failed_authentication
- {ActionDispatch::Flash::KEY => ActionDispatch::Flash::FlashHash.new(
- {slack_sign_in: {
- "error" => "invalid_scope_requested"
- }}
- )}
- end
-
def new_user
id = SecureRandom.uuid
User.new(name: "New Guy", slack_unique_id: id, slack_user_id: id, slack_team_id: id, avatar_url: "https://example.com/32.png")
diff --git a/test/helpers/application_helper_test.rb b/test/helpers/application_helper_test.rb
index 2cd374f..2165b0b 100644
--- a/test/helpers/application_helper_test.rb
+++ b/test/helpers/application_helper_test.rb
@@ -24,4 +24,22 @@ class ApplicationHelperTest < ActionView::TestCase
flash_message(:wat, message)
)
end
+
+ test "formats page specific title" do
+ content_for(:title) { "Page Title" }
+ assert_equal "Page Title | #{I18n.t("letterkenny")}", title
+ end
+
+ test "returns app name when page title is missing" do
+ assert_equal I18n.t("letterkenny"), title
+ end
+
+ test "formats page specific open graph description" do
+ content_for(:og_description) { "OG Description" }
+ assert_equal "OG Description", og_description
+ end
+
+ test "returns tagline when og_description is missing" do
+ assert_equal I18n.t("tagline"), og_description
+ end
end
diff --git a/test/helpers/users_helper_test.rb b/test/helpers/users_helper_test.rb
index 0424596..a172ff8 100644
--- a/test/helpers/users_helper_test.rb
+++ b/test/helpers/users_helper_test.rb
@@ -9,4 +9,14 @@ class UsersHelperTest < ActionView::TestCase
avatar(user)
)
end
+
+ test "should return a default avatar for users without an avatar" do
+ user = users(:slack)
+ user.avatar_url = nil
+
+ assert_dom_equal(
+ %(),
+ avatar(user)
+ )
+ end
end
diff --git a/test/support/authentication_helpers.rb b/test/support/authentication_helpers.rb
new file mode 100644
index 0000000..ba32896
--- /dev/null
+++ b/test/support/authentication_helpers.rb
@@ -0,0 +1,51 @@
+module AuthenticationHelpers
+ def log_in
+ visit root_url
+ assert has_button?("Sign in with Slack")
+ click_on "Sign in with Slack"
+ end
+
+ def log_out
+ visit destroy_session_url
+ end
+
+ # The slack_sign_in gem passes the results of the slack sign in flow to the
+ # controller as a flash message. We can simulate failed or successful authentication
+ # attempts by crafting the flash message, avoiding having to do the oauth dance
+ # during testing.
+
+ def slack_successful_authentication(user)
+ {
+ ActionDispatch::Flash::KEY => ActionDispatch::Flash::FlashHash.new(
+ slack_sign_in: {"success" => {
+ "ok" => true,
+ "scope" => "identity.basic,identity.email,identity.avatar,identity.team",
+ "user_id" => user.slack_user_id,
+ "team_id" => user.slack_team_id,
+ "enterprise_id" => nil,
+ "user" => {
+ "name" => user.name,
+ "id" => user.slack_user_id,
+ "image_24" => "https://example.com/24.png",
+ "image_32" => "https://example.com/32.png",
+ "image_48" => "https://example.com/48.png",
+ "image_72" => "https://example.com/72.png",
+ "image_192" => "https://example.com/192.png",
+ "image_512" => "https://example.com/512.png"
+ },
+ "team" => {
+ "id" => user.slack_team_id
+ }
+ }}
+ )
+ }
+ end
+
+ def slack_failed_authentication
+ {ActionDispatch::Flash::KEY => ActionDispatch::Flash::FlashHash.new(
+ {slack_sign_in: {
+ "error" => "invalid_scope_requested"
+ }}
+ )}
+ end
+end
diff --git a/test/support/quote_helpers.rb b/test/support/quote_helpers.rb
new file mode 100644
index 0000000..e2ec2e9
--- /dev/null
+++ b/test/support/quote_helpers.rb
@@ -0,0 +1,8 @@
+module QuotesHelpers
+ def assert_quote_rendered
+ assert_selector "h1.quote"
+ assert has_link?("Random Quote")
+ assert(has_link?("Wayne Quote") || has_link?("Katy Quote"), "Missing random character quote button")
+ assert has_link?("Permalink")
+ end
+end
diff --git a/test/system/nav_bar_test.rb b/test/system/nav_bar_test.rb
new file mode 100644
index 0000000..45af44f
--- /dev/null
+++ b/test/system/nav_bar_test.rb
@@ -0,0 +1,19 @@
+require "application_system_test_case"
+
+class NavBarTest < ApplicationSystemTestCase
+ test "when logged out the sign in with slack button is seen" do
+ visit root_url
+ assert_selector "button.slack-sign-in"
+ end
+
+ test "when logged in can see the admin link" do
+ log_in
+ assert_selector "div.signed-in-user"
+ find("div.signed-in-user").click
+ assert_selector "a.navbar-item", text: "Admin"
+ assert_selector "a.navbar-item", text: "Sign Out"
+ click_on "Sign Out"
+ refute_selector "div.signed-in-user"
+ assert_selector "button.slack-sign-in"
+ end
+end
diff --git a/test/test_helper.rb b/test/test_helper.rb
index 6ca2c48..2024c3b 100644
--- a/test/test_helper.rb
+++ b/test/test_helper.rb
@@ -6,6 +6,8 @@
require "minitest/autorun"
require "minitest/pride"
+Dir[Rails.root.join("test", "support", "**", "*.rb")].each { |f| require f }
+
class ActiveSupport::TestCase
# Run tests in parallel with specified workers
parallelize(workers: :number_of_processors)
@@ -14,11 +16,6 @@ class ActiveSupport::TestCase
fixtures :all
# Add more helper methods to be used by all tests here...
- def assert_quote_rendered
- assert_selector "h1.quote"
- assert has_link?("Random Quote")
- assert(has_link?("Wayne Quote") || has_link?("Katy Quote"), "Missing random character quote button")
- assert has_link?("Permalink")
- # assert_match(%r{/quotes/\d+}, current_path, "should redirect to quote_path")
- end
+ include AuthenticationHelpers
+ include QuotesHelpers
end
<%= avatar(current_user) %>
@@ -27,17 +27,17 @@
- <%= link_to root_path, title: "Admin", class: "navbar-item" do %>
+ <%= link_to root_path, title: t(".admin"), class: "navbar-item" do %>
- Admin
+ <%= t(".admin") %>
<% 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 %>
- Sign Out
+ <%= t(".signout") %>
<% end %>