From a6af2f898c783e152c118ed56abb4586dbe4fa06 Mon Sep 17 00:00:00 2001 From: mmeest Date: Fri, 25 Jul 2025 12:39:31 +0300 Subject: [PATCH] tests added --- .../admin_area/domains_controller_test.rb | 66 +++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 test/integration/admin_area/domains_controller_test.rb diff --git a/test/integration/admin_area/domains_controller_test.rb b/test/integration/admin_area/domains_controller_test.rb new file mode 100644 index 000000000..1f34f9f4c --- /dev/null +++ b/test/integration/admin_area/domains_controller_test.rb @@ -0,0 +1,66 @@ +require 'test_helper' + +class AdminDomainsControllerTest < ActionDispatch::IntegrationTest + include Devise::Test::IntegrationHelpers + include ActionDispatch::TestProcess + + setup do + @admin = users(:admin) + sign_in @admin + + @domain = domains(:shop) + end + + def test_index_renders_successfully + get admin_domains_path + assert_response :success + assert_match @domain.name, response.body + end + + def test_index_with_status_filter + status = @domain.statuses.first || 'client_hold' + get admin_domains_path, params: { statuses_contains: [status] } + assert_response :success + end + + def test_update_statuses_success + Domain.stub_any_instance(:admin_status_update, true) do + Domain.stub_any_instance(:update, true) do + patch admin_domain_path(@domain), + params: { domain: { statuses: ['client_hold', ''] } }, + headers: { 'HTTP_REFERER' => admin_domain_path(@domain) } + end + end + + assert_redirected_to admin_domain_path(@domain) + assert_equal I18n.t('domain_updated'), flash[:notice] + end + + def test_update_statuses_failure + Domain.stub_any_instance(:admin_status_update, false) do + Domain.stub_any_instance(:update, false) do + patch admin_domain_path(@domain), + params: { domain: { statuses: ['client_hold', ''] } }, + headers: { 'HTTP_REFERER' => admin_domain_path(@domain) } + end + end + + assert_response :success + assert_match I18n.t('failed_to_update_domain'), flash[:alert] + end + + def test_versions_page_success + get admin_domain_domain_versions_path(@domain) + assert_response :success + assert_match @domain.name, response.body + end + + def test_keep_domain + Domain.stub_any_instance(:keep, true) do + patch keep_admin_domain_path(@domain) + end + + assert_redirected_to edit_admin_domain_url(@domain) + assert flash[:notice].present? + end +end \ No newline at end of file