-
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.
Showing
6 changed files
with
199 additions
and
27 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,37 @@ | ||
class PmdkSchoolInformationsController < ApplicationController | ||
def new | ||
@pmdk_school_information = current_user.build_pmdk_school_information | ||
end | ||
|
||
def update | ||
@pmdk_school_information = current_user.pmdk_school_information | ||
if @pmdk_school_information.update(pmdk_school_information_params) | ||
flash[:success] = "pmdk school information updated" | ||
else | ||
render 'edit' | ||
end | ||
end | ||
|
||
def create | ||
@pmdk_school_information = current_user.build_pmdk_school_information(pmdk_school_information_params) | ||
if @pmdk_school_information.save | ||
flash[:success] = "pmdk schoool information saved" | ||
else | ||
render 'new' | ||
end | ||
end | ||
|
||
def edit | ||
@pmdk_school_information = current_user.pmdk_school_information | ||
end | ||
|
||
def show | ||
end | ||
private | ||
def pmdk_school_information_params | ||
params.require(:pmdk_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,12 @@ | ||
class PmdkSchoolInformation < 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 |
128 changes: 116 additions & 12 deletions
128
test/controllers/pmdk_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,132 @@ | ||
require "test_helper" | ||
|
||
class PmdkSchoolInformationsControllerTest < ActionDispatch::IntegrationTest | ||
def setup | ||
get login_path | ||
post login_path, params: {session: { | ||
email: users(:michael).email, password: 'password' | ||
}} | ||
end | ||
test "should get new" do | ||
get pmdk_school_informations_new_url | ||
get new_pmdk_school_information_path | ||
assert_response :success | ||
end | ||
|
||
test "should get update" do | ||
get pmdk_school_informations_update_url | ||
test "should update current pmdk school information" do | ||
get login_path | ||
post login_path, params: {session: { | ||
email: users(:archer).email, password: 'password' | ||
}} | ||
assert is_logged_in? | ||
get edit_pmdk_school_information_path(pmdk_school_informations(:pmdk_sc_one)) | ||
assert_response :success | ||
patch pmdk_school_information_path(pmdk_school_informations(:pmdk_sc_one)), | ||
params: {pmdk_school_information: { | ||
asal_sekolah: 'sma juanda timur', | ||
akreditas: 'Unggul', | ||
jumlah_nilai_un: 90.78, | ||
jumlah_pelajaran_un: 9 | ||
}} | ||
assert_equal 'sma juanda timur', pmdk_school_informations(:pmdk_sc_one).reload.asal_sekolah | ||
assert_equal 'Unggul', pmdk_school_informations(:pmdk_sc_one).reload.akreditas | ||
assert_equal 90.78, pmdk_school_informations(:pmdk_sc_one).reload.jumlah_nilai_un | ||
assert_equal 9, pmdk_school_informations(:pmdk_sc_one).reload.jumlah_pelajaran_un | ||
end | ||
|
||
test "should get create" do | ||
get pmdk_school_informations_create_url | ||
test "should reject to update pmdk school information for invalid data" do | ||
get login_path | ||
post login_path, params: {session: { | ||
email: users(:iana).email, password: 'password' | ||
}} | ||
assert is_logged_in? | ||
get edit_pmdk_school_information_path(pmdk_school_informations(:pmdk_sc_two)) | ||
assert_response :success | ||
patch pmdk_school_information_path(pmdk_school_informations(:pmdk_sc_two)), | ||
params: {pmdk_school_information: { | ||
asal_sekolah: 'sma juanda timur', | ||
akreditas: 'Unggul', | ||
jumlah_nilai_un: 90.78, | ||
jumlah_pelajaran_un: 0 | ||
}} | ||
assert_not_equal 0, pmdk_school_informations(:pmdk_sc_two).reload.jumlah_pelajaran_un | ||
end | ||
|
||
test "should get edit" do | ||
get pmdk_school_informations_edit_url | ||
test "should create new pmdk school information" do | ||
get new_pmdk_school_information_path | ||
assert_response :success | ||
assert_difference 'PmdkSchoolInformation.count' do | ||
post pmdk_school_informations_path, params: { | ||
pmdk_school_information: { | ||
asal_sekolah: 'sma juanda timur', | ||
akreditas: 'Unggul', | ||
jumlah_nilai_un: 90.78, | ||
jumlah_pelajaran_un: 9 | ||
} | ||
} | ||
end | ||
assert_not_nil PmdkSchoolInformation.find_by_asal_sekolah 'sma juanda timur' | ||
assert_not_nil PmdkSchoolInformation.find_by_akreditas 'Unggul' | ||
assert_not_nil PmdkSchoolInformation.find_by_jumlah_nilai_un 90.78 | ||
assert_not_nil PmdkSchoolInformation.find_by_jumlah_pelajaran_un 9 | ||
end | ||
|
||
test "should get show" do | ||
get pmdk_school_informations_show_url | ||
test "should reject for non permited params-pmdk school" do | ||
get new_pmdk_school_information_path | ||
assert_response :success | ||
assert_difference 'PmdkSchoolInformation.count' do | ||
post pmdk_school_informations_path, params: { | ||
pmdk_school_information: { | ||
asal_sekolah: 'sma juanda timur', | ||
akreditas: 'Unggul', | ||
jumlah_nilai_un: 90.78, | ||
jumlah_pelajaran_un: 9, | ||
user_id: 90900099 | ||
} | ||
} | ||
end | ||
assert_nil PmdkSchoolInformation.find_by_user_id 90900099 | ||
end | ||
test "should reject for invalid information-pmdk school" do | ||
get new_pmdk_school_information_path | ||
assert_response :success | ||
assert_no_difference 'PmdkSchoolInformation.count' do | ||
post pmdk_school_informations_path, params: { | ||
pmdk_school_information: { | ||
asal_sekolah: 'sma juanda timur', | ||
akreditas: 'Unggul', | ||
jumlah_nilai_un: 90.78, | ||
jumlah_pelajaran_un: 0, | ||
} | ||
} | ||
end | ||
assert_nil PmdkSchoolInformation.find_by_jumlah_nilai_un 90.78 | ||
end | ||
test "should get edit pmdk school information" do | ||
get login_path | ||
post login_path, params: {session: { | ||
email: users(:archer).email, password: 'password' | ||
}} | ||
assert is_logged_in? | ||
get edit_pmdk_school_information_path(pmdk_school_informations(:pmdk_sc_one)) | ||
assert_response :success | ||
end | ||
test "should reject for non permited params during update" do | ||
get login_path | ||
post login_path, params: {session: { | ||
email: users(:archer).email, password: 'password' | ||
}} | ||
get edit_pmdk_school_information_path(pmdk_school_informations(:pmdk_sc_one)) | ||
assert_response :success | ||
patch pmdk_school_information_path(pmdk_school_informations(:pmdk_sc_one)), | ||
params: {pmdk_school_information: { | ||
asal_sekolah: 'sma juanda timur', | ||
akreditas: 'Unggul', | ||
jumlah_nilai_un: 90.78, | ||
jumlah_pelajaran_un: 9, | ||
user_id: 90900091 | ||
}} | ||
assert_not_equal 90900091, pmdk_school_informations(:pmdk_sc_one).reload.user_id | ||
end | ||
# | ||
# test "should get show" do | ||
# get pmdk_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 | ||
pmdk_sc_one: | ||
user: archer | ||
asal_sekolah: MyString | ||
akreditas: MyString | ||
jumlah_pelajaran_un: 2 | ||
jumlah_nilai_un: 89.69 | ||
|
||
#two: | ||
# asal_sekolah: MyString | ||
# akreditas: MyString | ||
# jumlah_pelajaran_un: MyString | ||
# jumlah_nilai_un: MyString | ||
pmdk_sc_two: | ||
user: iana | ||
asal_sekolah: MyString | ||
akreditas: MyString | ||
jumlah_pelajaran_un: 7 | ||
jumlah_nilai_un: 63.89 |
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 PmdkSchoolInformationTest < ActiveSupport::TestCase | ||
# test "the truth" do | ||
# assert true | ||
# end | ||
def setup | ||
@pmdk_information = PmdkSchoolInformation.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 @pmdk_information.valid? | ||
end | ||
test "should reject for invalid asal sekolah - utbk" do | ||
@pmdk_information.asal_sekolah='a'*2 | ||
assert_not @pmdk_information.valid? | ||
@pmdk_information.asal_sekolah=' ' | ||
assert_not @pmdk_information.valid? | ||
@pmdk_information.asal_sekolah='a'*51 | ||
assert_not @pmdk_information.valid? | ||
end | ||
test "should reject for invalid jumlah nilai un-utbk" do | ||
@pmdk_information.jumlah_nilai_un= 1000.5 | ||
assert_not @pmdk_information.valid? | ||
@pmdk_information.jumlah_nilai_un= -12 | ||
assert_not @pmdk_information.valid? | ||
end | ||
test "should reject for invalid jumlah pelajaran un-utbk" do | ||
@pmdk_information.jumlah_pelajaran_un = 50 | ||
assert_not @pmdk_information.valid? | ||
@pmdk_information.jumlah_pelajaran_un = -1 | ||
assert_not @pmdk_information.valid? | ||
end | ||
test "should reject for invalid akreditas-utbk" do | ||
@pmdk_information.akreditas = 'a'*21 | ||
assert_not @pmdk_information.valid? | ||
@pmdk_information.akreditas = ' ' | ||
assert_not @pmdk_information.valid? | ||
end | ||
end |