Delegate Current.user to session

This commit is contained in:
Jose Farias
2024-10-23 18:49:40 -06:00
parent cf22fb454a
commit 208ace7214
4 changed files with 5 additions and 10 deletions
-2
View File
@@ -3,9 +3,7 @@ module Bubble::Assignable
included do
has_many :assignments, dependent: :delete_all
has_many :assignees, through: :assignments
has_many :assigners, through: :assignments
scope :unassigned, -> { where.missing :assignments }
scope :assigned_to, ->(users) { joins(:assignments).where(assignments: { assignee: users }) }
+2 -6
View File
@@ -1,10 +1,6 @@
class Current < ActiveSupport::CurrentAttributes
attribute :session, :user
attribute :session
delegate :user, to: :session, allow_nil: true
delegate :account, to: :user, allow_nil: true
def session=(session)
super
self.user = session.user
end
end
+2
View File
@@ -0,0 +1,2 @@
david:
user: david
+1 -2
View File
@@ -2,7 +2,7 @@ require "test_helper"
class BubbleTest < ActiveSupport::TestCase
setup do
Current.user = users(:kevin)
Current.session = sessions(:david)
end
test "boosting" do
@@ -15,7 +15,6 @@ class BubbleTest < ActiveSupport::TestCase
bubbles(:logo).assign users(:david)
assert_equal users(:kevin, :jz, :david), bubbles(:logo).assignees
assert_equal users(:david, :kevin), bubbles(:logo).assigners.uniq
assert_equal [ "David" ], Event.last.assignee_names
end