Skip to content

Commit

Permalink
bug fixes for allowed nill attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelSipayung committed Jan 26, 2024
1 parent a88da16 commit 9d0dc55
Show file tree
Hide file tree
Showing 22 changed files with 208 additions and 15 deletions.
16 changes: 16 additions & 0 deletions app/controllers/usm_school_informations_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
class UsmSchoolInformationsController < ApplicationController
def new
end

def update
end

def create
end

def edit
end

def show
end
end
2 changes: 2 additions & 0 deletions app/helpers/usm_school_informations_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module UsmSchoolInformationsHelper
end
3 changes: 2 additions & 1 deletion app/models/parent.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ class Parent < ApplicationRecord
belongs_to :user
validates :nama_ayah,:nama_ibu, presence: true, length: { minimum: 4, maximum: 25 }
# validates :nama_ibu, presence: true, length: { minimum: 4, maximum: 25 }
validates :nik_ayah,:nik_ibu, presence: true, length: { minimum: 16, maximum: 16 }
validates :nik_ayah,:nik_ibu, length: { minimum: 16, maximum: 16 },
allow_nil: true
# 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 }
Expand Down
2 changes: 1 addition & 1 deletion app/models/personal.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ class Personal < ApplicationRecord
validates :tanggal_lahir, presence: true, length: { minimum: 4, maximum: 20 }
validates :nik, presence: true, length: { minimum: 16, maximum: 16 }
validates :nisn, presence: true, length: { minimum: 10, maximum: 10 }
validates :no_kps, length: { minimum: 6, maximum: 6 }
validates :no_kps, length: { minimum: 6, maximum: 6 }, allow_nil: true
validates :domisili, presence: true, length: { minimum: 4, maximum: 30 }
end
4 changes: 2 additions & 2 deletions app/models/pmdk_school_information.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ class PmdkSchoolInformation < ApplicationRecord
validates :akreditas, presence: true, length: {minimum: 1, maximum: 20}
validates :jumlah_nilai_un, presence: false, numericality: {
greater_than_or_equal_to: 2, less_than_or_equal_to: 1000
}
}, allow_nil: true
validates :jumlah_pelajaran_un, presence: false, numericality: {
only_integer: true, greater_than_or_equal_to: 2,
less_than_or_equal_to: 10
}
}, allow_nil: true
end
22 changes: 22 additions & 0 deletions app/models/usm_school_information.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
class UsmSchoolInformation < ApplicationRecord
belongs_to :user
validates :jurusan_sekolah, presence: true, length: {minimum: 3, maximum: 50}
validates :asal_sekolah, presence: true, length: {minimum: 3, maximum: 50}
validates :akreditas, presence: true, length: {minimum: 1, maximum: 20}
validates :jumlah_nilai_un, presence: false, numericality: {
only_integer: false,
greater_than_or_equal_to: 2, less_than_or_equal_to: 1000
}, allow_nil: true
validates :jumlah_pelajaran_un, presence: false, numericality: {
only_integer: false, greater_than_or_equal_to: 2,
less_than_or_equal_to: 10
},allow_nil: true
validates :jumlah_pelajaran_semester_5, presence: true, numericality: {
only_integer: true, greater_than_or_equal_to: 2,
less_than_or_equal_to: 20
}
validates :jumlah_nilai_semester_5, presence: true, numericality: {
only_integer: false, greater_than_or_equal_to: 2,
less_than_or_equal_to: 2000
}
end
4 changes: 2 additions & 2 deletions app/models/utbk_school_information.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ class UtbkSchoolInformation < ApplicationRecord
validates :akreditas, presence: true, length: {minimum: 1, maximum: 20}
validates :jumlah_nilai_un, presence: false, numericality: {
greater_than_or_equal_to: 2, less_than_or_equal_to: 1000
}
}, allow_nil: true
validates :jumlah_pelajaran_un, presence: false, numericality: {
only_integer: true, greater_than_or_equal_to: 2,
less_than_or_equal_to: 10
}
}, allow_nil: true

