-
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.
- Loading branch information
1 parent
865bc1c
commit 50e9751
Showing
7 changed files
with
259 additions
and
37 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 |
---|---|---|
@@ -1,16 +1,36 @@ | ||
class UtbkSchoolInformationsController < ApplicationController | ||
def new | ||
@utbk_school_information = current_user.build_utbk_school_information | ||
end | ||
|
||
def update | ||
@utbk_school_information = current_user.utbk_school_information | ||
if @utbk_school_information.update(utbk_school_information_params) | ||
flash[:success] = "UTBK School information saved" | ||
else | ||
render 'edit' | ||
end | ||
end | ||
|
||
def create | ||
@utbk_school_information = current_user.build_utbk_school_information(utbk_school_information_params) | ||
if @utbk_school_information.save | ||
flash[:success] = "UTBK School information is saved" | ||
else | ||
render 'new' | ||
end | ||
end | ||
|
||
def edit | ||
@utbk_school_information = current_user.utbk_school_information | ||
end | ||
|
||
def show | ||
end | ||
private | ||
def utbk_school_information_params | ||
params.require(:utbk_school_information).permit(:asal_sekolah, :akreditas, | ||
:jumlah_pelajaran_un, | ||
:jumlah_nilai_un) | ||
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 |
---|---|---|
@@ -1,3 +1,13 @@ | ||
class UtbkSchoolInformation < ApplicationRecord | ||
belongs_to :user | ||
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: { | ||
greater_than_or_equal_to: 2, less_than_or_equal_to: 1000 | ||
} | ||
validates :jumlah_pelajaran_un, presence: false, numericality: { | ||
only_integer: true, greater_than_or_equal_to: 2, | ||
less_than_or_equal_to: 10 | ||
} | ||
|
||
end |
115 changes: 102 additions & 13 deletions
115
test/controllers/utbk_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 |
---|---|---|
@@ -1,28 +1,117 @@ | ||
require "test_helper" | ||
|
||
class UtbkSchoolInformationsControllerTest < ActionDispatch::IntegrationTest | ||
test "should get new" do | ||
get utbk_school_informations_new_url | ||
def setup | ||
get login_path | ||
post login_path, params: { | ||
session: {email: users(:michael).email, password: 'password'} | ||
} | ||
end | ||
test "should get new - utbk school information" do | ||
get new_utbk_school_information_path | ||
assert_response :success | ||
end | ||
|
||
test "should get update" do | ||
get utbk_school_informations_update_url | ||
test "should update - utbk school information" do | ||
get login_path | ||
post login_path, params: {session: { | ||
email: users(:archer).email, password: 'password' | ||
}} | ||
assert is_logged_in? | ||
get edit_utbk_school_information_url(utbk_school_informations(:utbk_sc_one)) | ||
assert_response :success | ||
patch utbk_school_information_path(utbk_school_informations(:utbk_sc_one)), params: { | ||
utbk_school_information: { | ||
asal_sekolah: 'sma 2 balige', jumlah_pelajaran_un: 3, | ||
jumlah_nilai_un: 200.5, akreditas: 'Baik sekali' | ||
} | ||
} | ||
assert_equal 'sma 2 balige', utbk_school_informations(:utbk_sc_one).reload.asal_sekolah | ||
assert_equal 'Baik sekali', utbk_school_informations(:utbk_sc_one).reload.akreditas | ||
assert_equal 3, utbk_school_informations(:utbk_sc_one).reload.jumlah_pelajaran_un | ||
assert_equal 200.5, utbk_school_informations(:utbk_sc_one).reload.jumlah_nilai_un | ||
end | ||
|
||
test "should get create" do | ||
get utbk_school_informations_create_url | ||
test "should reject update non permited params-utbk school" do | ||
get login_path | ||
post login_path, params: {session: { | ||
email: users(:archer).email, password: 'password' | ||
}} | ||
assert is_logged_in? | ||
get edit_utbk_school_information_url(utbk_school_informations(:utbk_sc_one)) | ||
assert_response :success | ||
patch utbk_school_information_path(utbk_school_informations(:utbk_sc_one)), params: { | ||
utbk_school_information: { | ||
asal_sekolah: 'sma 2 balige', jumlah_pelajaran_un: 3, | ||
jumlah_nilai_un: 200.5, akreditas: 'Baik sekali', user_id: 98777908 | ||
} | ||
} | ||
assert_nil UtbkSchoolInformation.find_by_user_id 98777908 | ||
end | ||
|
||
test "should get edit" do | ||
get utbk_school_informations_edit_url | ||
test "should reject update the utbk school for invalid information" do | ||
get login_path | ||
post login_path, params: {session: { | ||
email: users(:archer).email, password: 'password' | ||
}} | ||
assert is_logged_in? | ||
get edit_utbk_school_information_url(utbk_school_informations(:utbk_sc_one)) | ||
assert_response :success | ||
patch utbk_school_information_path(utbk_school_informations(:utbk_sc_one)), params: { | ||
utbk_school_information: { | ||
asal_sekolah: 'sma 9 balige', jumlah_pelajaran_un: 3, | ||
jumlah_nilai_un: 200.5, akreditas: ' ' | ||
} | ||
} | ||
assert_nil UtbkSchoolInformation.find_by_asal_sekolah 'sma 9 balige' | ||
end | ||
|
||
test "should get show" do | ||
get utbk_school_informations_show_url | ||
test "should create utbk school information" do | ||
get new_utbk_school_information_path | ||
assert_response :success | ||
assert_difference 'UtbkSchoolInformation.count' do | ||
post utbk_school_informations_path, params: { | ||
utbk_school_information: { | ||
asal_sekolah: 'sma 2 tarutung', jumlah_pelajaran_un: 9, | ||
jumlah_nilai_un: 100.5, akreditas: 'Baik' | ||
} | ||
} | ||
end | ||
assert_not_nil UtbkSchoolInformation.find_by_asal_sekolah 'sma 2 tarutung' | ||
assert_not_nil UtbkSchoolInformation.find_by_akreditas 'Baik' | ||
assert_not_nil UtbkSchoolInformation.find_by_jumlah_pelajaran_un 9 | ||
assert_not_nil UtbkSchoolInformation.find_by_jumlah_nilai_un 100.5 | ||
end | ||
test "should reject to create - utbk school information" do | ||
get new_utbk_school_information_path | ||
assert_response :success | ||
assert_no_difference 'UtbkSchoolInformation.count' do | ||
post utbk_school_informations_path, params: { | ||
utbk_school_information: { | ||
asal_sekolah: 'sm', jumlah_pelajaran_un: 9, | ||
jumlah_nilai_un: 100.5, akreditas: 'Baik' | ||
} | ||
} | ||
end | ||
assert_nil UtbkSchoolInformation.find_by_asal_sekolah 'sm' | ||
end | ||
test "should reject to create non permited params-utbk school" do | ||
get new_utbk_school_information_path | ||
assert_response :success | ||
assert_difference 'UtbkSchoolInformation.count' do | ||
post utbk_school_informations_path, params: { | ||
utbk_school_information: { | ||
asal_sekolah: 'sma 1 nauli', jumlah_pelajaran_un: 9, | ||
jumlah_nilai_un: 100.5, akreditas: 'Baik', user_id: 98978 | ||
} | ||
} | ||
end | ||
assert_nil UtbkSchoolInformation.find_by_user_id 98978 | ||
end | ||
test "should get edit - utbk school information" do | ||
get edit_utbk_school_information_url(utbk_school_informations(:utbk_sc_one)) | ||
assert_response :success | ||
end | ||
|
||
# test "should get show" do | ||
# get utbk_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
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 |
---|---|---|
@@ -1,13 +1,15 @@ | ||
# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html | ||
|
||
#one: | ||
# asal_sekolah: MyString | ||
# akreditas: MyString | ||
# jumlah_pelajaran_un: MyString | ||
# jumlah_nilai_un: MyString | ||
utbk_sc_one: | ||
user: archer | ||
asal_sekolah: MyString | ||
akreditas: MyString | ||
jumlah_pelajaran_un: 2 | ||
jumlah_nilai_un: 90.8 | ||
|
||
#two: | ||
# asal_sekolah: MyString | ||
# akreditas: MyString | ||
# jumlah_pelajaran_un: MyString | ||
# jumlah_nilai_un: MyString | ||
utbk_sc_two: | ||
user: iana | ||
asal_sekolah: MyString | ||
akreditas: MyString | ||
jumlah_pelajaran_un: 4 | ||
jumlah_nilai_un: 90.9 |
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 |
---|---|---|
@@ -1,7 +1,39 @@ | ||
require "test_helper" | ||
|
||
class UtbkSchoolInformationTest < ActiveSupport::TestCase | ||
# test "the truth" do | ||
# assert true | ||
# end | ||
def setup | ||
@utbk_information = UtbkSchoolInformation.new( | ||
user_id: users(:michael).id, asal_sekolah: 'sma tarutung', | ||
jumlah_pelajaran_un: 5, jumlah_nilai_un: 50.5, akreditas: 'A' | ||
) | ||
end | ||
test "should be a valid utbk information" do | ||
assert @utbk_information.valid? | ||
end | ||
test "should reject for invalid asal sekolah - utbk" do | ||
@utbk_information.asal_sekolah='a'*2 | ||
assert_not @utbk_information.valid? | ||
@utbk_information.asal_sekolah=' ' | ||
assert_not @utbk_information.valid? | ||
@utbk_information.asal_sekolah='a'*51 | ||
assert_not @utbk_information.valid? | ||
end | ||
test "should reject for invalid jumlah nilai un-utbk" do | ||
@utbk_information.jumlah_nilai_un= 1000.5 | ||
assert_not @utbk_information.valid? | ||
@utbk_information.jumlah_nilai_un= -12 | ||
assert_not @utbk_information.valid? | ||
end | ||
test "should reject for invalid jumlah pelajaran un-utbk" do | ||
@utbk_information.jumlah_pelajaran_un = 50 | ||
assert_not @utbk_information.valid? | ||
@utbk_information.jumlah_pelajaran_un = -1 | ||
assert_not @utbk_information.valid? | ||
end | ||
test "should reject for invalid akreditas-utbk" do | ||
@utbk_information.akreditas = 'a'*21 | ||
assert_not @utbk_information.valid? | ||
@utbk_information.akreditas = ' ' | ||
assert_not @utbk_information.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