From 1b7f625c695388bfc8d31ca441276e0910dc0dae Mon Sep 17 00:00:00 2001 From: Sergei Tsoganov Date: Fri, 12 May 2023 11:39:06 +0300 Subject: [PATCH] Fixed default sorting of epp logs --- app/controllers/admin/epp_logs_controller.rb | 8 ++++---- test/integration/admin_area/epp_logs_test.rb | 16 +++++++++------- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/app/controllers/admin/epp_logs_controller.rb b/app/controllers/admin/epp_logs_controller.rb index ec23d0fc3..7a6a9b3b6 100644 --- a/app/controllers/admin/epp_logs_controller.rb +++ b/app/controllers/admin/epp_logs_controller.rb @@ -6,16 +6,16 @@ module Admin # rubocop:disable Metrics/MethodLength def index @q = ApiLog::EppLog.ransack(PartialSearchFormatter.format(params[:q])) - @result = @q.result @q.sorts = 'id desc' if @q.sorts.empty? + @result = @q.result @epp_logs = @result if params[:q][:created_at_gteq].present? - @epp_logs = @epp_logs.where("extract(epoch from created_at) >= extract(epoch from ?::timestamp)", + @epp_logs = @epp_logs.where('extract(epoch from created_at) >= extract(epoch from ?::timestamp)', Time.parse(params[:q][:created_at_gteq])) end if params[:q][:created_at_lteq].present? - @epp_logs = @epp_logs.where("extract(epoch from created_at) <= extract(epoch from ?::timestamp)", + @epp_logs = @epp_logs.where('extract(epoch from created_at) <= extract(epoch from ?::timestamp)', Time.parse(params[:q][:created_at_lteq])) end @epp_logs = @epp_logs.page(params[:page]) @@ -35,7 +35,7 @@ module Admin default_date = params[:created_after] default_date = 'today' unless %w[today tomorrow yesterday].include?(default_date) - params[:q][:created_at_gteq] = Date.send(default_date).strftime("%Y-%m-%d") + params[:q][:created_at_gteq] = Date.send(default_date).strftime('%Y-%m-%d') end private diff --git a/test/integration/admin_area/epp_logs_test.rb b/test/integration/admin_area/epp_logs_test.rb index dc159511b..866ddbb15 100644 --- a/test/integration/admin_area/epp_logs_test.rb +++ b/test/integration/admin_area/epp_logs_test.rb @@ -17,7 +17,7 @@ class AdminEppLogsIntegrationTest < ApplicationSystemTestCase send_epp_request_hello visit admin_epp_logs_path - find(:xpath, "//tbody/tr/td/a", match: :first).click + find(:xpath, '//tbody/tr/td/a', match: :first).click assert_text 'Details' end @@ -27,12 +27,14 @@ class AdminEppLogsIntegrationTest < ApplicationSystemTestCase send_epp_request_hello visit admin_epp_logs_path - find(:xpath, "//a[contains(text(), 'Created at')]", match: :first).click - find(:xpath, "//a[contains(text(), 'Created at')]", match: :first).click - - epp_log_date = find(:xpath, "//table/tbody/tr/td[6]", match: :first).text(:all) date_now = Date.today.to_s(:db) + epp_log_date = find(:xpath, '//table/tbody/tr/td[6]', match: :first).text(:all) + assert_match /#{date_now}/, epp_log_date + find(:xpath, "//a[contains(text(), 'Created at')]", match: :first).click + find(:xpath, "//a[contains(text(), 'Created at')]", match: :first).click + + epp_log_date = find(:xpath, '//table/tbody/tr/td[6]', match: :first).text(:all) assert_match /#{date_now}/, epp_log_date end @@ -57,9 +59,9 @@ class AdminEppLogsIntegrationTest < ApplicationSystemTestCase - XML + XML get epp_hello_path, params: { frame: request_xml }, - headers: { 'HTTP_COOKIE' => 'session=non-existent' } + headers: { 'HTTP_COOKIE' => 'session=non-existent' } end end