Skip to content

Commit

Permalink
unit testing for source motivation&information
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelSipayung committed Jan 24, 2024
1 parent c340ade commit d3f1243
Show file tree
Hide file tree
Showing 52 changed files with 843 additions and 26 deletions.
3 changes: 1 addition & 2 deletions .idea/sample_app.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

70 changes: 70 additions & 0 deletions app/controllers/batch_lists_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
class BatchListsController < ApplicationController
before_action :set_batch_list, only: %i[ show edit update destroy ]

# GET /batch_lists or /batch_lists.json
def index
@batch_lists = BatchList.all
end

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

# GET /batch_lists/new
def new
@batch_list = BatchList.new
end

# GET /batch_lists/1/edit
def edit
end

# POST /batch_lists or /batch_lists.json
def create
@batch_list = BatchList.new(batch_list_params)

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

# PATCH/PUT /batch_lists/1 or /batch_lists/1.json
def update
respond_to do |format|
if @batch_list.update(batch_list_params)
format.html { redirect_to batch_list_url(@batch_list), notice: "Batch list was successfully updated." }
format.json { render :show, status: :ok, location: @batch_list }
else
format.html { render :edit, status: :unprocessable_entity }
format.json { render json: @batch_list.errors, status: :unprocessable_entity }
end
end
end

# DELETE /batch_lists/1 or /batch_lists/1.json
def destroy
@batch_list.destroy!

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

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

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

# GET /source_information_lists or /source_information_lists.json
def index
@source_information_lists = SourceInformationList.all
end

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

# GET /source_information_lists/new
def new
@source_information_list = SourceInformationList.new
end

# GET /source_information_lists/1/edit
def edit
end

# POST /source_information_lists or /source_information_lists.json
def create
@source_information_list = SourceInformationList.new(source_information_list_params)

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

# PATCH/PUT /source_information_lists/1 or /source_information_lists/1.json
def update
respond_to do |format|
if @source_information_list.update(source_information_list_params)
format.html { redirect_to source_information_list_url(@source_information_list), notice: "Source information list was successfully updated." }
format.json { render :show, status: :ok, location: @source_information_list }
else
format.html { render :edit, status: :unprocessable_entity }
format.json { render json: @source_information_list.errors, status: :unprocessable_entity }
end
end
end

# DELETE /source_information_lists/1 or /source_information_lists/1.json
def destroy
@source_information_list.destroy!

respond_to do |format|
format.html { redirect_to source_information_lists_url, notice: "Source information list was successfully destroyed." }
format.json { head :no_content }
end
end

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

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

# GET /source_motivation_lists or /source_motivation_lists.json
def index
@source_motivation_lists = SourceMotivationList.all
end

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

# GET /source_motivation_lists/new
def new
@source_motivation_list = SourceMotivationList.new
end

# GET /source_motivation_lists/1/edit
def edit
end

# POST /source_motivation_lists or /source_motivation_lists.json
def create
@source_motivation_list = SourceMotivationList.new(source_motivation_list_params)

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

# PATCH/PUT /source_motivation_lists/1 or /source_motivation_lists/1.json
def update
respond_to do |format|
if @source_motivation_list.update(source_motivation_list_params)
format.html { redirect_to source_motivation_list_url(@source_motivation_list), notice: "Source motivation list was successfully updated." }
format.json { render :show, status: :ok, location: @source_motivation_list }
else
format.html { render :edit, status: :unprocessable_entity }
format.json { render json: @source_motivation_list.errors, status: :unprocessable_entity }
end
end
end

# DELETE /source_motivation_lists/1 or /source_motivation_lists/1.json
def destroy
@source_motivation_list.destroy!

respond_to do |format|
format.html { redirect_to source_motivation_lists_url, notice: "Source motivation list was successfully destroyed." }
format.json { head :no_content }
end
end

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

# Only allow a list of trusted parameters through.
def source_motivation_list_params
params.require(:source_motivation_list).permit(:motivasi)
end
end
2 changes: 2 additions & 0 deletions app/helpers/batch_lists_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module BatchListsHelper
end
2 changes: 2 additions & 0 deletions app/helpers/source_information_lists_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module SourceInformationListsHelper
end
2 changes: 2 additions & 0 deletions app/helpers/source_motivation_lists_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module SourceMotivationListsHelper
end
7 changes: 7 additions & 0 deletions app/models/batch_list.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,9 @@
class BatchList < ApplicationRecord
validates :gelombang, presence: true, length: {minimum: 4, maximum: 25}, uniqueness: true
#aktif must boolean
validate :aktif_is_boolean
private
def aktif_is_boolean
errors.add(:aktif, "must be boolean") unless [true, false].include? aktif
end
end
1 change: 1 addition & 0 deletions app/models/source_information_list.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
class SourceInformationList < ApplicationRecord
validates :informasi, presence: true, length: {minimum: 4, maximum: 25}, uniqueness: true
end
1 change: 1 addition & 0 deletions app/models/source_motivation_list.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
class SourceMotivationList < ApplicationRecord
validates :motivasi, presence: true, length: {minimum: 4, maximum: 20}, uniqueness: true
end
12 changes: 12 additions & 0 deletions app/views/batch_lists/_batch_list.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<div id="<%= dom_id batch_list %>">
<p>
<strong>Gelombang:</strong>
<%= batch_list.gelombang %>
</p>

<p>
<strong>Aktif:</strong>
<%= batch_list.aktif %>
</p>

</div>
2 changes: 2 additions & 0 deletions app/views/batch_lists/_batch_list.json.jbuilder
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
json.extract! batch_list, :id, :gelombang, :aktif, :created_at, :updated_at
json.url batch_list_url(batch_list, format: :json)
27 changes: 27 additions & 0 deletions app/views/batch_lists/_form.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<%= form_with(model: batch_list) do |form| %>
<% if batch_list.errors.any? %>
<div style="color: red">
<h2><%= pluralize(batch_list.errors.count, "error") %> prohibited this batch_list from being saved:</h2>

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

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

<div>
<%= form.label :aktif, style: "display: block" %>
<%= form.check_box :aktif %>
</div>

<div>
<%= form.submit %>
</div>
<% end %>
10 changes: 10 additions & 0 deletions app/views/batch_lists/edit.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<h1>Editing batch list</h1>

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

<br>

<div>
<%= link_to "Show this batch list", @batch_list %> |
<%= link_to "Back to batch lists", batch_lists_path %>
</div>
14 changes: 14 additions & 0 deletions app/views/batch_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>Batch lists</h1>

<div id="batch_lists">
<% @batch_lists.each do |batch_list| %>
<%= render batch_list %>
<p>
<%= link_to "Show this batch list", batch_list %>
</p>
<% end %>
</div>

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

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

<br>

<div>
<%= link_to "Back to batch lists", batch_lists_path %>
</div>
10 changes: 10 additions & 0 deletions app/views/batch_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 @batch_list %>

<div>
<%= link_to "Edit this batch list", edit_batch_list_path(@batch_list) %> |
<%= link_to "Back to batch lists", batch_lists_path %>

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

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

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

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

</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
json.extract! source_information_list, :id, :informasi, :created_at, :updated_at
json.url source_information_list_url(source_information_list, format: :json)
10 changes: 10 additions & 0 deletions app/views/source_information_lists/edit.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<h1>Editing source information list</h1>

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

<br>

<div>
<%= link_to "Show this source information list", @source_information_list %> |
<%= link_to "Back to source information lists", source_information_lists_path %>
</div>
Loading

0 comments on commit d3f1243

Please sign in to comment.