Skip to content

Instantly share code, notes, and snippets.

@ProGM
ProGM / arel_cheatsheet_on_steroids.md
Last active July 4, 2024 14:08
Arel cheatsheet on Steroids

Arel Cheatsheet on Steroids

A (more) complete cheatsheet for Arel, including NamedFunction functions, raw SQL and window functions.

Tables

posts = Arel::Table.new(:posts)
posts = Post.arel_table # ActiveRecord

Table alias

@ssaunier
ssaunier / sidekiq.config
Created September 24, 2015 09:30
Running Sidekiq on AWS Elastic Beanstalk (Put that file in `.ebextensions` folder)
# Sidekiq interaction and startup script
commands:
create_post_dir:
command: "mkdir -p /opt/elasticbeanstalk/hooks/appdeploy/post"
ignoreErrors: true
files:
"/opt/elasticbeanstalk/hooks/appdeploy/post/50_restart_sidekiq.sh":
mode: "000755"
owner: root
group: root
@kevcha
kevcha / namespace_partials_sharing.md
Last active December 29, 2022 07:53
How to automatically share partials between namespaces in rails

When writing a rails app, we often have to deal with multiple namespaces. The most common case is having classic actions and some others in an admin namespace. Some actions may have same views between namespaces.

For exemple, you could have a ProjectsController with an action index :

class ProjectsController < ApplicationController
  def index
    # do something
  end
end
require 'rails_helper'
RSpec.describe TodosController, :type => :controller do
describe "GET #index" do
#describe "POST #create" do
#describe "GET #show" do
#describe "PATCH #update" do (or PUT #update)
#describe "DELETE #destroy" do
#describe "GET #new" do
@eileencodes
eileencodes / gist:5b0a2fe011dcff6203fe
Last active October 28, 2021 14:21
CollectionProxy `delete_all` and `destroy_all` behavior by dependency AND association type AND strategy

Testing behavior of a CollectionProxy based on :dependent option, delete method used and assocation type (:has_many vs :has_many :through)

:has_many association

class Category < ActiveRecord::Base
	has_many :contacts, through: :categorizations
	has_many :categorizations, dependent: DEPENDENT
end
@ngsmrk
ngsmrk / sidekiq_monitoring
Created August 11, 2014 11:51
Sidekiq queue checking via rails console
stats = Sidekiq::Stats.new
stats.queues
stats.enqueued
stats.processed
stats.failed
@troelskn
troelskn / raven.rb
Last active November 21, 2018 09:06
config/initializers/raven.rb
require 'raven'
require 'rake/task'
if Rails.env.production?
Raven.configure do |config|
config.dsn = 'http://xxx:xxx@app.getsentry.com/xxxxx'
end
module Rake
class Task
@tomas-stefano
tomas-stefano / Capybara.md
Last active July 3, 2024 12:47
Capybara cheatsheet

Capybara Actions

# Anchor
click_link 'Save'

# Button
click_button 'awesome'

# Both above
@SabretWoW
SabretWoW / rspec_model_testing_template.rb
Last active May 28, 2024 17:41
Rails Rspec model testing skeleton & cheat sheet using rspec-rails, shoulda-matchers, shoulda-callbacks, and factory_girl_rails. Pretty much a brain dump of examples of what you can (should?) test in a model. Pick & choose what you like, and please let me know if there are any errors or new/changed features out there. Reddit comment thread: http…
# This is a skeleton for testing models including examples of validations, callbacks,
# scopes, instance & class methods, associations, and more.
# Pick and choose what you want, as all models don't NEED to be tested at this depth.
#
# I'm always eager to hear new tips & suggestions as I'm still new to testing,
# so if you have any, please share!
#
# @kyletcarlson
#
# This skeleton also assumes you're using the following gems: