Skip to content

Instantly share code, notes, and snippets.

View agungsetiawan's full-sized avatar

Agung Setiawan agungsetiawan

View GitHub Profile
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'
@agungsetiawan
agungsetiawan / account_member_test.rb
Created February 11, 2020 23:42
Toying around with stub and mock on Minitest
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
class AssetType < ApplicationRecord
has_many :asset_inventories
end
class AssetInventory < ApplicationRecord
belongs_to :asset_type
end
class AssetType < ApplicationRecord
has_many :asset_inventories
after_save :set_accuracy
def set_accuracy
update_column(:accuracy, asset_accuracy)
end
def asset_accuracy
class AssetInventory < ApplicationRecord
belongs_to :asset_type
after_save :update_asset_accuracy
def update_asset_accuracy
asset_type.set_accuracy
end
end
class AssetType < ApplicationRecord
has_many :asset_inventories
#some codes omitted
def accuracy_status
if accuracy > 100
'warning'
elsif accuracy >= 80 && accuracy <= 100
'success'
test "can get accuracy status, accuracy > 100" do
asset_type = create(:asset_type, accuracy: 150)
assert_equal "warning", asset_type.accuracy_status
end
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
group :development, :test do
gem 'rspec-rails', '~> 3.9'
gem 'factory_bot_rails'
end
RSpec.configure do |config|
#other configurations ommitted for brevity
config.include FactoryBot::Syntax::Methods
end