From 9ca81d791360bcdf24bd1cb18864d3204b174e12 Mon Sep 17 00:00:00 2001 From: git-jls Date: Fri, 16 Dec 2016 17:07:03 +0100 Subject: [PATCH] Updated code base, no more deprecation warnings --- Gemfile | 2 + Gemfile.lock | 2 + app/controllers/api/v1/tickets_controller.rb | 10 +- app/controllers/api/v1/users_controller.rb | 8 +- app/models/concerns/reply_notifications.rb | 2 +- .../api/v1/tickets_controller_test.rb | 23 +- .../api/v1/users_controller_test.rb | 20 +- .../attachments_controller_test.rb | 12 +- .../email_addresses_controller_test.rb | 4 +- test/controllers/labelings_controller_test.rb | 14 +- test/controllers/replies_controller_test.rb | 40 +-- test/controllers/rules_controller_test.rb | 26 +- test/controllers/settings_controller_test.rb | 4 +- test/controllers/tickets_controller_test.rb | 230 ++++++++++++------ test/controllers/users_controller_test.rb | 58 +++-- test/integration/api/v1/api_login_test.rb | 12 +- 16 files changed, 313 insertions(+), 154 deletions(-) diff --git a/Gemfile b/Gemfile index 8fc1e4cfe..9561f244d 100644 --- a/Gemfile +++ b/Gemfile @@ -48,6 +48,8 @@ gem 'mysql2', "~> 0.4", group: :mysql # Optional SQLite for development gem 'sqlite3', "~> 1.3", group: :sqlite +gem 'rb-readline' + # authentication gem 'devise', "~> 4.2" gem 'devise_ldap_authenticatable', "~> 0.8" diff --git a/Gemfile.lock b/Gemfile.lock index e05431fb3..a5952e81a 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -220,6 +220,7 @@ GEM rb-fsevent (0.9.8) rb-inotify (0.9.7) ffi (>= 0.5.0) + rb-readline (0.5.3) react-rails (1.10.0) babel-transpiler (>= 0.7.0) coffee-script-source (~> 1.8) @@ -307,6 +308,7 @@ DEPENDENCIES rails-controller-testing rails-i18n (~> 5.0) rake (~> 12.0) + rb-readline react-rails (~> 1.10) recaptcha (~> 4.0) sass-rails (~> 5.0) diff --git a/app/controllers/api/v1/tickets_controller.rb b/app/controllers/api/v1/tickets_controller.rb index 23956a75e..733dec089 100644 --- a/app/controllers/api/v1/tickets_controller.rb +++ b/app/controllers/api/v1/tickets_controller.rb @@ -15,12 +15,12 @@ # along with this program. If not, see . class Api::V1::TicketsController < Api::V1::ApplicationController include TicketsStrongParams - + load_and_authorize_resource :ticket def index if current_user.agent && params.has_key?(:user_email) - user= User.find_by( email: Base64.urlsafe_decode64(params[:user_email]) ) + user = User.find_by( email: Base64.urlsafe_decode64(params[:user_email]) ) @tickets = Ticket.by_status(:open).viewable_by(user) else @tickets = Ticket.by_status(:open).viewable_by(current_user) @@ -35,9 +35,9 @@ def create @ticket = Ticket.new(ticket_params) if @ticket.save NotificationMailer.incoming_message(@ticket, params[:message]) - render nothing: true, status: :created + head :created else - render nothing: true, status: :bad_request + head :bad_request end end -end \ No newline at end of file +end diff --git a/app/controllers/api/v1/users_controller.rb b/app/controllers/api/v1/users_controller.rb index ff3c22f91..4a9b77372 100644 --- a/app/controllers/api/v1/users_controller.rb +++ b/app/controllers/api/v1/users_controller.rb @@ -20,15 +20,15 @@ class Api::V1::UsersController < Api::V1::ApplicationController def create @user = User.new(user_params) if @user.save - render nothing: true, status: :created + head :created else - render nothing: true, status: :bad_request + head :bad_request end end def show unless @user = User.find_by(email: Base64.urlsafe_decode64(params[:email])) - render nothing: true, status: :bad_request + head :bad_request end end -end \ No newline at end of file +end diff --git a/app/models/concerns/reply_notifications.rb b/app/models/concerns/reply_notifications.rb index 08b138531..e9bedb4cd 100644 --- a/app/models/concerns/reply_notifications.rb +++ b/app/models/concerns/reply_notifications.rb @@ -143,7 +143,7 @@ def set_default_notifications!(mail_message = nil) result += label.users end - self.notified_users = result.uniq + self.notified_users = result.to_a.uniq end end diff --git a/test/controllers/api/v1/tickets_controller_test.rb b/test/controllers/api/v1/tickets_controller_test.rb index 30e1f56a3..dbddbc3de 100644 --- a/test/controllers/api/v1/tickets_controller_test.rb +++ b/test/controllers/api/v1/tickets_controller_test.rb @@ -25,7 +25,10 @@ class Api::V1::TicketsControllerTest < ActionController::TestCase test 'should get index' do sign_in users(:bob) - get :index, auth_token: users(:bob).authentication_token, :format => :json + get :index, params: { + auth_token: users(:bob).authentication_token, + format: :json + } assert_response :success assert_not_nil assigns(:tickets) end @@ -33,25 +36,35 @@ class Api::V1::TicketsControllerTest < ActionController::TestCase test 'should show ticket' do sign_in users(:bob) - get :show, auth_token: users(:bob).authentication_token, id: @ticket.id, :format => :json + get :show, params: { + auth_token: users(:bob).authentication_token, + id: @ticket.id, + format: :json + } assert_response :success end test 'should show tickets as nested resource' do - get :index, auth_token: users(:bob).authentication_token, - user_email: Base64.urlsafe_encode64(users(:alice).email), :format => :json + get :index, params: { + auth_token: users(:bob).authentication_token, + user_email: Base64.urlsafe_encode64(users(:alice).email), + format: :json + } assert_response :success end test 'should create ticket' do sign_in users(:bob) assert_difference 'Ticket.count', 1 do - post :create, auth_token: users(:bob).authentication_token, ticket: { + post :create, params: { + auth_token: users(:bob).authentication_token, + ticket: { content: 'I need help', from: 'bob@xxxx.com', subject: 'Remote from API', priority: 'low'}, format: :json + } end assert_response :success end diff --git a/test/controllers/api/v1/users_controller_test.rb b/test/controllers/api/v1/users_controller_test.rb index 2813a39f2..d2499c6d5 100644 --- a/test/controllers/api/v1/users_controller_test.rb +++ b/test/controllers/api/v1/users_controller_test.rb @@ -9,19 +9,27 @@ class Api::V1::UsersControllerTest < ActionController::TestCase @charlie = users(:charlie) end - test 'should find a User' do - get :show, auth_token: users(:alice).authentication_token, email: Base64.urlsafe_encode64(users(:alice).email), :format => :json + test 'should find a user' do + get :show, params: { + auth_token: users(:alice).authentication_token, + email: Base64.urlsafe_encode64(users(:alice).email), + format: :json + } assert_response :success end - test 'should create a User ' do + test 'should create a user ' do sign_in users(:alice) assert_difference 'User.count', 1 do - post :create, auth_token: users(:alice).authentication_token, user: { - email: 'newuser@new.com'}, + post :create, params: { + auth_token: users(:alice).authentication_token, + user: { + email: 'newuser@new.com' + }, format: :json + } end assert_response :success end -end \ No newline at end of file +end diff --git a/test/controllers/attachments_controller_test.rb b/test/controllers/attachments_controller_test.rb index ac7550a94..9118a299a 100644 --- a/test/controllers/attachments_controller_test.rb +++ b/test/controllers/attachments_controller_test.rb @@ -27,18 +27,24 @@ class AttachmentsControllerTest < ActionController::TestCase test 'should get new' do sign_out users(:alice) - xhr :get, :new + get :new, xhr: true assert_response :success end test 'should show thumb' do - get :show, format: :thumb, id: @attachment.id + get :show, params: { + format: :thumb, + id: @attachment.id + } assert_response :success end test 'should download original' do - get :show, format: :original, id: @attachment.id + get :show, params: { + format: :original, + id: @attachment.id + } assert_response :success end diff --git a/test/controllers/email_addresses_controller_test.rb b/test/controllers/email_addresses_controller_test.rb index 6191faffa..78805c302 100644 --- a/test/controllers/email_addresses_controller_test.rb +++ b/test/controllers/email_addresses_controller_test.rb @@ -51,7 +51,7 @@ class EmailAddressesControllerTest < ActionController::TestCase assert_difference 'ActionMailer::Base.deliveries.size' do assert_no_difference 'EmailAddress.where(default: true).count' do assert_difference 'EmailAddress.count' do - post :create, email_address: { email: 'support@support.bla', default: '1' } + post :create, params: { email_address: { email: 'support@support.bla', default: '1' } } end end end @@ -65,7 +65,7 @@ class EmailAddressesControllerTest < ActionController::TestCase sign_in @alice assert_difference 'EmailAddress.count', -1 do - delete :destroy, id: @email_address.id + delete :destroy, params: { id: @email_address.id } end assert_redirected_to email_addresses_url diff --git a/test/controllers/labelings_controller_test.rb b/test/controllers/labelings_controller_test.rb index e45381bcf..e40d28729 100644 --- a/test/controllers/labelings_controller_test.rb +++ b/test/controllers/labelings_controller_test.rb @@ -27,11 +27,13 @@ class LabelingsControllerTest < ActionController::TestCase assert_difference 'Labeling.count' do - post :create, format: :js, labeling: { - labelable_id: tickets(:problem).id, - labelable_type: 'Ticket', - label: { - name: 'Hello' + post :create, format: :js, params: { + labeling: { + labelable_id: tickets(:problem).id, + labelable_type: 'Ticket', + label: { + name: 'Hello' + } } } @@ -41,7 +43,7 @@ class LabelingsControllerTest < ActionController::TestCase test 'should remove labeling' do assert_difference 'Labeling.count', -1 do - delete :destroy, id: @labeling, format: :js + delete :destroy, params: { id: @labeling, format: :js } assert_response :success end diff --git a/test/controllers/replies_controller_test.rb b/test/controllers/replies_controller_test.rb index b6b308c15..cec00f06d 100644 --- a/test/controllers/replies_controller_test.rb +++ b/test/controllers/replies_controller_test.rb @@ -31,10 +31,12 @@ class RepliesControllerTest < ActionController::TestCase assert_no_difference 'ActionMailer::Base.deliveries.size' do assert_no_difference 'Reply.count' do - post :create, reply: { + post :create, params: { + reply: { content: '', ticket_id: @ticket.id, notified_user_ids: [users(:bob).id], + } } assert_response :success # should get a form instead of a 500 @@ -46,10 +48,12 @@ class RepliesControllerTest < ActionController::TestCase # do we send a mail? assert_difference 'ActionMailer::Base.deliveries.size', User.agents.count do - post :create, reply: { + post :create, params: { + reply: { content: '

this is in bold

', ticket_id: @ticket.id, notified_user_ids: User.agents.pluck(:id), + } } end @@ -57,7 +61,7 @@ class RepliesControllerTest < ActionController::TestCase # html in the html part assert_match '

this is in bold

', - mail.html_part.body.decoded + mail.html_part.body.decoded # no html in the text part assert_match "\n\nthis is in bold\n", mail.text_part.body.decoded @@ -78,14 +82,16 @@ class RepliesControllerTest < ActionController::TestCase test 'reply should have attachments' do assert_difference 'Attachment.count', 2 do - post :create, reply: { - content: '**this is in bold**', - ticket_id: @ticket.id, - notified_user_ids: [users(:bob).id], - attachments_attributes: { - '0' => { file: fixture_file_upload('attachments/default-testpage.pdf') }, - '1' => { file: fixture_file_upload('attachments/default-testpage.pdf') } - } + post :create, params: { + reply: { + content: '**this is in bold**', + ticket_id: @ticket.id, + notified_user_ids: [users(:bob).id], + attachments_attributes: { + '0': { file: fixture_file_upload('attachments/default-testpage.pdf') }, + '1': { file: fixture_file_upload('attachments/default-testpage.pdf') } + } + } } end end @@ -97,10 +103,12 @@ class RepliesControllerTest < ActionController::TestCase # do we send a mail? assert_difference 'ActionMailer::Base.deliveries.size', User.agents.count do - post :create, reply: { + post :create, params: { + reply: { content: 'test', ticket_id: @ticket.id, notified_user_ids: [users(:bob).id, users(:alice).id] + } } end mail = ActionMailer::Base.deliveries.last @@ -111,9 +119,11 @@ class RepliesControllerTest < ActionController::TestCase @ticket.status = 'closed' @ticket.save - post :create, reply: { + post :create, params: { + reply: { content: 're-open please', ticket_id: @ticket.id, + } } @ticket.reload @@ -125,7 +135,9 @@ class RepliesControllerTest < ActionController::TestCase @reply.save! @reply.reload - get :show, id: @reply.id, format: :eml + get :show, params: { + id: @reply.id, format: :eml + } assert_response :success end diff --git a/test/controllers/rules_controller_test.rb b/test/controllers/rules_controller_test.rb index 43b290732..abc99331b 100644 --- a/test/controllers/rules_controller_test.rb +++ b/test/controllers/rules_controller_test.rb @@ -42,15 +42,19 @@ class RulesControllerTest < ActionController::TestCase test 'should get edit' do sign_in @alice - get :edit, id: @rule + get :edit, params: { + id: @rule + } assert_response :success end test 'should update' do sign_in @alice - put :update, id: @rule, rule: { + put :update, params: { + id: @rule, rule: { filter_field: 'subject', + } } assert_equal 'subject', assigns(:rule).filter_field assert_redirected_to rules_url @@ -67,12 +71,14 @@ class RulesControllerTest < ActionController::TestCase sign_in @alice assert_difference 'Rule.count' do - post :create, rule: { - filter_field: @rule.filter_field, - filter_operation: @rule.filter_operation, - filter_value: @rule.filter_value, - action_operation: @rule.action_operation, - action_value: @rule.action_value, + post :create, params: { + rule: { + filter_field: @rule.filter_field, + filter_operation: @rule.filter_operation, + filter_value: @rule.filter_value, + action_operation: @rule.action_operation, + action_value: @rule.action_value, + } } assert_redirected_to rules_url @@ -83,7 +89,9 @@ class RulesControllerTest < ActionController::TestCase sign_in @alice assert_difference 'Rule.count', -1 do - delete :destroy, id: @rule + delete :destroy, params: { + id: @rule + } assert_redirected_to rules_url end diff --git a/test/controllers/settings_controller_test.rb b/test/controllers/settings_controller_test.rb index 00d8cd8fc..450026568 100644 --- a/test/controllers/settings_controller_test.rb +++ b/test/controllers/settings_controller_test.rb @@ -35,9 +35,11 @@ class SettingsControllerTest < ActionController::TestCase if EmailTemplate.count == 0 assert_difference 'EmailTemplate.count', 2 do - put :update, id: @tenant.id, tenant: { + put :update, params: { + id: @tenant.id, tenant: { notify_user_when_account_is_created: true, notify_client_when_ticket_is_created: true + } } end end diff --git a/test/controllers/tickets_controller_test.rb b/test/controllers/tickets_controller_test.rb index c05c2247f..d1cea1e8a 100644 --- a/test/controllers/tickets_controller_test.rb +++ b/test/controllers/tickets_controller_test.rb @@ -57,7 +57,9 @@ class TicketsControllerTest < ActionController::TestCase assert_difference 'ActionMailer::Base.deliveries.size', User.agents.count do assert_difference 'Ticket.count' do - post :create, message: @simple_email, format: :json + post :create, params: { + message: @simple_email, format: :json + } assert_response :success end @@ -85,10 +87,12 @@ class TicketsControllerTest < ActionController::TestCase assert_difference 'ActionMailer::Base.deliveries.size', User.agents.count do assert_difference 'Ticket.count', 1 do - post :create, ticket: { - from: 'test@test.nl', - content: @ticket.content, - subject: @ticket.subject, + post :create, params: { + ticket: { + from: 'test@test.nl', + content: @ticket.content, + subject: @ticket.subject, + } } assert_redirected_to ticket_url(assigns(:ticket)) @@ -104,10 +108,12 @@ class TicketsControllerTest < ActionController::TestCase assert_no_difference 'ActionMailer::Base.deliveries.size', User.agents.count do assert_no_difference 'Ticket.count' do - post :create, ticket: { - from: 'invalid', - content: '', - subject: '', + post :create, params: { + ticket: { + from: 'invalid', + content: '', + subject: '', + } } assert_response :success @@ -122,11 +128,13 @@ class TicketsControllerTest < ActionController::TestCase assert_difference 'ActionMailer::Base.deliveries.size', User.agents.count do assert_difference 'Ticket.count' do - post :create, ticket: { + post :create, params: { + ticket: { from: 'test@test.nl', content: @ticket.content, subject: @ticket.subject, } + } assert_response :success end @@ -140,11 +148,13 @@ class TicketsControllerTest < ActionController::TestCase assert_no_difference 'ActionMailer::Base.deliveries.size' do assert_no_difference 'Ticket.count' do - post :create, ticket: { + post :create, params: { + ticket: { from: 'invalid', content: '', subject: '', } + } assert_response :success end @@ -166,11 +176,13 @@ class TicketsControllerTest < ActionController::TestCase assert_difference 'ActionMailer::Base.deliveries.size', User.agents.count do assert_difference 'Ticket.count', 1 do - post :create, ticket: { + post :create, params: { + ticket: { from: 'test@test.nl', content: @ticket.content, subject: @ticket.subject, } + } assert_redirected_to ticket_url(assigns(:ticket)) end @@ -196,11 +208,13 @@ class TicketsControllerTest < ActionController::TestCase sign_in users(:alice) assert_no_difference 'ActionMailer::Base.deliveries.size' do assert_no_difference 'Ticket.count' do - post :create, ticket: { + post :create, params: { + ticket: { from: 'invalid', content: '', subject: '', } + } assert_response :success end @@ -225,11 +239,13 @@ class TicketsControllerTest < ActionController::TestCase assert_difference 'ActionMailer::Base.deliveries.size', User.agents.count do assert_difference 'Ticket.count', 1 do - post :create, ticket: { + post :create, params: { + ticket: { from: 'test@test.nl', content: @ticket.content, subject: @ticket.subject, } + } assert_response :success end @@ -255,11 +271,13 @@ class TicketsControllerTest < ActionController::TestCase assert_no_difference 'ActionMailer::Base.deliveries.size', User.agents.count do assert_no_difference 'Ticket.count' do - post :create, ticket: { + post :create, params: { + ticket: { from: 'invalid', content: '', subject: '', } + } assert_response :success end @@ -299,7 +317,9 @@ class TicketsControllerTest < ActionController::TestCase assert_difference 'ActionMailer::Base.deliveries.size', User.agents.count do assert_difference 'Ticket.count' do - post :create, message: @simple_email, format: :json + post :create, params: { + message: @simple_email, format: :json + } assert_response :success end @@ -320,7 +340,9 @@ class TicketsControllerTest < ActionController::TestCase assert_difference 'ActionMailer::Base.deliveries.size', User.agents.count do assert_difference 'Ticket.count' do - post :create, message: @simple_email, format: :json + post :create, params: { + message: @simple_email, format: :json + } assert_response :success end @@ -354,7 +376,9 @@ class TicketsControllerTest < ActionController::TestCase assert_difference 'ActionMailer::Base.deliveries.size', User.agents.count do assert_difference 'Ticket.count' do - post :create, message: @simple_email, format: :json + post :create, params: { + message: @simple_email, format: :json + } assert_response :success end @@ -388,7 +412,9 @@ class TicketsControllerTest < ActionController::TestCase assert_difference 'ActionMailer::Base.deliveries.size', User.agents.count do assert_difference 'Ticket.count' do - post :create, message: @simple_email, format: :json + post :create, params: { + message: @simple_email, format: :json + } assert_response :success end @@ -424,15 +450,17 @@ class TicketsControllerTest < ActionController::TestCase Timecop.freeze(new_time) assert_equal new_time, Time.now - assert_difference 'ActionMailer::Base.deliveries.size', User.agents.count-1 do - assert_difference 'Ticket.count' do - post :create, message: @simple_email, format: :json + assert_difference 'ActionMailer::Base.deliveries.size', User.agents.count-1 do + assert_difference 'Ticket.count' do + post :create, params: { + message: @simple_email, format: :json + } - assert_response :success - end + assert_response :success end + end - refute_equal 0, assigns(:ticket).notified_users.count + refute_equal 0, assigns(:ticket).notified_users.count end test 'should not notify agent with schedule enabled and time not within range working hours when ticked created from MTA' do @@ -457,7 +485,9 @@ class TicketsControllerTest < ActionController::TestCase assert_difference 'ActionMailer::Base.deliveries.size', User.agents.count-1 do assert_difference 'Ticket.count' do - post :create, message: @simple_email, format: :json + post :create, params: { + message: @simple_email, format: :json + } assert_response :success end @@ -477,11 +507,13 @@ class TicketsControllerTest < ActionController::TestCase assert_difference 'ActionMailer::Base.deliveries.size', User.agents.count do assert_difference 'Ticket.count' do - post :create, ticket: { + post :create, params: { + ticket: { from: 'test@test.nl', content: @ticket.content, subject: @ticket.subject, } + } assert_response :success end @@ -502,11 +534,13 @@ class TicketsControllerTest < ActionController::TestCase assert_difference 'ActionMailer::Base.deliveries.size', User.agents.count do assert_difference 'Ticket.count' do - post :create, ticket: { + post :create, params: { + ticket: { from: 'test@test.nl', content: @ticket.content, subject: @ticket.subject, } + } assert_response :success end @@ -541,11 +575,13 @@ class TicketsControllerTest < ActionController::TestCase assert_difference 'ActionMailer::Base.deliveries.size', User.agents.count do assert_difference 'Ticket.count' do - post :create, ticket: { + post :create, params: { + ticket: { from: 'test@test.nl', content: @ticket.content, subject: @ticket.subject, } + } assert_response :success end @@ -579,11 +615,13 @@ class TicketsControllerTest < ActionController::TestCase assert_difference 'ActionMailer::Base.deliveries.size', User.agents.count do assert_difference 'Ticket.count' do - post :create, ticket: { + post :create, params: { + ticket: { from: 'test@test.nl', content: @ticket.content, subject: @ticket.subject, } + } assert_response :success end @@ -619,19 +657,21 @@ class TicketsControllerTest < ActionController::TestCase assert_equal new_time, Time.now - assert_difference 'ActionMailer::Base.deliveries.size', User.agents.count-1 do - assert_difference 'Ticket.count' do - post :create, ticket: { - from: 'test@test.nl', - content: @ticket.content, - subject: @ticket.subject, - } + assert_difference 'ActionMailer::Base.deliveries.size', User.agents.count-1 do + assert_difference 'Ticket.count' do + post :create, params: { + ticket: { + from: 'test@test.nl', + content: @ticket.content, + subject: @ticket.subject, + } + } - assert_response :success - end + assert_response :success end + end - refute_equal 0, assigns(:ticket).notified_users.count + refute_equal 0, assigns(:ticket).notified_users.count end test 'should not notify agent with schedule enabled and time not within range working hours when ticked created' do @@ -656,11 +696,13 @@ class TicketsControllerTest < ActionController::TestCase assert_difference 'ActionMailer::Base.deliveries.size', User.agents.count-1 do assert_difference 'Ticket.count' do - post :create, ticket: { + post :create, params: { + ticket: { from: 'test@test.nl', content: @ticket.content, subject: @ticket.subject, } + } assert_response :success end @@ -682,11 +724,13 @@ class TicketsControllerTest < ActionController::TestCase assert_difference 'ActionMailer::Base.deliveries.size', User.agents.count do assert_difference 'Ticket.count' do - post :create, ticket: { + post :create, params: { + ticket: { from: 'test@test.nl', content: @ticket.content, subject: @ticket.subject, } + } assert_redirected_to ticket_url(assigns(:ticket)) end @@ -708,11 +752,13 @@ class TicketsControllerTest < ActionController::TestCase assert_difference 'ActionMailer::Base.deliveries.size', User.agents.count do assert_difference 'Ticket.count' do - post :create, ticket: { + post :create, params: { + ticket: { from: 'test@test.nl', content: @ticket.content, subject: @ticket.subject, } + } assert_redirected_to ticket_url(assigns(:ticket)) end @@ -748,11 +794,13 @@ class TicketsControllerTest < ActionController::TestCase assert_difference 'ActionMailer::Base.deliveries.size', User.agents.count do assert_difference 'Ticket.count' do - post :create, ticket: { + post :create, params: { + ticket: { from: 'test@test.nl', content: @ticket.content, subject: @ticket.subject, } + } assert_redirected_to ticket_url(assigns(:ticket)) end @@ -788,11 +836,13 @@ class TicketsControllerTest < ActionController::TestCase assert_difference 'ActionMailer::Base.deliveries.size', User.agents.count do assert_difference 'Ticket.count' do - post :create, ticket: { + post :create, params: { + ticket: { from: 'test@test.nl', content: @ticket.content, subject: @ticket.subject, } + } assert_redirected_to ticket_url(assigns(:ticket)) end @@ -828,19 +878,21 @@ class TicketsControllerTest < ActionController::TestCase Timecop.freeze(new_time) assert_equal new_time, Time.now - assert_difference 'ActionMailer::Base.deliveries.size', User.agents.count-1 do - assert_difference 'Ticket.count' do - post :create, ticket: { - from: 'test@test.nl', - content: @ticket.content, - subject: @ticket.subject, - } + assert_difference 'ActionMailer::Base.deliveries.size', User.agents.count-1 do + assert_difference 'Ticket.count' do + post :create, params: { + ticket: { + from: 'test@test.nl', + content: @ticket.content, + subject: @ticket.subject, + } + } assert_redirected_to ticket_url(assigns(:ticket)) - end end + end - refute_equal 0, assigns(:ticket).notified_users.count + refute_equal 0, assigns(:ticket).notified_users.count end test 'should not notify agent with schedule enabled and time not within range working hours when ticked created with logged in agent' do @@ -866,11 +918,13 @@ class TicketsControllerTest < ActionController::TestCase assert_difference 'ActionMailer::Base.deliveries.size', User.agents.count-1 do assert_difference 'Ticket.count' do - post :create, ticket: { + post :create, params: { + ticket: { from: 'test@test.nl', content: @ticket.content, subject: @ticket.subject, } + } assert_redirected_to ticket_url(assigns(:ticket)) end @@ -887,7 +941,7 @@ class TicketsControllerTest < ActionController::TestCase test 'should only allow agents to view others tickets' do sign_in users(:bob) - get :show, { id: tickets(:multiple) } + get :show, params: { id: tickets(:multiple) } assert_response :unauthorized # redirect to sign in page end @@ -910,7 +964,7 @@ class TicketsControllerTest < ActionController::TestCase test 'should show ticket' do sign_in users(:alice) - get :show, id: @ticket.id + get :show, params: { id: @ticket.id } assert_response :success # should contain this for label adding with javascript @@ -939,7 +993,9 @@ class TicketsControllerTest < ActionController::TestCase # new assignee should receive notification assert_difference 'ActionMailer::Base.deliveries.size' do - put :update, id: @ticket.id, ticket: { assignee_id: users(:charlie).id } + put :update, params: { + id: @ticket.id, ticket: { assignee_id: users(:charlie).id } + } assert_redirected_to ticket_path(@ticket) end @@ -955,7 +1011,9 @@ class TicketsControllerTest < ActionController::TestCase # assignee should receive notification assert_difference 'ActionMailer::Base.deliveries.size' do - put :update, id: @ticket.id, ticket: { status: 'closed' } + put :update, params: { + id: @ticket.id, ticket: { status: 'closed' } + } assert_redirected_to ticket_path(@ticket) end @@ -971,7 +1029,9 @@ class TicketsControllerTest < ActionController::TestCase # assignee should receive notification assert_difference 'ActionMailer::Base.deliveries.size' do - put :update, id: @ticket.id, ticket: { priority: 'high' } + put :update, params: { + id: @ticket.id, ticket: { priority: 'high' } + } assert_redirected_to ticket_path(@ticket) end @@ -988,7 +1048,9 @@ class TicketsControllerTest < ActionController::TestCase # new assignee should not receive notification assert_no_difference 'ActionMailer::Base.deliveries.size' do - put :update, id: @ticket.id, ticket: { assignee_id: users(:charlie).id } + put :update, params: { + id: @ticket.id, ticket: { assignee_id: users(:charlie).id } + } assert_redirected_to ticket_path(@ticket) end @@ -1001,7 +1063,9 @@ class TicketsControllerTest < ActionController::TestCase # assignee should not receive notification assert_no_difference 'ActionMailer::Base.deliveries.size' do - put :update, id: @ticket.id, ticket: { status: 'closed' } + put :update, params: { + id: @ticket.id, ticket: { status: 'closed' } + } assert_redirected_to ticket_path(@ticket) end @@ -1014,7 +1078,9 @@ class TicketsControllerTest < ActionController::TestCase # assignee should not receive notification assert_no_difference 'ActionMailer::Base.deliveries.size' do - put :update, id: @ticket.id, ticket: { priority: 'high' } + put :update, params: { + id: @ticket.id, ticket: { priority: 'high' } + } assert_redirected_to ticket_path(@ticket) end @@ -1059,7 +1125,9 @@ class TicketsControllerTest < ActionController::TestCase assert_no_difference 'ActionMailer::Base.deliveries.size' do assert_difference 'Ticket.count' do - post :create, message: email, format: :json + post :create, params: { + message: email, format: :json + } assert_response :success @@ -1073,7 +1141,9 @@ class TicketsControllerTest < ActionController::TestCase assert_no_difference 'ActionMailer::Base.deliveries.size' do assert_no_difference 'Ticket.count' do - post :create, message: email, format: :json + post :create, params: { + message: email, format: :json + } assert_response :unprocessable_entity @@ -1095,7 +1165,9 @@ class TicketsControllerTest < ActionController::TestCase @ticket.save! @ticket.reload - get :show, id: @ticket.id, format: :eml + get :show, params: { + id: @ticket.id, format: :eml + } assert_response :success end @@ -1106,7 +1178,9 @@ class TicketsControllerTest < ActionController::TestCase @ticket.locked_at = Time.now @ticket.save! - get :show, id: @ticket.id + get :show, params: { + id: @ticket.id + } assert_response :success assert_match replies(:solution).content, @response.body end @@ -1114,7 +1188,9 @@ class TicketsControllerTest < ActionController::TestCase test 'should mark new ticket from MTA as unread for all users' do assert_difference 'Ticket.count' do - post :create, message: @simple_email, format: :json + post :create, params: { + message: @simple_email, format: :json + } assert_response :success @@ -1125,10 +1201,12 @@ class TicketsControllerTest < ActionController::TestCase test 'should mark new ticket as unread for all users' do assert_difference 'Ticket.count' do - post :create, ticket: { - from: 'test@test.nl', - content: @ticket.content, - subject: @ticket.subject, + post :create, params: { + ticket: { + from: 'test@test.nl', + content: @ticket.content, + subject: @ticket.subject, + } } assert_response :success @@ -1142,7 +1220,9 @@ class TicketsControllerTest < ActionController::TestCase test 'should mark new ticket as unread for all users when posted from MTA' do assert_difference 'Ticket.count' do - post :create, message: @simple_email, format: :json + post :create, params: { + message: @simple_email, format: :json + } assert_response :success @@ -1161,7 +1241,9 @@ class TicketsControllerTest < ActionController::TestCase assert_not_nil ticket.unread_users assert_not_nil user.unread_tickets - get :show, { id: ticket.id } + get :show, params: { + id: ticket.id + } assert_response :success diff --git a/test/controllers/users_controller_test.rb b/test/controllers/users_controller_test.rb index e48d2b3cc..63a852c16 100644 --- a/test/controllers/users_controller_test.rb +++ b/test/controllers/users_controller_test.rb @@ -40,14 +40,18 @@ class UsersControllerTest < ActionController::TestCase test 'should get edit' do sign_in @alice - get :edit, id: @alice.id + get :edit, params: { + id: @alice.id + } assert_response :success end test 'should modify signature' do sign_in @alice - put :update, id: @alice.id, user: { signature: 'Alice' } + put :update, params: { + id: @alice.id, user: { signature: 'Alice' } + } assert_equal 'Alice', assigns(:user).signature assert_redirected_to users_url end @@ -56,7 +60,9 @@ class UsersControllerTest < ActionController::TestCase sign_in @bob assert_no_difference 'User.agents.count' do - put :update, id: @bob.id, user: { agent: true, signature: 'Bob' } + put :update, params: { + id: @bob.id, user: { agent: true, signature: 'Bob' } + } end end @@ -64,12 +70,14 @@ class UsersControllerTest < ActionController::TestCase sign_in @bob assert_no_difference 'User.agents.count' do - post :create, user: { + post :create, params: { + user: { email: 'harry@getbrimir.com', password: 'testtest', password_confirmation: 'testtest', agent: true, signature: 'Harry' + } } end @@ -80,9 +88,11 @@ class UsersControllerTest < ActionController::TestCase sign_in @alice assert_difference 'Labeling.count' do - patch :update, id: @bob.id, user: { - email: 'test@test.test', - label_ids: [labels(:bug).id] + patch :update, params: { + id: @bob.id, user: { + email: 'test@test.test', + label_ids: [labels(:bug).id] + } } end @@ -99,11 +109,13 @@ class UsersControllerTest < ActionController::TestCase sign_in @bob assert_no_difference 'Labeling.count' do - patch :update, id: @bob.id, user: { - email: 'test@test.test', - label_ids: [labels(:bug).id], - password: 'testtest', - password_confirmation: 'testtest', + patch :update, params: { + id: @bob.id, user: { + email: 'test@test.test', + label_ids: [labels(:bug).id], + password: 'testtest', + password_confirmation: 'testtest', + } } end @@ -119,7 +131,9 @@ class UsersControllerTest < ActionController::TestCase sign_in @alice assert_no_difference 'User.count' do - delete :destroy, id: @bob.id + delete :destroy, params: { + id: @bob.id + } assert_response :unauthorized end @@ -127,7 +141,9 @@ class UsersControllerTest < ActionController::TestCase @bob.replies.destroy_all assert_difference 'User.count', -1 do - delete :destroy, id: @bob.id + delete :destroy, params: { + id: @bob.id + } assert_redirected_to users_url end end @@ -139,12 +155,14 @@ class UsersControllerTest < ActionController::TestCase assert_not @alice.schedule_enabled assert_difference 'Schedule.count' do - patch :update, id: @alice.id, user: { - email: @alice.email, - schedule_enabled: true, - schedule_attributes: { - start: '08:00', - end: '18:00' + patch :update, params: { + id: @alice.id, user: { + email: @alice.email, + schedule_enabled: true, + schedule_attributes: { + start: '08:00', + end: '18:00' + } } } assert_redirected_to users_url diff --git a/test/integration/api/v1/api_login_test.rb b/test/integration/api/v1/api_login_test.rb index 6ef52cfea..1f3d79a2f 100644 --- a/test/integration/api/v1/api_login_test.rb +++ b/test/integration/api/v1/api_login_test.rb @@ -5,8 +5,10 @@ class API::V1::ApiLoginTest < ActionDispatch::IntegrationTest test 'should sign in using single sign on' do host! "test.host" - - post '/api/v1/sessions', { email: 'bob@xxxx.com', password: 'testtest' } + + post '/api/v1/sessions', params: { + email: 'bob@xxxx.com', password: 'testtest' + } assert_response :success @@ -14,13 +16,15 @@ class API::V1::ApiLoginTest < ActionDispatch::IntegrationTest assert_not_nil result['authorization_token'] - get '/api/v1/tickets.json?auth_token=' + result['authorization_token'] + get '/api/v1/tickets.json', + params: { 'auth_token': result['authorization_token'] } assert_response :success end test 'do not login with fault post' do - post '/api/v1/sessions', wrong_param: 'wrong' + post '/api/v1/sessions', + params: { wrong_param: 'wrong' } assert_response :unauthorized