Skip to content

Commit

Permalink
refactoring utbk each score
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelSipayung committed Jan 31, 2024
1 parent 17320c6 commit 89e6c12
Show file tree
Hide file tree
Showing 38 changed files with 500 additions and 449 deletions.
19 changes: 0 additions & 19 deletions .idea/dataSources.xml

This file was deleted.

204 changes: 101 additions & 103 deletions .idea/sample_app.iml

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion app/controllers/majors_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def show; end
private

def major_params
params.require(:major).permit(:jurusan_1, :jurusan_2, :jurusan_3, :gelombang)
params.require(:major).permit(:jurusan1, :jurusan2, :jurusan3, :gelombang)
end

def set_major_dropdown_menu
Expand Down
10 changes: 5 additions & 5 deletions app/controllers/pmdk_each_score_informations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ def show; end

def pmdk_each_score_information_params
params.require(:pmdk_each_score_information).permit(
:matematika_semester_1, :matematika_semester_2, :matematika_semester_3, :matematika_semester_4,
:matematika_semester_5, :kimia_semester_1, :kimia_semester_2, :kimia_semester_3, :kimia_semester_4,
:kimia_semester_5, :fisika_semester_1, :fisika_semester_2, :fisika_semester_3, :fisika_semester_4,
:fisika_semester_5, :bahasa_inggris_semester_1, :bahasa_inggris_semester_2, :bahasa_inggris_semester_3,
:bahasa_inggris_semester_4, :bahasa_inggris_semester_5, :sertifikat
:matematika_semester1, :matematika_semester2, :matematika_semester3, :matematika_semester4,
:matematika5, :kimia1, :kimia2, :kimia3, :kimia4,
:kimia5, :fisika1, :fisika2, :fisika3, :fisika4,
:fisika5, :inggris1, :inggris2, :inggris3,
:inggris4, :inggris5, :sertifikat
)
end

Expand Down
32 changes: 15 additions & 17 deletions app/models/major.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,31 @@
# model major : handle major
class Major < ApplicationRecord
belongs_to :user
validates :jurusan_1, presence: true, length: { minimum: 4, maximum: 30 }
validates :jurusan_2, presence: true, length: { minimum: 4, maximum: 30 }
validates :jurusan_3, presence: true, length: { minimum: 4, maximum: 30 }
validates :jurusan1, presence: true, length: { minimum: 4, maximum: 30 }
validates :jurusan2, presence: true, length: { minimum: 4, maximum: 30 }
validates :jurusan3, presence: true, length: { minimum: 4, maximum: 30 }
validates :gelombang, presence: true, length: { minimum: 4, maximum: 30 }
# each jurusan_1 is different from jurusan_2 and jurusan_3
# each jurusan_2 is different from jurusan_3
validate :jurusan_1_not_equal_jurusan_2
validate :jurusan_1_not_equal_jurusan_3
validate :jurusan_2_not_equal_jurusan_3
validate :jurusan1_not_equal_jurusan2
validate :jurusan1_not_equal_jurusan3
validate :jurusan2_not_equal_jurusan3

private

def jurusan_1_not_equal_jurusan_2
return unless jurusan_1 == jurusan_2
def jurusan1_not_equal_jurusan2
return unless jurusan1 == jurusan2

errors.add(:jurusan_1, "can't be equal to jurusan_2")
errors.add(:jurusan1, "can't be equal to jurusan_2")
end

def jurusan_1_not_equal_jurusan_3
return unless jurusan_1 == jurusan_3
def jurusan1_not_equal_jurusan3
return unless jurusan1 == jurusan3

errors.add(:jurusan_1, "can't be equal to jurusan_3")
errors.add(:jurusan1, "can't be equal to jurusan_3")
end

def jurusan_2_not_equal_jurusan_3
return unless jurusan_2 == jurusan_3
def jurusan2_not_equal_jurusan3
return unless jurusan2 == jurusan3