end
2 changes: 2 additions & 0 deletions app/views/usm_school_informations/create.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<h1>UsmSchoolInformations#create</h1>
<p>Find me in app/views/usm_school_informations/create.html.erb</p>
2 changes: 2 additions & 0 deletions app/views/usm_school_informations/edit.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<h1>UsmSchoolInformations#edit</h1>
<p>Find me in app/views/usm_school_informations/edit.html.erb</p>
2 changes: 2 additions & 0 deletions app/views/usm_school_informations/new.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<h1>UsmSchoolInformations#new</h1>
<p>Find me in app/views/usm_school_informations/new.html.erb</p>
2 changes: 2 additions & 0 deletions app/views/usm_school_informations/show.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<h1>UsmSchoolInformations#show</h1>
<p>Find me in app/views/usm_school_informations/show.html.erb</p>
2 changes: 2 additions & 0 deletions app/views/usm_school_informations/update.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<h1>UsmSchoolInformations#update</h1>
<p>Find me in app/views/usm_school_informations/update.html.erb</p>
5 changes: 5 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
Rails.application.routes.draw do
get 'usm_school_informations/new'
get 'usm_school_informations/update'
get 'usm_school_informations/create'
get 'usm_school_informations/edit'
get 'usm_school_informations/show'
resources :accreditation_school_lists
resources :pmdk_school_lists
resources :all_school_lists
Expand Down
15 changes: 15 additions & 0 deletions db/migrate/20240126084849_create_usm_school_informations.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
class CreateUsmSchoolInformations < ActiveRecord::Migration[7.1]
def change
create_table :usm_school_informations do |t|
t.string :asal_sekolah
t.string :akreditas
t.integer :jumlah_pelajaran_un
t.decimal :jumlah_nilai_un
t.string :jurusan_sekolah
t.integer :jumlah_pelajaran_semester_5
t.decimal :jumlah_nilai_semester_5

t.timestamps
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddUserRefToUsmSchoolInformation < ActiveRecord::Migration[7.1]
def change
add_reference :usm_school_informations, :user, null: false, foreign_key: true
end
end
17 changes: 16 additions & 1 deletion db/schema.rb

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

28 changes: 28 additions & 0 deletions test/controllers/usm_school_informations_controller_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
require "test_helper"

class UsmSchoolInformationsControllerTest < ActionDispatch::IntegrationTest
test "should get new" do
get usm_school_informations_new_url
assert_response :success
end

test "should get update" do
get usm_school_informations_update_url
assert_response :success
end

test "should get create" do
get usm_school_informations_create_url
assert_response :success
end

test "should get edit" do
get usm_school_informations_edit_url
assert_response :success
end

test "should get show" do
get usm_school_informations_show_url
assert_response :success
end
end
21 changes: 21 additions & 0 deletions test/fixtures/usm_school_informations.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html

usm_one:
user: archer
asal_sekolah: MyString
akreditas: MyString
jumlah_pelajaran_un: 1
jumlah_nilai_un: 9.99
jurusan_sekolah: MyString
jumlah_pelajaran_semester_5: 1
jumlah_nilai_semester_5: 9.99

