Skip to content

Instantly share code, notes, and snippets.

Avatar
🐔
Debugging Everything

Rafael George cored

🐔
Debugging Everything
View GitHub Profile
@cored
cored / test_induced_design_damage.rb
Created Jun 25, 2021 — 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 …
View test_induced_design_damage.rb
# 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
View billable_event.rb
# frozen_string_literal: true
module Billing
module Models
class BillableEvent < ActiveRecord::Base
DrugHealthScreeningDataNotPresent = Class.new(StandardError)
acts_as_paranoid
belongs_to :event
View 20161010203646_rename_counties_table.rb
# frozen_string_literal: true
class RenameCountiesTable < ActiveRecord::Migration[5.0]
def change
rename_table :counties, :county_fees
end
end
View synchronize_canada_invoices_monthly_worker_spec.rb
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
View invoice_item.rb
# frozen_string_literal: true
module Billing
module Models
class InvoiceItem < ActiveRecord::Base
extend Memoist
include Mixins::Reportable
View config.yml
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
View canada.rb
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
View package.rb
# frozen_string_literal: true
module Checkr
module Internal
class Package < Resource
def self.get(package_id)
url = "/packages/#{package_id}"
key = ['get', url].join(':')
View update_account.rb
def self.call(payload)
new(body: payload).call
end
def initialize(body:)
@body = body
end
View metric_find_query_test.go
package cloudwatch_test
import (
"context"
"testing"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/cloudwatch"
"github.com/aws/aws-sdk-go/service/ec2"
"github.com/aws/aws-sdk-go/service/ec2/ec2iface"