diff --git a/app/controllers/utbk_scores_controller.rb b/app/controllers/utbk_scores_controller.rb index 25df1b0..95ab053 100644 --- a/app/controllers/utbk_scores_controller.rb +++ b/app/controllers/utbk_scores_controller.rb @@ -1,16 +1,40 @@ class UtbkScoresController < ApplicationController def new + @utbk_score = current_user.build_utbk_score end def update + @utbk_score = current_user.utbk_score + if @utbk_score.update(utbk_score_params) + flash[:success] = " utbk score is updated" + else + render 'edit' + end end def create + @utbk_score = current_user.build_utbk_score(utbk_score_params) + if @utbk_score.save + flash[:success] = "utbk score is saved" + else + render 'new' + end end def edit + @utbk_score = current_user.utbk_score end def show end + private + def utbk_score_params + params.require(:utbk_score).permit(:no_peserta, :tanggal_ujian, + :jumlah_nilai_semester_6, + :jumlah_pelajaran_semester_6, + :nilai_penalaran_umum, + :nilai_pengetahuan_kuantitatif, + :nilai_kemampuan_memahami_bacaan_dan_menulis, + :nilai_pengetahuan_dan_pemahaman_umum) + end end diff --git a/app/models/utbk_score.rb b/app/models/utbk_score.rb index 814153b..68475b6 100644 --- a/app/models/utbk_score.rb +++ b/app/models/utbk_score.rb @@ -1,3 +1,16 @@ class UtbkScore < ApplicationRecord belongs_to :user + validates :no_peserta, presence: true, + length: {minimum: 4, maximum: 30} + validates :tanggal_ujian, presence: true, length:{ minimum: 4, maximum: 10} + validates :nilai_penalaran_umum, + :nilai_pengetahuan_dan_pemahaman_umum, + :nilai_pengetahuan_kuantitatif, + :nilai_kemampuan_memahami_bacaan_dan_menulis, + presence: true, numericality: { only_integer: false, + greater_than_or_equal_to: 5, less_than_or_equal_to: 2000} + validates :jumlah_nilai_semester_6, presence: true, numericality: {only_integer: false, + greater_than_or_equal_to: 2, less_than_or_equal_to: 2000} + validates :jumlah_pelajaran_semester_6, presence: true, numericality: {only_integer: true, + greater_than_or_equal_to: 2, less_than_or_equal_to: 100} end diff --git a/test/controllers/utbk_scores_controller_test.rb b/test/controllers/utbk_scores_controller_test.rb index 508ddc1..ab5973e 100644 --- a/test/controllers/utbk_scores_controller_test.rb +++ b/test/controllers/utbk_scores_controller_test.rb @@ -1,28 +1,36 @@ require "test_helper" class UtbkScoresControllerTest < ActionDispatch::IntegrationTest - test "should get new" do - get utbk_scores_new_url - assert_response :success - end - - test "should get update" do - get utbk_scores_update_url - assert_response :success + def setup + get login_path + post login_path, params: {session: { + email: users(:michael).email, password: 'password' + }} end - - test "should get create" do - get utbk_scores_create_url + test "should get new" do + assert is_logged_in? + get new_utbk_score_url assert_response :success end + # test "should get update" do + # get utbk_scores_update_url + # assert_response :success + # end + # + # test "should get create" do + # get utbk_scores_create_url + # assert_response :success + # end + # test "should get edit" do - get utbk_scores_edit_url - assert_response :success - end - - test "should get show" do - get utbk_scores_show_url + assert is_logged_in? + get edit_utbk_score_url(utbk_scores(:utbk_score_two)) assert_response :success end + # + # test "should get show" do + # get utbk_scores_show_url + # assert_response :success + # end end diff --git a/test/fixtures/pmdk_each_score_informations.yml b/test/fixtures/pmdk_each_score_informations.yml index cb5fd44..de941cc 100644 --- a/test/fixtures/pmdk_each_score_informations.yml +++ b/test/fixtures/pmdk_each_score_informations.yml @@ -1,7 +1,7 @@ # Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html -one: - matematika_semester_1: MyString +#one: +# matematika_semester_1: MyString -two: - matematika_semester_1: MyString +#two: +# matematika_semester_1: MyString diff --git a/test/fixtures/pmdk_school_informations.yml b/test/fixtures/pmdk_school_informations.yml index dd8e46c..7814065 100644 --- a/test/fixtures/pmdk_school_informations.yml +++ b/test/fixtures/pmdk_school_informations.yml @@ -1,13 +1,13 @@ # 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 +#one: +# asal_sekolah: MyString +# akreditas: MyString +# jumlah_pelajaran_un: MyString +# jumlah_nilai_un: MyString -two: - asal_sekolah: MyString - akreditas: MyString - jumlah_pelajaran_un: MyString - jumlah_nilai_un: MyString +#two: +# asal_sekolah: MyString +# akreditas: MyString +# jumlah_pelajaran_un: MyString +# jumlah_nilai_un: MyString diff --git a/test/fixtures/pmdk_school_lists.yml b/test/fixtures/pmdk_school_lists.yml index f8711d5..fe92227 100644 --- a/test/fixtures/pmdk_school_lists.yml +++ b/test/fixtures/pmdk_school_lists.yml @@ -1,7 +1,7 @@ # Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html -one: - sekolah: MyString +#one: +# sekolah: MyString -two: - sekolah: MyString +#two: +# sekolah: MyString diff --git a/test/fixtures/pmdk_total_score_informations.yml b/test/fixtures/pmdk_total_score_informations.yml index 23009e1..3f707d4 100644 --- a/test/fixtures/pmdk_total_score_informations.yml +++ b/test/fixtures/pmdk_total_score_informations.yml @@ -1,7 +1,7 @@ # Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html -one: - jumlah_nilai_semester_1: MyString +#one: +# jumlah_nilai_semester_1: MyString -two: - jumlah_nilai_semester_1: MyString +#two: +# jumlah_nilai_semester_1: MyString diff --git a/test/fixtures/utbk_school_informations.yml b/test/fixtures/utbk_school_informations.yml index dd8e46c..7814065 100644 --- a/test/fixtures/utbk_school_informations.yml +++ b/test/fixtures/utbk_school_informations.yml @@ -1,13 +1,13 @@ # 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 +#one: +# asal_sekolah: MyString +# akreditas: MyString +# jumlah_pelajaran_un: MyString +# jumlah_nilai_un: MyString -two: - asal_sekolah: MyString - akreditas: MyString - jumlah_pelajaran_un: MyString - jumlah_nilai_un: MyString +#two: +# asal_sekolah: MyString +# akreditas: MyString +# jumlah_pelajaran_un: MyString +# jumlah_nilai_un: MyString diff --git a/test/fixtures/utbk_scores.yml b/test/fixtures/utbk_scores.yml index fccdaf9..288533d 100644 --- a/test/fixtures/utbk_scores.yml +++ b/test/fixtures/utbk_scores.yml @@ -1,9 +1,14 @@ # Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html -one: +utbk_score_one: + user: archer no_peserta: MyString tanggal_ujian: 2024-01-25 + nilai_penalaran_umum: 179.5 -two: +utbk_score_two: + user: iana no_peserta: MyString tanggal_ujian: 2024-01-25 + nilai_penalaran_umum: 189.5 + diff --git a/test/models/utbk_score_test.rb b/test/models/utbk_score_test.rb index 654cfbc..4113677 100644 --- a/test/models/utbk_score_test.rb +++ b/test/models/utbk_score_test.rb @@ -1,7 +1,95 @@ require "test_helper" class UtbkScoreTest < ActiveSupport::TestCase - # test "the truth" do - # assert true - # end + def setup + @score_utbk = UtbkScore.create!(user_id: users(:michael).id, no_peserta: '200-1bx', tanggal_ujian: '2020-12-11', + jumlah_nilai_semester_6: 1200.5, jumlah_pelajaran_semester_6: 11, + nilai_penalaran_umum: 120.5, + nilai_pengetahuan_kuantitatif: 150.5, + nilai_kemampuan_memahami_bacaan_dan_menulis: 300.5, + nilai_pengetahuan_dan_pemahaman_umum: 250.5) + end + test "should valid utbk score" do + assert_not_nil UtbkScore.find_by_jumlah_nilai_semester_6 1200.5 + assert_not_nil UtbkScore.find_by_nilai_penalaran_umum 120.5 + assert_not_nil UtbkScore.find_by_nilai_pengetahuan_kuantitatif 150.5 + assert_not_nil UtbkScore.find_by_nilai_pengetahuan_dan_pemahaman_umum 250.5 + assert_not_nil UtbkScore.find_by_nilai_kemampuan_memahami_bacaan_dan_menulis 300.5 + assert @score_utbk.valid? + end + test "should reject invalid no_peserta" do + @score_utbk.no_peserta =' ' + assert_not @score_utbk.valid? + @score_utbk.no_peserta = 'a'*3 + assert_not @score_utbk.valid? + @score_utbk.no_peserta = 'a' * 31 + assert_not @score_utbk.valid? + end + test "should reject invalid tanggal" do + @score_utbk.tanggal_ujian = ' ' + assert_not @score_utbk.valid? + @score_utbk.tanggal_ujian = '20000-290-90' + assert_not @score_utbk.valid? + @score_utbk.tanggal_ujian = '201' + assert_not @score_utbk.valid? + end + test "should reject invalid jumlah_nilai_semester_6" do + @score_utbk.jumlah_nilai_semester_6 = -12 + assert_not @score_utbk.valid? + @score_utbk.jumlah_nilai_semester_6 = 3000 + assert_not @score_utbk.valid? + @score_utbk.jumlah_nilai_semester_6 = 'abs' + assert_not @score_utbk.valid? + end + test "should reject for invalid jumlah pelajaran semester 6" do + @score_utbk.jumlah_pelajaran_semester_6 = -1 + assert_not @score_utbk.valid? + @score_utbk.jumlah_pelajaran_semester_6 = 101 + assert_not @score_utbk.valid? + @score_utbk.jumlah_pelajaran_semester_6 = 'abs' + assert_not @score_utbk.valid? + end + test "should reject for invalid nilai_penalaran_umum " do + @score_utbk.nilai_penalaran_umum = -1 + assert_not @score_utbk.valid? + @score_utbk.nilai_penalaran_umum = 2001 + assert_not @score_utbk.valid? + @score_utbk.nilai_penalaran_umum = 'abs' + assert_not @score_utbk.valid? + end + test "should reject for invalid nilai_pengetahuan_kuantitatif " do + @score_utbk.nilai_pengetahuan_kuantitatif = -1 + assert_not @score_utbk.valid? + @score_utbk.nilai_pengetahuan_kuantitatif = 2001 + assert_not @score_utbk.valid? + @score_utbk.nilai_pengetahuan_kuantitatif = 'abs' + assert_not @score_utbk.valid? + end + test "should reject for invalid nilai_kemampuan_memahami_bacaan_dan_menulis " do + @score_utbk.nilai_kemampuan_memahami_bacaan_dan_menulis = -1 + assert_not @score_utbk.valid? + @score_utbk.nilai_kemampuan_memahami_bacaan_dan_menulis = 2001 + assert_not @score_utbk.valid? + @score_utbk.nilai_kemampuan_memahami_bacaan_dan_menulis = 'abs' + assert_not @score_utbk.valid? + end + test "should reject for invalid nilai_pengetahuan_dan_pemahaman_umum " do + @score_utbk.nilai_pengetahuan_dan_pemahaman_umum = -1 + assert_not @score_utbk.valid? + @score_utbk.nilai_pengetahuan_dan_pemahaman_umum = 2001 + assert_not @score_utbk.valid? + @score_utbk.nilai_pengetahuan_dan_pemahaman_umum = 'abs' + assert_not @score_utbk.valid? + end + test "should accept decimal point to utbk score" do + @score_utbk.nilai_penalaran_umum = 149.98 + assert @score_utbk.valid? + assert_equal 149.98, @score_utbk.nilai_penalaran_umum + assert_equal 189.5, utbk_scores(:utbk_score_two).reload.nilai_penalaran_umum + assert_equal 179.5, utbk_scores(:utbk_score_one).reload.nilai_penalaran_umum + end + test "should reject jumlah matapelajaran un for non integer" do + @score_utbk.jumlah_pelajaran_semester_6 =90.98 + assert_not @score_utbk.valid? + end end diff --git a/test/test_helper.rb b/test/test_helper.rb index ca5c420..ce77d48 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -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