usm_two:
user: iana
asal_sekolah: MyString
akreditas: MyString
jumlah_pelajaran_un: 1
jumlah_nilai_un: 9.99
jurusan_sekolah: MyString
jumlah_pelajaran_semester_5: 1
jumlah_nilai_semester_5: 9.99
11 changes: 5 additions & 6 deletions test/models/parent_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
class ParentTest < ActiveSupport::TestCase
def setup
@user = users(:michael)
@parent = Parent.new(user_id: @user.id, nama_ayah: 'example', nama_ibu: 'example',
nik_ayah: 1234567891234567, nik_ibu: 1234567891234567, pendidikan_ayah: 'sma',
@parent = Parent.new(user_id: @user.id, nama_ayah: 'example', nama_ibu: 'example', pendidikan_ayah: 'sma',
pendidikan_ibu: 'sma', pekerjaan_ayah: 'wiraswasta', pekerjaan_ibu: 'wiraswasta',
tanggal_lahir_ayah: '1997-12-12', tanggal_lahir_ibu: '1997-12-12')
end
Expand Down Expand Up @@ -35,9 +34,9 @@ def setup
@parent.nama_ibu = "a"*26
assert_not @parent.valid?
end
test "nik_ayah should be present" do
test "nik_ayah should not be present" do
@parent.nik_ayah = ""
assert_not @parent.valid?
assert @parent.valid?
end
test "nik_ayah should not be too short" do
@parent.nik_ayah = "a"*15
Expand All @@ -47,9 +46,9 @@ def setup
@parent.nik_ayah = "a"*17
assert_not @parent.valid?
end
test "nik_ibu should be present" do
test "nik_ibu should not be present" do
@parent.nik_ibu = ""
assert_not @parent.valid?
assert @parent.valid?
end
test "nik_ibu should not be too short" do
@parent.nik_ibu = "a"*15
Expand Down
2 changes: 1 addition & 1 deletion test/models/personal_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ def setup
@user = users(:michael)
@personal = Personal.new(user_id: @user.id, nama_lengkap: "Example User", agama: 'islam', jenis_kelamin: 'laki-laki',
tempat_lahir: 'jakarta', tanggal_lahir: '1997-12-12',
nik: 1234567890123456, nisn: 1234567890, no_kps: 123456, domisili: 'jakarta')
nik: 1234567890123456, nisn: 1234567890, domisili: 'jakarta')
end
test "should be valid" do
assert @personal.valid?
Expand Down
54 changes: 54 additions & 0 deletions test/models/usm_school_information_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
require "test_helper"

class UsmSchoolInformationTest < ActiveSupport::TestCase
def setup
@usm_school =
UsmSchoolInformation.new(user_id: users(:michael).id, jurusan_sekolah: 'ipa',
asal_sekolah: 'sma santo tomas', akreditas: 'terakreditasi',
jumlah_pelajaran_semester_5: 8, jumlah_nilai_semester_5: 78.9)
end
test "should be a valid utbk information" do
assert @usm_school.valid?
end
test "should reject for invalid asal sekolah - usm" do
@usm_school.asal_sekolah='a'*2
assert_not @usm_school.valid?
@usm_school.asal_sekolah=' '
assert_not @usm_school.valid?
@usm_school.asal_sekolah='a'*51
assert_not @usm_school.valid?
end
test "should reject for invalid jumlah nilai un-usm" do
@usm_school.jumlah_nilai_un= 1000.5
assert_not @usm_school.valid?
@usm_school.jumlah_nilai_un= -12
assert_not @usm_school.valid?
end
test "should reject for invalid jumlah pelajaran un-usm" do
@usm_school.jumlah_pelajaran_un = 50
assert_not @usm_school.valid?
@usm_school.jumlah_pelajaran_un = -1
assert_not @usm_school.valid?
end
test "should reject for invalid akreditas-usm" do
@usm_school.akreditas = 'a'*21
assert_not @usm_school.valid?
@usm_school.akreditas = ' '
assert_not @usm_school.valid?
end
test "should reject for invalid jumlah pelajaran semester 5-usm" do
@usm_school.jumlah_pelajaran_semester_5 = 21
assert_not @usm_school.valid?
@usm_school.jumlah_pelajaran_semester_5 = -1
assert_not @usm_school.valid?
end
test "should reject for invalid jumlah nilai semester 5-usm" do
@usm_school.jumlah_nilai_semester_5 =-30.9
assert_not @usm_school.valid?
@usm_school.jumlah_nilai_semester_5 =2001
assert_not @usm_school.valid?
end
test "should allow non mandatory attribute to be empty-usm" do
assert @usm_school.valid?
end
end
2 changes: 1 addition & 1 deletion test/models/utbk_school_information_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

class UtbkSchoolInformationTest < ActiveSupport::TestCase
def setup
@utbk_information = UtbkSchoolInformation.new(
@usm_school = UtbkSchoolInformation.new(
user_id: users(:michael).id, asal_sekolah: 'sma tarutung',
jumlah_pelajaran_un: 5, jumlah_nilai_un: 50.5, akreditas: 'A'
)
Expand Down

0 comments on commit 9d0dc55

Please sign in to comment.