Skip to content

Commit

Permalink
Merge pull request #2 from MichaelSipayung/admin-access
Browse files Browse the repository at this point in the history
admin access unit testing
  • Loading branch information
MichaelSipayung authored Feb 1, 2024
2 parents 741db39 + 1033c93 commit e8a23b2
Show file tree
Hide file tree
Showing 39 changed files with 131 additions and 21 deletions.
2 changes: 2 additions & 0 deletions app/controllers/achievements_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
class AchievementsController < ApplicationController
before_action :set_achievement_dropdown_menu, only: %i[new create edit update]
before_action :current_achievement, only: %i[edit show update]
before_action :non_admin, only: %i[new create edit update]

def new
@achievement = current_user.achievements.build
end
Expand Down
2 changes: 2 additions & 0 deletions app/controllers/addresses_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
class AddressesController < ApplicationController
before_action :set_address_dropdown_menu, only: %i[new create edit update]
before_action :current_address, only: %i[edit show update]
before_action :non_admin, only: %i[new create edit update]

def new
@address = current_user.addresses.build
end
Expand Down
4 changes: 4 additions & 0 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,8 @@ def logged_in_user
def admin_user
redirect_to(root_url) unless current_user.admin? # look attribute admin? true:false
end

def non_admin
redirect_to(root_url) if current_user.admin? # look attribute admin? true:false
end
end
2 changes: 2 additions & 0 deletions app/controllers/extras_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
class ExtrasController < ApplicationController
before_action :set_extra_dropdown_menu, only: %i[new create edit update]
before_action :current_extra, only: %i[edit show update]
before_action :non_admin, only: %i[new create edit update]

def new
@extra = current_user.extras.build
end
Expand Down
2 changes: 2 additions & 0 deletions app/controllers/languages_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
class LanguagesController < ApplicationController
before_action :set_language_dropdown_menu, only: %i[new create edit update]
before_action :current_language, only: %i[edit update show]
before_action :non_admin, only: %i[new create edit update]

def new
@language = current_user.languages.build
end
Expand Down
2 changes: 2 additions & 0 deletions app/controllers/majors_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ class MajorsController < ApplicationController
before_action :set_major_dropdown_menu, only: %i[new create edit update]
before_action :current_user, only: %i[edit update show]
before_action :fill_major, only: %i[new create]
before_action :non_admin, only: %i[new create edit update]

def new
@major = current_user.build_major
end
Expand Down
2 changes: 2 additions & 0 deletions app/controllers/organizations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
class OrganizationsController < ApplicationController
before_action :set_organization_dropdown_menu, only: %i[new create edit update]
before_action :current_organization, only: %i[edit show update]
before_action :non_admin, only: %i[new create edit update]

def new
@organization = current_user.organizations.build
end
Expand Down
2 changes: 2 additions & 0 deletions app/controllers/parents_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ class ParentsController < ApplicationController
before_action :set_parent_dropdown_menu, only: %i[new create edit update]
before_action :current_parent, only: %i[show update edit]
before_action :fill_parent, only: %i[new create]
before_action :non_admin, only: %i[new create edit update]

def new
@parent = current_user.build_parent
end
Expand Down
2 changes: 2 additions & 0 deletions app/controllers/personals_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ class PersonalsController < ApplicationController
# before_action :set_personal, only: %i[edit update show]
before_action :current_personal, only: %i[edit update show]
before_action :fill_personal, only: %i[new create]
before_action :non_admin, only: %i[new create edit update]

def new
@personal = current_user.build_personal
end
Expand Down
2 changes: 2 additions & 0 deletions app/controllers/pmdk_each_score_informations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
class PmdkEachScoreInformationsController < ApplicationController
before_action :current_pmdk_each_score, only: %i[show edit update]
before_action :fill_pmdk_each_score, only: %i[new create]
before_action :non_admin, only: %i[new create edit update]

def new
@pmdk_each_score = current_user.build_pmdk_each_score_information
end
Expand Down
2 changes: 2 additions & 0 deletions app/controllers/pmdk_school_informations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ class PmdkSchoolInformationsController < ApplicationController
before_action :set_pmdk_school_dropdown, only: %i[new create edit update]
before_action :current_pmdk_school, only: %i[edit update show]
before_action :fill_pmdk_school, only: %i[new create]
before_action :non_admin, only: %i[new create edit update]

def new
@pmdk_school_information = current_user.build_pmdk_school_information
end
Expand Down
2 changes: 2 additions & 0 deletions app/controllers/pmdk_total_score_informations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
class PmdkTotalScoreInformationsController < ApplicationController
before_action :current_pmdk_total_score, only: %i[edit update show]
before_action :fill_pmdk_total, only: %i[new create]
before_action :non_admin, only: %i[new create edit update]