errors.add(:jurusan_2, "can't be equal to jurusan_3")
errors.add(:jurusan2, "can't be equal to jurusan_3")
end
end
12 changes: 6 additions & 6 deletions app/models/pmdk_each_score_information.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
# model pmdk_each_score_information : handle pmdk_each_score_information
class PmdkEachScoreInformation < ApplicationRecord
belongs_to :user
validates :matematika_semester_1, :matematika_semester_2, :matematika_semester_3, :matematika_semester_4,
:matematika_semester_5, :kimia_semester_1, :kimia_semester_2, :kimia_semester_3, :kimia_semester_4,
:kimia_semester_5, :fisika_semester_1, :fisika_semester_2, :fisika_semester_3, :fisika_semester_4,
:fisika_semester_5, :bahasa_inggris_semester_1, :bahasa_inggris_semester_2, :bahasa_inggris_semester_3,
:bahasa_inggris_semester_4, :bahasa_inggris_semester_5, presence: true,
numericality: { only_integer: false, greater_than_or_equal_to: 2, less_than_or_equal_to: 100 }
validates :matematika_semester1, :matematika_semester2, :matematika_semester3, :matematika_semester4,
:matematika5, :kimia1, :kimia2, :kimia3, :kimia4,
:kimia5, :fisika1, :fisika2, :fisika3, :fisika4,
:fisika5, :inggris1, :inggris2, :inggris3,
:inggris4, :inggris5, presence: true,
numericality: { only_integer: false, greater_than_or_equal_to: 2, less_than_or_equal_to: 100 }
has_one_attached :sertifikat
validates :sertifikat, content_type: [:pdf], size: { less_than: 1.megabytes }
end
10 changes: 6 additions & 4 deletions app/models/utbk_score.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@ class UtbkScore < ApplicationRecord
:nilai_kemampuan_memahami_bacaan_dan_menulis,
presence: true, numericality: { only_integer: false,
greater_than_or_equal_to: 5, less_than_or_equal_to: 2000 }
validates :jumlah_nilai_semester_6, presence: true, numericality: { only_integer: false,
greater_than_or_equal_to: 2, less_than_or_equal_to: 2000 }
validates :jumlah_pelajaran_semester_6, presence: true, numericality: { only_integer: true,
greater_than_or_equal_to: 2, less_than_or_equal_to: 100 }
validates :jumlah_nilai_semester_6,
presence: true, numericality: { only_integer: false,
greater_than_or_equal_to: 2, less_than_or_equal_to: 2000 }
validates :jumlah_pelajaran_semester_6,
presence: true, numericality: { only_integer: true,
greater_than_or_equal_to: 2, less_than_or_equal_to: 100 }
has_one_attached :sertifikat_utbk # active storange api
validates :sertifikat_utbk, content_type: [:pdf], size: { less_than: 1.megabytes }
end
10 changes: 5 additions & 5 deletions app/views/shared/_major_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
<div col-md-6 col-md-offset-3>
<%= form_with(model: @major, local: true, data: {turbo: false}) do |f| %>
<%= render "shared/error_messages", object: f.object %>
<%= f.select :jurusan_1, options_from_collection_for_select(@major_list, 'jurusan', 'jurusan'),
<%= f.select :jurusan1, options_from_collection_for_select(@major_list, 'jurusan', 'jurusan'),
{}, {class: 'form-select', required: true}%>
<%= f.select :jurusan2, options_from_collection_for_select(@major_list, 'jurusan', 'jurusan'),
{}, {class: 'form-select', required: true}%>
<%= f.select :jurusan3, options_from_collection_for_select(@major_list, 'jurusan', 'jurusan'),
{}, {class: 'form-select', required: true}%>
<%= f.select :jurusan_2, options_from_collection_for_select(@major_list, 'jurusan', 'jurusan'),
{}, {class: 'form-select', required: true}%>
<%= f.select :jurusan_3, options_from_collection_for_select(@major_list, 'jurusan', 'jurusan'),
{}, {class: 'form-select', required: true}%>
<%= f.select :gelombang, options_from_collection_for_select(@batch_list, 'gelombang', 'gelombang'),
{}, {class: 'form-select', required: true}%>
<%= f.submit "Simpan", class: 'btn btn-primary' %>
Expand Down
40 changes: 20 additions & 20 deletions app/views/shared/_pmdk_each_score_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,48 +4,48 @@
<div col-md-6 col-md-offset-3>
<%= form_with(model: @pmdk_each_score, local: true, data: {turbo: false}) do |f| %>
<%= render "shared/error_messages", object: f.object %>
<%= f.text_field :matematika_semester_1, class: 'form-control',
<%= f.text_field :matematika_semester1, class: 'form-control',
placeholder: 'Nilai Matematika Semester 1' %>
<%= f.text_field :matematika_semester_2, class: 'form-control',
placeholder: 'Nilai Matematika Semester 2' %>
<%= f.text_field :matematika_semester_3, class: 'form-control',
<%= f.text_field :matematika_semester2, class: 'form-control',
placeholder: 'Nilai Matematika Semester 2' %>
<%= f.text_field :matematika_semester3, class: 'form-control',
placeholder: 'Nilai Matematika Semester 3' %>
<%= f.text_field :matematika_semester_4, class: 'form-control',
<%= f.text_field :matematika_semester4, class: 'form-control',
placeholder: 'Nilai Matematika Semester 4' %>
<%= f.text_field :matematika_semester_5, class: 'form-control',
<%= f.text_field :matematika5, class: 'form-control',
placeholder: 'Nilai Matematika Semester 5' %>

