Compare commits

..

No commits in common. "455a20283e1f0a7ddeac2305eb8f3682ccf5ba82" and "c82a5897d7bf4a5663083362f24282cb8f0c3ea5" have entirely different histories.

10 changed files with 10 additions and 59 deletions

View file

@ -1,3 +1,2 @@
class ApplicationController < ActionController::Base class ApplicationController < ActionController::Base
include Authenticatable
end end

View file

@ -1,13 +0,0 @@
module Authenticatable
extend ActiveSupport::Concern
included do
before_action :authenticate_user
end
private
def authenticate_user
Current.user = User.find_by(id: session[:current_user_id]) || GuestUser.new
end
end

View file

@ -1,3 +0,0 @@
class Current < ActiveSupport::CurrentAttributes
attribute :user
end

View file

@ -1,3 +0,0 @@
class GuestUser
def registered? = false
end

View file

@ -1,5 +1,3 @@
class User < ApplicationRecord class User < ApplicationRecord
has_secure_password has_secure_password
def registered? = true
end end

View file

@ -19,11 +19,7 @@
<li class="mr-6"><%= link_to "Credit Card Bills", credit_card_bills_path, class: "text-white" %></li> <li class="mr-6"><%= link_to "Credit Card Bills", credit_card_bills_path, class: "text-white" %></li>
<li class="mr-6"><%= link_to "Incomes", incomes_path, class: "text-white" %></li> <li class="mr-6"><%= link_to "Incomes", incomes_path, class: "text-white" %></li>
<li class="mr-6"><%= link_to "Members", members_path, class: "text-white" %></li> <li class="mr-6"><%= link_to "Members", members_path, class: "text-white" %></li>
<% if Current.user.registered? %>
<li class="mr-6"><%= link_to "Log out", session_path, data: {turbo_method: :delete}, class: "text-white" %></li> <li class="mr-6"><%= link_to "Log out", session_path, data: {turbo_method: :delete}, class: "text-white" %></li>
<% else %>
<li class="mr-6"><%= link_to "Log in", new_session_path, class: "text-white" %></li>
<% end %>
</ul> </ul>
</nav> </nav>

View file

@ -4,15 +4,4 @@ class ApplicationSystemTestCase < ActionDispatch::SystemTestCase
driven_by :selenium, driven_by :selenium,
using: ENV["VISIBLE_SYSTEM_TESTS"].present? ? :chrome : :headless_chrome, using: ENV["VISIBLE_SYSTEM_TESTS"].present? ? :chrome : :headless_chrome,
screen_size: [ 1400, 1400 ] screen_size: [ 1400, 1400 ]
def login(email, password = "secret")
visit new_session_url
fill_in "Email", with: email
fill_in "Password", with: "secret"
click_on "Create Session"
assert_text "Session was successfully created"
end
end end

View file

@ -1,11 +0,0 @@
require "test_helper"
class GuestUserTest < ActiveSupport::TestCase
setup do
@user = GuestUser.new
end
def test_registered_false
assert_not @user.registered?
end
end

View file

@ -1,11 +1,7 @@
require "test_helper" require "test_helper"
class UserTest < ActiveSupport::TestCase class UserTest < ActiveSupport::TestCase
setup do # test "the truth" do
@user = users(:one) # assert true
end # end
def test_registered_true
assert @user.registered?
end
end end

View file

@ -6,14 +6,17 @@ class SessionsTest < ApplicationSystemTestCase
end end
test "should create session" do test "should create session" do
login(@user.email) visit new_session_url
fill_in "Email", with: @user.email
fill_in "Password", with: "secret"
click_on "Create Session"
assert_text "Session was successfully created" assert_text "Session was successfully created"
end end
test "should destroy Session" do test "should destroy Session" do
login(@user.email)
visit root_url visit root_url
click_on "Log out", match: :first click_on "Log out", match: :first