This file contains 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
# NOTE: only doing this in development as some production environments (Heroku) | |
# NOTE: are sensitive to local FS writes, and besides -- it's just not proper | |
# NOTE: to have a dev-mode tool do its thing in production. | |
if(Rails.env.development?) | |
task :set_annotation_options do | |
# You can override any of these by setting an environment variable of the | |
# same name. | |
Annotate.set_defaults({ | |
'position_in_routes' => "after", | |
'position_in_class' => "after", |
This file contains 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
# encoding: utf-8 | |
require 'datapoint_value' | |
class Datapoint < ActiveRecord::Base | |
include DatapointValue::Conversions | |
before_save :normalize_value | |
def self.upsert(params) | |
dp = where(token: params[:token], at: params[:at]).first |
This file contains 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
describe ActiveSupport::TimeZone do | |
it "has an invalid fraction, clearly" do | |
rub_a_dub_double = double.as_null_object | |
ymd = [rub_a_dub_double.year, rub_a_dub_double.month, rub_a_dub_double.day] | |
ActiveSupport::TimeZone['UTC'].local(*ymd) # ArgumentError: invalid fraction | |
Date.new(*ymd) # => ArgumentError: invalid date -- now that makes sense | |
end | |
end |
This file contains 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 ExclusionRules < FilterRules | |
CONDITIONAL_FILTERS = { | |
:if => lambda { |value| !value }, | |
:unless => lambda { |value| value } | |
}.freeze | |
def include_example?(example) | |
example.any_apply?(@rules) || example.any_apply?(CONDITIONAL_FILTERS) | |
end | |
end |
This file contains 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 TwilioCountryReport < TwilioReport | |
def generate_stats | |
@country_stats = HashWithIndifferentAccess.new { |h, country| h[country] = TwilioCountryStat.new(country) } | |
build_country_stats | |
country_stats | |
end | |
def country_stats | |
@country_stats.values | |
end |
This file contains 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
ENV["RAILS_ENV"] ||= 'test' | |
require File.expand_path("../../config/environment", __FILE__) | |
require 'rspec/rails' | |
require 'rspec/autorun' | |
require 'capybara/rspec' | |
require 'capybara/rails' | |
# Requires supporting ruby files with custom matchers and macros, etc, |
This file contains 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
require 'nokogiri' | |
RSpec::Matchers.define :have_xml do |xpath, matcher| | |
match do |body| | |
doc = Nokogiri::XML::Document.parse(body) | |
nodes = Array(doc.xpath(xpath)) | |
nodes.map! { |node| node.respond_to?(:content) ? node.content : node } | |
if nodes.empty? | |
false |
This file contains 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
<div class="stack"> | |
lorem ipsum | |
</div> |
This file contains 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 comes included in ActiveSupport 4+ | |
unless ActiveSupport::VERSION::MAJOR > 3 | |
require 'date' | |
module DateAndTime | |
module Zones | |
# Returns the simultaneous time in <tt>Time.zone</tt> if a zone is given or | |
# if Time.zone_default is set. Otherwise, it returns the current time. | |
# | |
# Time.zone = 'Hawaii' # => 'Hawaii' |
This file contains 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 PartialReportForm | |
include DelegatingFormObject.new(Report) | |
delegate :name, :name=, | |
to: :report | |
validates :name, | |
presence: true | |
end |
OlderNewer