From 96011fd315933443f827b74fd578579e07c85ec1 Mon Sep 17 00:00:00 2001 From: Michael Sipayung Date: Tue, 23 Jan 2024 14:18:38 +0700 Subject: [PATCH] unit testing for gender religion --- app/models/parent.rb | 4 +-- app/models/personal_gender_list.rb | 1 + app/models/personal_religion_list.rb | 2 ++ config/routes.rb | 2 ++ ...17020709_create_personal_religion_lists.rb | 9 ------- ...0117020749_create_personal_gender_lists.rb | 9 ------- db/schema.rb | 2 +- test/fixtures/personal_gender_lists.yml | 8 +++--- test/fixtures/personal_religion_lists.yml | 8 +++--- test/models/personal_gender_list_test.rb | 25 ++++++++++++++++--- test/models/personal_religion_list_test.rb | 25 ++++++++++++++++--- 11 files changed, 60 insertions(+), 35 deletions(-) delete mode 100644 db/migrate/20240117020709_create_personal_religion_lists.rb delete mode 100644 db/migrate/20240117020749_create_personal_gender_lists.rb diff --git a/app/models/parent.rb b/app/models/parent.rb index 02c951f..3363887 100644 --- a/app/models/parent.rb +++ b/app/models/parent.rb @@ -6,8 +6,8 @@ class Parent < ApplicationRecord # validates :nik_ibu, presence: true, length: { minimum: 16, maximum: 16 } validates :pendidikan_ayah, presence: true, length: { minimum: 2, maximum: 20 } validates :pendidikan_ibu, presence: true, length: { minimum: 2, maximum: 20 } - validates :pekerjaan_ayah, presence: true, length: { minimum: 4, maximum: 20 } - validates :pekerjaan_ibu, presence: true, length: { minimum: 4, maximum: 20 } + validates :pekerjaan_ayah, presence: true, length: { minimum: 3, maximum: 20 } + validates :pekerjaan_ibu, presence: true, length: { minimum: 3, maximum: 20 } validates :tanggal_lahir_ayah, :tanggal_lahir_ibu, presence: true, length: { minimum: 4, maximum: 20 } # validates :tanggal_lahir_ibu, presence: true, length: { minimum: 4, maximum: 20 } end diff --git a/app/models/personal_gender_list.rb b/app/models/personal_gender_list.rb index 154e7fa..1b6887c 100644 --- a/app/models/personal_gender_list.rb +++ b/app/models/personal_gender_list.rb @@ -1,2 +1,3 @@ class PersonalGenderList < ApplicationRecord + validates :jenis_kelamin, presence: true, length: {minimum: 4, maximum: 10}, uniqueness: true end diff --git a/app/models/personal_religion_list.rb b/app/models/personal_religion_list.rb index c641e84..fe39072 100644 --- a/app/models/personal_religion_list.rb +++ b/app/models/personal_religion_list.rb @@ -1,2 +1,4 @@ class PersonalReligionList < ApplicationRecord + validates :agama, presence: true, length: {minimum: 4, maximum: 20}, uniqueness: true + end diff --git a/config/routes.rb b/config/routes.rb index b6c6859..d280cf1 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,4 +1,6 @@ Rails.application.routes.draw do + resources :personal_religion_lists + resources :personal_gender_lists resources :parent_education_lists resources :parent_job_lists resources :high_school_majors diff --git a/db/migrate/20240117020709_create_personal_religion_lists.rb b/db/migrate/20240117020709_create_personal_religion_lists.rb deleted file mode 100644 index 0798285..0000000 --- a/db/migrate/20240117020709_create_personal_religion_lists.rb +++ /dev/null @@ -1,9 +0,0 @@ -class CreatePersonalReligionLists < ActiveRecord::Migration[7.1] - def change - create_table :personal_religion_lists do |t| - t.string :agama - - t.timestamps - end - end -end diff --git a/db/migrate/20240117020749_create_personal_gender_lists.rb b/db/migrate/20240117020749_create_personal_gender_lists.rb deleted file mode 100644 index 07a631e..0000000 --- a/db/migrate/20240117020749_create_personal_gender_lists.rb +++ /dev/null @@ -1,9 +0,0 @@ -class CreatePersonalGenderLists < ActiveRecord::Migration[7.1] - def change - create_table :personal_gender_lists do |t| - t.string :jenis_kelamin - - t.timestamps - end - end -end diff --git a/db/schema.rb b/db/schema.rb index 7c9cb56..791ff27 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.1].define(version: 2024_01_23_040009) do +ActiveRecord::Schema[7.1].define(version: 2024_01_23_041957) do create_table "achievements", force: :cascade do |t| t.string "nama_prestasi" t.date "tahun" diff --git a/test/fixtures/personal_gender_lists.yml b/test/fixtures/personal_gender_lists.yml index f68e75d..9c20a02 100644 --- a/test/fixtures/personal_gender_lists.yml +++ b/test/fixtures/personal_gender_lists.yml @@ -1,7 +1,7 @@ # Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html -#one: -# jenis_kelamin: MyString +one: + jenis_kelamin: MyString -#two: -# jenis_kelamin: MyString +two: + jenis_kelamin: MyString diff --git a/test/fixtures/personal_religion_lists.yml b/test/fixtures/personal_religion_lists.yml index 7c6101d..37aa4b5 100644 --- a/test/fixtures/personal_religion_lists.yml +++ b/test/fixtures/personal_religion_lists.yml @@ -1,7 +1,7 @@ # Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html -#one: -# agama: MyString +one: + agama: MyString -#two: -# agama: MyString +two: + agama: MyString diff --git a/test/models/personal_gender_list_test.rb b/test/models/personal_gender_list_test.rb index ea40ef8..d3ad49f 100644 --- a/test/models/personal_gender_list_test.rb +++ b/test/models/personal_gender_list_test.rb @@ -1,7 +1,26 @@ require "test_helper" class PersonalGenderListTest < ActiveSupport::TestCase - # test "the truth" do - # assert true - # end + def setup + @gender = PersonalGenderList.new(jenis_kelamin: "Laki-laki") + end + test "should accept for right information" do + assert @gender.valid? + end + test "should reject for blank gender" do + @gender.jenis_kelamin = " " + assert_not @gender.valid? + end + test "should reject for non unique gender" do + @gender.jenis_kelamin = personal_gender_lists(:one) + assert_not @gender.valid? + end + test "should reject for too long gender" do + @gender.jenis_kelamin = "a" * 11 + assert_not @gender.valid? + end + test "should reject for too short gender" do + @gender.jenis_kelamin = "a" * 3 + assert_not @gender.valid? + end end diff --git a/test/models/personal_religion_list_test.rb b/test/models/personal_religion_list_test.rb index bf6e53f..8ad4983 100644 --- a/test/models/personal_religion_list_test.rb +++ b/test/models/personal_religion_list_test.rb @@ -1,7 +1,26 @@ require "test_helper" class PersonalReligionListTest < ActiveSupport::TestCase - # test "the truth" do - # assert true - # end + def setup + @religion = PersonalReligionList.new(agama: 'protestan') + end + test "should accept the religion list" do + assert @religion.valid? + end + test "should reject religion if it too short" do + @religion.agama ='a'*3 + assert_not @religion.valid? + end + test "should reject religion if too long" do + @religion.agama = 'a'*21 + assert_not @religion.valid? + end + test "should reject duplicate religion" do + @religion.agama = personal_religion_lists(:one) + assert_not @religion.valid? + end + test "should reject an empty religion" do + @religion.agama ='' + assert_not @religion.valid? + end end