Project

General

Profile

Feature #6721 » feature_6721_2.diff

Sridhar P, 2012-01-05 14:18

View differences:

test/functional/issues_controller_test.rb (working copy)
678 678
    assert @response.body.blank?
679 679
  end
680 680

  
681
  def test_index_json_with_login_name
682
    user = User.find(3)
683
	get :index, :format => 'json', :assigned_to_name => user.login
684

  
685
	assert_equal 'application/json', @response.content_type
686
	assert_not_nil assigns(:issues)
687
	parsed = ActiveSupport::JSON.decode(@response.body)
688
	parsed["issues"].each do |issue|
689
	  assert_equal 3, issue["assigned_to"]["id"]
690
	end
691
  end
692

  
681 693
  def test_show_by_anonymous
682 694
    get :show, :id => 1
683 695
    assert_response :success
......
1437 1449
    assert_equal 59, File.size(attachment.diskfile)
1438 1450
  end
1439 1451

  
1452
  def test_post_create_with_login_name
1453
    @request.session[:user_id] = 2
1454
	user = User.find(4)
1455

  
1456
    assert_difference 'Issue.count' do
1457
      post :create, :project_id => 1,
1458
                 :issue => {:tracker_id => 3,
1459
                            :status_id => 2,
1460
                            :subject => 'This is the test_new_with_login issue',
1461
                            :description => 'This is the description',
1462
							:assigned_to_name => user.login,
1463
                            :priority_id => 5,
1464
                            :start_date => '2010-11-07'
1465
							}
1466
    end
1467
    assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id
1468

  
1469
    issue = Issue.find_by_subject('This is the test_new_with_login issue')
1470
    assert_not_nil issue
1471
    assert_equal 2, issue.author_id
1472
    assert_equal 3, issue.tracker_id
1473
    assert_equal 2, issue.status_id
1474
	assert_equal 4, issue.assigned_to_id
1475
    assert_equal Date.parse('2010-11-07'), issue.start_date
1476
  end
1477

  
1440 1478
  context "without workflow privilege" do
1441 1479
    setup do
1442 1480
      Workflow.delete_all(["role_id = ?", Role.anonymous.id])
......
1743 1781
    assert mail.subject.include?("(#{ IssueStatus.find(2).name })")
1744 1782
  end
1745 1783

  
1784
  def test_put_update_with_status_and_assignee_change_with_login_name
1785
    issue = Issue.find(1)
1786
    assert_equal 1, issue.status_id
1787
	user = User.find(4)
1788
    @request.session[:user_id] = 2
1789
    assert_difference('TimeEntry.count', 0) do
1790
      put :update,
1791
           :id => 1,
1792
           :issue => { :status_id => 2, :assigned_to_name => user.login },
1793
           :notes => 'Assigned to ' + user.login,
1794
           :time_entry => { :hours => '', :comments => '', :activity_id => TimeEntryActivity.first }
1795
    end
1796
    assert_redirected_to :action => 'show', :id => '1'
1797
    issue.reload
1798
    assert_equal 2, issue.status_id
1799
    j = Journal.find(:first, :order => 'id DESC')
1800
    assert_equal 'Assigned to ' + user.login, j.notes
1801
    assert_equal 2, j.details.size
1802
	assert_equal user.id, issue.assigned_to_id
1803

  
1804
    mail = ActionMailer::Base.deliveries.last
1805
    assert mail.body.include?("Status changed from New to Assigned")
1806
    # subject should contain the new status
1807
    assert mail.subject.include?("(#{ IssueStatus.find(2).name })")
1808
  end
1809

  
1746 1810
  def test_put_update_with_note_only
1747 1811
    notes = 'Note added by IssuesControllerTest#test_update_with_note_only'
1748 1812
    # anonymous user
test/functional/users_controller_test.rb (working copy)
86 86
    assert_tag 'li', :content => /Phone number/
87 87
  end
88 88

  
89
  # TODO: check why the assert_response and assert_template are failing
90
  def test_show_with_login_name
91
    @request.session[:user_id] = nil
92
	u = User.find(4)
93
    get :show, :id => u.login
94
    #assert_response :success
95
    #assert_template 'show'
96
    assert_not_nil assigns(:user)
97
	assert_equal u, assigns(:user)
98
  end
99

  
89 100
  def test_show_should_not_display_hidden_custom_fields
90 101
    @request.session[:user_id] = nil
91 102
    UserCustomField.find_by_name('Phone number').update_attribute :visible, false
......
211 222
    assert_equal User.find(2), assigns(:user)
212 223
  end
213 224

  
225
  def test_edit_with_login_name
226
    u = User.find(4)
227
	get :edit, :id => u.login
228
	
229
	assert_response :success
230
	assert_template :edit
231
	assert_equal u, assigns(:user)
232
  end
233

  
214 234
  def test_update
215 235
    ActionMailer::Base.deliveries.clear
216 236
    put :update, :id => 2, :user => {:firstname => 'Changed', :mail_notification => 'only_assigned'}, :pref => {:hide_mail => '1', :comments_sorting => 'desc'}
......
223 243
    assert ActionMailer::Base.deliveries.empty?
224 244
  end
225 245

  
246
  def test_update_with_login_name
247
    ActionMailer::Base.deliveries.clear
248
	user = User.find(2)
