-
Notifications
You must be signed in to change notification settings - Fork 1.8k
/
Copy pathuser_test.rb
145 lines (123 loc) · 4.27 KB
/
user_test.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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
require 'test_helper'
class UserTest < ActiveSupport::TestCase
test 'user creation' do
user = User.new(username: 'chris',
password: 'godzillas',
password_confirmation: 'godzillas',
email: 'test@publiclab.org')
assert user.save({})
assert user.first_time_poster
assert_not_nil user.id
assert_not_nil user.drupal_user
assert_not_nil user.uid
assert_not_nil user.email
assert_not_nil user.bio
assert_not_nil user.token
assert_not_nil user.path
assert_not_nil user.title
end
test 'basic user attributes' do
user = users(:jeff)
assert_equal user.notes, user.drupal_user.notes
assert_not_nil user.tags
assert_not_nil user.drupal_user.tags
assert_equal user.tags, user.drupal_user.tags
assert_not_nil user.user_tags
assert_not_nil user.drupal_user.user_tags
assert_equal user.user_tags, user.drupal_user.user_tags
assert_not_nil user.tagnames
assert_not_nil user.drupal_user.tagnames
assert_equal user.tagnames, user.drupal_user.tagnames
end
test 'user mysql native fulltext search' do
assert User.count > 0
if ActiveRecord::Base.connection.adapter_name == 'Mysql2'
users = User.search('really interesting')
assert_not_nil users
assert users.length > 0
end
end
test 'user questions' do
user = users(:jeff)
assert !user.questions.empty?
end
test 'user.notes and first time user' do
assert !drupal_users(:jeff).notes.empty?
assert !drupal_users(:jeff).first_time_poster
assert_not !drupal_users(:bob).notes.empty?
assert drupal_users(:bob).first_time_poster
assert_not !drupal_users(:lurker).notes.empty?
assert drupal_users(:lurker).first_time_poster
end
test 'user reset key' do
user = users(:jeff)
assert_nil user.reset_key
user.generate_reset_key
assert_not_nil user.reset_key
end
test 'should follow and unfollow user' do
bob = users(:bob)
jeff = users(:jeff)
assert_not bob.following?(jeff)
bob.follow(jeff)
assert bob.following?(jeff)
assert jeff.followers.include?(bob)
bob.unfollow(jeff)
assert_not bob.following?(jeff)
end
test "returns sha email for users who doesn't have image" do
bob = users(:bob)
assert_equal 'https://www.gravatar.com/avatar/927536542991ac10fe2c546bc386a521', bob.profile_image
end
test 'can add a user_tag and use has_tag method' do
tag = users(:bob).user_tags.new
tag.value = 'test:test'
assert tag.save
assert users(:bob).has_tag('test:test')
assert !users(:bob).has_tag('test:no')
end
test 'returns nodes created in past given period of time' do
lurker = users(:lurker)
node2 = users(:lurker).node.find_by_nid(20)
assert_equal [node2], lurker.content_followed_in_past_period(2.hours.ago)
end
test 'returns value of power tag' do
bob = users(:bob)
assert_equal bob.get_value_of_power_tag("skill") , "java"
end
test 'has power tag' do
bob = users(:bob)
assert bob.has_power_tag("skill")
end
test 'returns nodes coauthored by user with coauthored_notes method' do
jeff = users(:jeff)
bob = users(:bob)
assert bob.coauthored_notes.empty?
jeffs_note = nodes(:one)
jeffs_note.add_tag('with:bob', jeff)
coauthored_note = bob.coauthored_notes.first
assert_not_nil coauthored_note
assert_equal jeffs_note, coauthored_note
end
test 'contributor_count' do
contributor_count = User.contributor_count_for(Time.now-5.years, Time.now+5.days)
comment = Comment.new(uid: 99,
nid: 2,
status: 1,
comment: 'Note comment',
timestamp: Time.now.to_i + 2,
thread: '/02'
)
assert comment.save
current_contributor_count = User.contributor_count_for(Time.now-5.years, Time.now+5.days)
assert_equal current_contributor_count-contributor_count,1
end
test 'user with wrong email' do
user = User.new(username: 'chris',
password: 'godzillas',
password_confirmation: 'godzillas',
email: 'testpubliclab.org')
assert_not user.save({})
assert_equal 1, user.errors[:email].count
end
end