Skip to content

Instantly share code, notes, and snippets.

@litch
litch / feed_item_generator.rb
Last active December 10, 2015 11:48
I'm trying to decide what's the best way to build this out. Basically I'm going to observe all kinds of events in the system and create feed items for users based on a number of criteria - "John changed the Status of Job: JUE-923 to active". I'm facing a diliema on how to build the actual FeedItemGenerator part. Below are two ways and how they w…
#This works but is maybe not so great.
class FeedItemGenerator
include ActionView::Helpers
attr_accessor :feedable
attr_accessor :user
attr_accessor :event
def initialize(feedable, user, event=nil)
@feedable = feedable
it "can have the dig test requirement overridden" do
job = create :job
job.approve
sign_in(:dispatcher)
visit edit_job_path(job)
find(:css, "#job_no_dig_test_needed").set(true) #selenium test errors on this line - it can't find the selector but in reality it didn't find the job
click_button "Update"
visit job_path(job)
expect(page).to have_content "Activate"
end
@litch
litch / crawl_the_site.rb
Last active December 11, 2015 07:59
One of the most frustrating things I run into in development is that sometimes, when I have been doing my testing, (even FE testing) and making changes to FE code, and pushing to production and start getting 500's because some element in my production dataset is nil that is not nil in my factories.  So now I just cobbled together a test method t…
require_relative '../features_helper'
describe "as an admin", js: true do
it 'crawls the site with a tiny data set' do
default_url_options[:host] = "127.0.0.1:6543"
sign_in(:admin)
objects = [
create(:customer),
create(:job),
create(:employee),
@litch
litch / equipment_item.rb
Created January 23, 2013 17:58
Refactor me challenge!
class EquipmentItem
attr_accessor :task_items, equipment_hauls
def current_location
last_task = task_items.sort_by{|a| a.end_time }.last
last_haul = equipment_hauls.last
if last_task && last_haul
if last_task.end_time > last_haul.performed_at
last_task.timesheet.job
else
require "xpath" # XPath is a separate gem now
module Cucumber
module Rails
module CapybaraSelectDatesAndTimes
def select_date (date, options = {})
date = Date.parse(date)
# lookup id prefix by label
id_prefix = id_prefix_for(options[:label])
@litch
litch / can_be_in_diff_places.js
Created January 28, 2013 22:07
javascript to have a button do something but still pass through
$("#my_button_id").click(function () {
call_my_other_js;
});)
$("#my_button_id").click(function () {
$("form#formID").submit();
});)
$("#my_button_id").click(function () {
do_thing_3_for_kicks;
});)
App.Router.map(function() {
this.resource('tables', function() {
this.resource('table', {path: ':table_id'});
});
});
@litch
litch / Gemfile
Created February 24, 2013 17:34
Ruby 2.0.0 installation with RVM and running on heroku. RVM instructions sourced from: https://coderwall.com/p/tptocq A quick comparison of Ruby 2.0.0 performance loading rails can be found at my blog: www.superpumpup.com
source 'https://rubygems.org'
ruby "2.0.0"
gem 'rails', github: 'rails/rails'
gem 'arel', github: 'rails/arel'
...
class SpeakersController < ApplicationController
load_and_authorize_resource :event
load_and_authorize_resource :speaker, through: [:event], shallow: true #the array here could only be the single symbol but since i almost always wind up adding more, i just start with it
before_filter :new_speaker, :only => [:new, :create]
respond_to :html
def index
end
def show
@litch
litch / merchant_account_test.rb
Created May 28, 2013 19:44
crazy epic unit test
require 'test_helper'
class MerchantAccountTest < ActiveSupport::TestCase
setup do
@merchant_account = FactoryGirl.create(:merchant_account)
end
should "fetch authorized orders" do
@order = FactoryGirl.create(:order, venue: @merchant_account.venue)
credit_card_hash = {