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 Test::Unit::TestCase | |
# assert_form posts_url, :put do | |
# assert_text_field :post, :title | |
# assert_text_area :post, :body | |
# assert_submit | |
# end | |
def assert_form(url, http_method = :post) | |
http_method, hidden_http_method = form_http_method(http_method) | |
assert_select "form[action=?][method=#{http_method}]", url do | |
if hidden_http_method |
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
#recursively require all files in directory (and subdirectories) | |
Dir["#{File.dirname(__FILE__)}/squat/**/*.rb"].each {|file| require file } | |
#recursively require all files in directory but skip paths that match a pattern | |
Dir["#{File.dirname(__FILE__)}/squat/**/*.rb"].each do |file| | |
require file unless file =~ /\/model\// | |
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
# config/initializers/omniauth.rb | |
module OmniAuth | |
module Strategies | |
# tell OmniAuth to load our strategy | |
autoload :Pixelation, 'lib/pixelation_strategy' | |
end | |
end | |
Rails.application.config.middleware.use OmniAuth::Builder do | |
provider :twitter, "app_name", "secret" |
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 ApplicationModel < ActiveRecord::Base | |
self.abstract_class = true | |
class_attribute :formatted_attributes_options | |
self.formatted_attributes_options = {} | |
def self.formatted_attributes(*attributes) | |
options = attributes.extract_options! | |
attributes.each do |attribute| | |
formatted_attributes_options[attribute] = options |
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
module ApplicationHelper | |
def present(model, items = {}) | |
name = model.is_a?(String) ? model : model.class.model_name.underscore | |
items.merge!(name.to_sym => model) unless model.is_a?(String) | |
"#{name.classify}Presenter".constantize.new(controller, items) do |presenter| | |
yield(presenter) if block_given? | |
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
#I want to create many of a thing in one shot where thing is an activerecord class with | |
#validations. I can use the following where a listofthings is a vanilla ruby class. on | |
#valid? this class calls all the contained object's valid? method. and a naive save that | |
#calls save on each of the contained activerecord objects. There's some syntatic sugar, | |
#methods that hide the underlying list. This is minimal code for explanation. | |
#My thing is an activerecord class | |
#ListOfMyThings is a vanilla ruby class | |
#thing to note for form helpers to work you need | |
# _attributes=(attributes) method defined. |
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
guard 'annotate', notify: false do | |
watch( 'db/schema.rb' ) | |
end | |
guard 'cucumber', cli: '--format progress --no-profile', all_on_start: false do | |
watch(%r{features/.+\.feature}) | |
watch(%r{features/step_definitions/(.+)_steps\.rb}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] } | |
end | |
guard 'minitest', drb: false do |
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
# autoload concerns | |
module YourApp | |
class Application < Rails::Application | |
config.autoload_paths += %W( | |
#{config.root}/app/controllers/concerns | |
#{config.root}/app/models/concerns | |
) | |
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
# This file meant for globally available, utility methods. | |
############################### | |
## Ruby-level Extensions ## | |
############################### | |
class Object | |
def as(&block) | |
yield self | |
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
module Where | |
class <<self | |
attr_accessor :editor | |
def is_proc(proc) | |
source_location(proc) | |
end | |
def is_method(klass, method_name) | |
source_location(klass.method(method_name)) |
OlderNewer