Feature #6721 » feature_6721_4.diff
| 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_id => 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_id => 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_id => 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/models/user.rb (working copy) | ||
|---|---|---|
| 572 | 572 |
end |
| 573 | 573 |
end |
| 574 | 574 | |
| 575 |
# Overrides the find method to allow finding users by login name and id |
|
| 576 |
def self.find(*args) |
|
| 577 |
if args.first && args.first.is_a?(String) && !args.first.match(/^\d*$/) |
|
| 578 |
user = find_by_login(*args) |
|
| 579 |
raise ActiveRecord::RecordNotFound, "Couldn't find Project with identifier=#{args.first}" if user.nil?
|
|
| 580 |
user |
|
| 581 |
else |
|
| 582 |
super |
|
| 583 |
end |
|
| 584 |
end |
|
| 585 | ||
| 575 | 586 |
protected |
| 576 | 587 | |
| 577 | 588 |
def validate_password_length |
| app/controllers/issues_controller.rb (working copy) | ||
|---|---|---|
| 26 | 26 |
before_filter :authorize, :except => [:index] |
| 27 | 27 |
before_filter :find_optional_project, :only => [:index] |
| 28 | 28 |
before_filter :check_for_default_issue_status, :only => [:new, :create] |
| 29 |
before_filter :id_from_login, :only => [:index, :create, :update] |
|
| 29 | 30 |
before_filter :build_new_issue_from_params, :only => [:new, :create] |
| 30 | 31 |
accept_rss_auth :index, :show |
| 31 | 32 |
accept_api_auth :index, :show, :create, :update, :destroy |
| ... | ... | |
| 348 | 349 |
attributes[:custom_field_values].reject! {|k,v| v.blank?} if attributes[:custom_field_values]
|
| 349 | 350 |
attributes |
| 350 | 351 |
end |
| 352 | ||
| 353 |
def id_from_login |
|
| 354 |
if params[:issue] && |
|
| 355 |
params[:issue][:assigned_to_id] && |
|
| 356 |
params[:issue][:assigned_to_id].to_s.length > 0 && |
|
| 357 |
!params[:issue][:assigned_to_id].to_s.match(/^\d*$/) |
|
| 358 |
user = User.find_by_login(params[:issue][:assigned_to_id]) |
|
| 359 |
params[:issue][:assigned_to_id] = user.id.to_s |
|
| 360 |
elsif params[:assigned_to_id] && |
|
| 361 |
params[:assigned_to_id].to_s.length > 0 && |
|
| 362 |
!params[:assigned_to_id].match(/^\d*$/) |
|
| 363 |
user = User.find_by_login(params[:assigned_to_id]) |
|
| 364 |
params[:assigned_to_id] = user.id.to_s |
|
| 365 |
end |
|
| 366 |
end |
|
| 351 | 367 |
end |
- « Previous
- 1
- 2
- 3
- 4
- Next »