Skip to content

Instantly share code, notes, and snippets.

Building railsdevs in public.

Joe Masilotti joemasilotti

Building railsdevs in public.
View GitHub Profile
joemasilotti / cold_message.rb
Created Apr 27, 2022
Service layer extraction
View cold_message.rb
# AFTER the refactor
class ColdMessage
class BusinessBlank < StandardError; end
class MissingSubscription < StandardError; end
class ExistingConversation < StandardError
attr_reader :conversation
joemasilotti / Gemfile
Last active Jan 21, 2022
How To Test PDFs with Capybara Blog post with details:
View Gemfile
group :test do
gem 'rspec-rails'
gem 'capybara'
gem 'pdf-reader'
joemasilotti /
Last active Dec 31, 2021
Resetting NSUserDefaults in UI Testing

Resetting NSUserDefaults in UI Testing

  1. Add "UI-Testing" to launchArguments before launching the app under test
  2. On launch, check for the argument in AppDelegate.swift
  3. If it exists remove everything for the app's domain from NSUserDefaults
joemasilotti / sidekiq_policy.rb
Created Dec 22, 2021
ActiveSupport::EnvironmentInquirer example
View sidekiq_policy.rb
class SidekiqPolicy
attr_reader :user, :environment
def initialize(user, environment: Rails.env)
@user = user
@environment = environment
def visible?
user.admin? || environment.development?
joemasilotti / Multiple sheets in
Last active Oct 13, 2021
Multiple sheets in SwiftUI
View Multiple sheets in
joemasilotti / HTTP.swift
Last active Mar 25, 2021
Combine-powered HTTP client with success and failure JSON decoding
View HTTP.swift
enum HTTP {
struct Response<T> {
let value: T
let headers: [AnyHashable: Any]
enum HTTPError<T: LocalizedError>: LocalizedError {
case failedRequest
case invalidResponse
case invalidRequest(T)
joemasilotti /
Created Mar 4, 2021
Turbolinks + Turbo Native - Generic form handling with Stimulus

Turbolinks + Turbo Native - Generic form handling with Stimulus

These three files show how to handle forms with (legacy) Turbolinks in your Rails app with the new Turbo Native adapters.

  1. The Rails controller renders the form partial with an :unprocessable_entity status when encountering a form validation error
  2. The form is submitted via AJAX (local: false or remote: true depending on your Rails version)
  3. This is caught via the ajax:error->form#onError Stimulus action
  4. The Stimulus controller replaces the form's contents with the server-sided rendered HTML
  5. The native app is informed when the redirect occurs on a succesful submission
joemasilotti / ScriptMessageEnum.swift
Created Feb 10, 2021
Two approached to a Swift enum with associated type
View ScriptMessageEnum.swift
// Enum with manual parsing.
enum ScriptMessage {
case registerForRemoteNotifications
case showBackButton(url: URL)
case signOutCompleted
init?(body: [String: Any]) {
switch body["name"] as? String {
case "registerForRemoteNotifications":
self = .registerForRemoteNotifications
joemasilotti / TestVisitDelegate.swift
Created Dec 28, 2020
Using #function to record messages sent to Swift test doubles
View TestVisitDelegate.swift
class TestVisitDelegate: VisitDelegate {
func visitDidStart() {
func visitDidComplete() {
// MARK: Testing verification helpers.