Skip to content

Instantly share code, notes, and snippets.

@leejarvis
leejarvis / _form.rb
Last active December 21, 2015 15:39 — forked from siassaj/_form.rb
= simple_form_for @machine_visit_form do |f|
= f.error_notification
= f.input :refill_id, as: :hidden
= f.input :refill_date, as: :date
= f.input :refill_counter, as: :decimal, input_html: {value: number_with_precision(f.object.refill_counter, precision: 2) }
= f.fields_for :refill_line_items do |ff|
.well
= "#{ff.object.product_name}"
require 'test_helper'
class UserTest < ActiveSupport::TestCase
test 'full_name returns contatenated first and last name' do
user = build(:user, first_name: 'foo', last_name: 'bar')
assert_equal 'foo bar', user.full_name
end
end
require 'test_helper'
class AccountTest < ActiveSupport::TestCase
test 'presence on create' do
account = Account.create
refute account.valid?
end
test 'inclusion :subtype' do
# invalid
@leejarvis
leejarvis / raskell.rb
Created August 15, 2012 10:23 — forked from andkerosine/raskell.rb
Haskell-like list comprehensions in Ruby
$stack, $draws = [], {}
def method_missing *args
return if args[0][/^to_/]
$stack << args.map { |a| a or $stack.pop }
$draws[$stack.pop(2)[0][0]] = args[1] if args[0] == :<
end
class Array
def +@
@leejarvis
leejarvis / gist:1049216
Created June 27, 2011 16:25 — forked from ryanlecompte/gist:1049170
Example of has_many :through
class UserProject < ActiveRecord::Base
belongs_to :user
belongs_to :project
belongs_to :creator, :class_name => "User"
# add whatever else you want here, this is your join model
end
class User < ActiveRecord::Base
has_many :user_projects
has_many :projects, :through => :user_projects
##
# test/spec/mini 3
# http://gist.github.com/25455
# chris@ozmm.org
# file:lib/test/spec/mini.rb
#
def context(*args, &block)
return super unless (name = args.first) && block
require 'minitest/unit'
klass = Class.new(MiniTest::Unit::TestCase) do