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 file meant for globally available, utility methods. | |
############################### | |
## Ruby-level Extensions ## | |
############################### | |
class Object | |
def as(&block) | |
yield self | |
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 RailsEnvInquirer < ActiveSupport::StringInquirer | |
def live? | |
%w(production staging).include?(self) | |
end | |
def trial? | |
!live? | |
end | |
def grouping |
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 method allows you to not have to hardcode validation messages as a part of unit | |
# tests, instead relying, as the ActiveModel::Errors class does, on I18n dictionaries. | |
# Usage: assert_has_error(@new_user, :first_name, :regexp) | |
# Of course, in the above example, :regexp is a custom type of error that I implemented | |
# for my own app, but you can substitute things like :invalid, :blank, :inclusion, etc. | |
def assert_has_error(record, attribute, type = :invalid) | |
record.send(:run_validations!) # This in order to trigger the :validate callback first. | |
assert record.errors[attribute].include?(record.errors.generate_message(attribute, type)), "Expected #{record.class.model_name.human} record to have an error of type :#{type} for attribute #{record.class.human_attribute_name(attribute)}." | |
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
# In case you want to define a new inflection so you can call something like: | |
# | |
# "masochistic son of a gun".leet # => "m450ch1571c 50n 0f 4 9un" | |
# | |
# Do the following so that the requisite methods are injected into each relevant | |
# class/module: | |
# | |
# NewInflection.register :leet do |word| | |
# word.tr('aegilost', '43911057') | |
# end |