-
-
Notifications
You must be signed in to change notification settings - Fork 311
/
auth_accessors_spec.rb
114 lines (92 loc) · 2.96 KB
/
auth_accessors_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# frozen_string_literal: true
require "rails_helper"
module Alchemy
class MyCustomUser
end
describe "AuthAccessors" do
describe ".user_class_name" do
before do
Alchemy.user_class_name = "DummyClassName"
end
it "raises error if user_class_name is not a String" do
Alchemy.user_class_name = DummyUser
expect {
Alchemy.user_class_name
}.to raise_error(TypeError)
end
it "returns user_class_name with :: prefix" do
expect(Alchemy.user_class_name).to eq("::DummyClassName")
end
end
describe ".user_class" do
context "with no custom user_class_name set" do
before do
Alchemy.user_class_name = "User"
end
context "and the default user class exists" do
class ::User; end
it "returns the default user class" do
expect(Alchemy.user_class).to be(::User)
end
end
context "and the default user class does not exist" do
before do
if Object.constants.include?(:User)
Object.send(:remove_const, :User)
end
end
it "returns nil" do
expect(Alchemy.user_class).to be_nil
end
it "logs warning" do
expect(Rails.logger).to receive(:warn).with(a_string_matching("AlchemyCMS cannot find any user class"))
Alchemy.user_class
end
end
end
context "with custom user_class_name set" do
before do
Alchemy.user_class_name = "DummyUser"
end
context "and the custom User class exists" do
it "returns the custom user class" do
expect(Alchemy.user_class).to be(::DummyUser)
end
end
context "and the custom user class does not exist" do
before do
Alchemy.user_class_name = "NoUser"
end
it "returns nil" do
expect(Alchemy.user_class).to be_nil
end
it "logs warning" do
expect(Rails.logger).to receive(:warn).with(a_string_matching("AlchemyCMS cannot find any user class"))
Alchemy.user_class
end
end
end
end
describe "defaults" do
it "has default value for Alchemy.user_class_primary_key" do
expect(Alchemy.user_class_primary_key).to eq(:id)
end
it "has default value for Alchemy.signup_path" do
expect(Alchemy.signup_path).to eq("/signup")
end
it "has default value for Alchemy.login_path" do
expect(Alchemy.login_path).to eq("/login")
end
it "has default value for Alchemy.logout_path" do
expect(Alchemy.logout_path).to eq("/logout")
end
it "has default value for Alchemy.logout_method" do
expect(Alchemy.logout_method).to eq("delete")
end
end
after do
Alchemy.user_class_name = "DummyUser"
Alchemy.class_variable_set("@@user_class", nil)
end
end
end