diff --git a/app/models/accreditation_school_list.rb b/app/models/accreditation_school_list.rb index 9e5ec39..4bd0a35 100644 --- a/app/models/accreditation_school_list.rb +++ b/app/models/accreditation_school_list.rb @@ -1,2 +1,5 @@ class AccreditationSchoolList < ApplicationRecord + validates :akreditasi, presence: true, length: { + minimum: 1, maximum: 15 + }, uniqueness: true end diff --git a/app/models/all_school_list.rb b/app/models/all_school_list.rb index 920aad6..8acd560 100644 --- a/app/models/all_school_list.rb +++ b/app/models/all_school_list.rb @@ -1,2 +1,4 @@ class AllSchoolList < ApplicationRecord + validates :sekolah, presence: true, + length: {minimum: 5, maximum: 35}, uniqueness: true end diff --git a/app/models/pmdk_school_list.rb b/app/models/pmdk_school_list.rb index 98e4e8c..c5ce96f 100644 --- a/app/models/pmdk_school_list.rb +++ b/app/models/pmdk_school_list.rb @@ -1,2 +1,4 @@ class PmdkSchoolList < ApplicationRecord + validates :sekolah, presence: true, + length: {minimum: 5, maximum: 35}, uniqueness: true end diff --git a/db/schema.rb b/db/schema.rb index 9b4fef0..248e29f 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,13 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.1].define(version: 2024_01_24_030936) do +ActiveRecord::Schema[7.1].define(version: 2024_01_24_071057) do + create_table "accreditation_school_lists", force: :cascade do |t| + t.string "akreditasi" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + create_table "achievement_kategori_lists", force: :cascade do |t| t.string "kategori" t.datetime "created_at", null: false @@ -98,6 +104,12 @@ t.index ["user_id"], name: "index_addresses_on_user_id" end + create_table "all_school_lists", force: :cascade do |t| + t.string "sekolah" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + create_table "batch_lists", force: :cascade do |t| t.string "gelombang" t.boolean "aktif" @@ -273,6 +285,12 @@ t.index ["user_id"], name: "index_personals_on_user_id" end + create_table "pmdk_school_lists", force: :cascade do |t| + t.string "sekolah" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + create_table "relationships", force: :cascade do |t| t.integer "follower_id" t.integer "followed_id" diff --git a/test/controllers/accreditation_school_lists_controller_test.rb b/test/controllers/accreditation_school_lists_controller_test.rb index ae79341..5224592 100644 --- a/test/controllers/accreditation_school_lists_controller_test.rb +++ b/test/controllers/accreditation_school_lists_controller_test.rb @@ -2,6 +2,10 @@ class AccreditationSchoolListsControllerTest < ActionDispatch::IntegrationTest setup do + get login_path + post login_path, params: {session: { + email: users(:michael).email, password: 'password' + }} @accreditation_school_list = accreditation_school_lists(:one) end @@ -17,7 +21,8 @@ class AccreditationSchoolListsControllerTest < ActionDispatch::IntegrationTest test "should create accreditation_school_list" do assert_difference("AccreditationSchoolList.count") do - post accreditation_school_lists_url, params: { accreditation_school_list: { akreditasi: @accreditation_school_list.akreditasi } } + post accreditation_school_lists_url, + params: { accreditation_school_list: { akreditasi: 'baik' } } end assert_redirected_to accreditation_school_list_url(AccreditationSchoolList.last) @@ -34,7 +39,8 @@ class AccreditationSchoolListsControllerTest < ActionDispatch::IntegrationTest end test "should update accreditation_school_list" do - patch accreditation_school_list_url(@accreditation_school_list), params: { accreditation_school_list: { akreditasi: @accreditation_school_list.akreditasi } } + patch accreditation_school_list_url(@accreditation_school_list), + params: { accreditation_school_list: { akreditasi: 'terakreditasi' } } assert_redirected_to accreditation_school_list_url(@accreditation_school_list) end diff --git a/test/controllers/all_school_lists_controller_test.rb b/test/controllers/all_school_lists_controller_test.rb index 423fd39..c83659e 100644 --- a/test/controllers/all_school_lists_controller_test.rb +++ b/test/controllers/all_school_lists_controller_test.rb @@ -2,6 +2,10 @@ class AllSchoolListsControllerTest < ActionDispatch::IntegrationTest setup do + get login_path + post login_path, params: {session: { + email: users(:michael).email, password: 'password' + }} @all_school_list = all_school_lists(:one) end @@ -17,7 +21,7 @@ class AllSchoolListsControllerTest < ActionDispatch::IntegrationTest test "should create all_school_list" do assert_difference("AllSchoolList.count") do - post all_school_lists_url, params: { all_school_list: { sekolah: @all_school_list.sekolah } } + post all_school_lists_url, params: { all_school_list: { sekolah: 'sma bina nusantara' } } end assert_redirected_to all_school_list_url(AllSchoolList.last) @@ -34,7 +38,8 @@ class AllSchoolListsControllerTest < ActionDispatch::IntegrationTest end test "should update all_school_list" do - patch all_school_list_url(@all_school_list), params: { all_school_list: { sekolah: @all_school_list.sekolah } } + patch all_school_list_url(@all_school_list), + params: { all_school_list: { sekolah: 'sma taruna nusantara' } } assert_redirected_to all_school_list_url(@all_school_list) end diff --git a/test/controllers/pmdk_school_lists_controller_test.rb b/test/controllers/pmdk_school_lists_controller_test.rb index 09802fa..6b9ac86 100644 --- a/test/controllers/pmdk_school_lists_controller_test.rb +++ b/test/controllers/pmdk_school_lists_controller_test.rb @@ -2,6 +2,10 @@ class PmdkSchoolListsControllerTest < ActionDispatch::IntegrationTest setup do + get login_path + post login_path, params: { + session: {email: users(:michael).email,password: 'password'} + } @pmdk_school_list = pmdk_school_lists(:one) end @@ -17,7 +21,7 @@ class PmdkSchoolListsControllerTest < ActionDispatch::IntegrationTest test "should create pmdk_school_list" do assert_difference("PmdkSchoolList.count") do - post pmdk_school_lists_url, params: { pmdk_school_list: { sekolah: @pmdk_school_list.sekolah } } + post pmdk_school_lists_url, params: { pmdk_school_list: { sekolah: 'sma 1 bangsa' } } end assert_redirected_to pmdk_school_list_url(PmdkSchoolList.last) @@ -34,7 +38,8 @@ class PmdkSchoolListsControllerTest < ActionDispatch::IntegrationTest end test "should update pmdk_school_list" do - patch pmdk_school_list_url(@pmdk_school_list), params: { pmdk_school_list: { sekolah: @pmdk_school_list.sekolah } } + patch pmdk_school_list_url(@pmdk_school_list), + params: { pmdk_school_list: { sekolah: 'smk 1 tarutung' } } assert_redirected_to pmdk_school_list_url(@pmdk_school_list) end diff --git a/test/models/accreditation_school_list_test.rb b/test/models/accreditation_school_list_test.rb index cba12d9..3cd5418 100644 --- a/test/models/accreditation_school_list_test.rb +++ b/test/models/accreditation_school_list_test.rb @@ -1,7 +1,22 @@ require "test_helper" class AccreditationSchoolListTest < ActiveSupport::TestCase - # test "the truth" do - # assert true - # end + def setup + @accreditation = AccreditationSchoolList.new(akreditasi: 'A') + end + test "should accept for valid accreditation" do + assert @accreditation.valid? + end + test "should reject for empty accreditation" do + @accreditation.akreditasi = '' + assert_not @accreditation.valid? + end + test "should reject for too long accreditation " do + @accreditation.akreditasi ='a'*16 + assert_not @accreditation.valid? + end + test "should reject for non unique accreditation" do + @accreditation.akreditasi = accreditation_school_lists(:one).akreditasi + assert_not @accreditation.valid? + end end diff --git a/test/models/all_school_list_test.rb b/test/models/all_school_list_test.rb index 2b9a5e3..21ba41c 100644 --- a/test/models/all_school_list_test.rb +++ b/test/models/all_school_list_test.rb @@ -1,7 +1,26 @@ require "test_helper" class AllSchoolListTest < ActiveSupport::TestCase - # test "the truth" do - # assert true - # end + def setup + @all_school = AllSchoolList.new(sekolah: 'sma pelita') + end + test "should accept the right school" do + assert @all_school.valid? + end + test "should reject for empty school list" do + @all_school.sekolah = '' + assert_not @all_school.valid? + end + test "should reject for too short school name" do + @all_school.sekolah = 'a'*4 + assert_not @all_school.valid? + end + test "should reject for too long school name" do + @all_school.sekolah = 'a'*36 + assert_not @all_school.valid? + end + test "should reject for non unique school name" do + @all_school.sekolah = all_school_lists(:one).sekolah + assert_not @all_school.valid? + end end diff --git a/test/models/pmdk_school_list_test.rb b/test/models/pmdk_school_list_test.rb index 9a5ba09..f1238a7 100644 --- a/test/models/pmdk_school_list_test.rb +++ b/test/models/pmdk_school_list_test.rb @@ -1,7 +1,26 @@ require "test_helper" class PmdkSchoolListTest < ActiveSupport::TestCase - # test "the truth" do - # assert true - # end + def setup + @pmdk_school = PmdkSchoolList.new(sekolah: 'sma pelita') + end + test "should accept the right school" do + assert @pmdk_school.valid? + end + test "should reject for empty school list" do + @pmdk_school.sekolah = '' + assert_not @pmdk_school.valid? + end + test "should reject for too short school name" do + @pmdk_school.sekolah = 'a'*4 + assert_not @pmdk_school.valid? + end + test "should reject for too long school name" do + @pmdk_school.sekolah = 'a'*36 + assert_not @pmdk_school.valid? + end + test "should reject for non unique school name" do + @pmdk_school.sekolah = pmdk_school_lists(:one).sekolah + assert_not @pmdk_school.valid? + end end