|
1 | 1 | require 'spec_helper' |
2 | 2 |
|
3 | | -describe UsersController do |
| 3 | +describe UsersController do |
4 | 4 |
|
5 | 5 | before do |
6 | 6 | UsersController.any_instance.stubs(:honeypot_value).returns(nil) |
7 | 7 | UsersController.any_instance.stubs(:challenge_value).returns(nil) |
8 | 8 | end |
9 | 9 |
|
10 | | - describe '.show' do |
| 10 | + describe '.show' do |
11 | 11 | let!(:user) { log_in } |
12 | 12 |
|
13 | 13 | it 'returns success' do |
|
52 | 52 |
|
53 | 53 | it 'sets a flash error' do |
54 | 54 | flash[:error].should be_present |
55 | | - end |
| 55 | + end |
56 | 56 | end |
57 | 57 |
|
58 | 58 | context 'valid token' do |
|
74 | 74 | it 'logs in as the user' do |
75 | 75 | session[:current_user_id].should be_present |
76 | 76 | end |
77 | | - end |
| 77 | + end |
78 | 78 | end |
79 | 79 |
|
80 | 80 | describe '.activate_account' do |
|
90 | 90 |
|
91 | 91 | it 'sets a flash error' do |
92 | 92 | flash[:error].should be_present |
93 | | - end |
| 93 | + end |
94 | 94 | end |
95 | 95 |
|
96 | 96 | context 'valid token' do |
|
102 | 102 | end |
103 | 103 |
|
104 | 104 | it 'enqueues a welcome message if the user object indicates so' do |
105 | | - user.send_welcome_message = true |
| 105 | + user.send_welcome_message = true |
106 | 106 | user.expects(:enqueue_welcome_message).with('welcome_user') |
107 | 107 | get :activate_account, token: 'asdfasdf' |
108 | 108 | end |
109 | 109 |
|
110 | 110 | it "doesn't enqueue the welcome message if the object returns false" do |
111 | | - user.send_welcome_message = false |
| 111 | + user.send_welcome_message = false |
112 | 112 | user.expects(:enqueue_welcome_message).with('welcome_user').never |
113 | 113 | get :activate_account, token: 'asdfasdf' |
114 | 114 | end |
|
131 | 131 |
|
132 | 132 | it 'logs in as the user' do |
133 | 133 | session[:current_user_id].should be_present |
134 | | - end |
| 134 | + end |
135 | 135 |
|
136 | 136 | it "doesn't set @needs_approval" do |
137 | 137 | assigns[:needs_approval].should be_blank |
138 | | - end |
139 | | - |
| 138 | + end |
| 139 | + |
140 | 140 | end |
141 | 141 |
|
142 | 142 | context 'must_approve_users' do |
|
166 | 166 | end |
167 | 167 | end |
168 | 168 |
|
169 | | - describe '.change_email' do |
| 169 | + describe '.change_email' do |
170 | 170 | let(:new_email) { 'bubblegum@adventuretime.ooo' } |
171 | 171 |
|
172 | 172 | it "requires you to be logged in" do |
|
223 | 223 |
|
224 | 224 | it 'sets a flash error' do |
225 | 225 | flash[:error].should be_present |
226 | | - end |
| 226 | + end |
227 | 227 |
|
228 | 228 | it "doesn't log in the user" do |
229 | 229 | session[:current_user_id].should be_blank |
230 | | - end |
| 230 | + end |
231 | 231 | end |
232 | 232 |
|
233 | 233 | context 'valid token' do |
|
259 | 259 | SiteSetting.expects(:must_approve_users?).returns(true) |
260 | 260 | put :password_reset, token: 'asdfasdf', password: 'newpassword' |
261 | 261 | session[:current_user_id].should be_blank |
262 | | - end |
| 262 | + end |
263 | 263 | end |
264 | 264 |
|
265 | 265 |
|
266 | 266 | end |
267 | 267 |
|
268 | 268 |
|
269 | | - describe '.create' do |
270 | | - before do |
| 269 | + describe '.create' do |
| 270 | + before do |
271 | 271 | @user = Fabricate.build(:user) |
272 | | - @user.password = "strongpassword" |
| 272 | + @user.password = "strongpassword" |
273 | 273 | Mothership.stubs(:register_nickname).returns([true, nil]) |
274 | 274 | end |
275 | 275 |
|
|
282 | 282 | it "doesn't send a welcome email" do |
283 | 283 | User.any_instance.expects(:enqueue_welcome_message).with('welcome_user').never |
284 | 284 | xhr :post, :create, :name => @user.name, :username => @user.username, :password => "strongpassword", :email => @user.email |
285 | | - end |
| 285 | + end |
286 | 286 | end |
287 | 287 |
|
288 | 288 | context 'when creating an active user (confirmed email)' do |
|
294 | 294 | it 'should enqueue a signup email' do |
295 | 295 | User.any_instance.expects(:enqueue_welcome_message).with('welcome_user') |
296 | 296 | xhr :post, :create, :name => @user.name, :username => @user.username, :password => "strongpassword", :email => @user.email |
297 | | - end |
| 297 | + end |
298 | 298 |
|
299 | 299 | it "should be logged in" do |
300 | 300 | User.any_instance.expects(:enqueue_welcome_message) |
|
331 | 331 | xhr :post, :create, :name => @user.name, :username => @user.username, :password => "strongpassword", :email => @user.email |
332 | 332 | end |
333 | 333 |
|
334 | | - it 'should succeed' do |
| 334 | + it 'should succeed' do |
335 | 335 | should respond_with(:success) |
336 | 336 | end |
337 | 337 |
|
338 | 338 | it 'has the proper JSON' do |
339 | 339 | json = JSON::parse(response.body) |
340 | | - json["success"].should be_true |
| 340 | + json["success"].should be_true |
341 | 341 | end |
342 | 342 |
|
343 | | - it 'should not result in an active account' do |
| 343 | + it 'should not result in an active account' do |
344 | 344 | User.where(username: @user.username).first.active.should be_false |
345 | 345 | end |
346 | 346 | end |
|
391 | 391 | let(:new_username) { "#{user.username}1234" } |
392 | 392 |
|
393 | 393 | it 'raises an error without a new_username param' do |
394 | | - lambda { xhr :put, :username, username: user.username }.should raise_error(Discourse::InvalidParameters) |
| 394 | + lambda { xhr :put, :username, username: user.username }.should raise_error(Discourse::InvalidParameters) |
395 | 395 | end |
396 | 396 |
|
397 | 397 | it 'raises an error when you don\'t have permission to change the user' do |
|
402 | 402 |
|
403 | 403 | it 'raises an error when change_username fails' do |
404 | 404 | User.any_instance.expects(:change_username).with(new_username).returns(false) |
405 | | - lambda { xhr :put, :username, username: user.username, new_username: new_username }.should raise_error(Discourse::InvalidParameters) |
| 405 | + lambda { xhr :put, :username, username: user.username, new_username: new_username }.should raise_error(Discourse::InvalidParameters) |
406 | 406 | end |
407 | 407 |
|
408 | 408 | it 'should succeed when the change_username returns true' do |
|
671 | 671 |
|
672 | 672 | end |
673 | 673 |
|
| 674 | + describe "search_users" do |
| 675 | + |
| 676 | + let(:topic) { Fabricate :topic } |
| 677 | + let(:user) { Fabricate :user, username: "joecabot", name: "Lawrence Tierney" } |
| 678 | + |
| 679 | + before do |
| 680 | + Fabricate :post, user: user, topic: topic |
| 681 | + end |
| 682 | + |
| 683 | + it "searches when provided the term only" do |
| 684 | + xhr :post, :search_users, term: user.name.split(" ").last |
| 685 | + response.should be_success |
| 686 | + json = JSON.parse(response.body) |
| 687 | + json["users"].map { |u| u["username"] }.should include(user.username) |
| 688 | + end |
| 689 | + |
| 690 | + it "searches when provided the topic only" do |
| 691 | + xhr :post, :search_users, topic_id: topic.id |
| 692 | + response.should be_success |
| 693 | + json = JSON.parse(response.body) |
| 694 | + json["users"].map { |u| u["username"] }.should include(user.username) |
| 695 | + end |
| 696 | + |
| 697 | + it "searches when provided the term and topic" do |
| 698 | + xhr :post, :search_users, term: user.name.split(" ").last, topic_id: topic.id |
| 699 | + response.should be_success |
| 700 | + json = JSON.parse(response.body) |
| 701 | + json["users"].map { |u| u["username"] }.should include(user.username) |
| 702 | + end |
| 703 | + |
| 704 | + end |
| 705 | + |
674 | 706 | end |
0 commit comments