Skip to content

Commit

Permalink
unit testing for gender religion
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelSipayung committed Jan 23, 2024
1 parent 96011fd commit bc931e2
Show file tree
Hide file tree
Showing 28 changed files with 502 additions and 0 deletions.
70 changes: 70 additions & 0 deletions app/controllers/personal_gender_lists_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
class PersonalGenderListsController < ApplicationController
before_action :set_personal_gender_list, only: %i[ show edit update destroy ]

# GET /personal_gender_lists or /personal_gender_lists.json
def index
@personal_gender_lists = PersonalGenderList.all
end

# GET /personal_gender_lists/1 or /personal_gender_lists/1.json
def show
end

# GET /personal_gender_lists/new
def new
@personal_gender_list = PersonalGenderList.new
end

# GET /personal_gender_lists/1/edit
def edit
end

# POST /personal_gender_lists or /personal_gender_lists.json
def create
@personal_gender_list = PersonalGenderList.new(personal_gender_list_params)

respond_to do |format|
if @personal_gender_list.save
format.html { redirect_to personal_gender_list_url(@personal_gender_list), notice: "Personal gender list was successfully created." }
format.json { render :show, status: :created, location: @personal_gender_list }
else
format.html { render :new, status: :unprocessable_entity }
format.json { render json: @personal_gender_list.errors, status: :unprocessable_entity }
end
end
end

# PATCH/PUT /personal_gender_lists/1 or /personal_gender_lists/1.json
def update
respond_to do |format|
if @personal_gender_list.update(personal_gender_list_params)
format.html { redirect_to personal_gender_list_url(@personal_gender_list), notice: "Personal gender list was successfully updated." }
format.json { render :show, status: :ok, location: @personal_gender_list }
else
format.html { render :edit, status: :unprocessable_entity }
format.json { render json: @personal_gender_list.errors, status: :unprocessable_entity }
end
end
end

# DELETE /personal_gender_lists/1 or /personal_gender_lists/1.json
def destroy
@personal_gender_list.destroy!

respond_to do |format|
format.html { redirect_to personal_gender_lists_url, notice: "Personal gender list was successfully destroyed." }
format.json { head :no_content }
end
end

private
# Use callbacks to share common setup or constraints between actions.
def set_personal_gender_list
@personal_gender_list = PersonalGenderList.find(params[:id])
end

# Only allow a list of trusted parameters through.
def personal_gender_list_params
params.require(:personal_gender_list).permit(:jenis_kelamin)
end
end
70 changes: 70 additions & 0 deletions app/controllers/personal_religion_lists_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
class PersonalReligionListsController < ApplicationController
before_action :set_personal_religion_list, only: %i[ show edit update destroy ]

# GET /personal_religion_lists or /personal_religion_lists.json
def index
@personal_religion_lists = PersonalReligionList.all
end

# GET /personal_religion_lists/1 or /personal_religion_lists/1.json
def show
end

# GET /personal_religion_lists/new
def new
@personal_religion_list = PersonalReligionList.new
end

# GET /personal_religion_lists/1/edit
def edit
end

# POST /personal_religion_lists or /personal_religion_lists.json
def create
@personal_religion_list = PersonalReligionList.new(personal_religion_list_params)

respond_to do |format|
if @personal_religion_list.save
format.html { redirect_to personal_religion_list_url(@personal_religion_list), notice: "Personal religion list was successfully created." }
format.json { render :show, status: :created, location: @personal_religion_list }
else
format.html { render :new, status: :unprocessable_entity }
format.json { render json: @personal_religion_list.errors, status: :unprocessable_entity }
end
end
end

# PATCH/PUT /personal_religion_lists/1 or /personal_religion_lists/1.json
def update
respond_to do |format|
if @personal_religion_list.update(personal_religion_list_params)
format.html { redirect_to personal_religion_list_url(@personal_religion_list), notice: "Personal religion list was successfully updated." }
format.json { render :show, status: :ok, location: @personal_religion_list }
else
format.html { render :edit, status: :unprocessable_entity }
format.json { render json: @personal_religion_list.errors, status: :unprocessable_entity }
end
end
end

# DELETE /personal_religion_lists/1 or /personal_religion_lists/1.json
def destroy
@personal_religion_list.destroy!

respond_to do |format|
format.html { redirect_to personal_religion_lists_url, notice: "Personal religion list was successfully destroyed." }
format.json { head :no_content }
end
end

