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
1. | |
Buat program yang di dalamnya ada deklarasi 3 variabel. Misal masing-masing namanya adalah : | |
- first_name | |
- middle_name | |
- last_name | |
Output program ketika dijalankan adalah menggabungkan ketigaa nama tadi dengan nama tengah diambil huruf terdepan saja dan diberi tanda titik. Selain itu setiap huruf terdepan dari ketiga nama tadi harus huruf kapital dan jarak antar nama adalah satu spasi. | |
Contoh : | |
first_name = 'agung' |
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
class AccountMemberTest < ActiveSupport::TestCase | |
test "Select only Accepted status" do | |
create_list(:account, 5, :with_user) | |
accepted_member = AccountMember.accepted | |
assert_equal 5, accepted_member.count | |
end | |
test "Select only owner" do |
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
class AssetType < ApplicationRecord | |
has_many :asset_inventories | |
end | |
class AssetInventory < ApplicationRecord | |
belongs_to :asset_type | |
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
class AssetType < ApplicationRecord | |
has_many :asset_inventories | |
after_save :set_accuracy | |
def set_accuracy | |
update_column(:accuracy, asset_accuracy) | |
end | |
def asset_accuracy |
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
class AssetInventory < ApplicationRecord | |
belongs_to :asset_type | |
after_save :update_asset_accuracy | |
def update_asset_accuracy | |
asset_type.set_accuracy | |
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
class AssetType < ApplicationRecord | |
has_many :asset_inventories | |
#some codes omitted | |
def accuracy_status | |
if accuracy > 100 | |
'warning' | |
elsif accuracy >= 80 && accuracy <= 100 | |
'success' |
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
test "can get accuracy status, accuracy > 100" do | |
asset_type = create(:asset_type, accuracy: 150) | |
assert_equal "warning", asset_type.accuracy_status | |
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
test "can get accuracy status, accuracy > 100" do | |
asset_type = create(:asset_type, quantity_on_hand: 1) | |
create(:asset_inventory, asset_type: asset_type) | |
create(:asset_inventory, asset_type: asset_type) | |
assert_equal "warning", asset_type.accuracy_status | |
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
group :development, :test do | |
gem 'rspec-rails', '~> 3.9' | |
gem 'factory_bot_rails' | |
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
RSpec.configure do |config| | |
#other configurations ommitted for brevity | |
config.include FactoryBot::Syntax::Methods | |
end |
OlderNewer