From a1785ed3a851ee4dac98d4639e752e91a4633085 Mon Sep 17 00:00:00 2001 From: Michael Sipayung Date: Fri, 2 Feb 2024 09:05:47 +0700 Subject: [PATCH 1/2] access control for admin --- .../source_information_lists_controller.rb | 2 +- test/integration/require_admin_test.rb | 96 +++++++++++++++++++ 2 files changed, 97 insertions(+), 1 deletion(-) create mode 100644 test/integration/require_admin_test.rb diff --git a/app/controllers/source_information_lists_controller.rb b/app/controllers/source_information_lists_controller.rb index a5163c0..20ed408 100644 --- a/app/controllers/source_information_lists_controller.rb +++ b/app/controllers/source_information_lists_controller.rb @@ -3,7 +3,7 @@ # source information list controller : handle source information list class SourceInformationListsController < ApplicationController before_action :set_source_information_list, only: %i[show edit update destroy] - + before_action :admin_user, only: %i[create new edit update destroy] # GET /source_information_lists or /source_information_lists.json def index @source_information_lists = SourceInformationList.all diff --git a/test/integration/require_admin_test.rb b/test/integration/require_admin_test.rb new file mode 100644 index 0000000..e2a0c7c --- /dev/null +++ b/test/integration/require_admin_test.rb @@ -0,0 +1,96 @@ +require "test_helper" + +class RequireAdminTest < ActionDispatch::IntegrationTest + def setup + @user = users(:michael) + get login_path + post login_path, params: {session: { + email: @user.email, password: 'password' + }} + end + test 'province address list send get request' do + get new_address_province_list_url + assert_response :redirect + end + test 'kabupaten address list send get request' do + get new_address_kabupaten_list_url + assert_response :redirect + end + test 'kecamatan address list send get request' do + get new_address_kecamatan_list_url + assert_response :redirect + end + test 'personal religion list send get' do + get new_personal_religion_list_url + assert_response :redirect + end + test 'personal gender list send get' do + get new_personal_gender_list_url + assert_response :redirect + end + test 'parent job list send get' do + get new_parent_job_list_url + assert_response :redirect + end + test 'parent education list send get' do + get new_parent_education_list_url + assert_response :redirect + end + test 'source motivation list send get' do + get new_source_motivation_list_url + assert_response :redirect + end + test 'source information list send get' do + get new_source_information_list_url + assert_response :redirect + end + test 'pmdk school information list send get' do + get new_pmdk_school_list_url + assert_response :redirect + end + test 'organization degree list send get' do + get new_organization_degree_list_url + assert_response :redirect + end + test 'major list send get' do + get new_major_list_url + assert_response :redirect + end + test 'language name list send get' do + get new_language_name_list_url + assert_response :redirect + end + test 'language degree list send get' do + get new_language_degree_list_url + assert_response :redirect + end + test 'high school major send get' do + get new_high_school_major_url + assert_response :redirect + end + test 'extra list send get' do + get new_extra_list_url + assert_response :redirect + end + test 'batch list send get' do + get new_batch_list_url + assert_response :redirect + end + test 'all school list send get' do + get new_all_school_list_url + assert_response :redirect + end + test 'achievement tingkat list send get' do + get new_achievement_tingkat_list_url + assert_response :redirect + end + test 'achievement kategori list send get' do + get new_achievement_kategori_list_url + assert_response :redirect + end + test 'accreditation school list send get' do + get new_accreditation_school_list_url + assert_response :redirect + end + +end From 3a12c900c12f09e28f87f5df1e769a3f26b49826 Mon Sep 17 00:00:00 2001 From: Michael Sipayung Date: Fri, 2 Feb 2024 09:11:39 +0700 Subject: [PATCH 2/2] source information list unit test --- .idea/sample_app.iml | 204 +++++++++--------- ...ource_information_lists_controller_test.rb | 2 +- 2 files changed, 104 insertions(+), 102 deletions(-) diff --git a/.idea/sample_app.iml b/.idea/sample_app.iml index 55ffe2a..03eb973 100644 --- a/.idea/sample_app.iml +++ b/.idea/sample_app.iml @@ -324,33 +324,33 @@ + + + - - - - + - + - + - + - + @@ -361,13 +361,13 @@ - + + - @@ -380,99 +380,101 @@ + + + + - - - - - + + - - - - - - - - - - - - - - - - - - + + - + - + + - - - - + - - + + + + - - - - - - - - - - - - - - - - + + + - - + + - - + + - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - @@ -486,56 +488,44 @@ - - - - + - + - - - - - - - - - - + - + - - - + + + - - + + - + + - @@ -552,6 +542,7 @@ + @@ -562,20 +553,15 @@ - - - - - + + - - @@ -600,27 +586,43 @@ - + - - - - + + + + - + - + + + + + + + + + + + + + + + + + diff --git a/test/controllers/source_information_lists_controller_test.rb b/test/controllers/source_information_lists_controller_test.rb index 8204dac..a441f2a 100644 --- a/test/controllers/source_information_lists_controller_test.rb +++ b/test/controllers/source_information_lists_controller_test.rb @@ -6,7 +6,7 @@ class SourceInformationListsControllerTest < ActionDispatch::IntegrationTest setup do get login_path post login_path, params: { session: { - email: users(:michael).email, password: 'password' + email: users(:adminuser).email, password: 'password' } } @source_information_list = source_information_lists(:one) end