def new
@pmdk_total_score = current_user.build_pmdk_total_score_information
end
Expand Down
2 changes: 2 additions & 0 deletions app/controllers/sources_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ class SourcesController < ApplicationController
before_action :set_source_dropdown_menu, only: %i[new create edit update]
before_action :current_source, only: %i[edit update show]
before_action :fill_source, only: %i[new create]
before_action :non_admin, only: %i[new create edit update]

def new
@source = current_user.build_source
end
Expand Down
2 changes: 2 additions & 0 deletions app/controllers/usm_school_informations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ class UsmSchoolInformationsController < ApplicationController
before_action :set_usm_school_dropdown, only: %i[new create edit update]
before_action :current_usm_school, only: %i[edit update show]
before_action :fill_usm_school, only: %i[new create]
before_action :non_admin, only: %i[new create edit update]

def new
@usm_school = current_user.build_usm_school_information
end
Expand Down
2 changes: 2 additions & 0 deletions app/controllers/utbk_school_informations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ class UtbkSchoolInformationsController < ApplicationController
before_action :set_utbk_school_dropdown, only: %i[new create edit update]
before_action :current_utbk_school, only: %i[edit update show]
before_action :fill_utbk_school, only: %i[new create]
before_action :non_admin, only: %i[new create edit update]

def new
@utbk_school_information = current_user.build_utbk_school_information
end
Expand Down
3 changes: 2 additions & 1 deletion app/controllers/utbk_scores_controller.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
# frozen_string_literal: true

