diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index 6402a3da7..69a0d0e8e 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -12,7 +12,7 @@ **Sistem/Ops etkileri:** -[//]: # (Bu PR merge edildiğinde sunucular üzerinde bir değişiklik - paket kurulması, buildpack eklenmesi vb. - yapılması gerekecekmi, açıklayın.) +[//]: # (Bu PR merge edildiğinde sunucular üzerinde bir değişiklik - paket kurulması, buildpack eklenmesi vb. - yapılması gerekecek mi, açıklayın.) **Kontrol listesi:** diff --git a/.travis.yml b/.travis.yml index 35c0835f2..a5f5b609d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -58,3 +58,6 @@ notifications: on_failure: change rooms: - secure: ljbXmcdLA/wv+j3+RCE0qF/mZd/3PbHI0VOSBkeyJDXWcHHMduIyZlodzliuXL/8mfLbmcJ8MZT5tV9l0OGSgiFI/Ngz1fadsf+0Pim4MtREkp4yKRzfDbQqj8iQwzAAcIAxbIQhenVZtaadwBAM8Jawcjs0m2+iWXaiREU1IlRaK1NzGtkDx8gy5PnVgJhtWmhV7/l6a0Sg94shr53bchkuGwH/ugqgq9L+ec1gGKVpSOHhS0W5WjojMU+3K5/HCP/r9V2J2jYUjtzDSbEDFd18rH0qJjNq1hoaVeaW1uJzidSH7f7B6xXxJfUt4e2CiY+2CkR5LUbFx5V+6fNscEAA9u+zGh6Rn9rxciWkFfzKck6Eomoq5G+d+q/ItVagAMSIUELYCOup2+H/KtRNFTBWBqwECsvXZn7WwaZOdMXDfiTnI9eSWxJqaiwFMtC1A+bnKM7DX2qoZoGCNJAzzQ93EuXdxA1w1oYVs7lfh70qLx5OraXtcTUtfrv4tzms35S9JNNnEQyWN7neuPCS0Yh4QIFf4NX7aaYbwFD66uS25Iq2ochJ4oicFd8s+DxnaXc925GYXFVHk7wZWK/mFlGnZTuTbk4ElByqzRUN2sI5r7xYijv9cBcUM/1RqzXI3B/91Ft/kyCaYDrg3W1j79zLo+G5uIHU2/F1AQBIYlI= + template: + - "Build <%{build_url}|#%{build_number}> (<%{compare_url}|%{commit}>) of %{repository_slug}@%{branch}" + - "by %{author} %{result} in %{elapsed_time}" diff --git a/Gemfile.lock b/Gemfile.lock index e1f88da14..a879e7942 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -8,7 +8,7 @@ GIT GIT remote: https://github.com/rails/rails.git - revision: 16e235126ef0187a93b81ee959a8127097e2f394 + revision: 907280ddfd78c53e2eb5af6f12512dc38df38bd8 specs: actioncable (6.0.0.beta1) actionpack (= 6.0.0.beta1) @@ -63,7 +63,7 @@ GIT i18n (>= 0.7, < 2) minitest (~> 5.1) tzinfo (~> 1.1) - zeitwerk (~> 1.0) + zeitwerk (~> 1.2) rails (6.0.0.beta1) actioncable (= 6.0.0.beta1) actionmailbox (= 6.0.0.beta1) @@ -107,7 +107,7 @@ GIT GIT remote: https://github.com/rollbar/rollbar-gem.git - revision: e3a35525d1b14fab587e317548ed4f5c1052240d + revision: ada82d619e848ad6b64a33acd10b03730b4c3d41 specs: rollbar (2.18.2) multi_json @@ -142,7 +142,7 @@ GEM io-like (~> 0.3.0) ast (2.4.0) aws-eventstream (1.0.1) - aws-partitions (1.138.0) + aws-partitions (1.139.0) aws-sdk-core (3.46.1) aws-eventstream (~> 1.0) aws-partitions (~> 1.0) @@ -173,7 +173,7 @@ GEM bundler-audit (0.6.1) bundler (>= 1.2.0, < 3) thor (~> 0.18) - byebug (10.0.2) + byebug (11.0.0) capybara (3.13.2) addressable mini_mime (>= 0.1.3) @@ -411,7 +411,7 @@ GEM wicked_pdf (1.1.0) xpath (3.2.0) nokogiri (~> 1.8) - zeitwerk (1.1.0) + zeitwerk (1.2.0) PLATFORMS ruby diff --git a/Vagrantfile b/Vagrantfile index 5947e1db6..413ac07d3 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -37,6 +37,14 @@ Vagrant.configure('2') do |config| # rubocop:disable Metrics/BlockLength end end + config.vm.define 'ldap', autostart: false do |ldap| + ldap.vm.box = 'omu/debian-stable-server' + + ldap.vm.network :forwarded_port, guest: 389, host: 1389 + + ldap.vm.provision 'shell', path: 'lib/scripts/ldap.sh' + end + config.vm.define 'paas', autostart: false do |paas| paas.vm.box = 'omu/debian-stable-paas' @@ -47,16 +55,4 @@ Vagrant.configure('2') do |config| # rubocop:disable Metrics/BlockLength trigger.run = { inline: 'bash lib/scripts/paas.sh' } end end - - config.vm.define 'ldap', autostart: true do |ldap| - ldap.vm.box = 'omu/debian-stable-server' - - ldap.vm.network :forwarded_port, guest: 389, host: 1389 - - ldap.vm.provider :lxc do |lxc| - lxc.customize 'cgroup.memory.limit_in_bytes', '2048M' - end - - ldap.vm.provision 'shell', path: 'lib/scripts/ldap.sh' - end end diff --git a/app/controllers/account/addresses_controller.rb b/app/controllers/account/addresses_controller.rb index 519282f80..fc6aef710 100644 --- a/app/controllers/account/addresses_controller.rb +++ b/app/controllers/account/addresses_controller.rb @@ -2,7 +2,7 @@ module Account class AddressesController < ApplicationController - include LastUpdateFromMernis + include UpdateableFromMernis before_action :set_user before_action :set_address, only: %i[edit update destroy] @@ -58,7 +58,7 @@ def redirect_with(message) end def address_params - params.require(:address).permit(:phone_number, :full_address, :district_id) + params.require(:address).permit(:country, :phone_number, :full_address, :district_id) end end end diff --git a/app/controllers/user/confirmations_controller.rb b/app/controllers/account/confirmations_controller.rb similarity index 97% rename from app/controllers/user/confirmations_controller.rb rename to app/controllers/account/confirmations_controller.rb index 01441f1fe..7bec25ff9 100644 --- a/app/controllers/user/confirmations_controller.rb +++ b/app/controllers/account/confirmations_controller.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -class User +module Account class ConfirmationsController < Devise::ConfirmationsController # GET /resource/confirmation/new # def new diff --git a/app/controllers/account/identities_controller.rb b/app/controllers/account/identities_controller.rb index 4cc011356..ff2cd2658 100644 --- a/app/controllers/account/identities_controller.rb +++ b/app/controllers/account/identities_controller.rb @@ -2,7 +2,7 @@ module Account class IdentitiesController < ApplicationController - include LastUpdateFromMernis + include UpdateableFromMernis before_action :set_user before_action :set_identity, only: %i[edit update destroy] diff --git a/app/controllers/user/omniauth_callbacks_controller.rb b/app/controllers/account/omniauth_callbacks_controller.rb similarity index 97% rename from app/controllers/user/omniauth_callbacks_controller.rb rename to app/controllers/account/omniauth_callbacks_controller.rb index 94ae33f34..b6ba88702 100644 --- a/app/controllers/user/omniauth_callbacks_controller.rb +++ b/app/controllers/account/omniauth_callbacks_controller.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -class User +module Account class OmniauthCallbacksController < Devise::OmniauthCallbacksController # You should configure your model like this: # devise :omniauthable, omniauth_providers: [:twitter] diff --git a/app/controllers/user/passwords_controller.rb b/app/controllers/account/passwords_controller.rb similarity index 97% rename from app/controllers/user/passwords_controller.rb rename to app/controllers/account/passwords_controller.rb index d0b526b3b..f2c1d9e71 100644 --- a/app/controllers/user/passwords_controller.rb +++ b/app/controllers/account/passwords_controller.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -class User +module Account class PasswordsController < Devise::PasswordsController layout 'guest' diff --git a/app/controllers/account/profile_controller.rb b/app/controllers/account/profile_controller.rb deleted file mode 100644 index e4b09e739..000000000 --- a/app/controllers/account/profile_controller.rb +++ /dev/null @@ -1,30 +0,0 @@ -# frozen_string_literal: true - -module Account - class ProfileController < ApplicationController - before_action :purge_avatar, only: :update - - def edit; end - - def update - if current_user.update_without_password(profile_params) - redirect_to user_profile_path(current_user), notice: t('.success') - else - render(:edit) - end - end - - private - - def purge_avatar - current_user.avatar.purge - end - - def profile_params - params.require(:user).permit( - :avatar, :phone_number, :extension_number, :website, :twitter, :linkedin, :skype, :orcid, :public_photo, - :public_studies - ) - end - end -end diff --git a/app/controllers/account/profile_settings_controller.rb b/app/controllers/account/profile_settings_controller.rb new file mode 100644 index 000000000..3781b6ff6 --- /dev/null +++ b/app/controllers/account/profile_settings_controller.rb @@ -0,0 +1,30 @@ +# frozen_string_literal: true + +module Account + class ProfileSettingsController < ApplicationController + # before_action :purge_avatar, only: :update + + def edit; end + + def update + if current_user.update_without_password(profile_params) + redirect_to profile_path, notice: t('.success') + else + render(:edit) + end + end + + private + + # def purge_avatar + # current_user.avatar.purge + # end + + def profile_params + params.require(:user).permit( + :avatar, :country, :phone_number, :extension_number, :website, :twitter, :linkedin, :skype, :orcid, + :public_photo, :public_studies + ) + end + end +end diff --git a/app/controllers/user/registrations_controller.rb b/app/controllers/account/registrations_controller.rb similarity index 98% rename from app/controllers/user/registrations_controller.rb rename to app/controllers/account/registrations_controller.rb index 245d617d0..5783508ea 100644 --- a/app/controllers/user/registrations_controller.rb +++ b/app/controllers/account/registrations_controller.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -class User +module Account class RegistrationsController < Devise::RegistrationsController layout 'guest', except: %i[edit update] @@ -65,6 +65,8 @@ def update # super(resource) # end + private + def update_password_change_time current_user.update!(password_changed_at: Time.zone.now) end diff --git a/app/controllers/user/sessions_controller.rb b/app/controllers/account/sessions_controller.rb similarity index 84% rename from app/controllers/user/sessions_controller.rb rename to app/controllers/account/sessions_controller.rb index e8270039d..2345fce48 100644 --- a/app/controllers/user/sessions_controller.rb +++ b/app/controllers/account/sessions_controller.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -class User +module Account class SessionsController < Devise::SessionsController layout 'guest' # before_action :configure_sign_in_params, only: [:create] @@ -20,7 +20,11 @@ class SessionsController < Devise::SessionsController # super # end - # protected + protected + + def after_sign_out_path_for(_resource_or_scope) + login_path + end # If you have extra params to permit, append them to the sanitizer. # def configure_sign_in_params diff --git a/app/controllers/user/unlocks_controller.rb b/app/controllers/account/unlocks_controller.rb similarity index 97% rename from app/controllers/user/unlocks_controller.rb rename to app/controllers/account/unlocks_controller.rb index 93610b8c0..6f46d0325 100644 --- a/app/controllers/user/unlocks_controller.rb +++ b/app/controllers/account/unlocks_controller.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -class User +module Account class UnlocksController < Devise::UnlocksController # GET /resource/unlock/new # def new diff --git a/app/controllers/admin/administrative_functions_controller.rb b/app/controllers/admin/administrative_functions_controller.rb new file mode 100644 index 000000000..80344afeb --- /dev/null +++ b/app/controllers/admin/administrative_functions_controller.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +module Admin + class AdministrativeFunctionsController < ApplicationController + include ReferenceResource + + private + + def secure_params + params.require(:administrative_function).permit(:name, :code) + end + end +end diff --git a/app/controllers/admin/cities_controller.rb b/app/controllers/admin/cities_controller.rb index 1c678f794..f3f039632 100644 --- a/app/controllers/admin/cities_controller.rb +++ b/app/controllers/admin/cities_controller.rb @@ -2,7 +2,7 @@ module Admin class CitiesController < ApplicationController - include PagyBackendWithHelpers + include SearchableModule before_action :set_country before_action :set_city, only: %i[show edit update destroy] diff --git a/app/controllers/admin/countries_controller.rb b/app/controllers/admin/countries_controller.rb index 49fdc8fb2..16eb980ce 100644 --- a/app/controllers/admin/countries_controller.rb +++ b/app/controllers/admin/countries_controller.rb @@ -2,7 +2,7 @@ module Admin class CountriesController < ApplicationController - include PagyBackendWithHelpers + include SearchableModule before_action :set_country, only: %i[show edit update destroy] diff --git a/app/controllers/calendar_management/calendar_event_types_controller.rb b/app/controllers/calendar_management/calendar_event_types_controller.rb index 199468ab3..46166c3ac 100644 --- a/app/controllers/calendar_management/calendar_event_types_controller.rb +++ b/app/controllers/calendar_management/calendar_event_types_controller.rb @@ -2,7 +2,7 @@ module CalendarManagement class CalendarEventTypesController < ApplicationController - include PagyBackendWithHelpers + include SearchableModule before_action :set_calendar_event_type, only: %i[edit update destroy] diff --git a/app/controllers/calendar_management/calendars_controller.rb b/app/controllers/calendar_management/calendars_controller.rb index e4c745957..777884551 100644 --- a/app/controllers/calendar_management/calendars_controller.rb +++ b/app/controllers/calendar_management/calendars_controller.rb @@ -2,7 +2,7 @@ module CalendarManagement class CalendarsController < ApplicationController - include PagyBackendWithHelpers + include SearchableModule before_action :set_calendar, only: %i[show edit update destroy] diff --git a/app/controllers/committee/agenda_types_controller.rb b/app/controllers/committee/agenda_types_controller.rb index 0fbdaa779..ef5304d83 100644 --- a/app/controllers/committee/agenda_types_controller.rb +++ b/app/controllers/committee/agenda_types_controller.rb @@ -2,7 +2,7 @@ module Committee class AgendaTypesController < ApplicationController - include PagyBackendWithHelpers + include SearchableModule before_action :set_agenda_type, only: %i[edit update destroy] diff --git a/app/controllers/committee/agendas_controller.rb b/app/controllers/committee/agendas_controller.rb index f948015d9..ec70cbf27 100644 --- a/app/controllers/committee/agendas_controller.rb +++ b/app/controllers/committee/agendas_controller.rb @@ -2,7 +2,7 @@ module Committee class AgendasController < ApplicationController - include PagyBackendWithHelpers + include SearchableModule before_action :set_committee before_action :set_agenda, only: %i[edit update destroy] diff --git a/app/controllers/committee/dashboard_controller.rb b/app/controllers/committee/dashboard_controller.rb index 34dcb6137..99108e29f 100644 --- a/app/controllers/committee/dashboard_controller.rb +++ b/app/controllers/committee/dashboard_controller.rb @@ -2,7 +2,7 @@ module Committee class DashboardController < ApplicationController - include PagyBackendWithHelpers + include SearchableModule def index @committees = pagy_by_search( diff --git a/app/controllers/concerns/reference_resource.rb b/app/controllers/concerns/reference_resource.rb index 5a82a7ecb..cc98b4764 100644 --- a/app/controllers/concerns/reference_resource.rb +++ b/app/controllers/concerns/reference_resource.rb @@ -2,7 +2,7 @@ module ReferenceResource extend ActiveSupport::Concern - include PagyBackendWithHelpers + include SearchableModule # rubocop:disable Metrics/BlockLength # rubocop:disable Rails/LexicallyScopedActionFilter diff --git a/app/controllers/concerns/pagy_backend_with_helpers.rb b/app/controllers/concerns/searchable_module.rb similarity index 88% rename from app/controllers/concerns/pagy_backend_with_helpers.rb rename to app/controllers/concerns/searchable_module.rb index 6607bb398..9ffecc8ff 100644 --- a/app/controllers/concerns/pagy_backend_with_helpers.rb +++ b/app/controllers/concerns/searchable_module.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -module PagyBackendWithHelpers +module SearchableModule extend ActiveSupport::Concern include Pagy::Backend diff --git a/app/controllers/concerns/last_update_from_mernis.rb b/app/controllers/concerns/updateable_from_mernis.rb similarity index 91% rename from app/controllers/concerns/last_update_from_mernis.rb rename to app/controllers/concerns/updateable_from_mernis.rb index 54c53d70b..726abcc8e 100644 --- a/app/controllers/concerns/last_update_from_mernis.rb +++ b/app/controllers/concerns/updateable_from_mernis.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -module LastUpdateFromMernis +module UpdateableFromMernis extend ActiveSupport::Concern def elapsed_time(resource) diff --git a/app/controllers/course_management/available_courses_controller.rb b/app/controllers/course_management/available_courses_controller.rb index 974a1251d..dcc565eff 100644 --- a/app/controllers/course_management/available_courses_controller.rb +++ b/app/controllers/course_management/available_courses_controller.rb @@ -2,7 +2,7 @@ module CourseManagement class AvailableCoursesController < ApplicationController - include PagyBackendWithHelpers + include SearchableModule before_action :set_available_course, only: %i[show edit update destroy] diff --git a/app/controllers/course_management/course_group_types_controller.rb b/app/controllers/course_management/course_group_types_controller.rb index ca8176819..cd0c3bb17 100644 --- a/app/controllers/course_management/course_group_types_controller.rb +++ b/app/controllers/course_management/course_group_types_controller.rb @@ -2,7 +2,7 @@ module CourseManagement class CourseGroupTypesController < ApplicationController - include PagyBackendWithHelpers + include SearchableModule before_action :set_course_group_type, only: %i[edit update destroy] diff --git a/app/controllers/course_management/course_types_controller.rb b/app/controllers/course_management/course_types_controller.rb index feec4ba63..eb78a1b8e 100644 --- a/app/controllers/course_management/course_types_controller.rb +++ b/app/controllers/course_management/course_types_controller.rb @@ -2,7 +2,7 @@ module CourseManagement class CourseTypesController < ApplicationController - include PagyBackendWithHelpers + include SearchableModule before_action :set_course_type, only: %i[edit update destroy] diff --git a/app/controllers/course_management/courses_controller.rb b/app/controllers/course_management/courses_controller.rb index 6b7119353..839084d02 100644 --- a/app/controllers/course_management/courses_controller.rb +++ b/app/controllers/course_management/courses_controller.rb @@ -2,7 +2,7 @@ module CourseManagement class CoursesController < ApplicationController - include PagyBackendWithHelpers + include SearchableModule before_action :set_course, only: %i[show edit update destroy] diff --git a/app/controllers/course_management/curriculums_controller.rb b/app/controllers/course_management/curriculums_controller.rb index 4553a6c94..fa6042c36 100644 --- a/app/controllers/course_management/curriculums_controller.rb +++ b/app/controllers/course_management/curriculums_controller.rb @@ -2,7 +2,8 @@ module CourseManagement class CurriculumsController < ApplicationController - include PagyBackendWithHelpers + include SearchableModule + before_action :set_curriculum, only: %i[show edit update destroy openable_courses] def index diff --git a/app/controllers/first_registration/prospective_students_controller.rb b/app/controllers/first_registration/prospective_students_controller.rb index d6b3aa2d4..9cb0b920d 100644 --- a/app/controllers/first_registration/prospective_students_controller.rb +++ b/app/controllers/first_registration/prospective_students_controller.rb @@ -2,7 +2,7 @@ module FirstRegistration class ProspectiveStudentsController < ApplicationController - include PagyBackendWithHelpers + include SearchableModule before_action :set_prospective_student, only: %i[show register] before_action :can_register?, only: :register diff --git a/app/controllers/first_registration/registration_documents_controller.rb b/app/controllers/first_registration/registration_documents_controller.rb index 2dd659032..18ea656b8 100644 --- a/app/controllers/first_registration/registration_documents_controller.rb +++ b/app/controllers/first_registration/registration_documents_controller.rb @@ -2,7 +2,7 @@ module FirstRegistration class RegistrationDocumentsController < ApplicationController - include PagyBackendWithHelpers + include SearchableModule before_action :set_registration_document, only: %i[edit update destroy] diff --git a/app/controllers/public_profile_controller.rb b/app/controllers/public_profile_controller.rb index 356e9ecf7..b7336e931 100644 --- a/app/controllers/public_profile_controller.rb +++ b/app/controllers/public_profile_controller.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true class PublicProfileController < ApplicationController - include PagyBackendWithHelpers + include SearchableModule skip_before_action :authenticate_user! before_action :set_user, only: %i[show vcard] diff --git a/app/controllers/references/academic_terms_controller.rb b/app/controllers/references/academic_terms_controller.rb index be7325f1f..7d6116247 100644 --- a/app/controllers/references/academic_terms_controller.rb +++ b/app/controllers/references/academic_terms_controller.rb @@ -2,7 +2,7 @@ module References class AcademicTermsController < ApplicationController - include PagyBackendWithHelpers + include SearchableModule before_action :set_academic_term, only: %i[edit update destroy] diff --git a/app/controllers/units_controller.rb b/app/controllers/units_controller.rb index cce3d70aa..7e58b8d64 100644 --- a/app/controllers/units_controller.rb +++ b/app/controllers/units_controller.rb @@ -1,7 +1,8 @@ # frozen_string_literal: true class UnitsController < ApplicationController - include PagyBackendWithHelpers + include SearchableModule + before_action :set_unit, only: %i[edit update destroy show courses programs curriculums employees] def index diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 67763ccb9..c907a7d90 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -1,10 +1,10 @@ # frozen_string_literal: true class UsersController < ApplicationController - include PagyBackendWithHelpers - include LastUpdateFromMernis + include SearchableModule + include UpdateableFromMernis - before_action :set_user, except: %i[index new create] + before_action :set_user, except: :index before_action :set_address_elapsed_time, only: %i[save_address_from_mernis] before_action :set_identity_elapsed_time, only: %i[save_identity_from_mernis] before_action :nullify_slug, only: :update @@ -21,15 +21,6 @@ def show @positions = @user.positions.includes(:administrative_function, :duty) end - def new - @user = User.new - end - - def create - @user = User.new(user_params) - @user.save ? redirect_with('.success') : render(:new) - end - def edit; end def update diff --git a/app/lib/nokul/version.rb b/app/lib/nokul/version.rb index e7839ee68..0abf7c9b7 100644 --- a/app/lib/nokul/version.rb +++ b/app/lib/nokul/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module Nokul - VERSION = '0.5.3' + VERSION = '0.5.4' end diff --git a/app/models/academic_term.rb b/app/models/academic_term.rb index f86197d04..84cac2806 100644 --- a/app/models/academic_term.rb +++ b/app/models/academic_term.rb @@ -4,7 +4,7 @@ class AcademicTerm < ApplicationRecord include EnumForTerm # callbacks - after_save -> { AcademicTerm.where.not(id: id).update(active: false) }, if: :active? + after_save :deactivate_academic_terms # relations has_many :calendars, dependent: :nullify @@ -19,4 +19,10 @@ class AcademicTerm < ApplicationRecord # scopes scope :active, -> { where(active: true) } + + private + + def deactivate_academic_terms + AcademicTerm.where.not(id: id).update(active: false) if active? + end end diff --git a/app/models/address.rb b/app/models/address.rb index 778ca8bb3..66c3edba6 100644 --- a/app/models/address.rb +++ b/app/models/address.rb @@ -3,6 +3,12 @@ class Address < ApplicationRecord self.inheritance_column = nil + # virtual attributes + attr_accessor :country + + # callbacks + before_save :capitalize_attributes + # enums enum type: { formal: 1, informal: 2 } @@ -12,10 +18,16 @@ class Address < ApplicationRecord # validations validates :full_address, presence: true, length: { maximum: 255 } - validates :phone_number, length: { maximum: 255 } + validates :phone_number, length: { maximum: 255 }, + allow_nil: true, + allow_blank: true, + telephone_number: { country: proc { |record| record.country }, types: [:mobile] } validates :type, uniqueness: { scope: :user }, inclusion: { in: types.keys } validates_with AddressAndIdentityValidator, on: :create - # callbacks - before_save { self.full_address = full_address.capitalize_turkish } + private + + def capitalize_attributes + self.full_address = full_address.capitalize_turkish + end end diff --git a/app/models/administrative_function.rb b/app/models/administrative_function.rb index aa964424a..89a8268e9 100644 --- a/app/models/administrative_function.rb +++ b/app/models/administrative_function.rb @@ -1,14 +1,11 @@ # frozen_string_literal: true class AdministrativeFunction < ApplicationRecord + include ReferenceCallbacks + include ReferenceSearch + include ReferenceValidations + # relations has_many :positions, dependent: :destroy has_many :duties, through: :positions - - # validations - validates :code, uniqueness: true, numericality: { only_integer: true, greater_than: 0 } - validates :name, presence: true, uniqueness: true, length: { maximum: 255 } - - # callbacks - before_validation { self.name = name.capitalize_turkish if name } end diff --git a/app/models/agenda_type.rb b/app/models/agenda_type.rb index 1f5e5ac7e..d960553a1 100644 --- a/app/models/agenda_type.rb +++ b/app/models/agenda_type.rb @@ -5,12 +5,18 @@ class AgendaType < ApplicationRecord include PgSearch pg_search_scope(:search, against: :name, using: { tsearch: { prefix: true } }) + # callbacks + before_save :capitalize_attributes + # relations has_many :agendas, dependent: :nullify # validations validates :name, presence: true, length: { maximum: 255 } - # callbacks - before_save { self.name = name.capitalize_turkish } + private + + def capitalize_attributes + self.name = name.capitalize_turkish + end end diff --git a/app/models/assessment_method.rb b/app/models/assessment_method.rb index 36e40365c..3f6793e37 100644 --- a/app/models/assessment_method.rb +++ b/app/models/assessment_method.rb @@ -3,7 +3,9 @@ class AssessmentMethod < ApplicationRecord # search include ReferenceSearch - include ReferenceCallbacks + + # callbacks + before_validation :capitalize_attributes # relations has_many :course_assessment_methods, dependent: :destroy @@ -12,4 +14,10 @@ class AssessmentMethod < ApplicationRecord # validations validates :name, presence: true, uniqueness: true, length: { maximum: 255 } + + private + + def capitalize_attributes + self.name = name.capitalize_turkish if name + end end diff --git a/app/models/available_course.rb b/app/models/available_course.rb index 609dabdb9..daca6b956 100644 --- a/app/models/available_course.rb +++ b/app/models/available_course.rb @@ -14,6 +14,9 @@ class AvailableCourse < ApplicationRecord # dynamic_search search_keys :unit_id, :curriculum_id, :academic_term_id + # validations + before_validation :assign_academic_term, on: :create + # relations belongs_to :academic_term belongs_to :coordinator, class_name: 'Employee' @@ -27,13 +30,14 @@ class AvailableCourse < ApplicationRecord validates :assessments_approved, inclusion: { in: [true, false] } validates :course, uniqueness: { scope: %i[academic_term curriculum] } - # callbacks - before_validation(on: :create) do - self.academic_term = AcademicTerm.active.last - end - # delegates delegate :code, :name, :theoric, :practice, :laboratory, :credit, :program_type, to: :course delegate :name, to: :curriculum, prefix: true delegate :name, to: :unit, prefix: true + + private + + def assign_academic_term + self.academic_term = AcademicTerm.active.last + end end diff --git a/app/models/city.rb b/app/models/city.rb index eaaef40d6..43dec1cb3 100644 --- a/app/models/city.rb +++ b/app/models/city.rb @@ -1,8 +1,6 @@ # frozen_string_literal: true class City < ApplicationRecord - # alpha_2_code field follows the ISO3166-2 standard - # search include PgSearch pg_search_scope( @@ -11,6 +9,9 @@ class City < ApplicationRecord using: { tsearch: { prefix: true } } ) + # callbacks + before_validation :capitalize_attributes + # relations belongs_to :country has_many :districts, dependent: :destroy @@ -22,7 +23,7 @@ class City < ApplicationRecord validates :name, presence: true, uniqueness: { scope: %i[country_id] }, length: { maximum: 255 } # callbacks - before_validation do + def capitalize_attributes self.alpha_2_code = alpha_2_code.upcase(:turkic) if alpha_2_code self.name = name.capitalize_turkish if name end diff --git a/app/models/committee_decision.rb b/app/models/committee_decision.rb index 70b93aa02..330262c6a 100644 --- a/app/models/committee_decision.rb +++ b/app/models/committee_decision.rb @@ -1,6 +1,10 @@ # frozen_string_literal: true class CommitteeDecision < ApplicationRecord + # callbacks + before_validation :assign_year_and_decision_no, on: :create + after_create :change_status_to_decided + # relations belongs_to :meeting_agenda has_one :agenda, through: :meeting_agenda @@ -15,10 +19,6 @@ class CommitteeDecision < ApplicationRecord less_than_or_equal_to: 2050 } - # callbacks - before_validation :set_year_and_decision_no, on: :create - after_create { agenda.update(status: :decided) } - # delegates delegate :meeting_no, :meeting_date, :year, :unit, to: :meeting_agenda, prefix: true @@ -28,8 +28,12 @@ def count_of_decisions_by_year(year) private - def set_year_and_decision_no + def assign_year_and_decision_no self.year = meeting_agenda_year self.decision_no = "#{year}/#{count_of_decisions_by_year(year) + 1}" end + + def change_status_to_decided + agenda.update(status: :decided) + end end diff --git a/app/models/committee_meeting.rb b/app/models/committee_meeting.rb index 5c3c56b54..b9b6f228c 100644 --- a/app/models/committee_meeting.rb +++ b/app/models/committee_meeting.rb @@ -1,6 +1,9 @@ # frozen_string_literal: true class CommitteeMeeting < ApplicationRecord + # callbacks + before_validation :assign_year + # relations belongs_to :unit has_many :meeting_agendas, dependent: :destroy @@ -18,6 +21,9 @@ class CommitteeMeeting < ApplicationRecord less_than_or_equal_to: 2050 } - # callbacks - before_validation { self.year = meeting_date.try(:year) } + private + + def assign_year + self.year = meeting_date.try(:year) + end end diff --git a/app/models/concerns/reference_callbacks.rb b/app/models/concerns/reference_callbacks.rb index 8ad84bed0..5963a4bff 100644 --- a/app/models/concerns/reference_callbacks.rb +++ b/app/models/concerns/reference_callbacks.rb @@ -4,6 +4,12 @@ module ReferenceCallbacks extend ActiveSupport::Concern included do - before_validation { self.name = name.capitalize_turkish if name } + before_validation :capitalize_attributes + + private + + def capitalize_attributes + self.name = name.capitalize_turkish if name + end end end diff --git a/app/models/concerns/reference_validations.rb b/app/models/concerns/reference_validations.rb index 5feab986a..7d861badc 100644 --- a/app/models/concerns/reference_validations.rb +++ b/app/models/concerns/reference_validations.rb @@ -4,7 +4,7 @@ module ReferenceValidations extend ActiveSupport::Concern included do - validates :name, presence: true, uniqueness: true, length: { maximum: 255 } validates :code, uniqueness: true, numericality: { only_integer: true, greater_than_or_equal_to: 0 } + validates :name, presence: true, uniqueness: true, length: { maximum: 255 } end end diff --git a/app/models/country.rb b/app/models/country.rb index bfb8fe6b1..7281bf6b5 100644 --- a/app/models/country.rb +++ b/app/models/country.rb @@ -1,9 +1,6 @@ # frozen_string_literal: true class Country < ApplicationRecord - # alpha_2_code, alpha_3_code and and numeric code fields follow the ISO3166-1 standard. - # mernis_code obtained from YOKSIS - # search include PgSearch pg_search_scope( @@ -12,6 +9,9 @@ class Country < ApplicationRecord using: { tsearch: { prefix: true } } ) + # callbacks + before_validation :capitalize_attributes + # relations has_many :cities, dependent: :destroy has_many :districts, through: :cities @@ -28,8 +28,9 @@ class Country < ApplicationRecord numericality: { only_integer: true, greater_than: 0 } validates :yoksis_code, allow_nil: true, numericality: { only_integer: true, greater_than_or_equal_to: 1 } - # callbacks - before_validation do + private + + def capitalize_attributes self.name = name.capitalize_turkish if name self.alpha_2_code = alpha_2_code.upcase(:turkic) if alpha_2_code self.alpha_3_code = alpha_3_code.upcase(:turkic) if alpha_3_code diff --git a/app/models/course.rb b/app/models/course.rb index b4cf2c881..9c16905db 100644 --- a/app/models/course.rb +++ b/app/models/course.rb @@ -14,6 +14,10 @@ class Course < ApplicationRecord # dynamic_search search_keys :course_type_id, :program_type, :language_id, :unit_id, :status + # callbacks + before_validation :capitalize_attributes + before_validation :assign_credit + # enumerations enum program_type: { associate: 0, undergraduate: 1, master: 2, doctoral: 3 } enum status: { passive: 0, active: 1 } @@ -33,17 +37,21 @@ class Course < ApplicationRecord validates :status, inclusion: { in: statuses.keys } validates :theoric, numericality: { greater_than_or_equal_to: 0 } - # callbacks - before_validation do - self.name = name.capitalize_turkish if name - self.credit = calculate_credit + def name_with_code + "#{code} - #{name}" end def calculate_credit theoric.to_f + ((practice.to_f + laboratory.to_f) / 2) end - def name_with_code - "#{code} - #{name}" + private + + def capitalize_attributes + self.name = name.capitalize_turkish if name + end + + def assign_credit + self.credit = theoric.to_f + ((practice.to_f + laboratory.to_f) / 2) end end diff --git a/app/models/course_group.rb b/app/models/course_group.rb index 8a017ba24..0ca0d9ea1 100644 --- a/app/models/course_group.rb +++ b/app/models/course_group.rb @@ -14,6 +14,9 @@ class CourseGroup < ApplicationRecord # dynamic_search search_keys :unit_id, :course_group_type_id + # callbacks + before_validation :capitalize_attributes + # relations belongs_to :course_group_type belongs_to :unit @@ -30,6 +33,9 @@ class CourseGroup < ApplicationRecord less_than_or_equal_to: 300 } - # callbacks - before_validation { self.name = name.capitalize_turkish if name } + private + + def capitalize_attributes + self.name = name.capitalize_turkish if name + end end diff --git a/app/models/course_group_type.rb b/app/models/course_group_type.rb index 56e5a85ac..3cb36462b 100644 --- a/app/models/course_group_type.rb +++ b/app/models/course_group_type.rb @@ -5,6 +5,9 @@ class CourseGroupType < ApplicationRecord include PgSearch pg_search_scope(:search, against: :name, using: { tsearch: { prefix: true } }) + # callbacks + before_validation :capitalize_attributes + # relations has_many :course_groups, dependent: :nullify @@ -12,5 +15,7 @@ class CourseGroupType < ApplicationRecord validates :name, presence: true, uniqueness: true, length: { maximum: 255 } # callbacks - before_validation { self.name = name.capitalize_turkish if name } + def capitalize_attributes + self.name = name.capitalize_turkish if name + end end diff --git a/app/models/curriculum_course.rb b/app/models/curriculum_course.rb index 08d21dc0a..f8359ad7a 100644 --- a/app/models/curriculum_course.rb +++ b/app/models/curriculum_course.rb @@ -3,6 +3,9 @@ class CurriculumCourse < ApplicationRecord self.inheritance_column = :_type_disabled + # callbacks + before_validation :assign_type + # enums enum type: { compulsory: 0, elective: 1 } @@ -20,7 +23,7 @@ class CurriculumCourse < ApplicationRecord delegate :code, :credit, :course_type, :name, to: :course # callbacks - before_validation do + def assign_type self.type = curriculum_course_group.nil? ? :compulsory : :elective end end diff --git a/app/models/district.rb b/app/models/district.rb index f213b19c2..c2187fc3a 100644 --- a/app/models/district.rb +++ b/app/models/district.rb @@ -1,8 +1,6 @@ # frozen_string_literal: true class District < ApplicationRecord - # mernis_code field obtained from MERNIS - # search include PgSearch pg_search_scope( @@ -11,6 +9,9 @@ class District < ApplicationRecord using: { tsearch: { prefix: true } } ) + # callbacks + before_validation :capitalize_attributes + # relations belongs_to :city has_many :addresses, dependent: :nullify @@ -22,5 +23,7 @@ class District < ApplicationRecord validates :active, inclusion: { in: [true, false] } # callbacks - before_validation { self.name = name.capitalize_turkish if name } + def capitalize_attributes + self.name = name.capitalize_turkish if name + end end diff --git a/app/models/evaluation_type.rb b/app/models/evaluation_type.rb index d5be9ac71..664994e91 100644 --- a/app/models/evaluation_type.rb +++ b/app/models/evaluation_type.rb @@ -3,7 +3,9 @@ class EvaluationType < ApplicationRecord # search include ReferenceSearch - include ReferenceCallbacks + + # callbacks + before_validation :capitalize_attributes # relations has_many :course_evaluation_types, dependent: :destroy @@ -11,4 +13,10 @@ class EvaluationType < ApplicationRecord # validations validates :name, presence: true, uniqueness: true, length: { maximum: 255 } + + private + + def capitalize_attributes + self.name = name.capitalize_turkish if name + end end diff --git a/app/models/high_school_type.rb b/app/models/high_school_type.rb index 2e5622e8b..3ba3b61b5 100644 --- a/app/models/high_school_type.rb +++ b/app/models/high_school_type.rb @@ -1,9 +1,9 @@ # frozen_string_literal: true class HighSchoolType < ApplicationRecord - include ReferenceValidations include ReferenceCallbacks include ReferenceSearch + include ReferenceValidations # relations has_many :prospective_students, dependent: :nullify diff --git a/app/models/identity.rb b/app/models/identity.rb index 713df6e71..37f2cc69d 100644 --- a/app/models/identity.rb +++ b/app/models/identity.rb @@ -3,6 +3,9 @@ class Identity < ApplicationRecord self.inheritance_column = nil + # callbacks + before_save :capitalize_attributes + # enums enum type: { formal: 1, informal: 2 } enum gender: { male: 1, female: 2, other: 3 } @@ -31,7 +34,8 @@ class Identity < ApplicationRecord scope :user_identity, -> { formal.find_by(student_id: nil) } # callbacks - before_save do + # rubocop:disable Metrics/AbcSize + def capitalize_attributes self.fathers_name = fathers_name.capitalize_turkish if fathers_name self.first_name = first_name.capitalize_turkish self.last_name = last_name.upcase(:turkic) @@ -39,4 +43,5 @@ class Identity < ApplicationRecord self.place_of_birth = place_of_birth.capitalize_turkish if place_of_birth self.type = 'informal' if type.blank? end + # rubocop:enable Metrics/AbcSize end diff --git a/app/models/language.rb b/app/models/language.rb index 00a3af52e..49941f215 100644 --- a/app/models/language.rb +++ b/app/models/language.rb @@ -4,6 +4,9 @@ class Language < ApplicationRecord # search include ReferenceSearch + # callbacks + before_validation :capitalize_attributes + # relations has_many :courses, dependent: :nullify has_many :prospective_students, dependent: :nullify @@ -12,8 +15,9 @@ class Language < ApplicationRecord validates :name, presence: true, uniqueness: true, length: { maximum: 255 } validates :iso, presence: true, uniqueness: true, length: { maximum: 255 } - # callbacks - before_validation do + private + + def capitalize_attributes self.name = name.capitalize_turkish if name self.iso = iso.upcase(:turkic) if iso end diff --git a/app/models/prospective_student.rb b/app/models/prospective_student.rb index f7a0850e7..9d2c4e00d 100644 --- a/app/models/prospective_student.rb +++ b/app/models/prospective_student.rb @@ -13,6 +13,9 @@ class ProspectiveStudent < ApplicationRecord search_keys :meb_status, :military_status, :obs_status, :unit_id, :student_entrance_type_id, :registered + # callbacks + before_create :capitalize_attributes + # enumerations enum additional_score: { handicapped: 1 } enum gender: { male: 1, female: 2 } @@ -64,17 +67,6 @@ class ProspectiveStudent < ApplicationRecord validates :state_of_education, allow_nil: true, numericality: { only_integer: true, greater_than_or_equal_to: 0 } validates :top_student, inclusion: { in: [true, false] } - # callbacks - before_create do - self.first_name = first_name.capitalize_turkish - self.last_name = last_name.upcase(:turkic) - self.fathers_name = fathers_name.capitalize_turkish if fathers_name - self.mothers_name = mothers_name.capitalize_turkish if mothers_name - self.place_of_birth = place_of_birth.capitalize_turkish if place_of_birth - self.registration_city = registration_city.capitalize_turkish if registration_city - self.registration_district = registration_district.capitalize_turkish if registration_district - end - # custom methods def can_permanently_register? military_status && obs_status && meb_status @@ -83,4 +75,18 @@ def can_permanently_register? def can_temporarily_register? military_status end + + private + + # rubocop:disable Metrics/AbcSize + def capitalize_attributes + self.first_name = first_name.capitalize_turkish + self.last_name = last_name.upcase(:turkic) + self.fathers_name = fathers_name.capitalize_turkish if fathers_name + self.mothers_name = mothers_name.capitalize_turkish if mothers_name + self.place_of_birth = place_of_birth.capitalize_turkish if place_of_birth + self.registration_city = registration_city.capitalize_turkish if registration_city + self.registration_district = registration_district.capitalize_turkish if registration_district + end + # rubocop:enable Metrics/AbcSize end diff --git a/app/models/student.rb b/app/models/student.rb index 06f181e93..833f58d50 100644 --- a/app/models/student.rb +++ b/app/models/student.rb @@ -19,6 +19,8 @@ class Student < ApplicationRecord # background jobs after_create_commit :build_identity_information, if: proc { identity.nil? } + private + def build_identity_information Kps::IdentitySaveJob.perform_later(user, id) end diff --git a/app/models/student_disability_type.rb b/app/models/student_disability_type.rb index 050170fc4..e80cbe22c 100644 --- a/app/models/student_disability_type.rb +++ b/app/models/student_disability_type.rb @@ -1,9 +1,9 @@ # frozen_string_literal: true class StudentDisabilityType < ApplicationRecord - include ReferenceValidations include ReferenceCallbacks include ReferenceSearch + include ReferenceValidations # relations has_many :prospective_students, dependent: :nullify diff --git a/app/models/student_drop_out_type.rb b/app/models/student_drop_out_type.rb index 05a5ba875..a6e70b103 100644 --- a/app/models/student_drop_out_type.rb +++ b/app/models/student_drop_out_type.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true class StudentDropOutType < ApplicationRecord - include ReferenceValidations include ReferenceCallbacks include ReferenceSearch + include ReferenceValidations end diff --git a/app/models/student_education_level.rb b/app/models/student_education_level.rb index dcba427f4..2581492c6 100644 --- a/app/models/student_education_level.rb +++ b/app/models/student_education_level.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true class StudentEducationLevel < ApplicationRecord - include ReferenceValidations include ReferenceCallbacks include ReferenceSearch + include ReferenceValidations end diff --git a/app/models/student_entrance_point_type.rb b/app/models/student_entrance_point_type.rb index 158b99997..c08b11384 100644 --- a/app/models/student_entrance_point_type.rb +++ b/app/models/student_entrance_point_type.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true class StudentEntrancePointType < ApplicationRecord - include ReferenceValidations include ReferenceCallbacks include ReferenceSearch + include ReferenceValidations end diff --git a/app/models/student_entrance_type.rb b/app/models/student_entrance_type.rb index 89ba06f11..707074f67 100644 --- a/app/models/student_entrance_type.rb +++ b/app/models/student_entrance_type.rb @@ -1,9 +1,9 @@ # frozen_string_literal: true class StudentEntranceType < ApplicationRecord - include ReferenceValidations include ReferenceCallbacks include ReferenceSearch + include ReferenceValidations # relations has_many :prospective_students, dependent: :nullify diff --git a/app/models/student_grade.rb b/app/models/student_grade.rb index e0c9c3d89..c65dc43f6 100644 --- a/app/models/student_grade.rb +++ b/app/models/student_grade.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true class StudentGrade < ApplicationRecord - include ReferenceValidations include ReferenceCallbacks include ReferenceSearch + include ReferenceValidations end diff --git a/app/models/student_grading_system.rb b/app/models/student_grading_system.rb index ef9420f33..894d02416 100644 --- a/app/models/student_grading_system.rb +++ b/app/models/student_grading_system.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true class StudentGradingSystem < ApplicationRecord - include ReferenceValidations include ReferenceCallbacks include ReferenceSearch + include ReferenceValidations end diff --git a/app/models/student_punishment_type.rb b/app/models/student_punishment_type.rb index 2a8239170..63bf27c6c 100644 --- a/app/models/student_punishment_type.rb +++ b/app/models/student_punishment_type.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true class StudentPunishmentType < ApplicationRecord - include ReferenceValidations include ReferenceCallbacks include ReferenceSearch + include ReferenceValidations end diff --git a/app/models/student_studentship_status.rb b/app/models/student_studentship_status.rb index fc8af3cc8..93cc096f7 100644 --- a/app/models/student_studentship_status.rb +++ b/app/models/student_studentship_status.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true class StudentStudentshipStatus < ApplicationRecord - include ReferenceValidations include ReferenceCallbacks include ReferenceSearch + include ReferenceValidations end diff --git a/app/models/unit_instruction_language.rb b/app/models/unit_instruction_language.rb index 0909ae8af..ecff0002e 100644 --- a/app/models/unit_instruction_language.rb +++ b/app/models/unit_instruction_language.rb @@ -1,9 +1,9 @@ # frozen_string_literal: true class UnitInstructionLanguage < ApplicationRecord - include ReferenceValidations include ReferenceCallbacks include ReferenceSearch + include ReferenceValidations # relations has_many :units, dependent: :nullify diff --git a/app/models/unit_instruction_type.rb b/app/models/unit_instruction_type.rb index 3596a279b..0cbbe9cfd 100644 --- a/app/models/unit_instruction_type.rb +++ b/app/models/unit_instruction_type.rb @@ -1,9 +1,9 @@ # frozen_string_literal: true class UnitInstructionType < ApplicationRecord - include ReferenceValidations include ReferenceCallbacks include ReferenceSearch + include ReferenceValidations # relations has_many :units, dependent: :nullify diff --git a/app/models/unit_status.rb b/app/models/unit_status.rb index be920f652..00a2f0fab 100644 --- a/app/models/unit_status.rb +++ b/app/models/unit_status.rb @@ -1,9 +1,9 @@ # frozen_string_literal: true class UnitStatus < ApplicationRecord - include ReferenceValidations include ReferenceCallbacks include ReferenceSearch + include ReferenceValidations # relations has_many :units, dependent: :nullify diff --git a/app/models/unit_type.rb b/app/models/unit_type.rb index 6a965e4e8..dd9f193ba 100644 --- a/app/models/unit_type.rb +++ b/app/models/unit_type.rb @@ -1,9 +1,9 @@ # frozen_string_literal: true class UnitType < ApplicationRecord - include ReferenceValidations include ReferenceCallbacks include ReferenceSearch + include ReferenceValidations # enums enum group: { diff --git a/app/models/university_type.rb b/app/models/university_type.rb index d52308ef7..73bef52da 100644 --- a/app/models/university_type.rb +++ b/app/models/university_type.rb @@ -1,9 +1,9 @@ # frozen_string_literal: true class UniversityType < ApplicationRecord - include ReferenceValidations include ReferenceCallbacks include ReferenceSearch + include ReferenceValidations # relations has_many :units, dependent: :nullify diff --git a/app/models/user.rb b/app/models/user.rb index a9136cdb6..5e376972c 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1,6 +1,9 @@ # frozen_string_literal: true class User < ApplicationRecord + # virtual attributes + attr_accessor :country + # search include PgSearch pg_search_scope( @@ -30,8 +33,19 @@ class User < ApplicationRecord # validations validates :email, presence: true, uniqueness: true, length: { maximum: 255 } + validates :extension_number, allow_blank: true, + allow_nil: true, + length: { maximum: 8 }, + numericality: { only_integer: true } validates :id_number, uniqueness: true, numericality: { only_integer: true }, length: { is: 11 } + validates :linkedin, allow_blank: true, length: { maximum: 50 } + validates :phone_number, length: { maximum: 255 }, + allow_blank: true, + telephone_number: { country: proc { |record| record.country }, types: [:fixed_line] } validates :preferred_language, inclusion: { in: I18n.available_locales.map(&:to_s) } + validates :skype, allow_blank: true, length: { maximum: 50 } + validates :twitter, allow_blank: true, length: { maximum: 50 } + validates :website, allow_blank: true, length: { maximum: 50 } validates_with EmailAddress::ActiveRecordValidator, field: :email validates_with ImageValidator, field: :avatar, if: proc { |a| a.avatar.attached? } @@ -39,25 +53,17 @@ class User < ApplicationRecord after_create_commit :build_address_information, if: proc { addresses.formal.empty? } after_create_commit :build_identity_information, if: proc { identities.formal.empty? } - def build_address_information - Kps::AddressSaveJob.perform_later(self) - end - - def build_identity_information - Kps::IdentitySaveJob.perform_later(self) - end - # store accessors store :profile_preferences, accessors: %i[ - phone_number extension_number - website - twitter linkedin - skype orcid + phone_number public_photo public_studies + skype + twitter + website ], coder: JSON # permalinks @@ -69,6 +75,11 @@ def permalink username if domain.eql?(Tenant.configuration.email.domain) end + # send devise e-mails through active job + def send_devise_notification(notification, *args) + devise_mailer.send(notification, self, *args).deliver_later + end + # custom methods def accounts (students + employees).flatten @@ -85,4 +96,14 @@ def self.with_most_articles def self.with_most_projects where.not(projects_count: 0).order('projects_count desc').limit(10) end + + private + + def build_address_information + Kps::AddressSaveJob.perform_later(self) + end + + def build_identity_information + Kps::IdentitySaveJob.perform_later(self) + end end diff --git a/app/views/account/addresses/_form.html.erb b/app/views/account/addresses/_form.html.erb index 67c8188a7..77d0d05c2 100644 --- a/app/views/account/addresses/_form.html.erb +++ b/app/views/account/addresses/_form.html.erb @@ -12,10 +12,18 @@ <%= f.error_notification %> <%= f.error_notification message: f.object.errors[:base].to_sentence if f.object.errors[:base].present? %> -
+
<%= f.association :district, collection: City.includes(:districts).order(:name), as: :grouped_select, group_method: :districts, group_label_method: :name %>
-
+
+ <%= f.input :country, + as: :select, + collection: Country.order(:name).pluck(:name, :alpha_2_code), + label_method: :first, + value_method: :second, + selected: 'TR' %> +
+
<%= f.input :phone_number, placeholder: '555-444-3322' %>
@@ -33,4 +41,3 @@
<%= render 'select2' %> -<%= render 'input_mask' %> diff --git a/app/views/account/addresses/_input_mask.erb b/app/views/account/addresses/_input_mask.erb deleted file mode 100644 index 56862146a..000000000 --- a/app/views/account/addresses/_input_mask.erb +++ /dev/null @@ -1,5 +0,0 @@ - diff --git a/app/views/devise/passwords/edit.html.erb b/app/views/account/passwords/edit.html.erb similarity index 57% rename from app/views/devise/passwords/edit.html.erb rename to app/views/account/passwords/edit.html.erb index 5e16baa3f..11bb8efcd 100644 --- a/app/views/devise/passwords/edit.html.erb +++ b/app/views/account/passwords/edit.html.erb @@ -1,30 +1,30 @@ -
-
-
-

<%= t('devise.common.reset_password') %>

+
+
+
+

<%= t('.reset_password') %>

<%= simple_form_for(resource, as: resource_name, url: password_path(resource_name), html: { method: :put }) do |f| %> <%= f.error_notification %> <%= f.input :reset_password_token, as: :hidden %> <%= f.full_error :reset_password_token %> -
-
- +
+
+ <%= fa_icon('lock') %>
<%= f.input :password, required: true, label: false, wrapper: false %>
-
-
- +
+
+ <%= fa_icon('lock') %>
<%= f.input :password_confirmation, required: true, label: false, wrapper: false %>
- <%= f.button :submit, t('.reset_my_password'), class: 'btn btn-block btn-primary' %> + <%= f.button :submit, t('.reset_password'), class: 'btn btn-block btn-primary' %> <% end %>
diff --git a/app/views/account/passwords/new.html.erb b/app/views/account/passwords/new.html.erb new file mode 100644 index 000000000..91ad4ea8f --- /dev/null +++ b/app/views/account/passwords/new.html.erb @@ -0,0 +1,29 @@ +
+
+
+

<%= t('.reset_password') %>

+

<%= t('.hint') %>

+ <%= simple_form_for(resource, as: resource_name, url: password_path(resource_name), html: { method: :post }) do |f| %> + <%= f.error_notification %> +
+
+ @ +
+ <%= f.input :email, required: true, autofocus: true, label: false, wrapper: false %> +
+ + <%= f.button :submit, t('.send_instructions'), class: 'btn btn-block btn-primary' %> + <% end %> +
+ +
+
diff --git a/app/views/account/profile/_input_mask.erb b/app/views/account/profile/_input_mask.erb deleted file mode 100644 index c42aabba2..000000000 --- a/app/views/account/profile/_input_mask.erb +++ /dev/null @@ -1,6 +0,0 @@ - diff --git a/app/views/account/profile/edit.html.erb b/app/views/account/profile_settings/edit.html.erb similarity index 78% rename from app/views/account/profile/edit.html.erb rename to app/views/account/profile_settings/edit.html.erb index a466c44a5..4cba31a42 100644 --- a/app/views/account/profile/edit.html.erb +++ b/app/views/account/profile_settings/edit.html.erb @@ -1,6 +1,6 @@
- <%= simple_form_for current_user, url: user_profile_path(current_user), method: :post do |f| %> + <%= simple_form_for current_user, url: profile_path, method: :patch do |f| %>
<%= t('.profile_settings') %> @@ -22,8 +22,25 @@
+
+ +
+
+ <%= fa_icon('globe') %> +
+ <%= f.input :country, + as: :select, + collection: Country.order(:name).pluck(:name, :alpha_2_code), + label_method: :first, + value_method: :second, + selected: 'TR', + wrapper: false, + label: false %> +
+
+
- +
<%= fa_icon('phone') %> @@ -32,8 +49,8 @@
-
- +
+
<%= fa_icon('phone-square') %> @@ -43,17 +60,17 @@
- +
- <%= fa_icon('globe') %> + <%= fa_icon('home') %>
<%= f.input :website, wrapper: false, label: false %>
- +
<%= fa_icon('twitter') %> @@ -63,7 +80,7 @@
- +
<%= fa_icon('linkedin') %> @@ -73,7 +90,7 @@
- +
<%= fa_icon('skype') %> @@ -83,7 +100,7 @@
- +
<%= fa_icon('graduation-cap') %> @@ -126,5 +143,3 @@ <% end %>
- -<%= render 'input_mask' %> diff --git a/app/views/devise/registrations/edit.html.erb b/app/views/account/registrations/edit.html.erb similarity index 64% rename from app/views/devise/registrations/edit.html.erb rename to app/views/account/registrations/edit.html.erb index 7b8af6744..7dd9564d6 100644 --- a/app/views/devise/registrations/edit.html.erb +++ b/app/views/account/registrations/edit.html.erb @@ -1,13 +1,13 @@ -
-
-
-
- <%= fa_icon 'password' %> +
+
+
+
+ <%= fa_icon 'key' %> <%= t('.account_settings') %>
-
+
<%= simple_form_for(resource, as: resource_name, url: registration_path(resource_name), html: { method: :put }) do |f| %> -
+
<%= f.error_notification %>
@@ -15,13 +15,16 @@ <%= f.input :email, autofocus: true %>
- <%= f.input :password, autocomplete: 'off', hint: t('.leave_blank'), required: false %> + <%= f.input :password, autocomplete: 'off', hint: t('.leave_blank'), required: false, placeholder: false %>
- <%= f.input :password_confirmation, required: false %> + <%= f.input :password_confirmation, required: false, placeholder: false %>
- <%= f.input :current_password, hint: t('.current_password'), required: true %> + <%= f.input :current_password, label: t('.current_password'), + hint: t('.current_password_hint'), + required: true, + placeholder: false %>
<%= f.button :submit, class: 'btn btn-outline-success btn-sm' %> diff --git a/app/views/account/registrations/new.html.erb b/app/views/account/registrations/new.html.erb new file mode 100644 index 000000000..823c8b51c --- /dev/null +++ b/app/views/account/registrations/new.html.erb @@ -0,0 +1,58 @@ +
+
+
+

<%= t('.register') %>

+

<%= t('.create_your_account') %>

+ <%= simple_form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f| %> + <%= f.error_notification %> +
+
+ + <%= fa_icon('user') %> + +
+ <%= f.input :id_number, required: true, label: false, wrapper: false %> +
+ +
+
+ + <%= fa_icon('at') %> + +
+ <%= f.input :email, required: true, autofocus: true, label: false, wrapper: false %> +
+ +
+
+ + <%= fa_icon('lock') %> + +
+ <%= f.input :password, required: true, label: false, wrapper: false %> +
+ +
+
+ + <%= fa_icon('lock') %> + +
+ <%= f.input :password_confirmation, required: true, label: false, wrapper: false %> +
+ + <%= f.button :submit, t('.register'), class: 'btn btn-block btn-success' %> + <% end %> +
+ +
+
diff --git a/app/views/account/sessions/new.html.erb b/app/views/account/sessions/new.html.erb new file mode 100644 index 000000000..98f7dabfc --- /dev/null +++ b/app/views/account/sessions/new.html.erb @@ -0,0 +1,49 @@ +
+
+
+
+

<%= t('.login') %>

+

<%= t('.login_to_your_account') %>

+ <%= simple_form_for(resource, as: resource_name, url: session_path(resource_name)) do |f| %> +
+
+ + <%= fa_icon('user') %> + +
+ <%= f.input :id_number, required: true, autofocus: true, label: false, wrapper: false, as: :integer %> +
+
+
+ + <%= fa_icon('lock') %> + +
+ <%= f.input :password, required: true, label: false, wrapper: false %> +
+
+ <%= f.input :remember_me, as: :boolean, inline_label: true, label: t('.remember_login') %> +
+ +
+
+ <%= f.button :submit, t('.login'), class: 'btn btn-primary px-4' %> +
+
+ <%= link_to t('.did_you_forget'), recover_path, class: 'btn btn-link px-4', role: 'button' %> +
+
+ <% end %> +
+
+
+
+
+

<%= t('.register') %>

+

<%= t('.registration_description') %>

+ <%= link_to t('.create_account'), register_path, class: 'btn btn-primary active mt-3', role: 'button' %> +
+
+
+
+
diff --git a/app/views/admin/administrative_functions/_form.html.erb b/app/views/admin/administrative_functions/_form.html.erb new file mode 100644 index 000000000..e39126dc5 --- /dev/null +++ b/app/views/admin/administrative_functions/_form.html.erb @@ -0,0 +1,15 @@ +<%= render 'layouts/builders/form', + namespace: 'admin', + klass: @administrative_function, + params: [ + { + field: 'name', + width: 12, + required: true + }, + { + field: 'code', + width: 12, + required: true + } + ] %> diff --git a/app/views/admin/administrative_functions/edit.html.erb b/app/views/admin/administrative_functions/edit.html.erb new file mode 100644 index 000000000..2d3436368 --- /dev/null +++ b/app/views/admin/administrative_functions/edit.html.erb @@ -0,0 +1 @@ +<%= render 'form' %> diff --git a/app/views/admin/administrative_functions/index.html.erb b/app/views/admin/administrative_functions/index.html.erb new file mode 100644 index 000000000..0e91c181b --- /dev/null +++ b/app/views/admin/administrative_functions/index.html.erb @@ -0,0 +1,8 @@ +<%= render 'layouts/builders/index', + namespace: 'admin', + klass: 'administrative_function', + collection: @administrative_functions, + pagy: @pagy, + card_header: t('.card_header'), + params: ['name'], + actions: %w[edit destroy] %> diff --git a/app/views/admin/administrative_functions/new.html.erb b/app/views/admin/administrative_functions/new.html.erb new file mode 100644 index 000000000..2d3436368 --- /dev/null +++ b/app/views/admin/administrative_functions/new.html.erb @@ -0,0 +1 @@ +<%= render 'form' %> diff --git a/app/views/admin/yoksis_dashboard/index.html.erb b/app/views/admin/yoksis_dashboard/index.html.erb index 3883ea293..1a4979451 100644 --- a/app/views/admin/yoksis_dashboard/index.html.erb +++ b/app/views/admin/yoksis_dashboard/index.html.erb @@ -1,5 +1,6 @@
<% yoksis_klasses = %w[ + AdministrativeFunction HighSchoolType StudentDisabilityType StudentDropOutType diff --git a/app/views/devise/mailer/email_changed.html.erb b/app/views/devise/mailer/email_changed.html.erb index 5693962b1..a12519e55 100644 --- a/app/views/devise/mailer/email_changed.html.erb +++ b/app/views/devise/mailer/email_changed.html.erb @@ -1,4 +1,3 @@

<%= t('devise.mailer.common.hello', mail: @email) %>

-

<%= t('.body', support_mail: Tenant.configuration.email.support) %>

<%= t('.new_mail', mail: @resource.email) %>

diff --git a/app/views/devise/mailer/unlock_instructions.html.erb b/app/views/devise/mailer/unlock_instructions.html.erb index f60823131..e64bc04f1 100644 --- a/app/views/devise/mailer/unlock_instructions.html.erb +++ b/app/views/devise/mailer/unlock_instructions.html.erb @@ -1,5 +1,3 @@

<%= t('devise.mailer.common.hello', mail: @email) %>

-

<%= t('.body') %>

-

<%= link_to t('.unlock_my_account'), unlock_url(@resource, unlock_token: @token) %>

diff --git a/app/views/devise/passwords/new.html.erb b/app/views/devise/passwords/new.html.erb deleted file mode 100644 index 9330960f6..000000000 --- a/app/views/devise/passwords/new.html.erb +++ /dev/null @@ -1,29 +0,0 @@ -
-
-
-

<%= t('devise.common.reset_password') %>

-

<%= t('.hint') %>

- <%= simple_form_for(resource, as: resource_name, url: password_path(resource_name), html: { method: :post }) do |f| %> - <%= f.error_notification %> -
-
- @ -
- <%= f.input :email, required: true, autofocus: true, label: false, wrapper: false %> -
- - <%= f.button :submit, t('.send_instructions'), class: 'btn btn-block btn-primary' %> - <% end %> -
- -
-
diff --git a/app/views/devise/registrations/new.html.erb b/app/views/devise/registrations/new.html.erb deleted file mode 100644 index f1d76be46..000000000 --- a/app/views/devise/registrations/new.html.erb +++ /dev/null @@ -1,58 +0,0 @@ -
-
-
-

<%= t('devise.common.register') %>

-

<%= t('.create_your_account') %>

- <%= simple_form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f| %> - <%= f.error_notification %> -
-
- - <%= fa_icon('user') %> - -
- <%= f.input :id_number, required: true, label: false, wrapper: false %> -
- -
-
- - <%= fa_icon('at') %> - -
- <%= f.input :email, required: true, autofocus: true, label: false, wrapper: false %> -
- -
-
- - <%= fa_icon('lock') %> - -
- <%= f.input :password, required: true, label: false, wrapper: false %> -
- -
-
- - <%= fa_icon('lock') %> - -
- <%= f.input :password_confirmation, required: true, label: false, wrapper: false %> -
- - <%= f.button :submit, t('devise.common.register'), class: 'btn btn-block btn-success' %> - <% end %> -
- -
-
diff --git a/app/views/devise/sessions/new.html.erb b/app/views/devise/sessions/new.html.erb deleted file mode 100644 index 4718c3d87..000000000 --- a/app/views/devise/sessions/new.html.erb +++ /dev/null @@ -1,49 +0,0 @@ -
-
-
-
-

<%= t('devise.common.login') %>

-

<%= t('.login_to_your_account') %>

- <%= simple_form_for(resource, as: resource_name, url: session_path(resource_name)) do |f| %> -
-
- - <%= fa_icon('user') %> - -
- <%= f.input :id_number, required: true, autofocus: true, label: false, wrapper: false, as: :integer %> -
-
-
- - <%= fa_icon('lock') %> - -
- <%= f.input :password, required: true, label: false, wrapper: false %> -
-
- <%= f.input :remember_me, as: :boolean, inline_label: true, label: t('.remember_login') %> -
- -
-
- <%= f.button :submit, t('devise.common.login'), class: 'btn btn-primary px-4' %> -
-
- <%= link_to t('.did_you_forget'), new_password_path(resource_name), class: 'btn btn-link px-4', role: 'button' %> -
-
- <% end %> -
-
-
-
-
-

<%= t('devise.common.register') %>

-

<%= t('.registration_description') %>

- <%= link_to t('.create_account'), new_registration_path(resource_name), class: 'btn btn-primary active mt-3', role: 'button' %> -
-
-
-
-
diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 5becb44cb..5bd1fbce3 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -38,16 +38,16 @@ <%= link_to [:user, :addresses, { user_id: current_user.id }], class: 'dropdown-item' do %> <%= fa_icon('home', text: t('.addresses')) %> <% end %> - <%= link_to [:user, :profile, { user_id: current_user.id }], class: 'dropdown-item' do %> + <%= link_to :profile, class: 'dropdown-item' do %> <%= fa_icon('user', text: t('.profile_settings')) %> <% end %> - <%= link_to %i[edit user registration], class: 'dropdown-item' do %> + <%= link_to :account, class: 'dropdown-item' do %> <%= fa_icon('shield', text: t('.account_settings')) %> <% end %> - <%= link_to %i[destroy user session], class: 'dropdown-item', method: :delete do %> + <%= link_to :logout, class: 'dropdown-item', method: :delete do %> <%= fa_icon('lock', text: t('.logout')) %> <% end %>
diff --git a/app/views/layouts/builders/_form.html.erb b/app/views/layouts/builders/_form.html.erb index 183c13775..cac97ae9c 100644 --- a/app/views/layouts/builders/_form.html.erb +++ b/app/views/layouts/builders/_form.html.erb @@ -2,7 +2,7 @@
- <%= simple_form_for([namespace.try(:to_sym), klass].flatten) do |f| %> + <%= simple_form_for([namespace, klass].compact.flatten) do |f| %>
<%= f.error_notification %> @@ -26,7 +26,9 @@ label_method: parameter[:label_method].try(:to_sym), value_method: parameter[:value_method].try(:to_sym), group_method: parameter[:group_method].try(:to_sym), - group_label_method: parameter[:group_label_method].try(:to_sym) %> + group_label_method: parameter[:group_label_method].try(:to_sym), + priority: parameter[:priority], + selected: parameter[:selected] %> <% end %> <% end %>
diff --git a/app/views/users/_account.html.erb b/app/views/users/_account.html.erb index c204e9a93..5b9598dba 100644 --- a/app/views/users/_account.html.erb +++ b/app/views/users/_account.html.erb @@ -16,10 +16,6 @@ <%= t('.email') %> <%= @user.email %> - - <%= t('.preferred_language') %> - <%= @user.preferred_language %> - <%= t('created_at') %> <%= @user.created_at %> diff --git a/app/views/users/index.html.erb b/app/views/users/index.html.erb index 4dd26d657..6ada5003d 100644 --- a/app/views/users/index.html.erb +++ b/app/views/users/index.html.erb @@ -1,7 +1,3 @@ -
- <%= link_to_new(t('.new_user_link'), new_user_path) %> -
-
@@ -17,9 +13,8 @@ <%= t('.id_number') %> <%= t('.email') %> - <%= t('.preferred_language') %> - <%= t('.addresses') %> - <%= t('.identities') %> + <%= t('.first_name') %> + <%= t('.last_name') %> <%= t('actions') %> @@ -28,9 +23,8 @@ <%= user.id_number %> <%= user.email %> - <%= user.preferred_language %> - <%= user.addresses.count %> - <%= user.identities.count %> + <%= user.identities.user_identity.try(:first_name) %> + <%= user.identities.user_identity.try(:last_name) %> <%= link_to_actions(user) %> <% end %> diff --git a/app/views/users/new.html.erb b/app/views/users/new.html.erb deleted file mode 100644 index c993d8822..000000000 --- a/app/views/users/new.html.erb +++ /dev/null @@ -1 +0,0 @@ -<%= render 'form', user: @user, form_title: t('.form_title') %> diff --git a/config/locales/controllers/account/confirmations.en.yml b/config/locales/controllers/account/confirmations.en.yml new file mode 100644 index 000000000..2b8382e70 --- /dev/null +++ b/config/locales/controllers/account/confirmations.en.yml @@ -0,0 +1,6 @@ +tr: + devise: + confirmations: + confirmed: "Your email address has been successfully confirmed." + send_instructions: "You will receive an email with instructions for how to confirm your email address in a few minutes." + send_paranoid_instructions: "If your email address exists in our database, you will receive an email with instructions for how to confirm your email address in a few minutes." diff --git a/config/locales/controllers/account/confirmations.tr.yml b/config/locales/controllers/account/confirmations.tr.yml new file mode 100644 index 000000000..747e5f549 --- /dev/null +++ b/config/locales/controllers/account/confirmations.tr.yml @@ -0,0 +1,6 @@ +tr: + devise: + confirmations: + confirmed: "Eposta adresiniz başırılı bir şekilde onaylandı." + send_instructions: "Bir kaç dakika içerisinde eposta adresinizi nasıl onaylayacağınız hakkında bir eposta alacaksınız." + send_paranoid_instructions: "Eğer eposta adresinizi veritabanımızda kayıtlı ise bir kaç dakika içerisinde eposta adresinizi nasıl onaylayacağınız hakkında bir eposta alacaksınız." diff --git a/config/locales/controllers/account/devise.en.yml b/config/locales/controllers/account/devise.en.yml new file mode 100644 index 000000000..e20522d82 --- /dev/null +++ b/config/locales/controllers/account/devise.en.yml @@ -0,0 +1,43 @@ +en: + devise: + failure: + already_authenticated: You are already signed in. + inactive: Your account is not activated yet. + invalid: "Invalid %{authentication_keys} or password." + last_attempt: You have one more attempt before your account is locked. + locked: Your account is locked. + not_found_in_database: "Invalid %{authentication_keys} or password." + timeout: Your session expired. Please sign in again to continue. + unauthenticated: You need to sign in or sign up before continuing. + unconfirmed: You have to confirm your email address before continuing. + mailer: + common: + hello: 'Hello, %{mail}!' + confirmation_instructions: + subject: Confirmation instructions + email_changed: + body: 'You have successfully updated your registered e-mail address. You can drop us a line explaining the case at %{support_mail}, if you think there is a mistake.' + new_mail: 'Your new e-mail: %{mail}' + subject: Email Changed + password_change: + body: 'You have successfully updated your password. You can drop us a line explaining the case at %{support_mail}, if you think there is a mistake.' + subject: Password Changed + reset_password_instructions: + body: You or someone else made a request to reset your password. Click the link below to reset your password. + didnt_requested: You can ignore this e-mail if you didn't requested a password change. Your password will not change unless you click the link shown above and then set a new password. + reset_password: Reset Password + subject: Reset password instructions + unlock_instructions: + subject: Unlock instructions + body: Your account has been locked due to an excessive number of unsuccessful sign in attempts. Click the link below to unlock your account:' + unlock_my_account: Unlock my account + errors: + messages: + already_confirmed: was already confirmed, please try signing in + confirmation_period_expired: "needs to be confirmed within %{period}, please request a new one" + expired: has expired, please request a new one + not_found: not found + not_locked: was not locked + not_saved: + one: "1 error prohibited this %{resource} from being saved:" + other: "%{count} errors prohibited this %{resource} from being saved:" diff --git a/config/locales/controllers/account/devise.tr.yml b/config/locales/controllers/account/devise.tr.yml new file mode 100644 index 000000000..748a7c903 --- /dev/null +++ b/config/locales/controllers/account/devise.tr.yml @@ -0,0 +1,43 @@ +tr: + devise: + failure: + already_authenticated: Zaten giriş yaptınız. + inactive: Hesabınız henüz aktif edilmedi. + invalid: "Geçersiz %{authentication_keys} veya parola." + last_attempt: Hesabınız kilitlenmeden önceki son şansınız. + locked: Hesabınız kilitli. + not_found_in_database: "Geçersiz %{authentication_keys} veya parola." + timeout: Oturum süreniz sonlandı. Lütfen devam etmek için tekrar giriş yapın. + unauthenticated: Devam etmeden önce giriş yapmalı veya kayıt olmalısınız. + unconfirmed: Devam etmeden önce eposta adresinizi onaylamalısınız. + mailer: + common: + hello: 'Merhaba, %{mail}!' + confirmation_instructions: + subject: Onaylama talimatları + email_changed: + body: 'Kayıtlı e-mail adresiniz başarıyla değiştirilmiştir. Bir yanlışlık olduğunu düşünüyorsanız %{support_mail} adresine durumu anlatan bir e-mail gönderebilirsiniz.' + new_mail: 'Yeni e-mail adresiniz: %{mail}' + subject: Email Adresiniz Değişti + password_change: + body: 'Parolanız başarıyla değiştirilmiştir. Bir yanlışlık olduğunu düşünüyorsanız %{support_mail} adresine durumu anlatan bir e-mail gönderebilirsiniz.' + subject: Parolanız Değişti + reset_password_instructions: + body: Siz veya başka birisi parolanızı sıfırlama talebinde bulundu. Parolanızı sıfırlamak istiyorsanız aşağıdaki linke tıklayabilirsiniz. + didnt_requested: Eğer böyle bir istekte bulunmadıysanız bu e-mail'i görmezden gelebilirsiniz. Yukarıdaki linke tıklayarak yeni bir parola belirlemediğiniz sürece parolanız değişmeyecektir. + reset_password: Parolamı Sıfırla + subject: Parola sıfırlama talimatları + unlock_instructions: + subject: Kilit kaldırma talimalatları + body: 'Hesabınız çok fazla başarısız giriş denemesinden sonra güvenliğiniz için kilitlendi. Hesabınızı tekrar aktive etmek için lütfen aşağıdaki linke tıklayınız:' + unlock_my_account: Hesabımı aktive et + errors: + messages: + already_confirmed: zaten onaylandı, lütfen giriş yapmayı deneyin. + confirmation_period_expired: "%{period} süresi içerisinde onaylanması gerekiyor. Lütfen yeni bir tane isteyin." + expired: sona erdi, lütfen yeni bir tane isteyin. + not_found: bulunamadı + not_locked: kilitlenmedi + not_saved: + one: "Kaydedilirken %{resource}'dan 1 hata yakalandı:" + other: "Kaydedilirken %{resource}'dan %{count} hata yakalandı:" diff --git a/config/locales/controllers/account/duties.en.yml b/config/locales/controllers/account/duties.en.yml new file mode 100644 index 000000000..58948df06 --- /dev/null +++ b/config/locales/controllers/account/duties.en.yml @@ -0,0 +1,14 @@ +en: + account: + duties: + create: + success: Duty successfully created. + destroy: + success: Duty successfully deleted. + warning: Duty could not be deleted. + edit: + form_title: Update the Duty + new: + form_title: Create a Duty + update: + success: Duty successfully updated. diff --git a/config/locales/controllers/account/duties.tr.yml b/config/locales/controllers/account/duties.tr.yml new file mode 100644 index 000000000..db6803ac4 --- /dev/null +++ b/config/locales/controllers/account/duties.tr.yml @@ -0,0 +1,14 @@ +tr: + account: + duties: + create: + success: Görevlendirme başarıyla oluşturuldu. + destroy: + success: Görevlendirme başarıyla silindi. + warning: Görevlendirme silinemedi! + edit: + form_title: Görevlendirmeyi Güncelle + new: + form_title: Görevlendirme Oluştur + update: + success: Görevlendirme başarıyla güncellendi. diff --git a/config/locales/controllers/account/employees.en.yml b/config/locales/controllers/account/employees.en.yml new file mode 100644 index 000000000..92970c6db --- /dev/null +++ b/config/locales/controllers/account/employees.en.yml @@ -0,0 +1,14 @@ +en: + account: + employees: + create: + success: Employee successfully created. + destroy: + success: Employee successfully deleted. + warning: Employee could not be deleted. + edit: + form_title: Update the Employee + new: + form_title: Create a Employee + update: + success: Employee successfully updated. diff --git a/config/locales/controllers/account/employees.tr.yml b/config/locales/controllers/account/employees.tr.yml new file mode 100644 index 000000000..71f4b3759 --- /dev/null +++ b/config/locales/controllers/account/employees.tr.yml @@ -0,0 +1,14 @@ +tr: + account: + employees: + create: + success: Personel kaydı başarıyla oluşturuldu. + destroy: + success: Personel kaydı başarıyla silindi. + warning: Personel kaydı silinemedi! + edit: + form_title: Personel Kaydını Güncelle + new: + form_title: Personel Kaydı Oluştur + update: + success: Personel kaydı başarıyla güncellendi. diff --git a/config/locales/controllers/account/omniauth_callbacks.en.yml b/config/locales/controllers/account/omniauth_callbacks.en.yml new file mode 100644 index 000000000..20f21899e --- /dev/null +++ b/config/locales/controllers/account/omniauth_callbacks.en.yml @@ -0,0 +1,5 @@ +en: + devise: + omniauth_callbacks: + failure: "Could not authenticate you from %{kind} because \"%{reason}\"." + success: "Successfully authenticated from %{kind} account." diff --git a/config/locales/controllers/account/omniauth_callbacks.tr.yml b/config/locales/controllers/account/omniauth_callbacks.tr.yml new file mode 100644 index 000000000..93fd536ce --- /dev/null +++ b/config/locales/controllers/account/omniauth_callbacks.tr.yml @@ -0,0 +1,5 @@ +tr: + devise: + omniauth_callbacks: + failure: "\"%{reason}\" olduğu için %{kind}'den doğrulama yapılamıyor." + success: "%{kind} hesabından başarılı bir şekilde doğrulandı." diff --git a/config/locales/controllers/account/passwords.en.yml b/config/locales/controllers/account/passwords.en.yml new file mode 100644 index 000000000..b5151b2a6 --- /dev/null +++ b/config/locales/controllers/account/passwords.en.yml @@ -0,0 +1,18 @@ +en: + devise: + passwords: + no_token: "You can't access this page without coming from a password reset email. If you do come from a password reset email, please make sure you used the full URL provided." + send_instructions: "You will receive an email with instructions on how to reset your password in a few minutes." + send_paranoid_instructions: "If your email address exists in our database, you will receive a password recovery link at your email address in a few minutes." + updated: "Your password has been changed successfully. You are now signed in." + updated_not_active: "Your password has been changed successfully." + account: + passwords: + new: + hint: You can request password reset instruction by typing your e-mail. + login: Login + register: Register + reset_password: Reset Password + send_instructions: Send Reset Password Instructions + edit: + reset_password: Reset Password diff --git a/config/locales/controllers/account/passwords.tr.yml b/config/locales/controllers/account/passwords.tr.yml new file mode 100644 index 000000000..ef5dc21e8 --- /dev/null +++ b/config/locales/controllers/account/passwords.tr.yml @@ -0,0 +1,18 @@ +tr: + devise: + passwords: + no_token: Parola sıfırlama e-postasından gelmeden bu sayfaya erişemezsiniz. Eğer bir parola sıfırlama epostasından geliyorsanız tam bir URL kullandığınızdan emin olunuz. + send_instructions: Birkaç dakika içerisinde parolanızı nasıl sıfırlayacağınız hakkında bir eposta alacaksınız. + send_paranoid_instructions: Eğer eposta adresiniz sistemimizde kayıtlı ise birkaç dakika içerisinde eposta adresinize bir parola kurtarma linki alacaksınız. + updated: Parolanız başarılı bir şekilde değiştirildi. Girişiniz otomatik olarak gerçekleştirildi. + updated_not_active: Parolanız başarılı bir şekilde değiştirildi. + account: + passwords: + new: + hint: Hesabınızda kullandığınız e-mail adresini girerek parola sıfırlama talimatlarını alabilirsiniz. + login: Giriş Yap + register: Kayıt Ol + reset_password: Parolamı Sıfırla + send_instructions: Parola Sıfırlama Talimatlarını Gönder + edit: + reset_password: Parolamı Sıfırla diff --git a/config/locales/controllers/account/positions.en.yml b/config/locales/controllers/account/positions.en.yml new file mode 100644 index 000000000..91ef1eb6e --- /dev/null +++ b/config/locales/controllers/account/positions.en.yml @@ -0,0 +1,14 @@ +en: + account: + positions: + create: + success: Position successfully created. + destroy: + success: Position successfully deleted. + warning: Position could not be deleted. + edit: + form_title: Update the Position + new: + form_title: Create a Position + update: + success: Position successfully updated. diff --git a/config/locales/controllers/account/positions.tr.yml b/config/locales/controllers/account/positions.tr.yml new file mode 100644 index 000000000..6c1101ec6 --- /dev/null +++ b/config/locales/controllers/account/positions.tr.yml @@ -0,0 +1,14 @@ +tr: + account: + positions: + create: + success: İdari görev başarıyla oluşturuldu. + destroy: + success: İdari görev başarıyla silindi. + warning: İdari görev silinemedi! + edit: + form_title: İdari Görevi Güncelle + new: + form_title: İdari Görev Oluştur + update: + success: İdari görev başarıyla güncellendi. diff --git a/config/locales/controllers/account/profile.en.yml b/config/locales/controllers/account/profile.en.yml new file mode 100644 index 000000000..8b4face50 --- /dev/null +++ b/config/locales/controllers/account/profile.en.yml @@ -0,0 +1,24 @@ +en: + account: + profile_settings: + edit: + country: Country + extension_number: Extension Number + linkedin: Linkedin Username + orcid: ORCID + phone_number: Fixed Phone Number + profile_settings: Profile Settings + public_photo: Show picture on my profile + public_studies: Show academic studies on my profile + skype: Skype Username + twitter: Twitter Username + visiblity_settings: Visiblity Settings + website: Website + update: + success: Profile successfully updated. + simple_form: + placeholders: + user: + linkedin: linkedin.com/ + twitter: twitter.com/ + phone_number: 'I.e. 3623121919' diff --git a/config/locales/controllers/account/profile.tr.yml b/config/locales/controllers/account/profile.tr.yml new file mode 100644 index 000000000..62d69cd4f --- /dev/null +++ b/config/locales/controllers/account/profile.tr.yml @@ -0,0 +1,24 @@ +tr: + account: + profile_settings: + edit: + country: Ülke + extension_number: Dahili Numaranız + linkedin: Linkedin Kullanıcı Adı + orcid: ORCID + phone_number: Sabit Telefon Numaranız + profile_settings: Profil Ayarları + public_photo: Profilimde Fotoğrafımı Göster + public_studies: Profilimde Akademik Çalışmalarımı Göster + skype: Skype Kullanıcı Adı + twitter: Twitter Kullanıcı Adı + visiblity_settings: Görünürlük Ayarları + website: Web Sayfanız + update: + success: Profiliniz başarıyla güncellendi + simple_form: + placeholders: + user: + linkedin: linkedin.com/ + twitter: twitter.com/ + phone_number: 'Örn. 3623121919' diff --git a/config/locales/controllers/account/registrations.en.yml b/config/locales/controllers/account/registrations.en.yml new file mode 100644 index 000000000..a600af4cc --- /dev/null +++ b/config/locales/controllers/account/registrations.en.yml @@ -0,0 +1,23 @@ +en: + devise: + registrations: + user: + destroyed: "Bye! Your account has been successfully cancelled. We hope to see you again soon." + signed_up: "Welcome! You have signed up successfully." + signed_up_but_inactive: "You have signed up successfully. However, we could not sign you in because your account is not yet activated." + signed_up_but_locked: "You have signed up successfully. However, we could not sign you in because your account is locked." + signed_up_but_unconfirmed: "A message with a confirmation link has been sent to your email address. Please follow the link to activate your account." + update_needs_confirmation: "You updated your account successfully, but we need to verify your new email address. Please check your email and follow the confirm link to confirm your new email address." + updated: "Your account has been updated successfully." + account: + registrations: + edit: + account_settings: Account Settings + current_password: Current Password + current_password_hint: you must enter your current password for changing your e-mail address + leave_blank: leave blank if you don't want to change + new: + create_your_account: Create Your Account + did_you_forget: Forgot Your Password? + login: Login + register: Register diff --git a/config/locales/controllers/account/registrations.tr.yml b/config/locales/controllers/account/registrations.tr.yml new file mode 100644 index 000000000..835408e2f --- /dev/null +++ b/config/locales/controllers/account/registrations.tr.yml @@ -0,0 +1,23 @@ +tr: + devise: + registrations: + user: + destroyed: "Güle güle! Hesabınız başarılı bir şekilde iptal edildi. Sizi tekrar görmeyi umut ediyoruz." + signed_up: "Hoşgeldiniz! Başarılı bir şekilde kayıt oldunuz." + signed_up_but_inactive: "Başarılı bir şekilde kayıt oldunuz. Ancak henüz hesabınızı doğrulamadığınız için giriş yapamasınız." + signed_up_but_locked: "Başarılı bir şekilde kayıt oldunuz. Ancak hesabınız kilitli olduğu için giriş yapamazsınız." + signed_up_but_unconfirmed: "Eposta adresinize onaylama linkli bir mesaj gönderildi. Lütfen hesabınızı aktif etmek için linke tıklayın." + update_needs_confirmation: "Hesabınız başarılı bir şekilde güncellendi. Fakar eposta adresinizi onaylamanız gerekmekteir. Lütfen eposta kutunuzu kontrol ediniz ve yeni eposta adresinizi onaylama linkine tıklayınız." + updated: "Hesabınız başarılı bir şekilde güncellendi." + account: + registrations: + edit: + account_settings: Hesap Ayarları + current_password: Mevcut Parolanız + current_password_hint: e-mail adresinizi değiştirebilmek için mevcut parolanızı girmeniz gerekmektedir + leave_blank: değiştirmek istemiyorsanız boş bırakın + new: + create_your_account: Hesabınızı oluşturun + did_you_forget: Parolanı mı Unuttun? + login: Giriş Yap + register: Kayıt Ol diff --git a/config/locales/controllers/account/sessions.en.yml b/config/locales/controllers/account/sessions.en.yml new file mode 100644 index 000000000..178c34f27 --- /dev/null +++ b/config/locales/controllers/account/sessions.en.yml @@ -0,0 +1,16 @@ +en: + devise: + sessions: + already_signed_out: Already signed out. + signed_in: Signed in successfully. + signed_out: Signed out successfully. + account: + sessions: + new: + create_account: Create Account + did_you_forget: Forgot your password? + login: Login + login_to_your_account: Login to your account + registration_description: Students and staff joining to our university need to create an account by registering. + register: Register + remember_login: Remember Login diff --git a/config/locales/controllers/account/sessions.tr.yml b/config/locales/controllers/account/sessions.tr.yml new file mode 100644 index 000000000..2f0b5dc66 --- /dev/null +++ b/config/locales/controllers/account/sessions.tr.yml @@ -0,0 +1,16 @@ +tr: + devise: + sessions: + already_signed_out: Zaten çıkış yapmış durumdasınız! + signed_in: Hoşgeldiniz! + signed_out: Oturumunuz kapatıldı. + account: + sessions: + new: + create_account: Hesap Oluştur + did_you_forget: Parolanı mı Unuttun? + login: Giriş Yap + login_to_your_account: Hesabınıza giriş yapın + registration_description: Üniversitemize katılan öğrenci ve personellerin, kayıt olarak kendi hesaplarını oluşturmaları gerekmektedir. + register: Kayıt Ol + remember_login: Girişi hatırla diff --git a/config/locales/controllers/account/unlocks.en.yml b/config/locales/controllers/account/unlocks.en.yml new file mode 100644 index 000000000..8e5909389 --- /dev/null +++ b/config/locales/controllers/account/unlocks.en.yml @@ -0,0 +1,6 @@ +en: + devise: + unlocks: + send_instructions: "You will receive an email with instructions for how to unlock your account in a few minutes." + send_paranoid_instructions: "If your account exists, you will receive an email with instructions for how to unlock it in a few minutes." + unlocked: "Your account has been unlocked successfully. Please sign in to continue." diff --git a/config/locales/controllers/account/unlocks.tr.yml b/config/locales/controllers/account/unlocks.tr.yml new file mode 100644 index 000000000..6de67a92e --- /dev/null +++ b/config/locales/controllers/account/unlocks.tr.yml @@ -0,0 +1,6 @@ +tr: + devise: + unlocks: + send_instructions: "Birkaç dakika içerisinde hesabınızın kilidini nasıl kaldıracağınız hakkında bir eposta alacaksınız." + send_paranoid_instructions: "Eğer hesabınız varsa birkaç dakika içerisinde hesabınızın kilidini nasıl kaldırıcağınız hakkında bir eposta alacaksınız." + unlocked: "Başarılı bir şekilde hesabınızın kilidi kaldırıldı. Devam etmek için lütfen giriş yapın." diff --git a/config/locales/controllers/admin/administrative_functions.en.yml b/config/locales/controllers/admin/administrative_functions.en.yml new file mode 100644 index 000000000..93327a0a2 --- /dev/null +++ b/config/locales/controllers/admin/administrative_functions.en.yml @@ -0,0 +1,24 @@ +en: + activerecord: + attributes: + administrative_function: &administrative_function_attributes + name: Administrative Function + code: Code + helpers: + submit: + administrative_function: + create: Create Administrative Function + update: Update Administrative Function + admin: + administrative_functions: + create: + success: Administrative function successfully created. + destroy: + success: Administrative function successfully deleted. + warning: Administrative function can not be deleted! + index: + <<: *administrative_function_attributes + card_header: Administrative Functions + new_administrative_function_link: Create a New Administrative Function + update: + success: Administrative function successfully updated. diff --git a/config/locales/controllers/admin/administrative_functions.tr.yml b/config/locales/controllers/admin/administrative_functions.tr.yml new file mode 100644 index 000000000..771cc4a96 --- /dev/null +++ b/config/locales/controllers/admin/administrative_functions.tr.yml @@ -0,0 +1,24 @@ +tr: + activerecord: + attributes: + administrative_function: &administrative_function_attributes + name: İdari Görev + code: Kodu + helpers: + submit: + administrative_function: + create: İdari Görev Oluştur + update: İdari Görevi Güncelle + admin: + administrative_functions: + create: + success: İdari görev başarıyla oluşturuldu. + destroy: + success: İdari görev başarıyla silindi! + warning: İdari görev silinemedi! + index: + <<: *administrative_function_attributes + card_header: İdari Görevler + new_administrative_function_link: Yeni İdari Görev Oluştur + update: + success: İdari görev başarıyla güncellendi. diff --git a/config/locales/controllers/admin/yoksis_dashboard.en.yml b/config/locales/controllers/admin/yoksis_dashboard.en.yml index 22d042b8b..2304be75a 100644 --- a/config/locales/controllers/admin/yoksis_dashboard.en.yml +++ b/config/locales/controllers/admin/yoksis_dashboard.en.yml @@ -2,6 +2,7 @@ en: admin: yoksis_dashboard: card: + administrative_functions: Administrative Functions high_school_types: High School Types student_disability_types: Disability Types student_drop_out_types: Drop Out Types diff --git a/config/locales/controllers/admin/yoksis_dashboard.tr.yml b/config/locales/controllers/admin/yoksis_dashboard.tr.yml index d68d0cec6..b1bc6f984 100644 --- a/config/locales/controllers/admin/yoksis_dashboard.tr.yml +++ b/config/locales/controllers/admin/yoksis_dashboard.tr.yml @@ -2,6 +2,7 @@ tr: admin: yoksis_dashboard: card: + administrative_functions: İdari Görevler high_school_types: Lise Türleri student_disability_types: Engel Türleri student_drop_out_types: Ayrılma Nedenleri diff --git a/config/locales/gems/devise/en.yml b/config/locales/gems/devise/en.yml deleted file mode 100644 index 316640ff5..000000000 --- a/config/locales/gems/devise/en.yml +++ /dev/null @@ -1,72 +0,0 @@ -en: - devise: - confirmations: - confirmed: "Your email address has been successfully confirmed." - send_instructions: "You will receive an email with instructions for how to confirm your email address in a few minutes." - send_paranoid_instructions: "If your email address exists in our database, you will receive an email with instructions for how to confirm your email address in a few minutes." - failure: - already_authenticated: "You are already signed in." - inactive: "Your account is not activated yet." - invalid: "Invalid %{authentication_keys} or password." - last_attempt: "You have one more attempt before your account is locked." - locked: "Your account is locked." - not_found_in_database: "Invalid %{authentication_keys} or password." - timeout: "Your session expired. Please sign in again to continue." - unauthenticated: "You need to sign in or sign up before continuing." - unconfirmed: "You have to confirm your email address before continuing." - mailer: - common: - hello: 'Hello, %{mail}!' - confirmation_instructions: - subject: Confirmation instructions - email_changed: - body: 'You have successfully updated your registered e-mail address. You can drop us a line explaining the case at %{support_mail}, if you think there is a mistake.' - new_mail: 'Your new e-mail: %{mail}' - subject: Email Changed - password_change: - body: 'You have successfully updated your password. You can drop us a line explaining the case at %{support_mail}, if you think there is a mistake.' - subject: Password Changed - reset_password_instructions: - body: You or someone else made a request to reset your password. Click the link below to reset your password. - didnt_requested: You can ignore this e-mail if you didn't requested a password change. Your password will not change unless you click the link shown above and then set a new password. - reset_password: Reset Password - subject: Reset password instructions - unlock_instructions: - subject: Unlock instructions - body: Your account has been locked due to an excessive number of unsuccessful sign in attempts. Click the link below to unlock your account:' - unlock_my_account: Unlock my account - omniauth_callbacks: - failure: "Could not authenticate you from %{kind} because \"%{reason}\"." - success: "Successfully authenticated from %{kind} account." - passwords: - no_token: "You can't access this page without coming from a password reset email. If you do come from a password reset email, please make sure you used the full URL provided." - send_instructions: "You will receive an email with instructions on how to reset your password in a few minutes." - send_paranoid_instructions: "If your email address exists in our database, you will receive a password recovery link at your email address in a few minutes." - updated: "Your password has been changed successfully. You are now signed in." - updated_not_active: "Your password has been changed successfully." - registrations: - destroyed: "Bye! Your account has been successfully cancelled. We hope to see you again soon." - signed_up: "Welcome! You have signed up successfully." - signed_up_but_inactive: "You have signed up successfully. However, we could not sign you in because your account is not yet activated." - signed_up_but_locked: "You have signed up successfully. However, we could not sign you in because your account is locked." - signed_up_but_unconfirmed: "A message with a confirmation link has been sent to your email address. Please follow the link to activate your account." - update_needs_confirmation: "You updated your account successfully, but we need to verify your new email address. Please check your email and follow the confirm link to confirm your new email address." - updated: "Your account has been updated successfully." - sessions: - already_signed_out: "Signed out successfully." - signed_in: "Signed in successfully." - signed_out: "Signed out successfully." - unlocks: - send_instructions: "You will receive an email with instructions for how to unlock your account in a few minutes." - send_paranoid_instructions: "If your account exists, you will receive an email with instructions for how to unlock it in a few minutes." - unlocked: "Your account has been unlocked successfully. Please sign in to continue." - errors: - messages: - already_confirmed: "was already confirmed, please try signing in" - confirmation_period_expired: "needs to be confirmed within %{period}, please request a new one" - expired: "has expired, please request a new one" - not_found: "not found" - not_locked: "was not locked" - not_saved: - one: "1 error prohibited this %{resource} from being saved:" - other: "%{count} errors prohibited this %{resource} from being saved:" diff --git a/config/locales/gems/devise/tr.yml b/config/locales/gems/devise/tr.yml deleted file mode 100644 index f6c98390e..000000000 --- a/config/locales/gems/devise/tr.yml +++ /dev/null @@ -1,72 +0,0 @@ -tr: - devise: - confirmations: - confirmed: "Eposta adresiniz başırılı bir şekilde onaylandı." - send_instructions: "Bir kaç dakika içerisinde eposta adresinizi nasıl onaylayacağınız hakkında bir eposta alacaksınız." - send_paranoid_instructions: "Eğer eposta adresinizi veritabanımızda kayıtlı ise bir kaç dakika içerisinde eposta adresinizi nasıl onaylayacağınız hakkında bir eposta alacaksınız." - failure: - already_authenticated: "Zaten giriş yaptınız." - inactive: "Hesabınız henüz aktif edilmedi." - invalid: "Geçersiz %{authentication_keys} veya parola." - last_attempt: "Hesabınız kilitlenmeden önceki son şansınız." - locked: "Hesabınız kilitli." - not_found_in_database: "Geçersiz %{authentication_keys} veya parola." - timeout: "Oturum süreniz sonlandı. Lütfen devam etmek için tekrar giriş yapın." - unauthenticated: "Devam etmeden önce giriş yapmalı veya kayıt olmalısınız." - unconfirmed: "Devam etmeden önce eposta adresinizi onaylamalısınız." - mailer: - common: - hello: 'Merhaba, %{mail}!' - confirmation_instructions: - subject: Onaylama talimatları - email_changed: - body: 'Kayıtlı e-mail adresiniz başarıyla değiştirilmiştir. Bir yanlışlık olduğunu düşünüyorsanız %{support_mail} adresine durumu anlatan bir e-mail gönderebilirsiniz.' - new_mail: 'Yeni e-mail adresiniz: %{mail}' - subject: Email Adresiniz Değişti - password_change: - body: 'Şifreniz başarıyla değiştirilmiştir. Bir yanlışlık olduğunu düşünüyorsanız %{support_mail} adresine durumu anlatan bir e-mail gönderebilirsiniz.' - subject: Şifreniz Değişti - reset_password_instructions: - body: Siz veya başka birisi şifrenizi sıfırlama talebinde bulundu. Şifrenizi sıfırlamak istiyorsanız aşağıdaki linke tıklayabilirsiniz. - didnt_requested: Eğer böyle bir istekte bulunmadıysanız bu e-mail'i görmezden gelebilirsiniz. Yukarıdaki linke tıklayarak yeni bir şifre belirledikçe şifreniz değişmeyecektir. - reset_password: Şifremi Sıfırla - subject: Parola sıfırlama talimatları - unlock_instructions: - subject: Kilit kaldırma talimalatları - body: 'Hesabınız çok fazla başarısız giriş denemesinden sonra güvenliğiniz için kilitlendi. Hesabınızı tekrar aktive etmek için lütfen aşağıdaki linke tıklayınız:' - unlock_my_account: Hesabımı aktive et - omniauth_callbacks: - failure: "\"%{reason}\" olduğu için %{kind}'den doğrulama yapılamıyor." - success: "%{kind} hesabından başarılı bir şekilde doğrulandı." - passwords: - no_token: "Parola sıfırlama epostasından gelmeden bu sayfaya erişemezsiniz. Eğer bir parola sıfırlama epostasından geliyorsanız tam bir URL kullandığınızdan emin olunuz." - send_instructions: "Birkaç dakika içerisinde parolanızı nasıl sıfırlayacağınız hakkında bir eposta alacaksınız." - send_paranoid_instructions: "Eğer eposta adresiniz sistemimizde kayıtlı ise birkaç dakika içerisinde eposta adresinize bir parola kurtarma linki alacaksınız." - updated: "Parolanız başarılı bir şekilde değiştirildi. Şimdi giriş yapabilirsiniz." - updated_not_active: "Parolanız başarılı bir şekilde değiştirildi." - registrations: - destroyed: "Güle güle! Hesabınız başarılı bir şekilde iptal edildi. Sizi tekrar görmeyi umut ediyoruz." - signed_up: "Hoşgeldiniz! Başarılı bir şekilde kayıt oldunuz." - signed_up_but_inactive: "Başarılı bir şekilde kayıt oldunuz. Ancak henüz hesabınızı doğrulamadığınız için giriş yapamasınız." - signed_up_but_locked: "Başarılı bir şekilde kayıt oldunuz. Ancak hesabınız kilitli olduğu için giriş yapamazsınız." - signed_up_but_unconfirmed: "Eposta adresinize onaylama linkli bir mesaj gönderildi. Lütfen hesabınızı aktif etmek için linke tıklayın." - update_needs_confirmation: "Hesabınız başarılı bir şekilde güncellendi. Fakar eposta adresinizi onaylamanız gerekmekteir. Lütfen eposta kutunuzu kontrol ediniz ve yeni eposta adresinizi onaylama linkine tıklayınız." - updated: "Hesabınız başarılı bir şekilde güncellendi." - sessions: - already_signed_out: "Başarılı çıkış." - signed_in: "Başarılı giriş." - signed_out: "Başarılı çıkış." - unlocks: - send_instructions: "Birkaç dakika içerisinde hesabınızın kilidini nasıl kaldıracağınız hakkında bir eposta alacaksınız." - send_paranoid_instructions: "Eğer hesabınız varsa birkaç dakika içerisinde hesabınızın kilidini nasıl kaldırıcağınız hakkında bir eposta alacaksınız." - unlocked: "Başarılı bir şekilde hesabınızın kilidi kaldırıldı. Devam etmek için lütfen giriş yapın." - errors: - messages: - already_confirmed: "zaten naylandı, lütfen giriş yapmayı deneyin." - confirmation_period_expired: "%{period} süresi içerisinde onaylanması gerekiyor. Lütfen yeni bir tane isteyin." - expired: "sona erdi, lütfen yeni bir tane isteyin." - not_found: "bulunamadı" - not_locked: "kilitlenmedi" - not_saved: - one: "Kaydedilirken %{resource}'dan 1 hata yakalandı:" - other: "Kaydedilirken %{resource}'dan %{count} hata yakalandı:" diff --git a/config/locales/layouts/application/tr.yml b/config/locales/layouts/application/tr.yml index 8009276f3..1122334e5 100644 --- a/config/locales/layouts/application/tr.yml +++ b/config/locales/layouts/application/tr.yml @@ -3,9 +3,9 @@ tr: components: membership_notifications: address_information: Adres bilgileriniz - change_password: Şifrenizi değiştirin. + change_password: Parolanızı değiştirin. identity_information: Kimlik bilgileriniz - last_password_change: Son şifre değişikliği + last_password_change: Son parola değişikliği profile_completion_rate: Profil tamamlama oranı seems_missing: eksik görünüyor. upcoming_events: Yaklaşan akademik takvim olayları diff --git a/config/locales/models/account/en.yml b/config/locales/models/account/en.yml index 11a9e7ff6..5ff19a2bf 100644 --- a/config/locales/models/account/en.yml +++ b/config/locales/models/account/en.yml @@ -1,57 +1,5 @@ --- en: - account: - duties: - create: - success: Duty successfully created. - destroy: - success: Duty successfully deleted. - warning: Duty could not be deleted. - edit: - form_title: Update the Duty - new: - form_title: Create a Duty - update: - success: Duty successfully updated. - employees: - create: - success: Employee successfully created. - destroy: - success: Employee successfully deleted. - warning: Employee could not be deleted. - edit: - form_title: Update the Employee - new: - form_title: Create a Employee - update: - success: Employee successfully updated. - positions: - create: - success: Position successfully created. - destroy: - success: Position successfully deleted. - warning: Position could not be deleted. - edit: - form_title: Update the Position - new: - form_title: Create a Position - update: - success: Position successfully updated. - profile: - edit: - extension_number: Extension Number - linkedin: Linkedin Username - orcid: ORCID - phone_number: Phone Number - profile_settings: Profile Settings - public_photo: Show picture on my profile - public_studies: Show academic studies on my profile - skype: Skype Username - twitter: Twitter Username - visiblity_settings: Visiblity Settings - website: Website - update: - success: Profile successfully updated. activerecord: attributes: duty: @@ -83,8 +31,3 @@ en: position: create: Create Position update: Update Position - simple_form: - placeholders: - user: - linkedin: linkedin.com/ - twitter: twitter.com/ diff --git a/config/locales/models/account/tr.yml b/config/locales/models/account/tr.yml index 2485f6ef6..8b815face 100644 --- a/config/locales/models/account/tr.yml +++ b/config/locales/models/account/tr.yml @@ -1,57 +1,5 @@ --- tr: - account: - duties: - create: - success: Görevlendirme başarıyla oluşturuldu. - destroy: - success: Görevlendirme başarıyla silindi. - warning: Görevlendirme silinemedi! - edit: - form_title: Görevlendirmeyi Güncelle - new: - form_title: Görevlendirme Oluştur - update: - success: Görevlendirme başarıyla güncellendi. - employees: - create: - success: Personel kaydı başarıyla oluşturuldu. - destroy: - success: Personel kaydı başarıyla silindi. - warning: Personel kaydı silinemedi! - edit: - form_title: Personel Kaydını Güncelle - new: - form_title: Personel Kaydı Oluştur - update: - success: Personel kaydı başarıyla güncellendi. - positions: - create: - success: İdari görev başarıyla oluşturuldu. - destroy: - success: İdari görev başarıyla silindi. - warning: İdari görev silinemedi! - edit: - form_title: İdari Görevi Güncelle - new: - form_title: İdari Görev Oluştur - update: - success: İdari görev başarıyla güncellendi. - profile: - edit: - extension_number: Dahili numaranız - linkedin: Linkedin Kullanıcı Adı - orcid: ORCID - phone_number: Telefon numaranız - profile_settings: Profil Ayarları - public_photo: Profilimde Fotoğrafımı Göster - public_studies: Profilimde Akademik Çalışmalarımı Göster - skype: Skype Kullanıcı Adı - twitter: Twitter Kullanıcı Adı - visiblity_settings: Görünürlük Ayarları - website: Web Sayfanız - update: - success: Profiliniz başarıyla güncellendi activerecord: attributes: duty: @@ -83,8 +31,3 @@ tr: position: create: İdari Görev Oluştur update: İdari Görevi Güncelle - simple_form: - placeholders: - user: - linkedin: linkedin.com/ - twitter: twitter.com/ diff --git a/config/locales/models/addresses/en.yml b/config/locales/models/addresses/en.yml index 8eadd2576..98d789b0c 100644 --- a/config/locales/models/addresses/en.yml +++ b/config/locales/models/addresses/en.yml @@ -2,6 +2,7 @@ en: activerecord: attributes: address: &address_attributes + country: Country district: District full_address: Full Address phone_number: Phone Number diff --git a/config/locales/models/addresses/tr.yml b/config/locales/models/addresses/tr.yml index 4cfa773fb..d34eddef6 100644 --- a/config/locales/models/addresses/tr.yml +++ b/config/locales/models/addresses/tr.yml @@ -2,6 +2,7 @@ tr: activerecord: attributes: address: &address_attributes + country: Ülke district: İlçe full_address: Açık Adres phone_number: Cep Telefonu Numarası diff --git a/config/locales/models/user/en.yml b/config/locales/models/user/en.yml index 2d922ec52..6b36f98b8 100644 --- a/config/locales/models/user/en.yml +++ b/config/locales/models/user/en.yml @@ -27,39 +27,15 @@ en: password_changed_at: Last Password Change password_confirmation: Password Confirmation preferences: Visibility Settings - preferred_language: Preferred Language profile: Profile Settings projects_count: Projects Count - devise: - common: - login: Login - register: Register - reset_password: Reset Password - passwords: - edit: - reset_my_password: Reset my Password - new: - hint: You can request password reset instruction by typing your e-mail. - send_instructions: Send Reset Password Instructions - registrations: - edit: - account_settings: Account Settings - current_password: you must enter your current password for changing your e-mail address - leave_blank: leave blank if you don't want to change - new: - create_your_account: Create Your Account - did_you_forget: Forgot Your Password? - sessions: - new: - create_account: Create Account - did_you_forget: Forgot your password? - login_to_your_account: Login to your account - registration_description: Students and staff joining to our university need to create an account by registering. - remember_login: Remember Login + public_photo: Show picture on my profile + public_studies: Show academic studies on my profile helpers: submit: user: - update: Change my Password + create: Create Account + update: Update Account simple_form: placeholders: user: @@ -99,7 +75,9 @@ en: <<: *user_attributes addresses: Addresses card_header: User Accounts + first_name: First Name identities: Identities + last_name: Last Name new_user_link: Create a New User smart_search_placeholder: TC/YU number, e-mail address, first of last name new: diff --git a/config/locales/models/user/tr.yml b/config/locales/models/user/tr.yml index 78750630c..f1fbfecce 100644 --- a/config/locales/models/user/tr.yml +++ b/config/locales/models/user/tr.yml @@ -20,46 +20,22 @@ tr: start_date: Başlangıç Tarihi user: &user_attributes articles_count: Makale Sayısı - current_password: Mevcut Şifre + current_password: Mevcut Parola email: E-mail Adresi id_number: Kimlik Numarası password: Parola - password_changed_at: Son Şifre Değişikliği + password_changed_at: Son Parola Değişikliği password_confirmation: Parola (Tekrar) preferences: Görünürlük Ayarları - preferred_language: Tercih Edilen Dil profile: Profil Ayarları projects_count: Proje Sayısı - devise: - common: - login: Giriş Yap - register: Kayıt Ol - reset_password: Şifre Sıfırlama - passwords: - edit: - reset_my_password: Şifremi Sıfırla - new: - hint: Hesabınızda kullandığınız e-mail adresini girerek şifre sıfırlama talimatlarını alabilirsiniz. - send_instructions: Şifre Sıfırlama Talimatlarını Gönder - registrations: - edit: - account_settings: Hesap Ayarları - current_password: e-mail adresinizi değiştirebilmek için mevcut şifrenizi girmeniz gerekmektedir - leave_blank: değiştirmek istemiyorsanız boş bırakın - new: - create_your_account: Hesabınızı oluşturun - did_you_forget: Şifreni mi Unuttun? - sessions: - new: - create_account: Hesap Oluştur - did_you_forget: Şifreni mi Unuttun? - login_to_your_account: Hesabınıza giriş yapın - registration_description: Üniversitemize katılan öğrenci ve personellerin, kayıt olarak kendi hesaplarını oluşturmaları gerekmektedir. - remember_login: Girişi Hatırla + public_photo: Profilimde Fotoğrafımı Göster + public_studies: Profilimde Akademik Çalışmalarımı Göster helpers: submit: user: - update: Şifremi Değiştir + create: Hesap Oluştur + update: Hesabı Güncelle simple_form: placeholders: user: @@ -99,7 +75,9 @@ tr: <<: *user_attributes addresses: Adres Bilgileri card_header: Kullanıcı Hesapları + first_name: Adı identities: Kimlik Bilgileri + last_name: Soyadı new_user_link: Yeni Kullanıcı Oluştur smart_search_placeholder: TC/YU numarası, e-mail adresi, ad veya soyad new: diff --git a/config/routes.rb b/config/routes.rb index dfa89ee4f..b12f9f792 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -3,12 +3,11 @@ Rails.application.routes.draw do root to: 'home#index' + draw :account draw :admin draw :calendar_management draw :first_registration - draw :devise - draw :account draw :course_management draw :references @@ -21,7 +20,7 @@ end end - resources :users do + resources :users, except: [:new, :create] do get 'save_address_from_mernis', on: :member get 'save_identity_from_mernis', on: :member end diff --git a/config/routes/account.rb b/config/routes/account.rb index dbb88d5da..d16d7e18c 100644 --- a/config/routes/account.rb +++ b/config/routes/account.rb @@ -1,5 +1,25 @@ # frozen_string_literal: true +devise_for :users, controllers: { + registrations: 'account/registrations', + passwords: 'account/passwords', + sessions: 'account/sessions', + unlocks: 'account/unlocks' +} + +devise_scope :user do + get 'account', to: 'account/registrations#edit' + get 'login', to: 'account/sessions#new' + get 'register', to: 'account/registrations#new' + get 'recover', to: 'account/passwords#new' + delete 'logout', to: 'account/sessions#destroy' +end + +scope module: :account do + get '/profile', to: 'profile_settings#edit' + patch '/profile', to: 'profile_settings#update' +end + resources :users, only: [] do scope module: :account do resources :identities, except: [:show] do @@ -12,8 +32,5 @@ resources :employees, except: %i[index show] resources :duties, except: %i[index show] resources :positions, except: %i[index show] - - get '/profile', to: 'profile#edit' - post '/profile', to: 'profile#update' end end diff --git a/config/routes/admin.rb b/config/routes/admin.rb index 7d7a55432..4129855d9 100644 --- a/config/routes/admin.rb +++ b/config/routes/admin.rb @@ -18,6 +18,7 @@ # YOKSIS References get 'yoksis', to: 'yoksis_dashboard#index' + resources :administrative_functions, except: :show resources :high_school_types, except: :show resources :student_disability_types, except: :show resources :student_drop_out_types, except: :show diff --git a/config/routes/devise.rb b/config/routes/devise.rb deleted file mode 100644 index 2ef01d1b7..000000000 --- a/config/routes/devise.rb +++ /dev/null @@ -1,7 +0,0 @@ -# frozen_string_literal: true - -devise_for :users, path_prefix: 'devise', controllers: { - registrations: 'user/registrations', - passwords: 'user/passwords', - sessions: 'user/sessions' -} diff --git a/doc/development/test-unit.md b/doc/development/test-unit.md new file mode 100644 index 000000000..d9fe90b2f --- /dev/null +++ b/doc/development/test-unit.md @@ -0,0 +1,110 @@ +--- +author: M. Serhat Dundar +--- + +# Unit Tests + +- Unit Test yazarken ilgili modülleri testinize include ederek aşağıda örneklenen test yardımcılarını kullanabilirsiniz. +- Nokul'da kullanılan stil, her satırda bir attribute'ün test edilmesidir! + +-------------------------------------------------- + +## Associations + +### has_one + +```ruby + has_one :address + has_one :address, :identity +``` + +### has_many + +```ruby + has_many :addresses + has_many :addresses, :identities +``` + +### belongs_to + +```ruby + belongs_to :user + belongs_to :user, :unit +``` + +-------------------------------------------------- + +## Callbacks + +- Mümkün olan key değerleri `:before`, `:after` ve `:around`'tur. + +```ruby + has_initialize_callback :method_name, :key + has_find_callback :method_name, :key + has_touch_callback :method_name, :key + has_validation_callback :method_name, :key + has_save_callback :method_name, :key + has_create_callback :method_name, :key + has_update_callback :method_name, :key + has_destroy_callback :method_name, :key + has_commit_callback :method_name, :key + has_rollback_callback :method_name, :key +``` + +-------------------------------------------------- + +## Validations + +### Presence + +```ruby +validates_presence_of :name +validates_presence_of :name, :code, :year +``` + +### Presence of Nested Model + +```ruby +validates_presence_of_nested_model :lecturers +validates_presence_of_nested_model :lecturers, ids: 'employee_ids' +``` + +### Uniqueness + +```ruby +validates_uniqueness_of :name +validates_uniqueness_of :name, :code, :year +``` + +### Length + +```ruby +validates_length_of :name # default: { maximum: 255 } +validates_length_of :id_number, is: 11 +validates_length_of :description, maximum: 65535 +validates_length_of :first_name, minimum: 2 +``` + +### Numericality + +```ruby +validates_numericality_of :year +``` + +### Numerical Range + +```ruby +validates_numerical_range :yoksis_code, greater_than: 4000 +validates_numerical_range :yoksis_code, greater_than_or_equal_to: 1000 +validates_numerical_range :yoksis_code, less_than: 500 +validates_numerical_range :yoksis_code, less_than_or_equal_to: 2000 + +``` + +-------------------------------------------------- + +## Enums + +```ruby +has_enum :term, fall: 0, spring: 1, summer: 2 +``` diff --git a/lib/templates/ldap/openldap-2.4-bcyrpt-module.tar.gz b/lib/templates/ldap/openldap-2.4-bcyrpt-module.tar.gz new file mode 100644 index 000000000..3ee8eed29 Binary files /dev/null and b/lib/templates/ldap/openldap-2.4-bcyrpt-module.tar.gz differ diff --git a/plugins/support/Gemfile.lock b/plugins/support/Gemfile.lock index 4c1c1e618..ad7767718 100644 --- a/plugins/support/Gemfile.lock +++ b/plugins/support/Gemfile.lock @@ -1,6 +1,6 @@ GIT remote: https://github.com/rails/rails.git - revision: 16e235126ef0187a93b81ee959a8127097e2f394 + revision: 907280ddfd78c53e2eb5af6f12512dc38df38bd8 specs: actioncable (6.0.0.beta1) actionpack (= 6.0.0.beta1) @@ -55,7 +55,7 @@ GIT i18n (>= 0.7, < 2) minitest (~> 5.1) tzinfo (~> 1.1) - zeitwerk (~> 1.0) + zeitwerk (~> 1.2) rails (6.0.0.beta1) actioncable (= 6.0.0.beta1) actionmailbox (= 6.0.0.beta1) @@ -135,7 +135,7 @@ GEM websocket-driver (0.7.0) websocket-extensions (>= 0.1.0) websocket-extensions (0.1.3) - zeitwerk (1.1.0) + zeitwerk (1.2.0) PLATFORMS ruby diff --git a/plugins/tenant/common/Gemfile.lock b/plugins/tenant/common/Gemfile.lock index 5ecfa6828..25a5109d6 100644 --- a/plugins/tenant/common/Gemfile.lock +++ b/plugins/tenant/common/Gemfile.lock @@ -1,6 +1,6 @@ GIT remote: https://github.com/rails/rails.git - revision: 16e235126ef0187a93b81ee959a8127097e2f394 + revision: 907280ddfd78c53e2eb5af6f12512dc38df38bd8 specs: actioncable (6.0.0.beta1) actionpack (= 6.0.0.beta1) @@ -55,7 +55,7 @@ GIT i18n (>= 0.7, < 2) minitest (~> 5.1) tzinfo (~> 1.1) - zeitwerk (~> 1.0) + zeitwerk (~> 1.2) rails (6.0.0.beta1) actioncable (= 6.0.0.beta1) actionmailbox (= 6.0.0.beta1) @@ -85,7 +85,7 @@ PATH nokul-support PATH - remote: /vagrant/plugins/support + remote: /home/msdundar/projects/nokul/plugins/support specs: nokul-support (0.1.0) activesupport (~> 6.0.0.beta1) @@ -141,7 +141,7 @@ GEM websocket-driver (0.7.0) websocket-extensions (>= 0.1.0) websocket-extensions (0.1.3) - zeitwerk (1.1.0) + zeitwerk (1.2.0) PLATFORMS ruby diff --git a/plugins/tenant/omu/Gemfile.lock b/plugins/tenant/omu/Gemfile.lock index 6c891fac5..8c53ca6af 100644 --- a/plugins/tenant/omu/Gemfile.lock +++ b/plugins/tenant/omu/Gemfile.lock @@ -6,13 +6,13 @@ PATH rails (~> 6.0.0.beta1) PATH - remote: /vagrant/plugins/support + remote: /home/msdundar/projects/nokul/plugins/support specs: nokul-support (0.1.0) activesupport (~> 6.0.0.beta1) PATH - remote: /vagrant/plugins/tenant/common + remote: /home/msdundar/projects/nokul/plugins/tenant/common specs: nokul-tenant (0.1.0) nokul-support diff --git a/test/config/application_config_test.rb b/test/config/application_config_test.rb index 212c4d71a..f40fcf9be 100644 --- a/test/config/application_config_test.rb +++ b/test/config/application_config_test.rb @@ -40,4 +40,12 @@ class ApplicationConfigTest < ActiveSupport::TestCase test 'autoloader is set to :classic until Rails 6 stable' do assert_equal Rails.application.config.autoloader, :classic end + + test 'image_processor is set to :vips' do + assert_equal Rails.application.config.active_storage.variant_processor, :vips + end + + test 'schema format is set to :sql' do + assert_equal Rails.application.config.active_record.schema_format, :sql + end end diff --git a/test/controllers/accounts/addresses_controller_test.rb b/test/controllers/accounts/addresses_controller_test.rb index bb85ce1c9..3aa5629c1 100644 --- a/test/controllers/accounts/addresses_controller_test.rb +++ b/test/controllers/accounts/addresses_controller_test.rb @@ -7,7 +7,7 @@ class AddressesController < ActionDispatch::IntegrationTest setup do @user = users(:serhat) @user.addresses.informal.create( - phone_number: '03623121919', full_address: 'OMÜ BAUM', district_id: districts(:gerze).id + phone_number: '05554443322', full_address: 'OMÜ BAUM', district_id: districts(:gerze).id, country: 'tr' ) sign_in @user end @@ -27,14 +27,14 @@ class AddressesController < ActionDispatch::IntegrationTest assert_difference('@user.addresses.count') do post user_addresses_path(@user), params: { address: { - phone_number: '03623121919', full_address: 'OMÜ BAUM', district_id: districts(:gerze).id + phone_number: '05554443322', full_address: 'OMÜ BAUM', district_id: districts(:gerze).id, country: 'tr' } } end address = @user.addresses.find_by(type: :informal) - assert_equal '03623121919', address.phone_number + assert_equal '05554443322', address.phone_number assert_equal 'OMÜ BAUM', address.full_address assert_equal districts(:gerze), address.district @@ -63,13 +63,13 @@ class AddressesController < ActionDispatch::IntegrationTest patch user_address_path(@user, address), params: { address: { - phone_number: '03623121920', full_address: 'OMÜ UZEM' + phone_number: '05554441122', full_address: 'OMÜ UZEM', country: 'tr' } } address.reload - assert_equal '03623121920', address.phone_number + assert_equal '05554441122', address.phone_number assert_equal 'OMÜ UZEM', address.full_address assert_redirected_to user_addresses_path(@user) diff --git a/test/controllers/admin/administrative_functions_controller_test.rb b/test/controllers/admin/administrative_functions_controller_test.rb new file mode 100644 index 000000000..cc4228bd1 --- /dev/null +++ b/test/controllers/admin/administrative_functions_controller_test.rb @@ -0,0 +1,8 @@ +# frozen_string_literal: true + +require 'test_helper' +require_relative '../concerns/references_resource_test' + +class AdministrativeFunctionsControllerTest < ActionDispatch::IntegrationTest + include ReferenceResourceTest +end diff --git a/test/controllers/admin/assessment_method_controller_test.rb b/test/controllers/admin/assessment_methods_controller_test.rb similarity index 97% rename from test/controllers/admin/assessment_method_controller_test.rb rename to test/controllers/admin/assessment_methods_controller_test.rb index 30b85f1c8..054410ec9 100644 --- a/test/controllers/admin/assessment_method_controller_test.rb +++ b/test/controllers/admin/assessment_methods_controller_test.rb @@ -3,7 +3,7 @@ require 'test_helper' module Admin - class AssessmentMethodControllerTest < ActionDispatch::IntegrationTest + class AssessmentMethodsControllerTest < ActionDispatch::IntegrationTest setup do sign_in users(:serhat) @assessment_method = assessment_methods(:exam) diff --git a/test/controllers/users_controller_test.rb b/test/controllers/users_controller_test.rb index de476f022..bb2005f8f 100644 --- a/test/controllers/users_controller_test.rb +++ b/test/controllers/users_controller_test.rb @@ -18,31 +18,6 @@ class UsersControllerTest < ActionDispatch::IntegrationTest assert_response :success end - test 'should get new' do - get new_user_path - assert_response :success - end - - test 'should create user' do - skip 'this block on CircleCI since it needs IP permissions to run.' if ENV['CI'] - assert_difference('User.count') do - post users_path params: { - user: { - id_number: '70336212330', - email: 'new_user@gmail.com', - password: '123456', - password_confirmation: '123456' - } - } - end - - user = User.last - - assert_equal '70336212330', user.id_number - assert_redirected_to users_path - assert_equal t('users.create.success'), flash[:notice] - end - test 'should get edit' do get edit_user_path(@user) assert_response :success diff --git a/test/fixtures/addresses.yml b/test/fixtures/addresses.yml index 27ae93f8e..1f8ab876b 100644 --- a/test/fixtures/addresses.yml +++ b/test/fixtures/addresses.yml @@ -1,18 +1,18 @@ formal: type: formal - phone_number: 12345678 + phone_number: <% TelephoneNumber.parse('5554443322', :tr) %> full_address: 'Lorem ipsum street' district: atakum user: serhat informal: type: informal - phone_number: 12345678 + phone_number: <% TelephoneNumber.parse('5554443322', :tr) %> full_address: 'Cumhuriyet mahallesi' district: atakum user: serhat informal: type: informal - phone_number: 12345678 + phone_number: <% TelephoneNumber.parse('5554443322', :tr) %> full_address: 'Cumhuriyet mahallesi' district: atakum user: john diff --git a/test/models/academic_term_test.rb b/test/models/academic_term_test.rb index 405c0974a..09bbaff57 100644 --- a/test/models/academic_term_test.rb +++ b/test/models/academic_term_test.rb @@ -4,6 +4,7 @@ class AcademicTermTest < ActiveSupport::TestCase include AssociationTestModule + include CallbackTestModule include EnumerationTestModule include ValidationTestModule @@ -25,7 +26,7 @@ class AcademicTermTest < ActiveSupport::TestCase validates_length_of :year # enums - has_enum :term, values: { fall: 0, spring: 1, summer: 2 } + has_enum :term, fall: 0, spring: 1, summer: 2 # validations: AcademicTermValidator test 'one of the academic terms must be active' do @@ -42,7 +43,9 @@ class AcademicTermTest < ActiveSupport::TestCase end # callbacks - test 'callbacks only one academic term must be active' do + has_save_callback :deactivate_academic_terms, :after + + test 'callback ensures that only one academic term must be active' do active_term = AcademicTerm.active.last passive_term = academic_terms(:fall_2017_2018) diff --git a/test/models/address_test.rb b/test/models/address_test.rb index 8bb0c2b45..140292463 100644 --- a/test/models/address_test.rb +++ b/test/models/address_test.rb @@ -4,6 +4,7 @@ class AddressTest < ActiveSupport::TestCase include AssociationTestModule + include CallbackTestModule include EnumerationTestModule include ValidationTestModule @@ -27,13 +28,10 @@ class AddressTest < ActiveSupport::TestCase validates_length_of :phone_number # enumerations - has_enum :type, values: { formal: 1, informal: 2 } + has_enum :type, formal: 1, informal: 2 # callbacks - test 'callbacks must titlecase the full_address of an address' do - addresses(:formal).update!(full_address: 'ABC SOKAK', type: 'informal') - assert_equal addresses(:formal).full_address, 'Abc Sokak' - end + has_save_callback :capitalize_attributes, :before # address_validator test 'a user can only have one formal address' do diff --git a/test/models/administrative_function_test.rb b/test/models/administrative_function_test.rb index 576c25e49..eb582f3b2 100644 --- a/test/models/administrative_function_test.rb +++ b/test/models/administrative_function_test.rb @@ -3,27 +3,5 @@ require 'test_helper' class AdministrativeFunctionTest < ActiveSupport::TestCase - include AssociationTestModule - include ValidationTestModule - - # relations - has_many :duties - has_many :positions - - # validations: presence - validates_presence_of :code - validates_presence_of :name - - # validations: uniqueness - validates_uniqueness_of :code - validates_uniqueness_of :name - - # validations: length - validates_length_of :name - - # callbacks - test 'callbacks must titlecase the full_address of an address' do - administrative_functions(:rector).update!(name: 'REKTÖR') - assert_equal administrative_functions(:rector).name, 'Rektör' - end + include ReferenceTestModule end diff --git a/test/models/agenda_test.rb b/test/models/agenda_test.rb index f036a59d0..526556966 100644 --- a/test/models/agenda_test.rb +++ b/test/models/agenda_test.rb @@ -18,10 +18,10 @@ class AgendaTest < ActiveSupport::TestCase validates_presence_of :status # validations: length - validates_length_of :description, type: :text + validates_length_of :description, maximum: 65_535 # enums - has_enum :status, values: { recent: 0, decided: 1, delayed: 2 } + has_enum :status, recent: 0, decided: 1, delayed: 2 # scopes test 'active scope returns recent and delayed agendas' do diff --git a/test/models/agenda_type_test.rb b/test/models/agenda_type_test.rb index 8e1001291..8c073d9db 100644 --- a/test/models/agenda_type_test.rb +++ b/test/models/agenda_type_test.rb @@ -4,6 +4,7 @@ class AgendaTypeTest < ActiveSupport::TestCase include AssociationTestModule + include CallbackTestModule include ValidationTestModule # relations @@ -14,4 +15,7 @@ class AgendaTypeTest < ActiveSupport::TestCase # validations: length validates_length_of :name + + # callbacks + has_save_callback :capitalize_attributes, :before end diff --git a/test/models/assessment_method_test.rb b/test/models/assessment_method_test.rb index b9996495d..bb4250e74 100644 --- a/test/models/assessment_method_test.rb +++ b/test/models/assessment_method_test.rb @@ -4,6 +4,7 @@ class AssessmentMethodTest < ActiveSupport::TestCase include AssociationTestModule + include CallbackTestModule include ValidationTestModule # relations @@ -21,8 +22,5 @@ class AssessmentMethodTest < ActiveSupport::TestCase validates_length_of :name # callbacks - test 'callbacks must titlecase the name of a assessment method' do - assessment_method = AssessmentMethod.create!(name: 'test assessment method') - assert_equal assessment_method.name, 'Test Assessment Method' - end + has_validation_callback :capitalize_attributes, :before end diff --git a/test/models/available_course_lecturer_test.rb b/test/models/available_course_lecturer_test.rb index bd0526165..56939a558 100644 --- a/test/models/available_course_lecturer_test.rb +++ b/test/models/available_course_lecturer_test.rb @@ -6,10 +6,6 @@ class AvailableCourseLecturerTest < ActiveSupport::TestCase include AssociationTestModule include ValidationTestModule - setup do - @course_lecturer = available_course_lecturers(:ati_group_1_lecturer_john) - end - # relations belongs_to :group belongs_to :lecturer @@ -18,7 +14,7 @@ class AvailableCourseLecturerTest < ActiveSupport::TestCase validates_presence_of :coordinator test 'uniqueness validations for lecturer of a group' do - fake = @course_lecturer.dup + fake = available_course_lecturers(:ati_group_1_lecturer_john).dup assert_not fake.valid? assert_not_empty fake.errors[:lecturer] fake.group = available_course_groups(:ati_group_2) @@ -27,7 +23,7 @@ class AvailableCourseLecturerTest < ActiveSupport::TestCase # scopes test 'coordinator scope returns coordinator lecturers' do - assert_includes AvailableCourseLecturer.coordinator, @course_lecturer + assert_includes AvailableCourseLecturer.coordinator, available_course_lecturers(:ati_group_1_lecturer_john) assert_not_includes AvailableCourseLecturer.coordinator, available_course_lecturers(:ati_group_1_lecturer_serhat) end end diff --git a/test/models/available_course_test.rb b/test/models/available_course_test.rb index e57634de6..6cc2075d9 100644 --- a/test/models/available_course_test.rb +++ b/test/models/available_course_test.rb @@ -4,11 +4,7 @@ class AvailableCourseTest < ActiveSupport::TestCase include AssociationTestModule - include ValidationTestModule - - setup do - @available_course = available_courses(:ati_fall_2018_2019) - end + include CallbackTestModule # relations belongs_to :academic_term @@ -19,9 +15,12 @@ class AvailableCourseTest < ActiveSupport::TestCase has_many :evaluation_types has_many :groups + # callbacks + has_validation_callback :assign_academic_term, :before + # validations: uniqueness test 'uniqueness validations for course of a academic term and curriculum' do - fake = @available_course.dup + fake = available_courses(:ati_fall_2018_2019).dup assert_not fake.valid? assert_not_empty fake.errors[:course] fake.course = courses(:ydi) diff --git a/test/models/calendar_event_type_test.rb b/test/models/calendar_event_type_test.rb index 336ac1570..9651d55e8 100644 --- a/test/models/calendar_event_type_test.rb +++ b/test/models/calendar_event_type_test.rb @@ -24,14 +24,13 @@ class CalendarEventTypeTest < ActiveSupport::TestCase validates_length_of :identifier # enums - has_enum :category, values: { - applications: 1, - payments: 2, - registrations: 3, - advisor: 4, - exams: 5, - courses: 6, - submission: 7, - announcement: 8 - } + has_enum :category, + applications: 1, + payments: 2, + registrations: 3, + advisor: 4, + exams: 5, + courses: 6, + submission: 7, + announcement: 8 end diff --git a/test/models/calendar_test.rb b/test/models/calendar_test.rb index e9491ea7c..d41b3124e 100644 --- a/test/models/calendar_test.rb +++ b/test/models/calendar_test.rb @@ -25,7 +25,7 @@ class CalendarTest < ActiveSupport::TestCase # validations: length validates_length_of :name validates_length_of :timezone - validates_length_of :description, type: :text + validates_length_of :description, maximum: 65_535 # validations: nested models validates_presence_of_nested_model :committee_decisions diff --git a/test/models/city_test.rb b/test/models/city_test.rb index 830b76f0c..fd4aada3b 100644 --- a/test/models/city_test.rb +++ b/test/models/city_test.rb @@ -4,6 +4,7 @@ class CityTest < ActiveSupport::TestCase include AssociationTestModule + include CallbackTestModule include ValidationTestModule # relations @@ -25,13 +26,5 @@ class CityTest < ActiveSupport::TestCase validates_length_of :alpha_2_code # callbacks - test 'callbacks must titlecase the name and must upcase the alpha_2_code of a city' do - city = City.create( - name: 'wonderland', - alpha_2_code: 'wl-11', - country: countries(:turkey) - ) - assert_equal city.name, 'Wonderland' - assert_equal city.alpha_2_code, 'WL-11' - end + has_validation_callback :capitalize_attributes, :before end diff --git a/test/models/committee_decision_test.rb b/test/models/committee_decision_test.rb index 4dc50d8c3..47c31d155 100644 --- a/test/models/committee_decision_test.rb +++ b/test/models/committee_decision_test.rb @@ -4,12 +4,9 @@ class CommitteeDecisionTest < ActiveSupport::TestCase include AssociationTestModule + include CallbackTestModule include ValidationTestModule - setup do - @decision = committee_decisions(:one) - end - # relations belongs_to :meeting_agenda has_one :agenda @@ -21,7 +18,7 @@ class CommitteeDecisionTest < ActiveSupport::TestCase # validations: length validates_length_of :decision_no - validates_length_of :description, type: :text + validates_length_of :description, maximum: 65_535 # delegates %i[ @@ -31,11 +28,14 @@ class CommitteeDecisionTest < ActiveSupport::TestCase meeting_agenda_unit ].each do |property| test "a decision reach committee_meeting's #{property} parameter" do - assert @decision.send(property) + assert committee_decisions(:one).send(property) end end # callbacks + has_validation_callback :assign_year_and_decision_no, :before + has_create_callback :change_status_to_decided, :after + test 'before initialize callback must run for year and decision_no attribute' do decision = CommitteeDecision.create(description: 'Test Karar', meeting_agenda: meeting_agendas(:one)) assert_equal 2018, decision.year @@ -49,6 +49,6 @@ class CommitteeDecisionTest < ActiveSupport::TestCase # custom test 'count_of_decisions_by_year return decision count by year' do - assert_equal 3, @decision.send(:count_of_decisions_by_year, 2018) + assert_equal 3, committee_decisions(:one).send(:count_of_decisions_by_year, 2018) end end diff --git a/test/models/committee_meeting_test.rb b/test/models/committee_meeting_test.rb index d08d34d2b..9692e8b52 100644 --- a/test/models/committee_meeting_test.rb +++ b/test/models/committee_meeting_test.rb @@ -4,6 +4,7 @@ class CommitteeMeetingTest < ActiveSupport::TestCase include AssociationTestModule + include CallbackTestModule include ValidationTestModule # relations @@ -20,10 +21,5 @@ class CommitteeMeetingTest < ActiveSupport::TestCase validates_uniqueness_of :meeting_no # callbacks - test 'before initialize callback must run for year attribute' do - meeting = CommitteeMeeting.create( - meeting_no: 1, meeting_date: Time.current, unit: units(:muhendislik_fakultesi_yonetim_kurulu) - ) - assert_equal meeting.year, Time.current.year - end + has_validation_callback :assign_year, :before end diff --git a/test/models/concerns/association_test_module.rb b/test/models/concerns/association_test_module.rb index edb240458..8d8a405ea 100644 --- a/test/models/concerns/association_test_module.rb +++ b/test/models/concerns/association_test_module.rb @@ -4,20 +4,12 @@ module AssociationTestModule extend ActiveSupport::Concern class_methods do - # Examples - # has_many :addresses - # has_many :addresses, :identities, :student_numbers - # has_many :addresses, object: Address.first - # belongs_to :user - # belongs_to :user :unit - # has_one :identity - %i[has_many has_one belongs_to].each do |method| - define_method(method) do |*associations, object: nil| + define_method(method) do |*associations| associations.each do |association| - test "#{object} #{method} #{association}" do + test "can respond to #{method} #{association}" do # rubocop:disable Lint/AmbiguousBlockAssociation - object ||= class_name.delete_suffix('Test').constantize + object = class_name.delete_suffix('Test').constantize assert object.reflect_on_all_associations(method).select { |relation| relation.name.eql?(associations) } # rubocop:enable Lint/AmbiguousBlockAssociation end diff --git a/test/models/concerns/callback_test_module.rb b/test/models/concerns/callback_test_module.rb new file mode 100644 index 000000000..a792fe251 --- /dev/null +++ b/test/models/concerns/callback_test_module.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +module CallbackTestModule + extend ActiveSupport::Concern + + class_methods do + %i[initialize find touch validation save create update destroy commit rollback].each do |method| + define_method("has_#{method}_callback") do |key, kind| + test "has_#{method}_callback:#{kind} for #{key}" do + object = class_name.delete_suffix('Test').constantize + callbacks = object.send("_#{method}_callbacks") + assert callbacks.select { |callback| callback.filter.eql?(key) && callback.kind.eql?(kind) }.any? + end + end + end + end +end diff --git a/test/models/concerns/enumeration_test_module.rb b/test/models/concerns/enumeration_test_module.rb index 014f354bf..fa9578407 100644 --- a/test/models/concerns/enumeration_test_module.rb +++ b/test/models/concerns/enumeration_test_module.rb @@ -4,17 +4,12 @@ module EnumerationTestModule extend ActiveSupport::Concern class_methods do - # Examples - # has_enum :term, values: { fall: 0, spring: 1, summer: 2 } - # has_enum :term, values: { fall: 0, spring: 1, summer: 2 }, object: AcademicTerm.first - - def has_enum(enumerated_attribute, enums, object: nil) - enums = enums[:values] + def has_enum(enumerated_attribute, **enums) enums.each do |key, value| - test "#{object} has a enum key (#{key}) with a value of #{value}" do - object ||= class_name.delete_suffix('Test').constantize.take - enums = object.defined_enums[enumerated_attribute.to_s].with_indifferent_access - assert_equal enums[key], value + test "has a enum key (#{key}) with a value of #{value}" do + object = class_name.delete_suffix('Test').constantize.take + object_enums = object.defined_enums[enumerated_attribute.to_s].with_indifferent_access + assert_equal object_enums[key], value end end end diff --git a/test/models/concerns/reference_test_module.rb b/test/models/concerns/reference_test_module.rb index 3059f326b..b96849380 100644 --- a/test/models/concerns/reference_test_module.rb +++ b/test/models/concerns/reference_test_module.rb @@ -7,6 +7,9 @@ module ReferenceTestModule # callbacks included do + include CallbackTestModule + include ValidationTestModule + # validations: presence validates_presence_of :name validates_presence_of :code @@ -19,13 +22,10 @@ module ReferenceTestModule validates_length_of :name # validations: numericality - validates_numericality_of(:code) - validates_numerical_range(:code, :greater_than_or_equal_to, 0) + validates_numericality_of :code + validates_numerical_range :code, greater_than_or_equal_to: 0 # callbacks - test 'callbacks must titlecase the name for reference objects' do - @object.update(name: 'ışık ılık süt iç') - assert_equal @object.name, 'Işık Ilık Süt İç' - end + has_validation_callback :capitalize_attributes, :before end end diff --git a/test/models/concerns/validation_test_module.rb b/test/models/concerns/validation_test_module.rb index 2953f6a63..d77fcd6c1 100644 --- a/test/models/concerns/validation_test_module.rb +++ b/test/models/concerns/validation_test_module.rb @@ -4,14 +4,10 @@ module ValidationTestModule extend ActiveSupport::Concern class_methods do - # Examples - # validates_presence_of :name - # validates_presence_of :name, object: Unit.first - # validates_presence_of :name, :code :year - def validates_presence_of(*attributes, object: nil) + def validates_presence_of(*attributes) attributes.each do |attribute| - test "#{attribute} must be present (presence: true) for #{object}" do - object ||= class_name.delete_suffix('Test').constantize.take + test "#{attribute} must be present (presence: true)" do + object = class_name.delete_suffix('Test').constantize.take object.send("#{attribute}=", nil) assert_not object.valid? assert_not_empty object.errors[attribute] @@ -19,26 +15,20 @@ def validates_presence_of(*attributes, object: nil) end end - # Examples - # validates_presence_of_nested_model :lecturers - # validates_presence_of_nested_model :lecturers, ids: 'employee_ids' - def validates_presence_of_nested_model(attribute, ids: nil, object: nil) - test "nested model (#{attribute}) must be present for #{object}" do + def validates_presence_of_nested_model(attribute, ids: nil) + test "nested model (#{attribute}) must be present" do ids ||= "#{attribute.to_s.singularize}_ids" - object ||= class_name.delete_suffix('Test').constantize.take + object = class_name.delete_suffix('Test').constantize.take object.send("#{ids}=", nil) assert_not object.valid? assert_not_empty object.errors[attribute] end end - # Examples - # validates_uniqueness_of :name - # validates_uniqueness_of :name, :code, :year - def validates_uniqueness_of(*attributes, object: nil) + def validates_uniqueness_of(*attributes) attributes.each do |attribute| - test "#{attribute} must be unique (uniqueness: true) for #{object}" do - object ||= class_name.delete_suffix('Test').constantize.take + test "#{attribute} must be unique (uniqueness: true)" do + object = class_name.delete_suffix('Test').constantize.take duplicate_object = object.dup assert_not duplicate_object.valid? assert_not_empty duplicate_object.errors[attribute] @@ -46,56 +36,53 @@ def validates_uniqueness_of(*attributes, object: nil) end end - # Examples - # validates_length_of :name - # validates_length_of :description, type: :text - # validates_length_of :name, :code, :year - # validates_length_of :description, :summary, type: :text) - def validates_length_of(*attributes, type: :string, object: nil) - long_string = if type == :string - (0..256).map { ('a'..'z').to_a[rand(26)] }.join - elsif type == :text - (0..65_536).map { ('a'..'z').to_a[rand(26)] }.join - end + def validates_length_of(attribute, **args) + args = { maximum: 255 } if args.blank? + key = args.keys.first + value = args.values.first - attributes.each do |attribute| - test "#{attribute} can not be longer than character limits for #{object}" do - object ||= class_name.delete_suffix('Test').constantize.take - object.send("#{attribute}=", long_string) - assert_not object.valid? - assert object.errors.details[attribute].map { |err| err[:error] }.include?(:too_long) - end + value, error_key = if key.eql?(:is) + [value += 1, :wrong_length] + elsif key.eql?(:minimum) + [value -= 1, :too_short] + elsif key.eql?(:maximum) + [value += 1, :too_long] + end + + test "#{attribute} length must be #{args}" do + object = class_name.delete_suffix('Test').constantize.take + object.send("#{attribute}=", (0..value).map { ('a'..'z').to_a[rand(26)] }.join) + assert_not object.valid? + assert object.errors.details[attribute].map { |err| err[:error] }.include?(error_key) end end - # Examples - # validates_numericality_of :year - def validates_numericality_of(attribute, object: nil) - test "#{attribute} attribute of #{object} must be a number" do - object ||= class_name.delete_suffix('Test').constantize.take + def validates_numericality_of(attribute) + test "#{attribute} must be a number" do + object = class_name.delete_suffix('Test').constantize.take object.send("#{attribute}=", 'some string') assert_not object.valid? assert object.errors.details[attribute].map { |err| err[:error] }.include?(:not_a_number) end end - # Examples - # validates_numerical_range(:year, :greater_than_or_equal_to, 100) - # validates_numerical_range(:year, :less_than_or_equal_to, 100) - def validates_numerical_range(attribute, range_identifier, number, object: nil) - case range_identifier - when :greater_than, :less_than - number = number - when :greater_than_or_equal_to - number -= 1 - when :less_than_or_equal_to - number += 1 - end - test "#{attribute} attribute of #{object} must be #{range_identifier} #{number}" do - object ||= class_name.delete_suffix('Test').constantize.take - object.send("#{attribute}=", number) + def validates_numerical_range(attribute, **args) + key = args.keys.first + value = args.values.first + + value = if key.eql?(:greater_than) || key.eql?(:less_than) + value + elsif key.eql?(:greater_than_or_equal_to) + value -= 1 + elsif key.eql?(:less_than_or_equal_to) + value += 1 + end + + test "#{attribute} must be #{key} #{value}" do + object = class_name.delete_suffix('Test').constantize.take + object.send("#{attribute}=", value) assert_not object.valid? - assert object.errors.details[attribute].map { |err| err[:error] }.include?(range_identifier) + assert object.errors.details[attribute].map { |err| err[:error] }.include?(key) end end end diff --git a/test/models/country_test.rb b/test/models/country_test.rb index 56a032bcb..5340dc814 100644 --- a/test/models/country_test.rb +++ b/test/models/country_test.rb @@ -4,6 +4,7 @@ class CountryTest < ActiveSupport::TestCase include AssociationTestModule + include CallbackTestModule include ValidationTestModule # relations @@ -27,51 +28,16 @@ class CountryTest < ActiveSupport::TestCase # validations: length validates_length_of :name + validates_length_of :alpha_2_code, is: 2 + validates_length_of :alpha_3_code, is: 3 + validates_length_of :numeric_code, is: 3 + validates_length_of :mernis_code, is: 4 # validations: numericality - validates_numericality_of(:yoksis_code) - validates_numerical_range(:yoksis_code, :greater_than_or_equal_to, 1) + validates_numericality_of :numeric_code + validates_numericality_of :yoksis_code + validates_numerical_range :yoksis_code, greater_than_or_equal_to: 1 # callbacks - test 'callbacks must titlecase the name and must upcase the iso codes of a country' do - country = Country.create(name: 'wonderland of alice', alpha_2_code: 'wl', alpha_3_code: 'wlx', numeric_code: 123) - assert_equal country.name, 'Wonderland Of Alice' - assert_equal country.alpha_2_code, 'WL' - assert_equal country.alpha_3_code, 'WLX' - end - - # other validations - test 'alpha_2_code must be 2 characters' do - fake = countries(:turkey).dup - fake.alpha_2_code = (0...3).map { ('a'..'z').to_a[rand(26)] }.join - assert_not fake.valid? - assert fake.errors.details[:alpha_2_code].map { |err| err[:error] }.include?(:wrong_length) - end - - test 'alpha_3_code must be 3 characters' do - fake = countries(:turkey).dup - fake.alpha_3_code = (0...4).map { ('a'..'z').to_a[rand(26)] }.join - assert_not fake.valid? - assert fake.errors.details[:alpha_3_code].map { |err| err[:error] }.include?(:wrong_length) - end - - test 'numeric_code must be an integer with 3 digits' do - fake = countries(:turkey).dup - fake.numeric_code = (0...4).map { ('a'..'z').to_a[rand(26)] }.join - assert_not fake.valid? - - error_codes = fake.errors.details[:numeric_code].map { |err| err[:error] } - assert error_codes.include?(:wrong_length) - assert error_codes.include?(:not_a_number) - end - - test 'mernis_code must be an integer with 4 digits' do - fake = countries(:turkey).dup - fake.mernis_code = (0...5).map { ('a'..'z').to_a[rand(26)] }.join - assert_not fake.valid? - - error_codes = fake.errors.details[:mernis_code].map { |err| err[:error] } - assert error_codes.include?(:wrong_length) - assert error_codes.include?(:not_a_number) - end + has_validation_callback :capitalize_attributes, :before end diff --git a/test/models/course_assessment_method_test.rb b/test/models/course_assessment_method_test.rb index b31df565a..0a05ce217 100644 --- a/test/models/course_assessment_method_test.rb +++ b/test/models/course_assessment_method_test.rb @@ -6,10 +6,6 @@ class CourseAssessmentMethodTest < ActiveSupport::TestCase include AssociationTestModule include ValidationTestModule - setup do - @course_assessment_method = course_assessment_methods(:ati_midterm_exam_assessment) - end - # relations belongs_to :assessment_method belongs_to :course_evaluation_type @@ -21,7 +17,7 @@ class CourseAssessmentMethodTest < ActiveSupport::TestCase validates_uniqueness_of :assessment_method # validations: numericality - validates_numericality_of(:percentage) - validates_numerical_range(:percentage, :greater_than_or_equal_to, 0) - validates_numerical_range(:percentage, :less_than_or_equal_to, 100) + validates_numericality_of :percentage + validates_numerical_range :percentage, greater_than_or_equal_to: 0 + validates_numerical_range :percentage, less_than_or_equal_to: 100 end diff --git a/test/models/course_evaluation_type_test.rb b/test/models/course_evaluation_type_test.rb index 9199f5067..d1480a705 100644 --- a/test/models/course_evaluation_type_test.rb +++ b/test/models/course_evaluation_type_test.rb @@ -6,10 +6,6 @@ class CourseEvaluationTypeTest < ActiveSupport::TestCase include AssociationTestModule include ValidationTestModule - setup do - @course_evaluation_type = course_evaluation_types(:ati_midterm_evaluation_type) - end - # relations belongs_to :available_course belongs_to :evaluation_type @@ -20,14 +16,10 @@ class CourseEvaluationTypeTest < ActiveSupport::TestCase validates_presence_of :percentage # validations: numericality - validates_numericality_of(:percentage) - validates_numerical_range(:percentage, :greater_than_or_equal_to, 0) - validates_numerical_range(:percentage, :less_than_or_equal_to, 100) + validates_numericality_of :percentage + validates_numerical_range :percentage, greater_than_or_equal_to: 0 + validates_numerical_range :percentage, less_than_or_equal_to: 100 # validations: uniqueness - test 'uniqueness validations for evaluation type scoped with available course' do - fake = @course_evaluation_type.dup - assert_not fake.valid? - assert_not_empty fake.errors[:evaluation_type] - end + validates_uniqueness_of :evaluation_type end diff --git a/test/models/course_group_test.rb b/test/models/course_group_test.rb index b5cb997b1..9f916452a 100644 --- a/test/models/course_group_test.rb +++ b/test/models/course_group_test.rb @@ -4,12 +4,9 @@ class CourseGroupTest < ActiveSupport::TestCase include AssociationTestModule + include CallbackTestModule include ValidationTestModule - setup do - @course_group = course_groups(:bilgisayar_muhendligi_teknik_secmeli_1) - end - # relations belongs_to :course_group_type belongs_to :unit @@ -27,4 +24,7 @@ class CourseGroupTest < ActiveSupport::TestCase # validations: uniqueness validates_uniqueness_of :name + + # callbacks + has_validation_callback :capitalize_attributes, :before end diff --git a/test/models/course_group_type_test.rb b/test/models/course_group_type_test.rb index 0f56b60a9..6c11a9291 100644 --- a/test/models/course_group_type_test.rb +++ b/test/models/course_group_type_test.rb @@ -4,6 +4,7 @@ class CourseGroupTypeTest < ActiveSupport::TestCase include AssociationTestModule + include CallbackTestModule include ValidationTestModule # relations @@ -17,4 +18,7 @@ class CourseGroupTypeTest < ActiveSupport::TestCase # validations: length validates_length_of :name + + # callbacks + has_validation_callback :capitalize_attributes, :before end diff --git a/test/models/course_test.rb b/test/models/course_test.rb index c4f7f21fb..61af5d487 100644 --- a/test/models/course_test.rb +++ b/test/models/course_test.rb @@ -4,13 +4,10 @@ class CourseTest < ActiveSupport::TestCase include AssociationTestModule + include CallbackTestModule include EnumerationTestModule include ValidationTestModule - setup do - @course = courses(:test) - end - # relations belongs_to :course_type belongs_to :language @@ -34,18 +31,15 @@ class CourseTest < ActiveSupport::TestCase validates_length_of :code # enums - has_enum :status, values: { passive: 0, active: 1 } - has_enum :program_type, values: { associate: 0, undergraduate: 1, master: 2, doctoral: 3 } + has_enum :status, passive: 0, active: 1 + has_enum :program_type, associate: 0, undergraduate: 1, master: 2, doctoral: 3 # callbacks - test 'callbacks must titlecase the name for a course' do - course = @course.dup - course.update(code: 'DD101', name: 'deNEme dErSi') - assert_equal course.name, 'Deneme Dersi' - end + has_validation_callback :capitalize_attributes, :before + has_validation_callback :assign_credit, :before test 'callbacks must set value the credit for a course' do - course = @course.dup + course = courses(:test).dup course.update(code: 'DD101', theoric: 10, practice: 3) assert_equal course.credit, 11.5 end diff --git a/test/models/course_type_test.rb b/test/models/course_type_test.rb index 4ce961a91..9dbc494b3 100644 --- a/test/models/course_type_test.rb +++ b/test/models/course_type_test.rb @@ -6,10 +6,6 @@ class CourseTypeTest < ActiveSupport::TestCase include AssociationTestModule include ValidationTestModule - setup do - @course_type = course_types(:internship) - end - # relations has_many :courses @@ -27,9 +23,5 @@ class CourseTypeTest < ActiveSupport::TestCase validates_length_of :code # validations: numericality - test 'presence numericality for min_credit of a course type' do - @course_type.min_credit = -1 - assert_not @course_type.valid? - assert_not_empty @course_type.errors[:min_credit] - end + validates_numerical_range :min_credit, greater_than_or_equal_to: 0 end diff --git a/test/models/curriculum_course_group_test.rb b/test/models/curriculum_course_group_test.rb index 0e8b41aee..3764a784a 100644 --- a/test/models/curriculum_course_group_test.rb +++ b/test/models/curriculum_course_group_test.rb @@ -6,10 +6,6 @@ class CurriculumCourseGroupTest < ActiveSupport::TestCase include AssociationTestModule include ValidationTestModule - setup do - @curriculum_course_group = curriculum_course_groups(:one) - end - # relations belongs_to :course_group belongs_to :curriculum_semester @@ -25,11 +21,11 @@ class CurriculumCourseGroupTest < ActiveSupport::TestCase validates_uniqueness_of :course_group_id # validations: numericality - validates_numericality_of(:ects) - validates_numerical_range(:ects, :greater_than, 0) + validates_numericality_of :ects + validates_numerical_range :ects, greater_than: 0 # delegates test 'must have a name method' do - assert_equal @curriculum_course_group.name, @curriculum_course_group.course_group.name + assert_equal curriculum_course_groups(:one).name, curriculum_course_groups(:one).course_group.name end end diff --git a/test/models/curriculum_course_test.rb b/test/models/curriculum_course_test.rb index 5edb95225..25f3fd450 100644 --- a/test/models/curriculum_course_test.rb +++ b/test/models/curriculum_course_test.rb @@ -4,13 +4,10 @@ class CurriculumCourseTest < ActiveSupport::TestCase include AssociationTestModule + include CallbackTestModule include EnumerationTestModule include ValidationTestModule - setup do - @curriculum_course = curriculum_courses(:one) - end - # relations belongs_to :course belongs_to :curriculum_semester @@ -21,18 +18,20 @@ class CurriculumCourseTest < ActiveSupport::TestCase validates_presence_of :ects # validations: numericality - validates_numericality_of(:ects) - validates_numerical_range(:ects, :greater_than, 0) + validates_numericality_of :ects + validates_numerical_range :ects, greater_than: 0 # validations: uniqueness validates_uniqueness_of :course # enums - has_enum :type, values: { compulsory: 0, elective: 1 } + has_enum :type, compulsory: 0, elective: 1 # callbacks + has_validation_callback :assign_type, :before + test 'callbacks must set value the type for a curriculum course' do - curriculum_course = @curriculum_course.dup + curriculum_course = curriculum_courses(:one).dup curriculum_course.course = courses(:test) curriculum_course.save assert_equal 'compulsory', curriculum_course.type diff --git a/test/models/curriculum_semester_test.rb b/test/models/curriculum_semester_test.rb index 9defb22af..e109b81ca 100644 --- a/test/models/curriculum_semester_test.rb +++ b/test/models/curriculum_semester_test.rb @@ -7,10 +7,6 @@ class CurriculumSemesterTest < ActiveSupport::TestCase include EnumerationTestModule include ValidationTestModule - setup do - @semester = curriculum_semesters(:one) - end - # relations belongs_to :curriculum has_many :courses @@ -22,14 +18,14 @@ class CurriculumSemesterTest < ActiveSupport::TestCase validates_presence_of :sequence # validations: numericality - validates_numericality_of(:sequence) - validates_numerical_range(:sequence, :greater_than, 0) + validates_numericality_of :sequence + validates_numerical_range :sequence, greater_than: 0 # enums - has_enum :term, values: { fall: 0, spring: 1, summer: 2 } + has_enum :term, fall: 0, spring: 1, summer: 2 # custom methods test 'total_ects method' do - assert_equal @semester.total_ects, 6.0 + assert_equal curriculum_semesters(:one).total_ects, 6.0 end end diff --git a/test/models/curriculum_test.rb b/test/models/curriculum_test.rb index d799bfa4b..3210e6311 100644 --- a/test/models/curriculum_test.rb +++ b/test/models/curriculum_test.rb @@ -7,10 +7,6 @@ class CurriculumTest < ActiveSupport::TestCase include EnumerationTestModule include ValidationTestModule - setup do - @curriculum = curriculums(:one) - end - # constants { MAX_NUMBER_OF_SEMESTERS: 12, @@ -47,23 +43,23 @@ class CurriculumTest < ActiveSupport::TestCase validates_uniqueness_of :name # validations: numericality - validates_numericality_of(:semesters_count) - validates_numerical_range(:semesters_count, :greater_than_or_equal_to, 0) + validates_numericality_of :semesters_count + validates_numerical_range :semesters_count, greater_than_or_equal_to: 0 # enums - has_enum :status, values: { passive: 0, active: 1 } + has_enum :status, passive: 0, active: 1 # custom methods test 'build_semester method' do - Curriculum.reset_counters(@curriculum.id, :semesters_count) - @curriculum.semesters.destroy_all - @curriculum.build_semesters(number_of_semesters: 8, type: :periodic) - assert_equal 8, @curriculum.semesters.size - assert_equal [1, 2, 3, 4], @curriculum.semesters.pluck(:year).uniq + Curriculum.reset_counters(curriculums(:one).id, :semesters_count) + curriculums(:one).semesters.destroy_all + curriculums(:one).build_semesters(number_of_semesters: 8, type: :periodic) + assert_equal 8, curriculums(:one).semesters.size + assert_equal [1, 2, 3, 4], curriculums(:one).semesters.pluck(:year).uniq - @curriculum.semesters = [] - @curriculum.build_semesters(number_of_semesters: 2, type: :yearly) - assert_equal 2, @curriculum.semesters.size - assert_equal [1, 2], @curriculum.semesters.pluck(:year).uniq + curriculums(:one).semesters = [] + curriculums(:one).build_semesters(number_of_semesters: 2, type: :yearly) + assert_equal 2, curriculums(:one).semesters.size + assert_equal [1, 2], curriculums(:one).semesters.pluck(:year).uniq end end diff --git a/test/models/district_test.rb b/test/models/district_test.rb index f2efcfd74..5c346497c 100644 --- a/test/models/district_test.rb +++ b/test/models/district_test.rb @@ -4,6 +4,7 @@ class DistrictTest < ActiveSupport::TestCase include AssociationTestModule + include CallbackTestModule include ValidationTestModule # relations @@ -21,20 +22,11 @@ class DistrictTest < ActiveSupport::TestCase # validations: length validates_length_of :name + validates_length_of :mernis_code, is: 4 + + # validations: numericality + validates_numericality_of :mernis_code # callbacks - test 'callbacks must titlecase the name of a district' do - district = District.create!(name: 'wonderland of samsun', city: cities(:samsun), active: true) - assert_equal district.name, 'Wonderland Of Samsun' - end - - test 'mernis_code must be an integer with 4 digits' do - fake = districts(:vezirkopru).dup - fake.mernis_code = (0...5).map { ('a'..'z').to_a[rand(26)] }.join - assert_not fake.valid? - - error_codes = fake.errors.details[:mernis_code].map { |err| err[:error] } - assert error_codes.include?(:wrong_length) - assert error_codes.include?(:not_a_number) - end + has_validation_callback :capitalize_attributes, :before end diff --git a/test/models/evaluation_type_test.rb b/test/models/evaluation_type_test.rb index 8d6722d56..45cfb844f 100644 --- a/test/models/evaluation_type_test.rb +++ b/test/models/evaluation_type_test.rb @@ -5,6 +5,7 @@ class EvaluationTypeTest < ActiveSupport::TestCase include AssociationTestModule include ValidationTestModule + include CallbackTestModule # relations has_many :available_courses @@ -20,8 +21,5 @@ class EvaluationTypeTest < ActiveSupport::TestCase validates_length_of :name # callbacks - test 'callbacks must titlecase the name of a evaluation type' do - evaluation_type = EvaluationType.create!(name: 'test evaluation type') - assert_equal evaluation_type.name, 'Test Evaluation Type' - end + has_validation_callback :capitalize_attributes, :before end diff --git a/test/models/high_school_type_test.rb b/test/models/high_school_type_test.rb index 753da59fb..0a920b43f 100644 --- a/test/models/high_school_type_test.rb +++ b/test/models/high_school_type_test.rb @@ -4,13 +4,8 @@ class HighSchoolTypeTest < ActiveSupport::TestCase include AssociationTestModule - include ValidationTestModule include ReferenceTestModule - setup do - @object = high_school_types(:aksam_lisesi) - end - # relations has_many :prospective_students end diff --git a/test/models/identity_test.rb b/test/models/identity_test.rb index 57213e77c..d7245f211 100644 --- a/test/models/identity_test.rb +++ b/test/models/identity_test.rb @@ -4,6 +4,7 @@ class IdentityTest < ActiveSupport::TestCase include AssociationTestModule + include CallbackTestModule include EnumerationTestModule include ValidationTestModule @@ -30,40 +31,19 @@ class IdentityTest < ActiveSupport::TestCase validates_length_of :place_of_birth validates_length_of :registered_to - # validations: uniqueness - test 'an identity can not belong to multiple students' do - student_identity = identities(:formal_student).dup - assert_not student_identity.valid? - assert_not_empty student_identity.errors[:student_id] - end + # callbacks + has_save_callback :capitalize_attributes, :before # enums - has_enum :type, values: { formal: 1, informal: 2 } - has_enum :gender, values: { male: 1, female: 2, other: 3 } - has_enum :marital_status, values: { single: 1, married: 2, divorced: 3, unknown: 4 } + has_enum :type, formal: 1, informal: 2 + has_enum :gender, male: 1, female: 2, other: 3 + has_enum :marital_status, single: 1, married: 2, divorced: 3, unknown: 4 # scopes test 'user_identity can return formal identities which does not belongs_to students' do assert_equal identities(:formal_user), users(:serhat).identities.user_identity end - # callbacks - test 'callbacks must titlecase first_name, mothers_name, fathers_name and place_of_birth of an identity' do - identity = identities(:formal_user) - identity.update( - first_name: 'ışık', - last_name: 'ılık', - mothers_name: 'süt', - fathers_name: 'iç', - place_of_birth: 'ıişüğ' - ) - assert_equal identity.first_name, 'Işık' - assert_equal identity.last_name, 'ILIK' - assert_equal identity.mothers_name, 'Süt' - assert_equal identity.fathers_name, 'İç' - assert_equal identity.place_of_birth, 'Iişüğ' - end - # identity validator test 'a user can only have one formal user identity' do fake = identities(:formal_user).dup diff --git a/test/models/language_test.rb b/test/models/language_test.rb index f87d30242..342e69b7f 100644 --- a/test/models/language_test.rb +++ b/test/models/language_test.rb @@ -4,6 +4,7 @@ class LanguageTest < ActiveSupport::TestCase include AssociationTestModule + include CallbackTestModule include ValidationTestModule # relations @@ -23,9 +24,5 @@ class LanguageTest < ActiveSupport::TestCase validates_length_of :iso # callbacks - test 'callbacks must titlecase the name of a language' do - language = Language.create(name: 'jewish', iso: 'jww') - assert_equal language.name, 'Jewish' - assert_equal language.iso, 'JWW' - end + has_validation_callback :capitalize_attributes, :before end diff --git a/test/models/prospective_student_test.rb b/test/models/prospective_student_test.rb index 49700f2fc..d98e3f377 100644 --- a/test/models/prospective_student_test.rb +++ b/test/models/prospective_student_test.rb @@ -4,6 +4,7 @@ class ProspectiveStudentTest < ActiveSupport::TestCase include AssociationTestModule + include CallbackTestModule include EnumerationTestModule include ValidationTestModule @@ -38,32 +39,13 @@ class ProspectiveStudentTest < ActiveSupport::TestCase validates_length_of :registration_district # enums - has_enum :additional_score, values: { handicapped: 1 } - has_enum :gender, values: { male: 1, female: 2 } - has_enum :nationality, values: { turkish: 1, kktc: 2, foreign: 3 } - has_enum :placement_type, values: { general_score: 1, additional_score: 2 } + has_enum :additional_score, handicapped: 1 + has_enum :gender, male: 1, female: 2 + has_enum :nationality, turkish: 1, kktc: 2, foreign: 3 + has_enum :placement_type, general_score: 1, additional_score: 2 # callbacks - test 'callbacks must titlecase the name for a prospective_student' do - prospective_student = prospective_students(:serhat).dup - prospective_student.update!( - id_number: '10114899148', - first_name: 'first name', - last_name: 'last name', - fathers_name: 'fathers name', - mothers_name: 'mothers name', - place_of_birth: 'place of birth', - registration_city: 'registration city', - registration_district: 'registration district' - ) - assert_equal prospective_student.first_name, 'First Name' - assert_equal prospective_student.last_name, 'LAST NAME' - assert_equal prospective_student.fathers_name, 'Fathers Name' - assert_equal prospective_student.mothers_name, 'Mothers Name' - assert_equal prospective_student.place_of_birth, 'Place Of Birth' - assert_equal prospective_student.registration_city, 'Registration City' - assert_equal prospective_student.registration_district, 'Registration District' - end + has_create_callback :capitalize_attributes, :before # search test 'prospective_student is a searchable model' do diff --git a/test/models/registration_document_test.rb b/test/models/registration_document_test.rb index d4120073f..30bd6a031 100644 --- a/test/models/registration_document_test.rb +++ b/test/models/registration_document_test.rb @@ -19,7 +19,7 @@ class RegistrationDocumentTest < ActiveSupport::TestCase validates_uniqueness_of :unit_id # validations: length - validates_length_of :description, type: :text + validates_length_of :description, maximum: 65_535 # delegations test 'a registration document can refer to the name field of related document_type' do diff --git a/test/models/student_disability_type_test.rb b/test/models/student_disability_type_test.rb index 2f9d62cf6..7a18709db 100644 --- a/test/models/student_disability_type_test.rb +++ b/test/models/student_disability_type_test.rb @@ -4,13 +4,8 @@ class StudentDisabilityTypeTest < ActiveSupport::TestCase include AssociationTestModule - include ValidationTestModule include ReferenceTestModule - setup do - @object = student_disability_types(:autism) - end - # relations has_many :prospective_students end diff --git a/test/models/student_drop_out_type_test.rb b/test/models/student_drop_out_type_test.rb index 1218a86a5..e6dd37458 100644 --- a/test/models/student_drop_out_type_test.rb +++ b/test/models/student_drop_out_type_test.rb @@ -3,10 +3,5 @@ require 'test_helper' class StudentDropOutTypeTest < ActiveSupport::TestCase - include ValidationTestModule include ReferenceTestModule - - setup do - @object = student_drop_out_types(:erasmus) - end end diff --git a/test/models/student_education_level_test.rb b/test/models/student_education_level_test.rb index b74be2539..1228842b9 100644 --- a/test/models/student_education_level_test.rb +++ b/test/models/student_education_level_test.rb @@ -3,10 +3,5 @@ require 'test_helper' class StudentEducationLevelTest < ActiveSupport::TestCase - include ValidationTestModule include ReferenceTestModule - - setup do - @object = student_education_levels(:phd) - end end diff --git a/test/models/student_entrance_point_type_test.rb b/test/models/student_entrance_point_type_test.rb index 46831bd17..24a2f363d 100644 --- a/test/models/student_entrance_point_type_test.rb +++ b/test/models/student_entrance_point_type_test.rb @@ -3,10 +3,5 @@ require 'test_helper' class StudentEntrancePointTypeTest < ActiveSupport::TestCase - include ValidationTestModule include ReferenceTestModule - - setup do - @object = student_entrance_point_types(:mf1) - end end diff --git a/test/models/student_entrance_type_test.rb b/test/models/student_entrance_type_test.rb index 86ac2d90d..b27cb0830 100644 --- a/test/models/student_entrance_type_test.rb +++ b/test/models/student_entrance_type_test.rb @@ -4,13 +4,8 @@ class StudentEntranceTypeTest < ActiveSupport::TestCase include AssociationTestModule - include ValidationTestModule include ReferenceTestModule - setup do - @object = student_entrance_types(:dgs) - end - # relations has_many :prospective_students end diff --git a/test/models/student_grade_test.rb b/test/models/student_grade_test.rb index 420f83a69..e4cdb2290 100644 --- a/test/models/student_grade_test.rb +++ b/test/models/student_grade_test.rb @@ -3,10 +3,5 @@ require 'test_helper' class StudentGradeTest < ActiveSupport::TestCase - include ValidationTestModule include ReferenceTestModule - - setup do - @object = student_grades(:scientific_preparation) - end end diff --git a/test/models/student_grading_system_test.rb b/test/models/student_grading_system_test.rb index f00a4f650..cd5c70285 100644 --- a/test/models/student_grading_system_test.rb +++ b/test/models/student_grading_system_test.rb @@ -3,10 +3,5 @@ require 'test_helper' class StudentGradingSystemTest < ActiveSupport::TestCase - include ValidationTestModule include ReferenceTestModule - - setup do - @object = student_grading_systems(:four_point_grading_system) - end end diff --git a/test/models/student_punishment_type_test.rb b/test/models/student_punishment_type_test.rb index 225fb2ab5..11c2d5649 100644 --- a/test/models/student_punishment_type_test.rb +++ b/test/models/student_punishment_type_test.rb @@ -3,10 +3,5 @@ require 'test_helper' class StudentPunishmentTypeTest < ActiveSupport::TestCase - include ValidationTestModule include ReferenceTestModule - - setup do - @object = student_punishment_types(:warning) - end end diff --git a/test/models/student_studentship_status_test.rb b/test/models/student_studentship_status_test.rb index a40d0a2f1..aa0773794 100644 --- a/test/models/student_studentship_status_test.rb +++ b/test/models/student_studentship_status_test.rb @@ -3,10 +3,5 @@ require 'test_helper' class StudentStudentshipStatusTest < ActiveSupport::TestCase - include ValidationTestModule include ReferenceTestModule - - setup do - @object = student_studentship_statuses(:can_be_a_student) - end end diff --git a/test/models/student_test.rb b/test/models/student_test.rb index b3181ae24..768787549 100644 --- a/test/models/student_test.rb +++ b/test/models/student_test.rb @@ -4,6 +4,7 @@ class StudentTest < ActiveSupport::TestCase include AssociationTestModule + include CallbackTestModule include ValidationTestModule include ActiveJob::TestHelper @@ -21,13 +22,16 @@ class StudentTest < ActiveSupport::TestCase validates_uniqueness_of :student_number validates_uniqueness_of :unit_id + # callback tests + has_commit_callback :build_identity_information, :after + # delegations test 'a student can communicate with addresses over the user' do assert students(:serhat).addresses end - # callback tests - test 'student runs Kps::IdentitySaveJob after being created' do + # job tests + test 'student enqueues Kps::IdentitySaveJob after being created' do users(:serhat).students.destroy_all assert_enqueued_with(job: Kps::IdentitySaveJob) do Student.create(student_number: '1234', user: users(:serhat), unit: units(:omu)) diff --git a/test/models/unit_instruction_language_test.rb b/test/models/unit_instruction_language_test.rb index 1db094bb2..97ba72518 100644 --- a/test/models/unit_instruction_language_test.rb +++ b/test/models/unit_instruction_language_test.rb @@ -4,13 +4,8 @@ class UnitInstructionLanguageTest < ActiveSupport::TestCase include AssociationTestModule - include ValidationTestModule include ReferenceTestModule - setup do - @object = unit_instruction_languages(:english) - end - # relations has_many :units end diff --git a/test/models/unit_instruction_type_test.rb b/test/models/unit_instruction_type_test.rb index 571fa6bfb..79ac587ce 100644 --- a/test/models/unit_instruction_type_test.rb +++ b/test/models/unit_instruction_type_test.rb @@ -4,13 +4,8 @@ class UnitInstructionTypeTest < ActiveSupport::TestCase include AssociationTestModule - include ValidationTestModule include ReferenceTestModule - setup do - @object = unit_instruction_types(:normal_education) - end - # relations has_many :units end diff --git a/test/models/unit_status_test.rb b/test/models/unit_status_test.rb index 0eed15d0d..d156ad8b9 100644 --- a/test/models/unit_status_test.rb +++ b/test/models/unit_status_test.rb @@ -4,13 +4,8 @@ class UnitStatusTest < ActiveSupport::TestCase include AssociationTestModule - include ValidationTestModule include ReferenceTestModule - setup do - @object = unit_statuses(:passive) - end - # relations has_many :units end diff --git a/test/models/unit_type_test.rb b/test/models/unit_type_test.rb index ef6419541..3ea6674fc 100644 --- a/test/models/unit_type_test.rb +++ b/test/models/unit_type_test.rb @@ -5,32 +5,21 @@ class UnitTypeTest < ActiveSupport::TestCase include AssociationTestModule include EnumerationTestModule - include ValidationTestModule include ReferenceTestModule - setup do - @object = unit_types(:university) - end - # relations has_many :units # enums - has_enum :group, values: { - other: 0, - faculty: 1, - department: 2, - major: 3, - undergraduate_program: 4, - graduate_program: 5, - institute: 6, - research_center: 7, - committee: 8, - administrative: 9 - } - - test 'senate scope returns types of senato' do - assert_includes UnitType.senate, unit_types(:senate) - assert_not_includes UnitType.senate, unit_types(:university) - end + has_enum :group, + other: 0, + faculty: 1, + department: 2, + major: 3, + undergraduate_program: 4, + graduate_program: 5, + institute: 6, + research_center: 7, + committee: 8, + administrative: 9 end diff --git a/test/models/university_type_test.rb b/test/models/university_type_test.rb index 0b5ecb9cf..dde2201a5 100644 --- a/test/models/university_type_test.rb +++ b/test/models/university_type_test.rb @@ -4,13 +4,8 @@ class UniversityTypeTest < ActiveSupport::TestCase include AssociationTestModule - include ValidationTestModule include ReferenceTestModule - setup do - @object = university_types(:foundation) - end - # relations has_many :units end diff --git a/test/models/user_test.rb b/test/models/user_test.rb index 4f11411b7..287dc74b9 100644 --- a/test/models/user_test.rb +++ b/test/models/user_test.rb @@ -4,6 +4,7 @@ class UserTest < ActiveSupport::TestCase include AssociationTestModule + include CallbackTestModule include ValidationTestModule include ActiveJob::TestHelper @@ -31,18 +32,21 @@ class UserTest < ActiveSupport::TestCase # validations: length validates_length_of :email - - test 'id_number must be 11 characters' do - fake = users(:serhat).dup - ['123456789121', '123', '123456789,5', '14254455.77'].each do |value| - fake.id_number = value - assert_not fake.valid? - assert_not_empty fake.errors[:id_number] - end - end + validates_length_of :extension_number, maximum: 8 + validates_length_of :id_number, is: 11 + validates_length_of :linkedin, maximum: 50 + validates_length_of :phone_number + validates_length_of :skype, maximum: 50 + validates_length_of :twitter, maximum: 50 + validates_length_of :website, maximum: 50 # validations: numericality - validates_numericality_of(:id_number) + validates_numericality_of :id_number + validates_numericality_of :extension_number + + # callback tests + has_commit_callback :build_address_information, :after + has_commit_callback :build_identity_information, :after # validations: email test 'email addresses validated against RFC' do @@ -99,8 +103,8 @@ class UserTest < ActiveSupport::TestCase assert users(:serhat).accounts end - # callback tests - test 'user runs Kps::AddressSaveJob after being created' do + # job tests + test 'user enqueues Kps::AddressSaveJob after being created' do assert_enqueued_with(job: Kps::AddressSaveJob) do User.create( id_number: '12345678912', diff --git a/test/system/account_settings_page_flow_test.rb b/test/system/account_settings_page_flow_test.rb index 9b4797bd2..9b84e96d8 100644 --- a/test/system/account_settings_page_flow_test.rb +++ b/test/system/account_settings_page_flow_test.rb @@ -12,7 +12,7 @@ class AccountSettingsFlowTest < ApplicationSystemTestCase SUPPORTED_SCREEN_RESOLUTIONS.each do |resolution| test "can update account password with a valid password under a #{resolution} screen" do page.driver.browser.manage.window.resize_to(*resolution) - visit(edit_user_registration_path) + visit(account_path) { password: 'password', password_confirmation: 'password', @@ -21,12 +21,12 @@ class AccountSettingsFlowTest < ApplicationSystemTestCase fill_in("user[#{key}]", with: value) end click_button(t('helpers.submit.user.update')) - assert_equal t('devise.registrations.updated'), page.find('div', class: 'toast-message').text + assert_equal t('devise.registrations.user.updated'), page.find('div', class: 'toast-message').text end test "can not update account password with a missing password under a #{resolution} screen" do page.driver.browser.manage.window.resize_to(*resolution) - visit(edit_user_registration_path) + visit(account_path) { password: 'password', password_confirmation: 'password' diff --git a/test/system/login_page_flow_test.rb b/test/system/login_page_flow_test.rb index 3d13a9870..a1d287518 100644 --- a/test/system/login_page_flow_test.rb +++ b/test/system/login_page_flow_test.rb @@ -8,13 +8,13 @@ class LoginPageFlowTest < ApplicationSystemTestCase test "can login with correct credentials with a #{resolution} screen" do page.driver.browser.manage.window.resize_to(resolution[0], resolution[1]) visit('/') - assert find_button(t('devise.common.login'), visible: true).visible? - assert find_link(t('devise.sessions.new.did_you_forget'), visible: true).visible? - assert find_link(t('devise.sessions.new.create_account'), visible: true).visible? + assert find_button(t('account.sessions.new.login'), visible: true).visible? + assert find_link(t('account.sessions.new.did_you_forget'), visible: true).visible? + assert find_link(t('account.sessions.new.create_account'), visible: true).visible? fill_in('user[id_number]', with: users(:serhat).id_number) fill_in('user[password]', with: '123456') - check(t('devise.sessions.new.remember_login')) - click_button(t('devise.common.login')) + check(t('account.sessions.new.remember_login')) + click_button(t('account.sessions.new.login')) assert_equal t('devise.sessions.signed_in'), page.find('div', class: 'toast-message').text end end diff --git a/test/system/profile_setting_flow_test.rb b/test/system/profile_setting_flow_test.rb index a585756e4..e5f30dd60 100644 --- a/test/system/profile_setting_flow_test.rb +++ b/test/system/profile_setting_flow_test.rb @@ -12,7 +12,7 @@ class ProfileSettingFlowTest < ApplicationSystemTestCase SUPPORTED_SCREEN_RESOLUTIONS.each do |resolution| test "can profile setting with correct credentials with a #{resolution} screen" do page.driver.browser.manage.window.resize_to(*resolution) - visit(user_profile_path(@user)) + visit(profile_path) attach_file('user[avatar]', File.absolute_path('test/fixtures/files/valid_jpg_picture.jpg')) { phone_number: '362 312 1919', @@ -26,7 +26,7 @@ class ProfileSettingFlowTest < ApplicationSystemTestCase fill_in("user[#{key}]", with: value) end click_button(t('save')) - assert_equal t('account.profile.update.success'), page.find('div', class: 'toast-message').text + assert_equal t('account.profile_settings.update.success'), page.find('div', class: 'toast-message').text end end end diff --git a/test/system/reset_password_flow_test.rb b/test/system/reset_password_flow_test.rb index 906934c60..96d34e0a3 100644 --- a/test/system/reset_password_flow_test.rb +++ b/test/system/reset_password_flow_test.rb @@ -7,12 +7,12 @@ class ResetPasswordFlowTest < ApplicationSystemTestCase SUPPORTED_SCREEN_RESOLUTIONS.each do |resolution| test "can login with correct credentials with a #{resolution} screen" do page.driver.browser.manage.window.resize_to(resolution[0], resolution[1]) - visit(new_user_password_path) - assert find_button(t('devise.passwords.new.send_instructions'), visible: true).visible? - assert find_link(t('devise.common.login'), visible: true).visible? - assert find_link(t('devise.common.register'), visible: true).visible? + visit(recover_path) + assert find_button(t('account.passwords.new.send_instructions'), visible: true).visible? + assert find_link(t('account.passwords.new.login'), visible: true).visible? + assert find_link(t('account.passwords.new.register'), visible: true).visible? fill_in('user[email]', with: users(:serhat).email) - click_button(t('devise.passwords.new.send_instructions')) + click_button(t('account.passwords.new.send_instructions')) assert_equal t('devise.passwords.send_instructions'), page.find('div', class: 'toast-message').text end end diff --git a/test/system/sign_up_page_flow_test.rb b/test/system/sign_up_page_flow_test.rb index 8f2428060..c2b88fa4a 100644 --- a/test/system/sign_up_page_flow_test.rb +++ b/test/system/sign_up_page_flow_test.rb @@ -8,26 +8,26 @@ class SignUpPageFlowTest < ApplicationSystemTestCase test "can sign up with a valid identification number under a #{resolution} screen" do skip 'this block on CircleCI since it makes requests to Xokul' if ENV['CI'] page.driver.browser.manage.window.resize_to(*resolution) - visit(new_user_registration_path) + visit(register_path) { id_number: '70336212330', email: 'new_user@gmail.com', password: '123456', password_confirmation: '123456' }.each do |key, value| fill_in("user[#{key}]", with: value) end - click_button(t('devise.common.register')) - assert_equal t('devise.registrations.signed_up'), page.find('div', class: 'toast-message').text + click_button(t('account.registrations.new.register')) + assert_equal t('devise.registrations.user.signed_up'), page.find('div', class: 'toast-message').text end test "can not sign up with missing credentials with a #{resolution} screen" do skip 'this block on CircleCI since it makes requests to Xokul' if ENV['CI'] page.driver.browser.manage.window.resize_to(*resolution) - visit(new_user_registration_path) + visit(register_path) { email: 'new_user@gmail.com' }.each do |key, value| fill_in("user[#{key}]", with: value) end - click_button(t('devise.common.register')) + click_button(t('account.registrations.new.register')) assert_not page.has_content?('Please fill out this field.') end end diff --git a/test/test_helper.rb b/test/test_helper.rb index 39c5a0e9c..ba3c196d9 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -24,9 +24,10 @@ # Test Modules require_relative 'models/concerns/association_test_module' -require_relative 'models/concerns/validation_test_module' +require_relative 'models/concerns/callback_test_module' require_relative 'models/concerns/enumeration_test_module' require_relative 'models/concerns/reference_test_module' +require_relative 'models/concerns/validation_test_module' module ActiveSupport class TestCase