private
# Use callbacks to share common setup or constraints between actions.
def set_personal_religion_list
@personal_religion_list = PersonalReligionList.find(params[:id])
end

# Only allow a list of trusted parameters through.
def personal_religion_list_params
params.require(:personal_religion_list).permit(:agama)
end
end
2 changes: 2 additions & 0 deletions app/helpers/personal_gender_lists_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module PersonalGenderListsHelper
end
2 changes: 2 additions & 0 deletions app/helpers/personal_religion_lists_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module PersonalReligionListsHelper
end
22 changes: 22 additions & 0 deletions app/views/personal_gender_lists/_form.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<%= form_with(model: personal_gender_list) do |form| %>
<% if personal_gender_list.errors.any? %>
<div style="color: red">
<h2><%= pluralize(personal_gender_list.errors.count, "error") %> prohibited this personal_gender_list from being saved:</h2>

<ul>
<% personal_gender_list.errors.each do |error| %>
<li><%= error.full_message %></li>
<% end %>
</ul>
</div>
<% end %>

<div>
<%= form.label :jenis_kelamin, style: "display: block" %>
<%= form.text_field :jenis_kelamin %>
</div>

<div>
<%= form.submit %>
</div>
<% end %>
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<div id="<%= dom_id personal_gender_list %>">
<p>
<strong>Jenis kelamin:</strong>
<%= personal_gender_list.jenis_kelamin %>
</p>

</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
json.extract! personal_gender_list, :id, :jenis_kelamin, :created_at, :updated_at
json.url personal_gender_list_url(personal_gender_list, format: :json)
10 changes: 10 additions & 0 deletions app/views/personal_gender_lists/edit.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<h1>Editing personal gender list</h1>

<%= render "form", personal_gender_list: @personal_gender_list %>

<br>

<div>
<%= link_to "Show this personal gender list", @personal_gender_list %> |
<%= link_to "Back to personal gender lists", personal_gender_lists_path %>
</div>
14 changes: 14 additions & 0 deletions app/views/personal_gender_lists/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<p style="color: green"><%= notice %></p>

<h1>Personal gender lists</h1>

<div id="personal_gender_lists">
<% @personal_gender_lists.each do |personal_gender_list| %>
<%= render personal_gender_list %>
<p>
<%= link_to "Show this personal gender list", personal_gender_list %>
</p>
<% end %>
</div>

<%= link_to "New personal gender list", new_personal_gender_list_path %>
1 change: 1 addition & 0 deletions app/views/personal_gender_lists/index.json.jbuilder
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
json.array! @personal_gender_lists, partial: "personal_gender_lists/personal_gender_list", as: :personal_gender_list
9 changes: 9 additions & 0 deletions app/views/personal_gender_lists/new.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<h1>New personal gender list</h1>

<%= render "form", personal_gender_list: @personal_gender_list %>

<br>

<div>
<%= link_to "Back to personal gender lists", personal_gender_lists_path %>
</div>
10 changes: 10 additions & 0 deletions app/views/personal_gender_lists/show.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<p style="color: green"><%= notice %></p>

<%= render @personal_gender_list %>

<div>
<%= link_to "Edit this personal gender list", edit_personal_gender_list_path(@personal_gender_list) %> |
<%= link_to "Back to personal gender lists", personal_gender_lists_path %>

<%= button_to "Destroy this personal gender list", @personal_gender_list, method: :delete %>
</div>
1 change: 1 addition & 0 deletions app/views/personal_gender_lists/show.json.jbuilder
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
json.partial! "personal_gender_lists/personal_gender_list", personal_gender_list: @personal_gender_list
22 changes: 22 additions & 0 deletions app/views/personal_religion_lists/_form.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<%= form_with(model: personal_religion_list) do |form| %>
<% if personal_religion_list.errors.any? %>
<div style="color: red">
<h2><%= pluralize(personal_religion_list.errors.count, "error") %> prohibited this personal_religion_list from being saved:</h2>

<ul>
<% personal_religion_list.errors.each do |error| %>
<li><%= error.full_message %></li>
<% end %>
</ul>
</div>
<% end %>

<div>
<%= form.label :agama, style: "display: block" %>
<%= form.text_field :agama %>
</div>

<div>
<%= form.submit %>
</div>
<% end %>
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<div id="<%= dom_id personal_religion_list %>">
<p>
<strong>Agama:</strong>
<%= personal_religion_list.agama %>
</p>

