Skip to content

Instantly share code, notes, and snippets.

View joahking's full-sized avatar
🏠
Working from home

Joaquin joahking

🏠
Working from home
View GitHub Profile
require 'capitate'
require 'capitate/recipes'
set :project_root, File.dirname(__FILE__)
load 'deploy' if respond_to?(:namespace) # cap2 differentiator
Dir['vendor/plugins/*/recipes/*.rb'].each { |plugin| load(plugin) }
set :application, "misustento"
set :domain, "misustento.com"
set :domain_aliases, ["misustento.es"]
# now there is no metaprogramming involve, but finger saving it is indeed :-)
describe 'active ones' do
it 'should require required attributes' do
REQUIRED_ATTRS = [ :email, :name, :birthday, :phone, :address, :city,
:province, :postal_code,
:country, :nationality,
:employment_status ] unless defined?(REQUIRED_ATTRS)
Candidate.new.attribute_names.each do |attr|
# this is an AR model class
named_scope :privates, :conditions => { :public => false }
named_scope :named_like, lambda { |name| { :conditions => "name LIKE '#{name}%'" }}
# we want to concatenate named_scopes at later points in code
def self.by_privacy_and_name(privates = false, name = nil)
# we want a named_scope to concatenate other namescopes afterwards
gs = if privates
self.privates # with named_scopes everything runs fine
else
@joahking
joahking / devise_bdd_template.rb
Created January 9, 2010 15:43
template for rails with devise as auth, rspec and cucumber
# Delete unnecessary files
run 'rm README'
run 'rm public/index.html'
run 'rm public/favicon.ico'
run 'rm public/robots.txt'
run 'cp config/database.yml config/database.yml.example'
file '.gitignore', <<-END
log
When /^I fill the captcha incorrectly$/ do
captcha_evaluates_to false
end
When /^I fill the captcha correctly$/ do
captcha_evaluates_to true
end
# if you move this method correctly to features/support/recaptcha_helper.rb and include it in World => you feature will fail!
def captcha_evaluates_to(result)
// this allows culerity to wait until all ajax requests have finished
jQuery(function($) {
var original_ajax = $.ajax;
var count_down = function(callback) {
return function() {
try {
if(callback) {
callback.apply(this, arguments);
};
} catch(e) {

(a gist based on the old toolmantim article on setting up remote repos)

To collaborate in a distributed development process you’ll need to push code to remotely accessible repositories.

This is somewhat of a follow-up to the previous article setting up a new rails app with git.

For the impatient

Set up the new bare repo on the server:

@joahking
joahking / show_revision.rb
Created January 18, 2011 15:02
cap deploy:show_revision
namespace :deploy do
desc "Shows deployed revision."
task :cat_revision do
run "cat #{current_path}/REVISION"
end
desc "Shows deployed revision using git."
task :show_revision do
run "cd #{current_path}; git log -n 1"
end
@joahking
joahking / confirm_dialog_steps.rb
Created March 2, 2011 15:03
bypass confirm dialog
Then /^(.+) and I confirm dialog box$/ do |step|
bypass_confirm_dialog
Then step
end
@joahking
joahking / phone_number.rb
Last active November 1, 2016 22:11
example of usage of concerns
# app/models/concerns/phone_number.rb
# concern to validate spanish phone numbers and provide some custom formatters
module PhoneNumber
extend ActiveSupport::Concern
PHONE_REGEXP = /\+\d{2}\s\d{3}\s\d{3}\s\d{3}/.freeze # e.g. +34 900 123 123
included do
validates :phone_number, presence: true, format: { with: PHONE_REGEXP, message: "invalid phone number" }
end