Skip to content

Instantly share code, notes, and snippets.

View plicjo's full-sized avatar

Joshua Plicque plicjo

View GitHub Profile
@plicjo
plicjo / gist:664d15000a6b5de59f1a
Created October 23, 2015 19:56
Going different places after sign in and sign out in Devise
class ApplicationController < ActionController::Base
private
# Overwriting the sign_out redirect path method
def after_sign_out_path_for(resource_or_scope)
root_path
end
# Overwriting the sign_in redirect path method
def after_sign_out_path_for(resource_or_scope)
@plicjo
plicjo / application_helper.rb
Created April 17, 2016 21:44
A Simple Rails Search Engine
module ApplicationHelper
YEAR_DESC_OPENED = 1996
OLDEST_SUPPORTED_BIRTH_YEAR = 1910
def years_in_business
(YEAR_DESC_OPENED..current_year).to_a.reverse
end
def current_year
Date.current.year
Capybara is a testing framework for clicking around in the browser (integration test).
You can use Capybara with Minitest here: https://github.com/blowmage/minitest-rails-capybara
Sometimes you'll need to run tests with Javascript enabled. I recommend using a gem poltergeist for that. https://github.com/teampoltergeist/poltergeist
For mockups/wirreframing, try out Balsamiq.
@plicjo
plicjo / tests_acceptance_foo-test.js
Created September 7, 2016 03:12 — forked from code0100fun/tests_acceptance_foo-test.js
Ember CLI QUnit text content helpers
// tests/acceptance/foo-test.js
// Assert that text should be found
assert.hasText('Not Found'); // Error: Could not find text "Not Found" on the page
// Provide custom message
assert.hasText('Not Found', 'Expected to find "Not Found"'); // Error: Expected to find "Not Found"
// Find any number of elements containing the query text
text('Found'); // [<div>Found</div>, <input value="Found">]
@plicjo
plicjo / general ledger decorator
Last active June 28, 2017 15:04
GSAF General Ledger
class GeneralLedgerDecorator < LittleDecorator
def division_colspan(division)
division_members(division).each_with_object([1]) do |member, num_columns|
num_columns << 1 if division_member_has_data?(division, member)
end.size
end
def division_member_has_data?(division, member)
data = record.get_division_member_data(division, member)
(data[:administration_fees].to_f + data[:origination_member_fees].to_f + data[:working_member_fees].to_f) > 0
@plicjo
plicjo / firebird.sh
Last active September 7, 2017 18:34
Install Firebird on CI
#!/usr/bin/env bash
wget http://downloads.sourceforge.net/project/firebird/firebird-linux-amd64/2.5-Release/FirebirdSS-2.5.0.26074-0.amd64.tar.gz
tar -zxvf FirebirdSS-2.5.0.26074-0.amd64.tar.gz
cd FirebirdSS-2.5.0.26074-0.amd64/
./install.sh
@plicjo
plicjo / puffing-billy-with-cucumber.rb
Last active March 29, 2018 06:34
Setting up Puffing Billy with Cucumber
# Gemfile
group :test do
gem 'capybara' # Simulate user
gem 'cucumber-rails', require: false # Acceptance tests
gem 'database_cleaner' # Clean test db
gem 'factory_girl_rails' # Factories for tests
gem 'puffing-billy' # Handle external HTTP requests made by front-end (JavaScript)
gem 'rspec-rails' # Functional tests
gem 'selenium-webdriver' # Visually run tests
@plicjo
plicjo / .zshrc
Created September 18, 2019 21:57
source ~/hcd
module Boxr
def self.downscope_token_for_box_ui_element(token, folder_id)
OpenStruct.new(access_token: 'bar')
end
def self.refresh_tokens(refresh_token, options = {})
OpenStruct.new(access_token: 'new_token', refresh_token: 'new_refresh_token')
end
class Client
import React, { useState, useEffect } from 'react';
export default function HookExample() {
// State hook
const [count, setCount] = useState(0)
// Using multiple state hooks
// const [age, setAge] = useState(42);
// const [fruit, setFruit] = useState('banana');
// const [todo, setTodo] = useState(null)'