Skip to content

Commit

Permalink
unit testing for gender religion
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelSipayung committed Jan 23, 2024
1 parent e080d69 commit 96011fd
Show file tree
Hide file tree
Showing 11 changed files with 60 additions and 35 deletions.
4 changes: 2 additions & 2 deletions app/models/parent.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions app/models/personal_gender_list.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
class PersonalGenderList < ApplicationRecord
validates :jenis_kelamin, presence: true, length: {minimum: 4, maximum: 10}, uniqueness: true
end
2 changes: 2 additions & 0 deletions app/models/personal_religion_list.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
class PersonalReligionList < ApplicationRecord
validates :agama, presence: true, length: {minimum: 4, maximum: 20}, uniqueness: true

end
2 changes: 2 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down
9 changes: 0 additions & 9 deletions db/migrate/20240117020709_create_personal_religion_lists.rb

This file was deleted.

9 changes: 0 additions & 9 deletions db/migrate/20240117020749_create_personal_gender_lists.rb

This file was deleted.

2 changes: 1 addition & 1 deletion db/schema.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions test/fixtures/personal_gender_lists.yml
Original file line number Diff line number Diff line change
@@ -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
8 changes: 4 additions & 4 deletions test/fixtures/personal_religion_lists.yml
Original file line number Diff line number Diff line change
@@ -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
25 changes: 22 additions & 3 deletions test/models/personal_gender_list_test.rb
Original file line number Diff line number Diff line change
@@ -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
25 changes: 22 additions & 3 deletions test/models/personal_religion_list_test.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 96011fd

Please sign in to comment.