This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # see http://errtheblog.com/posts/19-streaming-capistrano | |
| namespace :logs do | |
| desc "tail production log files" | |
| task :tail, :roles => :app do | |
| run "tail -f #{shared_path}/log/production.log" do |channel, stream, data| | |
| puts # for an extra line break before the host name | |
| puts "#{channel[:host]}: #{data}" | |
| break if stream == :err | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # This file is copied to spec/ when you run 'rails generate rspec:install' | |
| ENV["RAILS_ENV"] ||= 'test' | |
| require File.expand_path("../../config/environment", __FILE__) | |
| require 'rspec/rails' | |
| require 'paperclip/matchers' | |
| require 'webmock/rspec' | |
| # Requires supporting ruby files with custom matchers and macros, etc, | |
| # in spec/support/ and its subdirectories. | |
| Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # spec/support/factory_girl_with.rb | |
| # replace instance variables and before blocks with memoized factory instances | |
| module FactoryGirl | |
| module With | |
| def with(name, options = {}) | |
| let(name) { ::Factory.create(name, options) } | |
| end | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| IT | |
| basic out of the box example definition. | |
| it { should be_true } | |
| SPECIFY | |
| alias for IT. use to make your example more readable | |
| specify { @user.should be_true } | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # config/application.rb | |
| config.devise_oauth2_providable.access_token_expires_in = 1.second # 15.minute default | |
| config.devise_oauth2_providable.refresh_token_expires_in = 1.minute # 1.month default | |
| config.devise_oauth2_providable.authorization_token_expires_in = 5.seconds # 1.minute default |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env ruby | |
| require 'rubygems' | |
| require 'thor' | |
| module Backgrounded | |
| class CLI < Thor | |
| desc 'enqueue', 'enqueue a clazz.method invocation for resque backgrounded workers' | |
| method_option :queue, :aliases => "-q", :desc => "resque queue to enqueue the operation to", :default => 'backgrounded' | |
| method_option :rails_env, :aliases => '-e', :desc => 'control which rails env used to load the redis config', :default => 'production' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # utility for performing multiple fetches on hashes | |
| # ex: | |
| # h = {:foo => {:bar => :baz}} | |
| # h.deep_fetch :foo, :bar | |
| class Hash | |
| def deep_fetch(*keys, last_key) | |
| scope = self | |
| keys.each do |key| | |
| scope = scope.fetch key, {} | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class UuidValidator < ActiveModel::EachValidator | |
| VALID_UUID_REGEX = /^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/ | |
| def validate_each(record, attribute, value) | |
| record.errors[attribute] << (options[:message] || "is invalid") unless UuidValidator.valid_uuid?(value) | |
| end | |
| def self.valid_uuid?(value) | |
| !!VALID_UUID_REGEX.match(value.to_s) | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # VERSIONING | |
| # all production gems should use STRICT version dependencies ex: "1.0.0" | |
| # development and test gems can you LOOSE version dependencies ex: "~> 1.0.0" | |
| source 'http://rubygems.org' | |
| # list gems for *all* environments/groups here | |
| # ex: rails, mysql2, rails-console-tweaks | |
| # list gems for frontend app servers here |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| user = User.new | |
| # execute instance method in background | |
| user.backgrounded.do_stuff | |
| # execute class method in background | |
| User.backgrounded.do_something_else | |
| # perform work on a custom queue | |
| user.backgrounded(:queue => 'custom').do_something_else |