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_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 / 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 / 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 / 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 / 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 / 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 / rofi_alt_tab_window_switching.md
Last active December 27, 2019 08:24
Rofi: Alt+Tab Window Switching

Rofi: Alt+Tab (Super+Tab) Window Switching

This is using “Super” instead of “Alt”. If you want to use the latter you only need to replace all “Super” instances with “Tab”.

Bash Script

#!/bin/bash

# Related discussion:
@lujanfernaud
lujanfernaud / javascript_avoiding_mutations_the_easy_way.md
Last active February 2, 2019 12:51
Javascript: Avoiding Mutations the Easy Way

JavaScript: Avoiding Mutations the Easy Way

Removing an Element from an Array

// Bad:
list.pop()

// Good:
list.filter(element => element !== 'hi')
@lujanfernaud
lujanfernaud / ruby_graphql_custom_scalar_hash.md
Created January 29, 2019 17:47
Ruby GraphQL: Custom Scalar Hash

Ruby GraphQL: Custom Scalar Hash

module CustomScalars
  class Hash < GraphQL::Schema::Scalar
    description 'Represents a regular hash.'
  end
end
@lujanfernaud
lujanfernaud / rails_capybara_open_page_with_assets.md
Created October 31, 2018 07:25
Rails and Capybara: Open Page With Assets

Rails and Capybara: Open Page With Assets

To automatically open pages saved when using save_and_open_page we need to add the launchy gem to the test environment.

# Gemfile

group :test do
  gem 'launchy', '~> 2.4', '>= 2.4.3'
end