Skip to content

Instantly share code, notes, and snippets.

View cored's full-sized avatar
🐽
Hacking Everything

Rafael George cored

🐽
Hacking Everything
View GitHub Profile
@cored
cored / inventory.rbb
Last active November 18, 2024 14:38
inventory.rb
class Inventory
NotCheckedInCustomer = Class.new(StandardError)
def initialize
@customers = []
end
Customer = Struct.new(:license_number,
:usage_type,
:checkin_time,
@cored
cored / test_induced_design_damage.rb
Created June 25, 2021 17:01 — forked from dhh/test_induced_design_damage.rb
This is an extraction from Jim Weirich's "Decoupling from Rails" talk, which explained how to apply the hexagonal design pattern to make every layer of your application easily unit testable (without touching the database etc). It only seeks to extract a single method, the EmployeesController#create method, to illustrate the design damage that's …
# Original Rails controller and action
class EmployeesController < ApplicationController
def create
@employee = Employee.new(employee_params)
if @employee.save
redirect_to @employee, notice: "Employee #{@employee.name} created"
else
render :new
end
# frozen_string_literal: true
module Billing
module Models
class BillableEvent < ActiveRecord::Base
DrugHealthScreeningDataNotPresent = Class.new(StandardError)
acts_as_paranoid
belongs_to :event
# frozen_string_literal: true
class RenameCountiesTable < ActiveRecord::Migration[5.0]
def change
rename_table :counties, :county_fees
end
end
require 'sidekiq/testing'
RSpec.describe Billing::Workers::SynchronizeCanadaInvoicesMonthlyWorker do
subject(:synchronize_invoices_worker) { described_class }
before do
Sidekiq::Testing.inline!
allow(Invoices::Synchronize).to receive(:call)
end
# frozen_string_literal: true
module Billing
module Models
class InvoiceItem < ActiveRecord::Base
extend Memoist
include Mixins::Reportable
version: 2
jobs:
build:
parallelism: 4
docker:
- image: circleci/ruby:2.5.3-node-browsers
environment:
MYSQL_PORT: 3306
RACK_ENV: test
REDIS_URL: redis://127.0.0.1:6379
@cored
cored / canada.rb
Last active December 5, 2019 23:09
def self.create_canada_account(payload, client_id)
account_id = payload[:account][:checkr_internal_id]
client_name = payload[:account][:name]
sfdc_id = payload[:account][:sfdc_id]
Billing::Models::CanadaAccount.create!(
account_id: account_id,
client_name: client_name,
client_id: client_id,
sfdc_id: sfdc_id
# frozen_string_literal: true
module Checkr
module Internal
class Package < Resource
def self.get(package_id)
url = "/packages/#{package_id}"
key = ['get', url].join(':')
def self.call(payload)
new(body: payload).call
end
def initialize(body:)
@body = body
end