<%= f.text_field :kimia_semester_1, class: 'form-control',
<%= f.text_field :kimia1, class: 'form-control',
placeholder: 'Nilai Kimia Semester 1' %>
<%= f.text_field :kimia_semester_2, class: 'form-control',
<%= f.text_field :kimia2, class: 'form-control',
placeholder: 'Nilai Kimia Semester 2' %>
<%= f.text_field :kimia_semester_3, class: 'form-control',
<%= f.text_field :kimia3, class: 'form-control',
placeholder: 'Nilai Kimia Semester 3' %>
<%= f.text_field :kimia_semester_4, class: 'form-control',
<%= f.text_field :kimia4, class: 'form-control',
placeholder: 'Nilai Kimia Semester 4' %>
<%= f.text_field :kimia_semester_5, class: 'form-control',
<%= f.text_field :kimia5, class: 'form-control',
placeholder: 'Nilai Kimia Semester 5' %>

<%= f.text_field :fisika_semester_1, class: 'form-control',
<%= f.text_field :fisika1, class: 'form-control',
placeholder: 'Nilai Fisika Semester 1' %>
<%= f.text_field :fisika_semester_2, class: 'form-control',
<%= f.text_field :fisika2, class: 'form-control',
placeholder: 'Nilai Fisika Semester 2' %>
<%= f.text_field :fisika_semester_3, class: 'form-control',
<%= f.text_field :fisika3, class: 'form-control',
placeholder: 'Nilai Fisika Semester 3' %>
<%= f.text_field :fisika_semester_4, class: 'form-control',
<%= f.text_field :fisika4, class: 'form-control',
placeholder: 'Nilai Fisika Semester 4' %>
<%= f.text_field :fisika_semester_5, class: 'form-control',
placeholder: 'Nilai Fisika Semester 5' %>

<%= f.text_field :bahasa_inggris_semester_1, class: 'form-control',
<%= f.text_field :inggris1, class: 'form-control',
placeholder: 'Nilai Bahasa Inggris Semester 1' %>
<%= f.text_field :bahasa_inggris_semester_2, class: 'form-control',
<%= f.text_field :inggris2, class: 'form-control',
placeholder: 'Nilai Bahasa Inggris Semester 2' %>
<%= f.text_field :bahasa_inggris_semester_3, class: 'form-control',
<%= f.text_field :inggris3, class: 'form-control',
placeholder: 'Nilai Bahasa Inggris Semester 3' %>
<%= f.text_field :bahasa_inggris_semester_4, class: 'form-control',
<%= f.text_field :inggris4, class: 'form-control',
placeholder: 'Nilai Bahasa Inggris Semester 4' %>
<%= f.text_field :bahasa_inggris_semester_5, class: 'form-control',
<%= f.text_field :inggris5, class: 'form-control',
placeholder: 'Nilai Bahasa Inggris Semester 5' %>
<%= f.file_field :sertifikat, accept: 'application/pdf' %>
<% if @pmdk_each_score.persisted? && @pmdk_each_score.sertifikat.attached? %>
Expand Down
6 changes: 3 additions & 3 deletions db/migrate/20240117033057_create_majors.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
class CreateMajors < ActiveRecord::Migration[7.1]
def change
create_table :majors do |t|
t.string :jurusan_1
t.string :jurusan_2
t.string :jurusan_3
t.string :jurusan1
t.string :jurusan2
t.string :jurusan3
t.string :gelombang

