Skip to content

Instantly share code, notes, and snippets.

@toolmantim
toolmantim / all_links_render_test.rb
Created March 7, 2013 05:55
A simple Rails 3/4 integration test that spiders your application's links, checking that none return a 500 or 404
@teamon
teamon / post_representer.rb
Created May 7, 2014 18:25
Ruby representers without a library
module PostRepresenter
include Representer
using Representer
def basic(post)
select(post, :id, :name)
end
def details(post)
basic(post) & comments(post)
module WillPaginate
module ActionView
def will_paginate(collection = nil, options = {})
options[:renderer] ||= FoundationLinkRenderer
super.try :html_safe
end
class FoundationLinkRenderer < LinkRenderer
protected
@chrismcg
chrismcg / example_form_model.ex
Created August 2, 2015 11:34
Example Phoenix / Ecto Form Model
defmodule Phlink.Form do
use Ecto.Schema
import Ecto.Changeset
@primary_key false
schema "non_db_form.user" do
field :name, :string
field :thing, :string
end
@required_fields ~w(name)
@rabidpraxis
rabidpraxis / s3_mass_bucket_delete.rb
Created April 2, 2013 16:53
Delete s3 bucket with minimal api calls
require 'fog'
bucket = 'bucket-name'
credentials = {
:provider => 'AWS',
:aws_access_key_id => 'access_key_id',
:aws_secret_access_key => 'secret_key',
}
fog = Fog::Storage.new(credentials)
@bigfive
bigfive / active_admin_helper.rb
Last active November 15, 2018 21:33
Active admin reskin
module ActiveAdminHelper
def admin_arbre_context
@admin_arbre_context ||= Arbre::Context.new(assigns, self)
end
def default_renderer
case controller.send(:resource_class).name
when "ActiveAdmin::Page"
"page"
@chrisgaunt
chrisgaunt / rails_test_engine_cucumber.markdown
Created August 3, 2011 03:57
Rails 3.1: Test engine with Cucumber & test/dummy app

Run from the root of the engine project:

rails generate cucumber:install --capybara

Edit features/support/env.rb and add to the top:

ENV["RAILS_ENV"] ||= "test"
require File.expand_path("../../../test/dummy/config/environment.rb",  __FILE__)
ENV["RAILS_ROOT"] ||= File.dirname(__FILE__) + "../../../test/dummy"
@peterhellberg
peterhellberg / Gemfile
Created April 10, 2012 11:51
Sinatra acceptance testing, using minitest/spec and capybara-webkit
source :rubygems
gem "sinatra", "~> 1.3.2"
group :test do
gem "minitest", "~> 2.10"
gem "rack-test", "~> 0.6.1"
gem "capybara", "~> 1.1"
gem "capybara-webkit", "~> 0.11"
gem "capybara_minitest_spec", "~> 0.2"
@mperham
mperham / after.rb
Created July 4, 2012 19:30
Thread-friendly shared connection
class ActiveRecord::Base
mattr_accessor :shared_connection
@@shared_connection = nil
def self.connection
@@shared_connection || ConnectionPool::Wrapper.new(:size => 1) { retrieve_connection }
end
end
ActiveRecord::Base.shared_connection = ActiveRecord::Base.connection
@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