From e1da6de36f0d31f96d31ff7140718d263cfe0cca Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Thu, 21 Jul 2016 17:50:00 +0000 Subject: [PATCH] Removes calls to #assert_template and #assigns in integration tests. git-svn-id: http://svn.redmine.org/redmine/trunk@15727 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- test/integration/account_test.rb | 7 ----- test/integration/admin_test.rb | 2 +- .../api_test/authentication_test.rb | 4 +-- test/integration/api_test/issues_test.rb | 7 ++--- test/integration/api_test/roles_test.rb | 4 +-- test/integration/api_test/search_test.rb | 26 +++++++++---------- test/integration/api_test/users_test.rb | 4 +-- test/integration/issues_test.rb | 2 -- test/integration/projects_test.rb | 2 +- test/integration/sudo_mode_test.rb | 18 ++++++------- test/test_helper.rb | 2 +- 11 files changed, 33 insertions(+), 45 deletions(-) diff --git a/test/integration/account_test.rb b/test/integration/account_test.rb index 0f12a1c83..b1fd3f45a 100644 --- a/test/integration/account_test.rb +++ b/test/integration/account_test.rb @@ -27,7 +27,6 @@ class AccountTest < Redmine::IntegrationTest get "/my/account" assert_response :success - assert_template "my/account" end def test_login_should_set_session_token @@ -67,7 +66,6 @@ class AccountTest < Redmine::IntegrationTest cookies[:autologin] = token.value get '/my/page' assert_response :success - assert_template 'my/page' assert_equal user.id, session[:user_id] assert_not_nil user.reload.last_login_on end @@ -106,7 +104,6 @@ class AccountTest < Redmine::IntegrationTest get "/account/lost_password" assert_response :success - assert_template "account/lost_password" assert_select 'input[name=mail]' post "/account/lost_password", :mail => 'jSmith@somenet.foo' @@ -119,7 +116,6 @@ class AccountTest < Redmine::IntegrationTest get "/account/lost_password", :token => token.value assert_response :success - assert_template "account/password_recovery" assert_select 'input[type=hidden][name=token][value=?]', token.value assert_select 'input[name=new_password]' assert_select 'input[name=new_password_confirmation]' @@ -202,7 +198,6 @@ class AccountTest < Redmine::IntegrationTest get '/account/register' assert_response :success - assert_template 'account/register' post '/account/register', :user => {:login => "newuser", :language => "en", @@ -211,7 +206,6 @@ class AccountTest < Redmine::IntegrationTest assert_redirected_to '/my/account' follow_redirect! assert_response :success - assert_template 'my/account' user = User.find_by_login('newuser') assert_not_nil user @@ -275,7 +269,6 @@ class AccountTest < Redmine::IntegrationTest post '/login', :username => 'foo', :password => 'bar' assert_response :success - assert_template 'account/register' assert_select 'input[name=?][value=""]', 'user[firstname]' assert_select 'input[name=?][value=Smith]', 'user[lastname]' assert_select 'input[name=?]', 'user[login]', 0 diff --git a/test/integration/admin_test.rb b/test/integration/admin_test.rb index 22a675a71..73f89139d 100644 --- a/test/integration/admin_test.rb +++ b/test/integration/admin_test.rb @@ -30,7 +30,7 @@ class AdminTest < Redmine::IntegrationTest log_user("admin", "admin") get "/users/new" assert_response :success - assert_template "users/new" + post "/users", :user => { :login => "psmith", :firstname => "Paul", :lastname => "Smith", :mail => "psmith@somenet.foo", diff --git a/test/integration/api_test/authentication_test.rb b/test/integration/api_test/authentication_test.rb index afc7904a1..887436f1d 100644 --- a/test/integration/api_test/authentication_test.rb +++ b/test/integration/api_test/authentication_test.rb @@ -129,7 +129,7 @@ class Redmine::ApiTest::AuthenticationTest < Redmine::ApiTest::Base get '/users/current', {}, {'X-Redmine-API-Key' => user.api_key, 'X-Redmine-Switch-User' => su.login} assert_response :success - assert_equal su, assigns(:user) + assert_select 'h2', :text => su.name assert_equal su, User.current end @@ -152,7 +152,7 @@ class Redmine::ApiTest::AuthenticationTest < Redmine::ApiTest::Base get '/users/current', {}, {'X-Redmine-API-Key' => user.api_key, 'X-Redmine-Switch-User' => su.login} assert_response :success - assert_equal user, assigns(:user) + assert_select 'h2', :text => user.name assert_equal user, User.current end end diff --git a/test/integration/api_test/issues_test.rb b/test/integration/api_test/issues_test.rb index b1e189181..50119f4d1 100644 --- a/test/integration/api_test/issues_test.rb +++ b/test/integration/api_test/issues_test.rb @@ -46,8 +46,7 @@ class Redmine::ApiTest::IssuesTest < Redmine::ApiTest::Base test "GET /issues.xml should contain metadata" do get '/issues.xml' - assert_select 'issues[type=array][total_count=?][limit="25"][offset="0"]', - assigns(:issue_count).to_s + assert_select 'issues[type=array][total_count][limit="25"][offset="0"]' end test "GET /issues.xml with nometa param should not contain metadata" do @@ -62,9 +61,7 @@ class Redmine::ApiTest::IssuesTest < Redmine::ApiTest::Base test "GET /issues.xml with offset and limit" do get '/issues.xml?offset=2&limit=3' - - assert_equal 3, assigns(:limit) - assert_equal 2, assigns(:offset) + assert_select 'issues[type=array][total_count][limit="3"][offset="2"]' assert_select 'issues issue', 3 end diff --git a/test/integration/api_test/roles_test.rb b/test/integration/api_test/roles_test.rb index 47d501749..5b6892b6d 100644 --- a/test/integration/api_test/roles_test.rb +++ b/test/integration/api_test/roles_test.rb @@ -25,8 +25,8 @@ class Redmine::ApiTest::RolesTest < Redmine::ApiTest::Base assert_response :success assert_equal 'application/xml', @response.content_type - assert_equal 3, assigns(:roles).size + assert_select 'roles role', 3 assert_select 'roles[type=array] role id', :text => '2' do assert_select '~ name', :text => 'Developer' end @@ -37,11 +37,11 @@ class Redmine::ApiTest::RolesTest < Redmine::ApiTest::Base assert_response :success assert_equal 'application/json', @response.content_type - assert_equal 3, assigns(:roles).size json = ActiveSupport::JSON.decode(response.body) assert_kind_of Hash, json assert_kind_of Array, json['roles'] + assert_equal 3, json['roles'].size assert_include({'id' => 2, 'name' => 'Developer'}, json['roles']) end diff --git a/test/integration/api_test/search_test.rb b/test/integration/api_test/search_test.rb index 21351ce83..f09a447a0 100644 --- a/test/integration/api_test/search_test.rb +++ b/test/integration/api_test/search_test.rb @@ -48,26 +48,26 @@ class Redmine::ApiTest::SearchTest < Redmine::ApiTest::Base get '/search.xml', :q => '', :all_words => '' assert_response :success - assert_equal 0, assigns(:results).size + assert_select 'result', 0 end test "GET /search.xml with query strings should return results" do - get '/search.xml', :q => 'recipe subproject commit', :all_words => '' + issue = Issue.generate!(:subject => 'searchapi') + + get '/search.xml', :q => 'searchapi', :all_words => '' assert_response :success - assert_not_empty(assigns(:results)) assert_select 'results[type=array]' do - assert_select 'result', :count => assigns(:results).count - assigns(:results).size.times.each do |i| - assert_select 'result' do - assert_select 'id', :text => assigns(:results)[i].id.to_s - assert_select 'title', :text => assigns(:results)[i].event_title - assert_select 'type', :text => assigns(:results)[i].event_type - assert_select 'url', :text => url_for(assigns(:results)[i].event_url(:only_path => false)) - assert_select 'description', :text => assigns(:results)[i].event_description - assert_select 'datetime' - end + assert_select 'result', 1 + + assert_select 'result' do + assert_select 'id', :text => issue.id.to_s + assert_select 'title', :text => "Bug ##{issue.id} (New): searchapi" + assert_select 'type', :text => 'issue' + assert_select 'url', :text => "http://www.example.com/issues/#{issue.id}" + assert_select 'description', :text => '' + assert_select 'datetime' end end end diff --git a/test/integration/api_test/users_test.rb b/test/integration/api_test/users_test.rb index 140d78840..9118a8b9c 100644 --- a/test/integration/api_test/users_test.rb +++ b/test/integration/api_test/users_test.rb @@ -26,7 +26,7 @@ class Redmine::ApiTest::UsersTest < Redmine::ApiTest::Base assert_response :success assert_equal 'application/xml', response.content_type assert_select 'users' do - assert_select 'user', assigns(:users).size + assert_select 'user', User.active.count end end @@ -37,7 +37,7 @@ class Redmine::ApiTest::UsersTest < Redmine::ApiTest::Base assert_equal 'application/json', response.content_type json = ActiveSupport::JSON.decode(response.body) assert json.key?('users') - assert_equal assigns(:users).size, json['users'].size + assert_equal User.active.count, json['users'].size end test "GET /users/:id.xml should return the user" do diff --git a/test/integration/issues_test.rb b/test/integration/issues_test.rb index 76a417c92..c231eeb0e 100644 --- a/test/integration/issues_test.rb +++ b/test/integration/issues_test.rb @@ -40,7 +40,6 @@ class IssuesTest < Redmine::IntegrationTest get '/projects/ecookbook/issues/new' assert_response :success - assert_template 'issues/new' issue = new_record(Issue) do post '/projects/ecookbook/issues', @@ -58,7 +57,6 @@ class IssuesTest < Redmine::IntegrationTest # check redirection assert_redirected_to :controller => 'issues', :action => 'show', :id => issue follow_redirect! - assert_equal issue, assigns(:issue) # check issue attributes assert_equal 'jsmith', issue.author.login diff --git a/test/integration/projects_test.rb b/test/integration/projects_test.rb index 4dafc4209..2cff5cf9b 100644 --- a/test/integration/projects_test.rb +++ b/test/integration/projects_test.rb @@ -25,7 +25,7 @@ class ProjectsTest < Redmine::IntegrationTest log_user("admin", "admin") get "/admin/projects" assert_response :success - assert_template "admin/projects" + post "/projects/1/archive" assert_redirected_to "/admin/projects" assert !Project.find(1).active? diff --git a/test/integration/sudo_mode_test.rb b/test/integration/sudo_mode_test.rb index 1731a61bd..6d2e76102 100644 --- a/test/integration/sudo_mode_test.rb +++ b/test/integration/sudo_mode_test.rb @@ -113,21 +113,21 @@ class SudoModeTest < Redmine::IntegrationTest assert_response :success assert_select 'h2', 'Confirm your password to continue' assert_select 'form[action="/roles"]' - assert assigns(:sudo_form).errors.blank? + assert_select '#flash_error', 0 post '/roles', role: { name: 'new role', issues_visibility: 'all' } assert_response :success assert_select 'h2', 'Confirm your password to continue' assert_select 'form[action="/roles"]' - assert_match /"new role"/, response.body - assert assigns(:sudo_form).errors.blank? + assert_select 'input[type=hidden][name=?][value=?]', 'role[name]', 'new role' + assert_select '#flash_error', 0 post '/roles', role: { name: 'new role', issues_visibility: 'all' }, sudo_password: 'wrong' assert_response :success assert_select 'h2', 'Confirm your password to continue' assert_select 'form[action="/roles"]' - assert_match /"new role"/, response.body - assert assigns(:sudo_form).errors[:password].present? + assert_select 'input[type=hidden][name=?][value=?]', 'role[name]', 'new role' + assert_select '#flash_error' assert_difference 'Role.count' do post '/roles', role: { name: 'new role', issues_visibility: 'all', assignable: '1', permissions: %w(view_calendar) }, sudo_password: 'admin' @@ -144,16 +144,16 @@ class SudoModeTest < Redmine::IntegrationTest assert_response :success assert_select 'h2', 'Confirm your password to continue' assert_select 'form[action="/my/account"]' - assert_match /"newmail@test\.com"/, response.body - assert assigns(:sudo_form).errors.blank? + assert_select 'input[type=hidden][name=?][value=?]', 'user[mail]', 'newmail@test.com' + assert_select '#flash_error', 0 # wrong password post '/my/account', user: { mail: 'newmail@test.com' }, sudo_password: 'wrong' assert_response :success assert_select 'h2', 'Confirm your password to continue' assert_select 'form[action="/my/account"]' - assert_match /"newmail@test\.com"/, response.body - assert assigns(:sudo_form).errors[:password].present? + assert_select 'input[type=hidden][name=?][value=?]', 'user[mail]', 'newmail@test.com' + assert_select '#flash_error' # correct password post '/my/account', user: { mail: 'newmail@test.com' }, sudo_password: 'jsmith' diff --git a/test/test_helper.rb b/test/test_helper.rb index 0be4d42ae..f43b10df0 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -321,7 +321,7 @@ module Redmine get "/login" assert_equal nil, session[:user_id] assert_response :success - assert_template "account/login" + post "/login", :username => login, :password => password assert_equal login, User.find(session[:user_id]).login end -- 2.39.5