-
Notifications
You must be signed in to change notification settings - Fork 510
Expand file tree
/
Copy pathapplication_helper_test.rb
More file actions
73 lines (57 loc) · 1.88 KB
/
Copy pathapplication_helper_test.rb
File metadata and controls
73 lines (57 loc) · 1.88 KB
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
require "test_helper"
class ApplicationHelperTest < ActionView::TestCase
test "only at most 2 initials" do
assert_equal "jz", at_most_two_initials("jdz")
end
test "single initials allowed" do
assert_equal "q", at_most_two_initials("q")
end
test "nil returns nil" do
assert_nil at_most_two_initials(nil)
end
test "can have numbers" do
assert_equal "P2", at_most_two_initials("P2")
end
test "does not change case" do
assert_equal "p2", at_most_two_initials("p2")
end
test "returns the correct two initials when there are more than two" do
assert_equal "kS", at_most_two_initials("kRxS")
end
test "can have spaces" do
assert_equal "pQ", at_most_two_initials("p v Q")
end
# Profile picture helper tests
test "user_avatar_image_tag returns nil when user has no profile picture" do
user = users(:keith)
assert_nil user_avatar_image_tag(user)
end
test "user_avatar_image_tag returns image tag when user has profile picture" do
user = users(:keith)
user.profile_picture.attach(
io: StringIO.new("fake image data"),
filename: "test.jpg",
content_type: "image/jpeg"
)
result = user_avatar_image_tag(user)
assert_not_nil result
assert_includes result, "img"
assert_includes result, "test.jpg"
end
test "user_avatar_url returns fallback when user has no profile picture" do
user = users(:keith)
fallback_url = "http://example.com/default.jpg"
assert_equal fallback_url, user_avatar_url(user, fallback: fallback_url)
end
test "user_avatar_url returns profile picture URL when user has profile picture" do
user = users(:keith)
user.profile_picture.attach(
io: StringIO.new("fake image data"),
filename: "test.jpg",
content_type: "image/jpeg"
)
result = user_avatar_url(user)
assert_not_nil result
assert_includes result, "test.jpg"
end
end