Skip to content

Instantly share code, notes, and snippets.

View ghiculescu's full-sized avatar

Alex Ghiculescu ghiculescu

View GitHub Profile
@ghiculescu
ghiculescu / test.rb
Last active June 17, 2021 14:39
#13071
# frozen_string_literal: true
require "bundler/inline"
gemfile(true) do
source "https://rubygems.org"
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
gem "rails", github: "rails/rails", branch: "main"
> @rails/[email protected] lint
> coffeelint app/assets/javascripts && eslint test/ujs/public/test
✓ app/assets/javascripts/rails-ujs.coffee
✓ app/assets/javascripts/rails-ujs/features/confirm.coffee
⚡ app/assets/javascripts/rails-ujs/features/disable.coffee
⚡ #93: Unnecessary double quotes are forbidden.
✓ app/assets/javascripts/rails-ujs/features/method.coffee
⚡ app/assets/javascripts/rails-ujs/features/remote.coffee
"data-confirm: clicking on a link with data-confirm attribute. Confirm yes. (0, 6, 6)Rerun\n40 ms\ndata-confirm: clicking on a button with data-confirm attribute. Confirm yes. (0, 6, 6)Rerun\n26 ms\ndata-confirm: clicking on a link with data-confirm attribute. Confirm No. (0, 3, 3)Rerun\n66 ms\ndata-confirm: clicking on a button with data-confirm attribute. Confirm No. (0, 3, 3)Rerun\n70 ms\ndata-confirm: clicking on a button with data-confirm attribute. Confirm error. (0, 3, 3)Rerun\n68 ms\ndata-confirm: clicking on a submit button with form and data-confirm attributes. Confirm No. (0, 3, 3)Rerun\n71 ms\ndata-confirm: binding to confirm event of a link and returning false (0, 1, 1)Rerun\n69 ms\ndata-confirm: binding to confirm event of a button and returning false (0, 1, 1)Rerun\n66 ms\ndata-confirm: binding to confirm:complete event of a link and returning false (0, 2, 2)Rerun\n69 ms\ndata-confirm: binding to confirm:complete event of a button and returning false (0, 2, 2)Rerun\n66 ms\ndata-confirm: a butto
@ghiculescu
ghiculescu / notes.md
Created June 2, 2021 14:08
Optimizing Rails fixtures

I had a thought while riding to work today: how much faster would CI and tests be if we had a lot less fixtures. I had a suspicion that cutting down on our fixtures load would make CI a lot faster.

Let's test this hypothesis:

Given this test class:

class SomethingTest < ActiveSupport::TestCase
  test "something" do
  end
def display_expected_hours_in_pay_period(user)
freq = user.next_pay_group.typed_frequency
case freq
when Frequency::Weekly
t("periods.week").downcase
when Frequency::Fortnightly
t("periods.fortnight").downcase
when Frequency::SemiMonthly
t("periods.period").downcase
# This file is autogenerated. Do not edit it by hand. Regenerate it with:
# srb rbi gems
# typed: false
#
# If you would like to make changes to this file, great! Please create the gem's shim here:
#
# https://github.com/sorbet/sorbet-typed/new/master?filename=lib/sorbet-rails/all/sorbet-rails.rbi
#
# sorbet-rails-0.5.7
fetch("https://YOUR_DOMAIN.canny.io/api/users/get", {"credentials":"include","headers":{"accept":"*/*","accept-language":"en-GB,en;q=0.9,en-US;q=0.8","content-type":"application/json","sec-fetch-mode":"cors","sec-fetch-site":"same-origin"},"referrer":"https://YOUR_DOMAIN.canny.io/admin/users","referrerPolicy":"no-referrer-when-downgrade","body":"{\"__host\":\"YOUR_DOMAIN.canny.io\___LOTS_OF_OTHER_CRAP_HERE___\"limit\":1000}","method":"POST","mode":"cors"}).then(d => d.json().then(t => console.log(t.result.users.sort((a, b) => b.voteCount - a.voteCount))))

srb rbi suggest-typed internally runs srb tc --typed=strict --error-white-list=7022 --suggest-typed -a

--error-white-list means "only output errors of this kind", and 7022 is the error that is used to suggest a type. therefore, this runs sorbet at typed: strict across the board, and then outputs errors with type suggestions where appropriate.

THE PROBLEM is that when we run this on our (big) codebase, a bunch of files get downgraded to typed: ignore. but if we run srb tc on the same codebase, with higher sigils (eg. typed: true) on those files, there's no errors.

the type sorbet suggests is one level lower than the file's current min error level: https://github.com/sorbet/sorbet/blob/c33b7e2e41657b482a631e2edb931258995406bc/main/realmain.cc#L525

errors have a minLevel that comes from their what, which is an ErrorClass: https://github.com/sorbet/sorbet/blob/09fc62528d3b25357e297b594e699ab096d8b12d/core/Error.h#L132.

@ghiculescu
ghiculescu / active_record_5_adapter_with_default_scopes_spec.rb
Last active September 3, 2019 17:18
How to replicate https://github.com/CanCanCommunity/cancancan/pull/600 - switch to master, add this test file, then run the test command below. It should fail for you too!
# frozen_string_literal: true
require 'spec_helper'
if CanCan::ModelAdapters::ActiveRecordAdapter.version_greater_or_equal?('5.0.0')
describe CanCan::ModelAdapters::ActiveRecord5Adapter do
context 'with postgresql' do
before :each do
connect_db
ActiveRecord::Migration.verbose = false
if rand > 0.5
"do this"
else
"do that"
end