-
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
b6d339b
commit ccf3fa3
Showing
15 changed files
with
400 additions
and
255 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
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 |
---|---|---|
@@ -0,0 +1,36 @@ | ||
class ParentsController < ApplicationController | ||
def new | ||
@parent = current_user.build_parent | ||
end | ||
|
||
def update | ||
@parent = current_user.parent | ||
if @parent.update(parent_params) | ||
flash[:success] = "Parent data updated" | ||
else | ||
render 'edit' | ||
end | ||
end | ||
|
||
def create | ||
@parent = current_user.build_parent(parent_params) | ||
if @parent.save | ||
flash[:success] = "Parent data saved" | ||
else | ||
render 'new' | ||
end | ||
end | ||
|
||
def edit | ||
@parent = current_user.parent | ||
end | ||
|
||
def show | ||
end | ||
private | ||
def parent_params | ||
params.require(:parent).permit(:nama_ayah, :nama_ibu, :nik_ayah,:nik_ibu, :pendidikan_ayah, | ||
:pendidikan_ibu, :tanggal_lahir_ayah, :tanggal_lahir_ibu, | ||
:pekerjaan_ayah, :pekerjaan_ibu) | ||
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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
module ParentsHelper | ||
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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<h1>Parents#create</h1> | ||
<p>Find me in app/views/parents/create.html.erb</p> |
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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<h1>Parents#edit</h1> | ||
<p>Find me in app/views/parents/edit.html.erb</p> |
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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<h1>Parents#new</h1> | ||
<p>Find me in app/views/parents/new.html.erb</p> |
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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<h1>Parents#show</h1> | ||
<p>Find me in app/views/parents/show.html.erb</p> |
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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<h1>Parents#update</h1> | ||
<p>Find me in app/views/parents/update.html.erb</p> |
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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
require "test_helper" | ||
|
||
class ParentsControllerTest < ActionDispatch::IntegrationTest | ||
def setup | ||
get login_path | ||
post login_path, params: {session: {email: users(:archer).email, password: 'password'}} | ||
end | ||
test "should get new" do | ||
assert is_logged_in? | ||
get new_parent_path | ||
assert_response :success | ||
end | ||
|
||
test "should get edit" do | ||
assert is_logged_in? | ||
get edit_parent_path(parents(:myparent)) | ||
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,7 +1,62 @@ | ||
require "test_helper" | ||
|
||
class ParentTest < ActionDispatch::IntegrationTest | ||
# test "the truth" do | ||
# assert true | ||
# end | ||
def setup | ||
get login_path | ||
post login_path, params: {session: {email: users(:michael).email, password: 'password'}} | ||
end | ||
test "should not create new parent data for invalid data" do | ||
@user = users(:archer) | ||
get login_path | ||
post login_path, params: {session: {email: @user.email, password: 'password'}} | ||
get new_parent_path | ||
assert_template 'parents/new' | ||
assert_no_difference 'Parent.count', -1 do | ||
post parents_path, params: {parent: {nama_ayah: 'example', nama_ibu: 'example', nik_ayah: '123', nik_ibu: '1234', | ||
pendidikan_ayah: 'sma', pendidikan_ibu: 'slta', tanggal_lahir_ayah: '2020-12-11', | ||
tanggal_lahir_ibu: '2013-12-10', pekerjaan_ayah: 'buruh', pekerjaan_ibu: 'guru'}} | ||
end | ||
assert_template 'parents/new' | ||
end | ||
test "should create new parent data for valid valid information" do | ||
@user = users(:archer) | ||
get login_path | ||
post login_path, params: {session: {email: @user.email, password: 'password'}} | ||
get new_parent_path | ||
assert_template 'parents/new' | ||
assert_difference 'Parent.count' do | ||
post parents_path, params: {parent: { | ||
nama_ayah: 'example', nama_ibu: 'example', nik_ayah: '1234567890121345', nik_ibu: '1234567890123415', | ||
pendidikan_ayah: 'sma', pendidikan_ibu: 'slta', tanggal_lahir_ayah: '2020-12-11', | ||
tanggal_lahir_ibu: '2013-12-10', pekerjaan_ayah: 'buruh', pekerjaan_ibu: 'guru' | ||
}} | ||
end | ||
assert_response :success | ||
end | ||
test "should update data for valid information" do | ||
get edit_parent_path(parents(:myparent)) | ||
assert_template 'parents/edit' | ||
patch parent_path(parents(:myparent)), params: { parent: { | ||
nama_ayah: 'daniel', nama_ibu: 'nisa', nik_ayah: '1234567890121345', nik_ibu: '1234567890123415', | ||
pendidikan_ayah: 'sma', pendidikan_ibu: 'slta', tanggal_lahir_ayah: '2020-12-11', | ||
tanggal_lahir_ibu: '2013-12-10', pekerjaan_ayah: 'Tentara', pekerjaan_ibu: 'guru sd' | ||
}} | ||
assert_equal 'daniel', parents(:myparent).reload.nama_ayah | ||
assert_equal 'nisa', parents(:myparent).reload.nama_ibu | ||
assert_equal 'Tentara', parents(:myparent).reload.pekerjaan_ayah | ||
assert_equal 'guru sd', parents(:myparent).reload.pekerjaan_ibu | ||
end | ||
test "should not update data for invalid information" do | ||
get edit_parent_path(parents(:myparent)) | ||
assert_template 'parents/edit' | ||
patch parent_path(parents(:myparent)), params: { parent: { | ||
nama_ayah: 'daniel', nama_ibu: 'nisa bana', nik_ayah: '1234567890121345', nik_ibu: '1234567890123415', | ||
pendidikan_ayah: '', pendidikan_ibu: '', tanggal_lahir_ayah: '2020-12-11', | ||
tanggal_lahir_ibu: '2013-12-10', pekerjaan_ayah: 'Tentara', pekerjaan_ibu: 'guru sd' | ||
}} | ||
assert_template 'parents/edit' | ||
assert_equal 'sma', parents(:myparent).reload.pendidikan_ayah | ||
assert_equal 'slta', parents(:myparent).reload.pendidikan_ibu | ||
assert_equal 'nisa', parents(:myparent).reload.nama_ibu | ||
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