# utbk_score : handle utbk score data
# utbk_score : handle utbk score data
class UtbkScoresController < ApplicationController
before_action :current_utbk, only: %i[edit update show]
before_action :fill_utbk, only: %i[new create]
before_action :non_admin, only: %i[new create edit update]
def new
@utbk_score = current_user.build_utbk_score
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class AccreditationSchoolListsControllerTest < ActionDispatch::IntegrationTest
setup do
get login_path
post login_path, params: { session: {
email: users(:michael).email, password: 'password'
email: users(:adminuser).email, password: 'password'
} }
@accreditation_school_list = accreditation_school_lists(:one)
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class AchievementKategoriListsControllerTest < ActionDispatch::IntegrationTest
setup do
get login_path
post login_path, params: { session: {
email: users(:michael).email, password: 'password'
email: users(:adminuser).email, password: 'password'
} }
@achievement_kategori_list = achievement_kategori_lists(:one)
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class AchievementTingkatListsControllerTest < ActionDispatch::IntegrationTest
setup do
get login_path
post login_path, params: { session: {
email: users(:michael).email, password: 'password'
email: users(:adminuser).email, password: 'password'
} }
@achievement_tingkat_list = achievement_tingkat_lists(:one)
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class AddressKabupatenListsControllerTest < ActionDispatch::IntegrationTest
setup do
get login_path
post login_path, params: {
session: { email: users(:michael).email, password: 'password' }
session: { email: users(:adminuser).email, password: 'password' }
}
@address_kabupaten_list = address_kabupaten_lists(:acehtengah)
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class AddressKecamatanListsControllerTest < ActionDispatch::IntegrationTest
setup do
get login_path
post login_path, params: {
session: { email: users(:michael).email, password: 'password' }
session: { email: users(:adminuser).email, password: 'password' }
}
@address_kecamatan_list = address_kecamatan_lists(:kecacehtengah)
end
Expand Down
2 changes: 1 addition & 1 deletion test/controllers/address_province_lists_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class AddressProvinceListsControllerTest < ActionDispatch::IntegrationTest
setup do
get login_path
post login_path, params: {
session: { email: users(:michael).email, password: 'password' }
session: { email: users(:adminuser).email, password: 'password' }
}
@address_province_list = address_province_lists(:aceh)
end
Expand Down
2 changes: 1 addition & 1 deletion test/controllers/all_school_lists_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class AllSchoolListsControllerTest < ActionDispatch::IntegrationTest
setup do
get login_path
post login_path, params: { session: {
email: users(:michael).email, password: 'password'
email: users(:adminuser).email, password: 'password'
} }
@all_school_list = all_school_lists(:one)
end
Expand Down
2 changes: 1 addition & 1 deletion test/controllers/batch_lists_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class BatchListsControllerTest < ActionDispatch::IntegrationTest
setup do
get login_path
post login_path, params: { session: {
email: users(:michael).email, password: 'password'
email: users(:adminuser).email, password: 'password'
} }
@batch_list = batch_lists(:one)
end
Expand Down
2 changes: 1 addition & 1 deletion test/controllers/extra_lists_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class ExtraListsControllerTest < ActionDispatch::IntegrationTest
setup do
get login_path
post login_path, params: { session: {
email: users(:michael).email,
email: users(:adminuser).email,
password: 'password'
} }
@extra_list = extra_lists(:one)
Expand Down
2 changes: 1 addition & 1 deletion test/controllers/high_school_majors_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class HighSchoolMajorsControllerTest < ActionDispatch::IntegrationTest
setup do
get login_path
post login_path, params: { session: {
email: users(:michael).email, password: 'password'
email: users(:adminuser).email, password: 'password'
} }
@high_school_major = high_school_majors(:one)
end
Expand Down
2 changes: 1 addition & 1 deletion test/controllers/language_degree_lists_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class LanguageDegreeListsControllerTest < ActionDispatch::IntegrationTest
setup do
get login_path
post login_path, params: { session: {
email: users(:michael).email,
email: users(:adminuser).email,
password: 'password'
} }
@language_degree_list = language_degree_lists(:one)
Expand Down
2 changes: 1 addition & 1 deletion test/controllers/language_name_lists_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class LanguageNameListsControllerTest < ActionDispatch::IntegrationTest
setup do
get login_path
post login_path, params: { session: {
email: users(:michael).email,
email: users(:adminuser).email,
password: 'password'
} }
@language_name_list = language_name_lists(:one)
Expand Down
2 changes: 1 addition & 1 deletion test/controllers/major_lists_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class MajorListsControllerTest < ActionDispatch::IntegrationTest
setup do
get login_path
post login_path, params: { session: {
email: users(:michael).email, password: 'password'
email: users(:adminuser).email, password: 'password'
} }
@major_list = major_lists(:one)
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class OrganizationDegreeListsControllerTest < ActionDispatch::IntegrationTest
setup do
get login_path
post login_path, params: { session: {
email: users(:michael).email,
email: users(:adminuser).email,
password: 'password'
} }
@organization_degree_list = organization_degree_lists(:one)
Expand Down
2 changes: 1 addition & 1 deletion test/controllers/parent_education_lists_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class ParentEducationListsControllerTest < ActionDispatch::IntegrationTest
setup do
get login_path
post login_path, params: { session: {
email: users(:michael).email, password: 'password'
email: users(:adminuser).email, password: 'password'
} }
@parent_education_list = parent_education_lists(:one)
end
Expand Down
2 changes: 1 addition & 1 deletion test/controllers/parent_job_lists_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class ParentJobListsControllerTest < ActionDispatch::IntegrationTest
setup do
get login_path
post login_path, params: { session: {
email: users(:michael).email, password: 'password'
email: users(:adminuser).email, password: 'password'
} }
@parent_job_list = parent_job_lists(:one)
end
Expand Down
2 changes: 1 addition & 1 deletion test/controllers/personal_gender_lists_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class PersonalGenderListsControllerTest < ActionDispatch::IntegrationTest
setup do
get login_path
post login_path, params: { session: {
email: users(:michael).email, password: 'password'
email: users(:adminuser).email, password: 'password'
} }
@personal_gender_list = personal_gender_lists(:one)
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class PersonalReligionListsControllerTest < ActionDispatch::IntegrationTest
setup do
get login_path
post login_path, params: { session: {
email: users(:michael).email, password: 'password'
email: users(:adminuser).email, password: 'password'
} }
@personal_religion_list = personal_religion_lists(:one)
end
Expand Down
2 changes: 1 addition & 1 deletion test/controllers/pmdk_school_lists_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class PmdkSchoolListsControllerTest < ActionDispatch::IntegrationTest
setup do
get login_path
post login_path, params: {
session: { email: users(:michael).email, password: 'password' }
session: { email: users(:adminuser).email, password: 'password' }
}
@pmdk_school_list = pmdk_school_lists(:one)
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class SourceMotivationListsControllerTest < 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_motivation_list = source_motivation_lists(:one)
end
Expand Down
1 change: 1 addition & 0 deletions test/controllers/users_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ def setup
assert_redirected_to root_url
end
test 'should redirect destroy when logged in as admin' do
@user = users(:adminuser)
get login_path
post login_path, params: { session: { email: @user.email, password: 'password' } }
assert_difference 'User.count', -1 do
Expand Down
7 changes: 7 additions & 0 deletions test/fixtures/users.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@ michael:
name: Michael Hartl
email: [email protected]
password_digest: <%=User.digest('password') %>
admin: false
activated: true
activated_at: <%= Time.zone.now %>
adminuser:
name: Januari
email: [email protected]
password_digest: <%=User.digest('password') %>
admin: true
activated: true
activated_at: <%= Time.zone.now %>
Expand Down
Loading

0 comments on commit e8a23b2

Please sign in to comment.