Skip to content

Instantly share code, notes, and snippets.

@cupakromer
cupakromer / gist:9980762
Last active August 29, 2015 13:58
RSpec asserting on ActiveSupport deprecations

It seems that assert_deprecated is only part of ActiveSupport. So it is not part of rspec-expectations. It would probably only be added to rspec-rails but a quick google search did not turn up many uses of assert_deprecated.

I saw no past issues logged for RSpec regarding assert_deprecated so you are welcome to log it and argue your case for it. Though I see it being only part of ActiveSupport providing some barriers to adding it into rspec-expectations.

Now it should be fairly easy to roll your own matcher as well. There are two general approaches you could take:

@Kingside
Kingside / CSS Class Names in Rails View Helpers
Created March 7, 2014 02:16
Advanced Rails View Helper Usage - Passing Conditional and/or Multiple CSS Class Names
link_to(post.title, post, class: ["post", ("active" if post.active?)])
@shekibobo
shekibobo / serialized_encoding.rake
Last active August 29, 2015 13:56
Convert serialized yaml from syck to psych
require 'yaml'
# original idea comes from http://darwinweb.net/articles/convert-syck-to-psych-yaml-format
namespace :encoding do
desc 'convert serialized Content data from syck yaml serializations to psych'
task :psych => :environment do
content_id = ENV['content_id']
if content_id
convert_data Content.find(content_id)
@peterc
peterc / methods_returning.rb
Last active October 29, 2023 03:10
Object#methods_returning - to work out which method on an object returns what we want
require 'stringio'
require 'timeout'
class Object
def methods_returning(expected, *args, &blk)
old_stdout = $>
$> = StringIO.new
methods.select do |meth|
Timeout::timeout(1) { dup.public_send(meth, *args, &blk) == expected rescue false } rescue false
@stereoscott
stereoscott / active_admin_extensions.rb
Created January 12, 2014 00:29
Sample ActiveRecord model that uses paperclip to upload a csv report to s3
module ActiveAdmin
module Reports
module DSL
def enable_reports
action_item only: :index do
link_to("Download", {action: :report, params: params}, {method: :post, data: { confirm: "Are you sure you want to generate this report?"}})
end
collection_action :report, method: :post do
@gonzalo-bulnes
gonzalo-bulnes / XXXXXXXXXXXXX_add_authentication_token_to_users.rb
Last active March 6, 2019 15:15
(Update: I've packaged this gist into a gem to make its use easier, see: https://github.com/gonzalo-bulnes/simple_token_authentication.) Add token authentication to your Rails API. Follows the José Valim recomendations and is fully compatible with Devise (tokens are created the first time users sign in). See https://gist.github.com/josevalim/fb7…
# db/migrate/XXXXXXXXXXXXX_add_authentication_token_to_users.rb
class AddAuthenticationTokenToUsers < ActiveRecord::Migration
def change
add_column :users, :authentication_token, :string
add_index :users, :authentication_token, :unique => true
end
end
@stereoscott
stereoscott / active_admin.rb
Last active March 15, 2020 10:47
Stream CSV exports in ActiveAdmin in Rails 4
# if you want to monkey patch every controller, put this in initializers/active_admin.rb
ActiveAdmin::ResourceController.class_eval do
include ActiveAdmin::CSVStream
end
@gokure
gokure / my_configs.vim
Last active December 20, 2016 09:58
VIM config file for @amix/vimrc https://github.com/amix/vimrc
" My pathogen
try
call pathogen#infect('~/.vim/bundle/{}')
catch
endtry
syntax enable
set number
set numberwidth=5
@aprock
aprock / RoundedTransformation.java
Created August 12, 2013 18:08
Rounded Corner Image Transformation for square's Picasso
import android.graphics.Bitmap;
import android.graphics.Bitmap.Config;
import android.graphics.BitmapShader;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.RectF;
import android.graphics.Shader;
// enables hardware accelerated rounded corners
// original idea here : http://www.curious-creature.org/2012/12/11/android-recipe-1-image-with-rounded-corners/
@emad-elsaid
emad-elsaid / OnlyAdminsAuthorization.rb
Last active January 5, 2016 17:09
add apartment to your project - active admin adapter included this code will create databases and drop them when you create accounts
# app/models/OnlyAdminsAuthorization.rb
class OnlyAdminsAuthorization < ActiveAdmin::AuthorizationAdapter
def authorized?(action, subject = nil)
classname = (subject.is_a? Class)? subject.name : subject.class.name
account = Account.current
# check if expired