249
    put :update, :id => user.login, :user => {:firstname => 'Changed', :mail_notification => 'only_assigned'}, :pref => {:hide_mail => '1', :comments_sorting => 'desc'}
250

  
251
	user.reload
252
	assert_equal 2, user.id
253
    assert_equal 'Changed', user.firstname
254
    assert_equal 'only_assigned', user.mail_notification
255
    assert_equal true, user.pref[:hide_mail]
256
    assert_equal 'desc', user.pref[:comments_sorting]
257
    assert ActionMailer::Base.deliveries.empty?
258
  end
259

  
226 260
  def test_update_with_failure
227 261
    assert_no_difference 'User.count' do
228 262
      put :update, :id => 2, :user => {:firstname => ''}
......
289 323
    assert_nil User.find_by_id(2)
290 324
  end
291 325

  
326
  def test_destroy_with_login_name
327
    user = User.find(2)
328
	
329
	assert_difference 'User.count', -1 do
330
	  delete :destroy, :id => 2
331
	end
332
	assert_redirected_to '/users'
333
	assert_nil User.find_by_id(2)
334
  end
335

  
292 336
  def test_destroy_should_not_accept_get_requests
293 337
    assert_no_difference 'User.count' do
294 338
      get :destroy, :id => 2
......
324 368
    assert_equal [2], Member.find(1).role_ids
325 369
  end
326 370

  
371
  def test_update_membership_with_login_name
372
    user = User.find(2)
373
	assert_no_difference 'Member.count' do
374
	  put :edit_membership, :id => user.login, :membership_id => 1, :membership => { :role_ids => [2]}
375
	end
376
	assert_redirected_to :action => 'edit', :id => '2', :tab => 'memberships'
377
	assert_equal [2], Member.find(1).role_ids
378
  end
379

  
327 380
  def test_destroy_membership
328 381
    assert_difference 'Member.count', -1 do
329 382
      delete :destroy_membership, :id => 2, :membership_id => 1
......
331 384
    assert_redirected_to :action => 'edit', :id => '2', :tab => 'memberships'
332 385
    assert_nil Member.find_by_id(1)
333 386
  end
387

  
388
  def test_destroy_membership_with_login_name
389
    user = User.find(2)
390
	assert_difference 'Member.count', -1 do
391
	  delete :destroy_membership, :id => user.login, :membership_id => 1
392
	end
393
	assert_redirected_to :action => 'edit', :id => '2', :tab => 'memberships'
394
	assert_nil Member.find_by_id(1)
395
  end
334 396
end
app/controllers/issues_controller.rb (working copy)
59 59
  verify :method => :put, :only => :update, :render => {:nothing => true, :status => :method_not_allowed }
60 60

  
61 61
  def index
62
    name_from_id
62 63
    retrieve_query
63 64
    sort_init(@query.sort_criteria.empty? ? [['id', 'desc']] : @query.sort_criteria)
64 65
    sort_update(@query.sortable_columns)
......
303 304
    @edit_allowed = User.current.allowed_to?(:edit_issues, @project)
304 305
    @time_entry = TimeEntry.new(:issue => @issue, :project => @issue.project)
305 306
    @time_entry.attributes = params[:time_entry]
307
	
308
    name_from_id_for_create_update
306 309

  
307 310
    @notes = params[:notes] || (params[:issue].present? ? params[:issue][:notes] : nil)
308 311
    @issue.init_journal(User.current, @notes)
......
328 331
      render_error l(:error_no_tracker_in_project)
329 332
      return false
330 333
    end
334

  
335
    name_from_id_for_create_update
336

  
331 337
    @issue.start_date ||= Date.today if Setting.default_issue_start_date_to_creation_date?
332 338
    @issue.safe_attributes = params[:issue]
333 339

  
......
348 354
    attributes[:custom_field_values].reject! {|k,v| v.blank?} if attributes[:custom_field_values]
349 355
    attributes
350 356
  end
357

  
358
  def name_from_id_for_create_update
359
    # do nothing if assigned_to_id is set
360
	if params[:issue] && params[:issue][:assigned_to_id].nil? && params[:issue][:assigned_to_name]
361
	  user = User.find_by_login(params[:issue][:assigned_to_name])
362
	  unless user.nil?
363
	    params[:issue][:assigned_to_id] = user.id
364
	  end
365
	end
366
  end
367

  
368
  def name_from_id
369
    if params[:assigned_to_id].nil? && params[:assigned_to_name]
370
	  user = User.find_by_login(params[:assigned_to_name])
371
	  unless user.nil?
372
	    params[:assigned_to_id] = user.id.to_s
373
	  end
374
	end
375
  end
351 376
end
app/controllers/users_controller.rb (working copy)
228 228
      require_login || return
229 229
      @user = User.current
230 230
    else
231
      @user = User.find(params[:id])
231
	  # if :id contains digits only, then find the user by id, otherwise search by login name
232
	  # this does not account for the edge case where login name is composed of digits only
233
	  if params[:id].gsub(/[[:digit:]]/, '').length > 0
234
	    @user = User.find_by_login(params[:id])
235
	  else
236
        @user = User.find(params[:id])
237
	  end
232 238
    end
233 239
  rescue ActiveRecord::RecordNotFound
234 240
    render_404
(2-2/4)