Skip to content

Commit

Permalink
unit test: accreditation, all_sch, pmdk_sch
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelSipayung committed Jan 24, 2024
1 parent 9a2e506 commit 81cda93
Show file tree
Hide file tree
Showing 10 changed files with 110 additions and 16 deletions.
3 changes: 3 additions & 0 deletions app/models/accreditation_school_list.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
class AccreditationSchoolList < ApplicationRecord
validates :akreditasi, presence: true, length: {
minimum: 1, maximum: 15
}, uniqueness: true
end
2 changes: 2 additions & 0 deletions app/models/all_school_list.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
class AllSchoolList < ApplicationRecord
validates :sekolah, presence: true,
length: {minimum: 5, maximum: 35}, uniqueness: true
end
2 changes: 2 additions & 0 deletions app/models/pmdk_school_list.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
class PmdkSchoolList < ApplicationRecord
validates :sekolah, presence: true,
length: {minimum: 5, maximum: 35}, uniqueness: true
end
20 changes: 19 additions & 1 deletion db/schema.rb

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

10 changes: 8 additions & 2 deletions test/controllers/accreditation_school_lists_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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)
Expand All @@ -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

Expand Down
9 changes: 7 additions & 2 deletions test/controllers/all_school_lists_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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)
Expand All @@ -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

Expand Down
9 changes: 7 additions & 2 deletions test/controllers/pmdk_school_lists_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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)
Expand All @@ -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

Expand Down
21 changes: 18 additions & 3 deletions test/models/accreditation_school_list_test.rb
Original file line number Diff line number Diff line change
@@ -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
25 changes: 22 additions & 3 deletions test/models/all_school_list_test.rb
Original file line number Diff line number Diff line change
@@ -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
25 changes: 22 additions & 3 deletions test/models/pmdk_school_list_test.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 81cda93

Please sign in to comment.