Skip to content

Commit

Permalink
Move test classes to ScopeTest namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
lewispb committed Aug 13, 2023
1 parent 04a8849 commit ac9dc6a
Showing 1 changed file with 27 additions and 27 deletions.
54 changes: 27 additions & 27 deletions test/scope_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,63 +2,63 @@

require "test_helper"

class Identity
def id
1
class ScopeTest < ActiveSupport::TestCase
class Identity
def id
1
end
end
end

class Person
include Kredis::Attributes
class Person
include Kredis::Attributes

kredis_list :names_with_scope, scope: :identity
kredis_list :names_with_scope_and_key, scope: :identity, key: ->(person) { "custom_key_#{person.example_method}" }
kredis_list :names_with_scope, scope: :identity
kredis_list :names_with_scope_and_key, scope: :identity, key: ->(person) { "custom_key_#{person.example_method}" }

def identity
Identity.new
end
def identity
Identity.new
end

def example_method
"example"
def example_method
"example"
end
end
end

class Family
include Kredis::Attributes
class Family
include Kredis::Attributes

kredis_list :members
kredis_list :pets, key: "pets"
kredis_list :members_with_nil_scope, scope: ->(person) { nil }
kredis_list :members
kredis_list :pets, key: "pets"
kredis_list :members_with_nil_scope, scope: ->(person) { nil }

def id
1
def id
1
end
end
end


class ScopeTest < ActiveSupport::TestCase
setup do
@person = Person.new
@family = Family.new
end

test "key is scoped" do
assert_equal @person.names_with_scope.key, "identities:1:people:names_with_scope"
assert_equal @person.names_with_scope.key, "scope_test:identities:1:scope_test:people:names_with_scope"
end

test "key is scoped and has custom key component" do
assert_equal @person.names_with_scope_and_key.key, "identities:1:custom_key_example"
assert_equal @person.names_with_scope_and_key.key, "scope_test:identities:1:custom_key_example"
end

test "scope is nil and key is generated normally" do
assert_equal @family.members_with_nil_scope.key, "families:1:members_with_nil_scope"
assert_equal @family.members_with_nil_scope.key, "scope_test:families:1:members_with_nil_scope"
end

test "custom key" do
assert_equal @family.pets.key, "pets"
end

test "key without scope" do
assert_equal @family.members.key, "families:1:members"
assert_equal @family.members.key, "scope_test:families:1:members"
end
end

0 comments on commit ac9dc6a

Please sign in to comment.