Skip to content

Instantly share code, notes, and snippets.

View lujanfernaud's full-sized avatar
🦪
Working from home

Luján Fernaud lujanfernaud

🦪
Working from home
View GitHub Profile
@lujanfernaud
lujanfernaud / rspec_only_failures.md
Last active January 28, 2020 08:58
RSpec: Run Only Failures

RSpec: Run Only Failures

In spec/spec_helper.rb:

RSpec.configure do |config|
  # This setting allows us to only re-run examples that had failures.
  # https://relishapp.com/rspec/rspec-core/docs/command-line/only-failures
  #
 # Usage:
@lujanfernaud
lujanfernaud / rails_url_helpers.md
Created January 28, 2020 19:01
Rails: URL Helpers

Rails: URL Helpers

Access path helpers from outside controllers.

Rails.application.routes.url_helpers
Rails.application.routes.url_helpers.dashboard_path
Rails.application.routes.url_helpers.users_path
Rails.application.routes.url_helpers.pages_path
@lujanfernaud
lujanfernaud / rubocop_autocorrect_specific_cops.md
Last active February 27, 2020 12:08
RuboCop: Autocorrect Using Specific Cops

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:

@lujanfernaud
lujanfernaud / rake_tasks_helper.rb
Last active March 27, 2020 13:00
RSpec: Rake Tasks Helper
# Example usage =============
#
# describe :namespace do
# include RakeTasksHelper
#
# describe ':task' do
# it 'works' do
# invoke_task('namespace:task')
# end
# end
@lujanfernaud
lujanfernaud / rails_tables_finder.rb
Last active April 3, 2020 18:04
Rails: Tables Finder
# Example:
#
# > TablesFinder.call(column_name: 'site_id')
# => ['events', 'users']
class TablesFinder
VALID_ATTRIBUTES = %w[
COLUMN_NAME
].freeze
def self.call(args)
@lujanfernaud
lujanfernaud / rspec_include_based_on_type.md
Last active May 8, 2020 06:25
RSpec: Include based on type

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
@lujanfernaud
lujanfernaud / rspec_add_metadata_based_on_path.md
Created May 8, 2020 06:32
RSpec: Add metadata based on path

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 / sidekiq_clear_specific_queue.md
Created July 27, 2020 07:31
Sidekiq: Clear a Specific Queue

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:

@lujanfernaud
lujanfernaud / log_interactor_execution.rb
Last active August 7, 2020 12:37
Debugging: LogInteractorExecution
# Usage:
#
# class SomeInteractor
# include Interactor
# include LogInteractorExecution
#
# # ...
#
# private
#