t.timestamps
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def change
t.numeric :kimia_semester_4
t.numeric :kimia_semester_5

t.numeric :bahasa_inggris_semester_1
t.numeric :inggris1
t.numeric :bahasa_inggris_semester_2
t.numeric :bahasa_inggris_semester_3
t.numeric :bahasa_inggris_semester_4
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# frozen_string_literal: true

class ChangeColumnMajorToNormalCase < ActiveRecord::Migration[7.1]
def change
rename_column :majors, :jurusan_1, :jurusan1
rename_column :majors, :jurusan_2, :jurusan2
rename_column :majors, :jurusan_3, :jurusan3
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# frozen_string_literal: true

class ChangeColumnPmdkEachToNormalCase < ActiveRecord::Migration[7.1]
def change
rename_column :pmdk_each_score_informations, :matematika_semester_1,
:matematika_semester1
rename_column :pmdk_each_score_informations, :matematika_semester_2,
:matematika_semester2
rename_column :pmdk_each_score_informations, :matematika_semester_3,
:matematika_semester3
rename_column :pmdk_each_score_informations, :matematika_semester_4,
:matematika_semester4
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# frozen_string_literal: true

class RenameColumnPmdkEachToNormalCase < ActiveRecord::Migration[7.1]
def change
rename_column :pmdk_each_score_informations, :matematika_semester_5,
:matematika5
rename_column :pmdk_each_score_informations, :fisika_semester_1,
:fisika1
rename_column :pmdk_each_score_informations, :fisika_semester_2,
:fisika2
rename_column :pmdk_each_score_informations, :fisika_semester_3,
:fisika3
rename_column :pmdk_each_score_informations, :fisika_semester_4,
:fisika4
rename_column :pmdk_each_score_informations, :fisika_semester_5,
:fisika5
rename_column :pmdk_each_score_informations, :kimia_semester_1,
:kimia1
rename_column :pmdk_each_score_informations, :kimia_semester_2,
:kimia2
rename_column :pmdk_each_score_informations, :kimia_semester_3,
:kimia3
rename_column :pmdk_each_score_informations, :kimia_semester_4,
:kimia4
rename_column :pmdk_each_score_informations, :kimia_semester_5,
:kimia5
rename_column :pmdk_each_score_informations, :inggris1,
:inggris1
rename_column :pmdk_each_score_informations, :bahasa_inggris_semester_2,
:inggri2
rename_column :pmdk_each_score_informations, :bahasa_inggris_semester_3,
:inggris3
rename_column :pmdk_each_score_informations, :bahasa_inggris_semester_4,
:inggris4
rename_column :pmdk_each_score_informations, :bahasa_inggris_semester_5,
:inggris5
end
end
7 changes: 7 additions & 0 deletions db/migrate/20240131233338_rename_column_in_pmdk.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# frozen_string_literal: true

class RenameColumnInPmdk < ActiveRecord::Migration[7.1]
def change
rename_column :pmdk_each_score_informations, :inggri2, :inggris2
end
end
48 changes: 24 additions & 24 deletions db/schema.rb

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

2 changes: 1 addition & 1 deletion test/controllers/achievements_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def setup
end

test 'should get edit' do
assert is_logged_in?
assert logged_in?
puts users(:michael).inspect # This will print the michael user to the console
get edit_achievement_path achievements(:first_achievement)
assert_response :success
Expand Down
2 changes: 1 addition & 1 deletion test/controllers/organizations_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def setup
assert_response :success
end
test 'should get edit' do
assert is_logged_in?
assert logged_in?
get edit_organization_path(organizations(:one))
assert_response :success
end
Expand Down
Loading

0 comments on commit 89e6c12

Please sign in to comment.