Skip to content

Instantly share code, notes, and snippets.

View hogihung's full-sized avatar

John F. Hogarty hogihung

  • Left Foot Media, Inc.
  • Jacksonville, FL
View GitHub Profile
@hogihung
hogihung / Base-database_cleaner.rb
Last active August 29, 2015 14:04
Base Database Cleaner config for use with Ruby 2.1.2, Rails 4.1.4, and RSpec
# /spec/support/database_cleaner.rb
RSpec.configure do |config|
config.before(:suite) do
DatabaseCleaner.strategy = :truncation
end
config.before(:each) do
DatabaseCleaner.start
end
@hogihung
hogihung / Base-combined_dot-files
Created July 27, 2014 14:57
Base .rspec and .pryrc files for RSpec, Pry, and Hirb support with Ruby 2.1.2 and Rails 4.1.4
.rspec
-color
--require spec_helper
--format documentation
.pryrc
require 'hirb'
Hirb.enable({:width => 155, :height => 500})
@hogihung
hogihung / Base-spec_helper.rb
Created July 27, 2014 14:55
Base RSpec Configuration File, Ruby 2.1.2 and Rails 4.1.4
require 'simplecov'
SimpleCov.start 'rails'
# This file is copied to spec/ when you run 'rails generate rspec:install'
ENV["RAILS_ENV"] ||= 'test'
require 'spec_helper'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
# Requires supporting ruby files with custom matchers and macros, etc, in
@hogihung
hogihung / Base-Gemfile
Last active August 29, 2015 14:04
Base Gemfile for Ruby 2.1.2 and Rails 4.1.4 app with RSpec and Capybara testing.
source 'https://rubygems.org'
ruby '2.1.2'
gem 'rails', '4.1.4'
gem 'sass-rails', '~> 4.0.3'
gem 'uglifier', '>= 1.3.0'
gem 'coffee-rails', '~> 4.0.0'
gem 'jquery-rails'
gem 'jbuilder', '~> 2.0'
@hogihung
hogihung / user_registration_login.feature
Last active August 29, 2015 14:01
User Registration and Login Feature
Feature: Registration
Scenario: User provides valid information
Given a unique email, password and matching password confirmation
When the user clicks the Sign up button
Then the output should be "A message with a confirmation link has been sent to your email address. Please open the link to activate your account."
Scenario: User supplies email, but no password
Given a unique email, but no password or password confirmation
When the user clicks the Sign up button
@hogihung
hogihung / make_equip_files.rake
Created May 5, 2014 13:48
Rake task to export records to formatted : delimited CSV files.
require 'csv'
equip_dom = "/tmp/equip.db_new"
equip_mow = "/tmp/equip.db.mow_new"
namespace :oob_export do
task :domestic => :environment do
puts "Building equip.db file."
CSV.open(equip_dom, 'w+', col_sep: ':') do |csv|
Baytech.where(region: "USA").all.each do |baytech|
AWS_ACCESS_KEY_ID: "XXXXXXXXXXXXXXXXXXXXX"
AWS_SECRET_ACCESS_KEY: "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
development:
SENDGRID_USERNAME: "yourappname@heroku.com"
SENDGRID_PASSWORD: "yourPW"
AWS_BUCKET: myname-bloccit-dev
production:
AWS_BUCKET: myname-bloccit-prod
@hogihung
hogihung / pop_posts_refactor
Created March 30, 2014 13:27
Bloc - Popular Post Refactor
mkdir app/controllers/topics/
mv app/controllers/posts_controller.rb app/controllers/topics/posts_controller.rb
mkdir app/views/topics/posts/
mv app/views/posts/_form.html.erb app/views/topics/posts/_form.html.erb
mv app/views/posts/edit.html.erb app/views/topics/posts/edit.html.erb
mv app/views/posts/new.html.erb app/views/topics/posts/new.html.erb
mv app/views/posts/show.html.erb app/views/topics/posts/show.html.erb
@hogihung
hogihung / title_case.rb
Created March 27, 2014 15:45
Bloc Exercise - Title Case
class String
def title_case
articles = ["of", "and", "the", "a"]
s = self.downcase
a = s.split(' ')
a.each do |i|
i.capitalize! unless articles.include? i
end
a.first.capitalize!
@hogihung
hogihung / populate.rake
Last active March 31, 2016 20:29
A rake Task for importing data via CSV files
require 'csv'
baytechs_file = "/path/to/file/baytechs.CSV"
devices_file = "/path/to/file/devices.CSV"
namespace :oob_import do
task :baytechs => :environment do
Baytech.delete_all
CSV.foreach(baytechs_file, headers: true) do |row|
p row