-
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.
bugs on update usm school information
- Loading branch information
1 parent
9d0dc55
commit 55fc99b
Showing
6 changed files
with
236 additions
and
122 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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 UsmSchoolInformationsController < ApplicationController | ||
def new | ||
@usm_school = current_user.build_usm_school_information | ||
end | ||
|
||
def update | ||
@usm_school = current_user.usm_school_information | ||
if @usm_school.update(usm_school_information_params) | ||
flash[:success] = "usm school information is updated" | ||
else | ||
render 'edit' | ||
end | ||
end | ||
|
||
def create | ||
@usm_school = current_user.build_usm_school_information(usm_school_information_params) | ||
if @usm_school.save | ||
flash[:success] = "usm school information is saved" | ||
else | ||
render 'new' | ||
end | ||
end | ||
|
||
def edit | ||
@usm_school = current_user.usm_school_information | ||
end | ||
|
||
def show | ||
end | ||
private | ||
def usm_school_information_params | ||
params.require(:usm_school_information).permit( | ||
:jurusan_sekolah, :asal_sekolah, :akreditas, :jumlah_nilai_un, | ||
:jumlah_pelajaran_un, :jumlah_pelajaran_semester_5, :jumlah_nilai_semester_5 | ||
) | ||
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
119 changes: 106 additions & 13 deletions
119
test/controllers/usm_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,121 @@ | ||
require "test_helper" | ||
|
||
class UsmSchoolInformationsControllerTest < ActionDispatch::IntegrationTest | ||
test "should get new" do | ||
get usm_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 usm school information" do | ||
assert is_logged_in? | ||
get new_usm_school_information_url | ||
assert_response :success | ||
end | ||
|
||
test "should get update" do | ||
get usm_school_informations_update_url | ||
test "should get edit usm school information" do | ||
get login_path | ||
post login_path, params: {session: { | ||
email: users(:archer).email, password: 'password' | ||
}} | ||
assert is_logged_in? | ||
get edit_usm_school_information_url(usm_school_informations(:usm_one)) | ||
assert_response :success | ||
end | ||
|
||
test "should get create" do | ||
get usm_school_informations_create_url | ||
test "should create usm school information" do | ||
get new_usm_school_information_url | ||
assert_response :success | ||
assert_difference 'UsmSchoolInformation.count' do | ||
post usm_school_informations_path, params: { | ||
usm_school_information: { | ||
jurusan_sekolah: 'ipa MA', asal_sekolah: 'sma santo tomas 2', akreditas: 'terakreditasi', | ||
jumlah_pelajaran_semester_5: 15, jumlah_nilai_semester_5: 799.9 | ||
} | ||
} | ||
end | ||
assert_not_nil UsmSchoolInformation.find_by_jurusan_sekolah 'ipa MA' | ||
assert_not_nil UsmSchoolInformation.find_by_asal_sekolah 'sma santo tomas 2' | ||
assert_not_nil UsmSchoolInformation.find_by_jumlah_pelajaran_semester_5 15 | ||
assert_not_nil UsmSchoolInformation.find_by_jumlah_nilai_semester_5 799.9 | ||
end | ||
|
||
test "should get edit" do | ||
get usm_school_informations_edit_url | ||
test "should reject for invalid usm school information" do | ||
get new_usm_school_information_url | ||
assert_response :success | ||
assert_no_difference 'UsmSchoolInformation.count' do | ||
post usm_school_informations_path, params: { | ||
usm_school_information: { | ||
jurusan_sekolah: 'ipa MA', asal_sekolah: 'sma santo tomas 2', akreditas: 'terakreditasi', | ||
jumlah_pelajaran_semester_5: 15, jumlah_nilai_semester_5: 0 | ||
} | ||
} | ||
end | ||
end | ||
|
||
test "should get show" do | ||
get usm_school_informations_show_url | ||
test "should create usm school information but reject non permited params" do | ||
get new_usm_school_information_url | ||
assert_response :success | ||
assert_difference 'UsmSchoolInformation.count' do | ||
post usm_school_informations_path, params: { | ||
usm_school_information: { | ||
jurusan_sekolah: 'ipa MA', asal_sekolah: 'sma santo tomas 2', akreditas: 'terakreditasi', | ||
jumlah_pelajaran_semester_5: 15, jumlah_nilai_semester_5: 799.9, user_id: 87999822 | ||
} | ||
} | ||
end | ||
assert_nil UsmSchoolInformation.find_by_user_id 87999822 | ||
end | ||
test "should update the usm school information" do | ||
get login_path | ||
post login_path, params: {session: { | ||
email: users(:archer).email, password: 'password' | ||
}} | ||
assert is_logged_in? | ||
get edit_usm_school_information_url(usm_school_informations(:usm_one)) | ||
assert_response :success | ||
patch usm_school_information_path(usm_school_informations(:usm_one)), params: { | ||
usm_school_information: { | ||
jurusan_sekolah: 'ipa MA', asal_sekolah: 'sma santo tomas 2', akreditas: 'terakreditasi', | ||
jumlah_pelajaran_semester_5: 15, jumlah_nilai_semester_5: 799.9 | ||
} | ||
} | ||
usm_school_informations(:usm_one).reload | ||
puts usm_school_informations(:usm_one).reload.jurusan_sekolah | ||
assert_equal 'ipa MA', usm_school_informations(:usm_one).reload.jurusan_sekolah | ||
assert_equal 'sma santo tomas 2', usm_school_informations(:usm_one).asal_sekolah | ||
assert_equal 'terakreditasi', usm_school_informations(:usm_one).akreditas | ||
assert_equal 15, usm_school_informations(:usm_one).jumlah_pelajaran_semester_5 | ||
assert_equal 799.9, usm_school_informations(:usm_one).jumlah_nilai_semester_5 | ||
end | ||
test "should reject non permited params during update usm school information" do | ||
get login_path | ||
post login_path, params: {session: { | ||
email: users(:archer).email, password: 'password' | ||
}} | ||
assert is_logged_in? | ||
get edit_usm_school_information_url(usm_school_informations(:usm_one)) | ||
assert_response :success | ||
patch usm_school_information_path(usm_school_informations(:usm_one)), params: { | ||
usm_school_information: { | ||
jurusan_sekolah: 'ipa MA', asal_sekolah: 'sma santo tomas 2', akreditas: 'terakreditasi', | ||
jumlah_pelajaran_semester_5: 15, jumlah_nilai_semester_5: 799.9, user_id: 9990998 | ||
} | ||
} | ||
usm_school_informations(:usm_one).reload | ||
assert_not_equal 9990998, usm_school_informations(:usm_one).user_id | ||
end | ||
test "should reject to update usm school information for invalid data" do | ||
get login_path | ||
post login_path, params: {session: { | ||
email: users(:archer).email, password: 'password' | ||
}} | ||
assert is_logged_in? | ||
get edit_usm_school_information_url(usm_school_informations(:usm_one)) | ||
assert_response :success | ||
patch usm_school_information_path(usm_school_informations(:usm_one)), params: { | ||
usm_school_information: { | ||
jurusan_sekolah: 'ipa MA', asal_sekolah: 'sm', akreditas: 'terakreditasi', | ||
jumlah_pelajaran_semester_5: 15, jumlah_nilai_semester_5: 799.9 | ||
} | ||
} | ||
assert_not_equal 'sm', usm_school_informations(:usm_one).reload.asal_sekolah | ||
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