</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
json.extract! personal_religion_list, :id, :agama, :created_at, :updated_at
json.url personal_religion_list_url(personal_religion_list, format: :json)
10 changes: 10 additions & 0 deletions app/views/personal_religion_lists/edit.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<h1>Editing personal religion list</h1>

<%= render "form", personal_religion_list: @personal_religion_list %>

<br>

<div>
<%= link_to "Show this personal religion list", @personal_religion_list %> |
<%= link_to "Back to personal religion lists", personal_religion_lists_path %>
</div>
14 changes: 14 additions & 0 deletions app/views/personal_religion_lists/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<p style="color: green"><%= notice %></p>

<h1>Personal religion lists</h1>

<div id="personal_religion_lists">
<% @personal_religion_lists.each do |personal_religion_list| %>
<%= render personal_religion_list %>
<p>
<%= link_to "Show this personal religion list", personal_religion_list %>
</p>
<% end %>
</div>

<%= link_to "New personal religion list", new_personal_religion_list_path %>
1 change: 1 addition & 0 deletions app/views/personal_religion_lists/index.json.jbuilder
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
json.array! @personal_religion_lists, partial: "personal_religion_lists/personal_religion_list", as: :personal_religion_list
9 changes: 9 additions & 0 deletions app/views/personal_religion_lists/new.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<h1>New personal religion list</h1>

<%= render "form", personal_religion_list: @personal_religion_list %>

<br>

<div>
<%= link_to "Back to personal religion lists", personal_religion_lists_path %>
</div>
10 changes: 10 additions & 0 deletions app/views/personal_religion_lists/show.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<p style="color: green"><%= notice %></p>

<%= render @personal_religion_list %>

<div>
<%= link_to "Edit this personal religion list", edit_personal_religion_list_path(@personal_religion_list) %> |
<%= link_to "Back to personal religion lists", personal_religion_lists_path %>

<%= button_to "Destroy this personal religion list", @personal_religion_list, method: :delete %>
</div>
1 change: 1 addition & 0 deletions app/views/personal_religion_lists/show.json.jbuilder
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
json.partial! "personal_religion_lists/personal_religion_list", personal_religion_list: @personal_religion_list
9 changes: 9 additions & 0 deletions db/migrate/20240123041849_create_personal_gender_lists.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class CreatePersonalGenderLists < ActiveRecord::Migration[7.1]
def change
create_table :personal_gender_lists do |t|
t.string :jenis_kelamin

t.timestamps
end
end
end
9 changes: 9 additions & 0 deletions db/migrate/20240123041957_create_personal_religion_lists.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class CreatePersonalReligionLists < ActiveRecord::Migration[7.1]
def change
create_table :personal_religion_lists do |t|
t.string :agama

t.timestamps
end
end
end
53 changes: 53 additions & 0 deletions test/controllers/personal_gender_lists_controller_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
require "test_helper"

class PersonalGenderListsControllerTest < ActionDispatch::IntegrationTest
setup do
get login_path
post login_path, params: {session: {
email: users(:michael).email, password: 'password'
}}
@personal_gender_list = personal_gender_lists(:one)
end

test "should get index" do
get personal_gender_lists_url
assert_response :success
end

test "should get new" do
get new_personal_gender_list_url
assert_response :success
end

test "should create personal_gender_list" do
assert_difference("PersonalGenderList.count") do
post personal_gender_lists_url, params: { personal_gender_list: { jenis_kelamin: 'perempuan' } }
end

assert_redirected_to personal_gender_list_url(PersonalGenderList.last)
end

test "should show personal_gender_list" do
get personal_gender_list_url(@personal_gender_list)
assert_response :success
end

test "should get edit" do
get edit_personal_gender_list_url(@personal_gender_list)
assert_response :success
end

test "should update personal_gender_list" do
patch personal_gender_list_url(@personal_gender_list),
params: { personal_gender_list: { jenis_kelamin: 'pria' } }
assert_redirected_to personal_gender_list_url(@personal_gender_list)
end

test "should destroy personal_gender_list" do
assert_difference("PersonalGenderList.count", -1) do
delete personal_gender_list_url(@personal_gender_list)
end

assert_redirected_to personal_gender_lists_url
end
end
Loading

0 comments on commit bc931e2

Please sign in to comment.