Skip to content

Instantly share code, notes, and snippets.

Avatar
👨‍🔬

Luján Fernaud lujanfernaud

👨‍🔬
View GitHub Profile
@lujanfernaud
lujanfernaud / minitest_and_database_cleaner.md
Last active Oct 20, 2020
Minitest and Database Cleaner
View minitest_and_database_cleaner.md

Minitest and Database Cleaner

test_helper.rb

require 'database_cleaner'
require 'database_cleaner_support'

DatabaseCleaner.clean_with :truncation
DatabaseCleaner.strategy = :transaction
@lujanfernaud
lujanfernaud / log_interactor_execution.rb
Last active Aug 7, 2020
Debugging: LogInteractorExecution
View log_interactor_execution.rb
# Usage:
#
# class SomeInteractor
# include Interactor
# include LogInteractorExecution
#
# # ...
#
# private
#
@lujanfernaud
lujanfernaud / sidekiq_clear_specific_queue.md
Created Jul 27, 2020
Sidekiq: Clear a Specific Queue
View sidekiq_clear_specific_queue.md

Sidekiq: Clear a Specific Queue

Find the queue by name:

> queue = Sidekiq::Queue.all.detect { |queue| queue.name == 'compliance_requests' }
=> #<Sidekiq::Queue:0x00007fa5c4069778 @name="compliance_requests", @rname="queue:compliance_requests">

Clear the queue:

View rspec_add_metadata_based_on_path.md

RSpec: Add metadata based on path

RSpec.configure do |config|
  config.define_derived_metadata(file_path: %r{platforms/.*/spec/controllers/}) do |metadata|
    metadata[:type] = :controller
    metadata[:platform_controller] = true
  end

  config.include MainAppRoutesHelper, platform_controller: true
@lujanfernaud
lujanfernaud / rspec_include_based_on_type.md
Last active May 8, 2020
RSpec: Include based on type
View rspec_include_based_on_type.md

RSpec: Include based on type

# spec/support/user_support.rb
RSpec.configure do |config|
 config.include UserHelper, type: :user
 config.include_context "user_context", type: :use
end
View rails_tables_finder.rb
# Example:
#
# > TablesFinder.call(column_name: 'site_id')
# => ['events', 'users']
class TablesFinder
VALID_ATTRIBUTES = %w[
COLUMN_NAME
].freeze
def self.call(args)
@lujanfernaud
lujanfernaud / rake_tasks_helper.rb
Last active Mar 27, 2020
RSpec: Rake Tasks Helper
View rake_tasks_helper.rb
# Example usage =============
#
# describe :namespace do
# include RakeTasksHelper
#
# describe ':task' do
# it 'works' do
# invoke_task('namespace:task')
# end
# end
@lujanfernaud
lujanfernaud / seeds-faker-carrierwave.rb
Created Sep 7, 2017
Rails: Seed database with remote Faker images and CarrierWave
View seeds-faker-carrierwave.rb
# We need to use 'remote_<object>_url' as attribute instead of '<object>'.
# Having Image, we would use 'remote_image_url: <url>'.
titles = [Faker::RockBand.name, Faker::BossaNova.artist, Faker::Book.title]
54.times do |n|
start_date = Faker::Date.between(1.day.from_now, 6.months.from_now)
end_date = start_date + 1.day
Event.create!(title: titles.sample + " ##{n}",
@lujanfernaud
lujanfernaud / rubocop_autocorrect_specific_cops.md
Last active Feb 27, 2020
RuboCop: Autocorrect Using Specific Cops
View rubocop_autocorrect_specific_cops.md

RuboCop: Autocorrect Using Specific Cops

We can autocorrect using only some cops by passing --only CopType/CopName.

rubocop --only Style/HashTransformKeys

First run with --safe-auto-correct to see the affected changes:

You can’t perform that action at this time.