Ruby and other tools licenses
- Ruby (Ruby license)
- PostgreSQL (PostgreSQL license)
- wkhtmltopdf (GPL)
# spec/support/timezone.rb | |
module TimeZoneHelpers | |
extend ActiveSupport::Concern | |
def self.randomise_timezone! | |
offsets = ActiveSupport::TimeZone.all.group_by(&:formatted_offset) | |
zones = offsets[offsets.keys.sample] # Random offset to better vary the time zone differences | |
Time.zone = zones.sample # Random zone from the offset (can be just 1st, but let's do random) | |
puts "Current rand time zone: #{Time.zone}. Repro: Time.zone = #{Time.zone.name.inspect}" | |
end |
module Jobs | |
class CloudinaryUpload < Struct.new(:uploader_class, :model, :field, :file_name, :content_type, :data) | |
include Logging | |
def upload | |
uploader = uploader_class.new(model, field) | |
store = Cloudinary::CarrierWave::Storage.new(uploader) | |
io = Cloudinary::Blob.new(data, original_filename: file_name, content_type: content_type) | |
uploader.cache!(io) | |
store.store!(uploader.file) |
Initially asked at RORO but I will elaborate with an example.
What we need to do is the following:
class BackgroundWorkerStarter | |
attr_reader :env | |
def initialize(env) | |
@env = env | |
end | |
def start! | |
write_pid!(pid_file) if pid_file |
class CreditCard | |
include ActiveAttr::Model | |
attribute :number | |
attribute :expiry | |
attribute :cvn | |
attribute :name | |
validate :must_be_valid | |
validates :number, :expiry, :cvn, :name, presence: true |
# Example 1, not so cool (look at the 'less-than' and OR condition) | |
# plain AR: | |
Property.joins(:reservations). | |
where(status: 'reserved'). | |
where("reservations.status = ? OR reservations.reservation_type = ?", 'active', 'offline'). | |
where(reservations: {reservation_fee_received: false}). | |
where("reservations.fee_due_at < ?", DateTime.now) | |
# with squeel: |
ENV["RAILS_ENV"] ||= 'test' | |
cur_dir = File.expand_path(File.dirname(__FILE__) + '/..') | |
$LOAD_PATH << "#{cur_dir}" | |
if defined? Rails | |
# Most likely going with the full env | |
puts "Running faster_helper with full Rails env..." | |
# Eagerly load the Rails so that stubbed dependencies still work | |
# http://stackoverflow.com/questions/11133712/using-rails-model-that-is-already-declared |
class CommentsController < ApplicationController | |
def create | |
@article = Article.find(params[:article_id]) | |
@comment = @article.comments.build(params[:comment]) | |
@comment.save # etc | |
end | |
end |
# spec/support/database_cleaner.rb | |
require 'database_cleaner' | |
RSpec.configure do |config| | |
config.before(:suite) do | |
DatabaseCleaner.clean_with :truncation # Delete leftovers if any | |
DatabaseCleaner.strategy = :transaction | |
end | |
config.before(:each) do |