Skip to content

Instantly share code, notes, and snippets.

View structuralartistry's full-sized avatar
💭
Spending an hour doing trying to do something trivial on github ui

Alexi Karuna structuralartistry

💭
Spending an hour doing trying to do something trivial on github ui
View GitHub Profile
@structuralartistry
structuralartistry / test_helper_additons_for_capybara.rb
Created December 12, 2010 21:02
Add this code to Test/Unit test_helper.rb to be able to use Capybara in your integration tests
# This is working in a Rails 3/1.9.2 app
# For using Capybara in Test/Unit Integration tests -- majority of this taken from the tartare-rails gem
# Make sure you have the capybara gem installed -- gem install capybara
# You can also create a folder: Rails_root/test/integration/helpers and place Files within to abstract some of the Capybara steps....
require 'capybara/rails'
module ActionController
class IntegrationTest
@structuralartistry
structuralartistry / fading_flash_notice_rails
Created December 23, 2010 00:31
Simple fading flash[:notice] in Rails with jQuery
# I struggled with getting a fading flash[:notice] that would work both with standard served pages as well
# as ajax requests. I saw a number of posts online but did not have luck with or they seemed too
# complicated. This is what I ended up with from experimentation.
# Place the following code in application_helper.rb. Note that you need to either change or name your
# containers as I have in this code:
# application_helper.rb
module ApplicationHelper
ruby-1.8.7-p334 :002 > ruby-1.8.7-p334 :002 > DateTime.now.methods.sort
=> ["+", "-", "<", "<<", "<=", "<=>", "==", "===", "=~", ">", ">=", ">>", "__id__", "__send__", "_dump", "`", "acts_like?", "ajd", "amjd", "as_json", "asctime", "b64encode", "between?", "binding_n", "blank?", "breakpoint", "class", "class_eval", "clone", "copy_instance_variables_from", "ctime", "cwday", "cweek", "cwyear", "day", "day_fraction", "dclone", "debugger", "decode64", "decode_b", "display", "downto", "dup", "duplicable?", "enable_warnings", "encode64", "england", "enum_for", "eql?", "equal?", "extend", "freeze", "frozen?", "gem", "gregorian", "gregorian?", "hash", "hour", "html_safe?", "id", "inspect", "instance_eval", "instance_exec", "instance_of?", "instance_values", "instance_variable_defined?", "instance_variable_get", "instance_variable_names", "instance_variable_set", "instance_variables", "is_a?", "italy", "jd", "julian", "julian?", "kind_of?", "ld", "leap?", "load", "load_dependency", "mday", "method", "methods", "min"
@structuralartistry
structuralartistry / gist:6ab5f0d3860dd7392cc9
Last active August 6, 2016 19:54
Lookup module mixin
# the point of this is to add simple lookup table-like values to an AR model or really any other rails class.
# it assumes that if you have a lookup named :some_lookup that the model will have a :some_lookup_id field
# EXAMPLE:
class MyModel < ActiveRecord::Base
include Lookup
lookup_for :function_type do
[
@structuralartistry
structuralartistry / gist:dc4b06dbfa75a1233f72
Last active August 29, 2015 14:10
Making constants consistent and mungeable in tests
# config/initializers/app_config.rb
APP_CONFIG = AppConfig.new(YAML.load_file("#{Rails.root}/config/application.yml")[Rails.env])
# then you have application.yml or whatever you want to call it:
# config/application.yml (or some better name)
development:
<<: *defaults
require 'spec_helper'
describe Lookup do
# in theory this should work with an active record query or whatever code returning an appropriate array
# of hashes in the result in the block passed, but not going this far to test right now
describe 'with an object for lookup data' do
class MyClass
include Lookup
@structuralartistry
structuralartistry / gist:b5eef431fe87b988475bc3dc9e19e7a0
Created October 10, 2017 21:14
Unicode \u2028 line breaks tweet
I
love
unicode
line
breaks!