Skip to content

Commit

Permalink
adding more strict rule to address
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelSipayung committed Jan 24, 2024
1 parent 2595129 commit a545733
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 6 deletions.
1 change: 1 addition & 0 deletions app/models/address_kabupaten_list.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ class AddressKabupatenList < ApplicationRecord
belongs_to :address_kecamatan_list
validates :kabupaten, presence: true, uniqueness: true,
length: { minimum: 3, maximum: 35 }
validates :address_kecamatan_list_id, presence: true
end
1 change: 1 addition & 0 deletions app/models/address_kecamatan_list.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ class AddressKecamatanList < ApplicationRecord
belongs_to :address_province_list
validates :kecamatan, presence: true, uniqueness: true,
length: { minimum: 3, maximum: 35 }
validates :address_province_list_id, presence: true
end
5 changes: 3 additions & 2 deletions test/controllers/address_kabupaten_lists_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ class AddressKabupatenListsControllerTest < ActionDispatch::IntegrationTest
test "should create address_kabupaten_list" do
assert_difference("AddressKabupatenList.count") do
post address_kabupaten_lists_url,
params: { address_kabupaten_list: { kabupaten: 'luake' } }
params: { address_kabupaten_list:
{ kabupaten: 'luake',
address_kecamatan_list_id: address_kecamatan_lists(:acehtimur).id} }
end

assert_redirected_to address_kabupaten_list_url(AddressKabupatenList.last)
end

Expand Down
8 changes: 6 additions & 2 deletions test/models/address_kabupaten_list_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class AddressKabupatenListTest < ActiveSupport::TestCase
def setup
@address_kabupaten =
AddressKabupatenList.new(kabupaten: 'toba',
address_kecamatan_list_id: address_kecamatan_lists(:one).id)
address_kecamatan_list_id: address_kecamatan_lists(:acehtengah).id)
end
test "should be valid kabupaten" do
assert @address_kabupaten.valid?
Expand All @@ -20,10 +20,14 @@ def setup
end
test "should reject for too long kabupaten" do
@address_kabupaten.kabupaten = "a" * 36
assert @address_kabupaten.valid?
assert_not @address_kabupaten.valid?
end
test "should reject for too short kebupaten" do
@address_kabupaten.kabupaten = 'a'*2
assert_not @address_kabupaten.valid?
end
test "should reject for nill kecamatan_id" do
@address_kabupaten.address_kecamatan_list_id=nil
assert_not @address_kabupaten.valid?
end
end
6 changes: 5 additions & 1 deletion test/models/address_kecamatan_list_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class AddressKecamatanListTest < ActiveSupport::TestCase
def setup
@address_kecamatan =
AddressKecamatanList.new(kecamatan: 'toba',
address_province_list_id: address_province_lists(:one).id)
address_province_list_id: address_province_lists(:aceh).id)
end
test "should be valid kecamatan" do
assert @address_kecamatan.valid?
Expand All @@ -26,4 +26,8 @@ def setup
@address_kecamatan.kecamatan = "a" * 2
assert_not @address_kecamatan.valid?
end
test "should reject for null province id" do
@address_kecamatan.address_province_list_id=nil
assert_not @address_kecamatan.valid?
end
end
2 changes: 1 addition & 1 deletion test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
require_relative "../config/environment"
require "rails/test_help"
require "minitest/reporters"
# Minitest::Reporters.use!
Minitest::Reporters.use!
#for convenience, but conflict on rubymine idea

module ActiveSupport
Expand Down

0 comments on commit a545733

Please sign in to comment.