-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bug fixes for allowed nill attribute
- Loading branch information
1 parent
a88da16
commit 9d0dc55
Showing
22 changed files
with
208 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
module UsmSchoolInformationsHelper | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
db/migrate/20240126084849_create_usm_school_informations.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
5 changes: 5 additions & 0 deletions
5
db/migrate/20240126085158_add_user_ref_to_usm_school_information.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
28 changes: 28 additions & 0 deletions
28
test/controllers/usm_school_informations_controller_test.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters