Skip to content

Instantly share code, notes, and snippets.

View adarsh's full-sized avatar

Adarsh Pandit adarsh

View GitHub Profile
class User < ActiveRecord::Base
has_one :subscription, dependent: :destroy
end
class Subscription < ActiveRecord::Base
acts_as_paranoid
belongs_to :user
enum plan: ServicePlans.plan_names
@Bartuz
Bartuz / validate_with_matcher.rb
Last active August 17, 2023 14:15 — forked from otaviomedeiros/validate_with_matcher.rb
RSpec matcher for validates_with
# RSpec matcher for validates_with.
# https://gist.github.com/2032846
# Usage:
#
# describe User do
# it { should validate_with CustomValidator }
# end
RSpec::Matchers.define :validate_with do |expected_validator, options|
match do |subject|
@validator = subject.class.validators.find do |validator|
@nalipaz
nalipaz / .direnv
Last active January 19, 2017 00:11
Make direnv do function aliases
export_alias() {
local name=$1
local alias_dir=$PWD/.direnv/aliases
mkdir -p "$alias_dir"
PATH_add "$alias_dir"
local target="$alias_dir/$name"
if declare -f "$name" >/dev/null; then
echo "#!/usr/bin/env bash" > "$target"
declare -f "$name" >> "$target" 2>/dev/null
echo "$@" >> "$target"