Skip to content

Instantly share code, notes, and snippets.

products GET /products(.:format) products#index
POST /products(.:format) products#create
new_product GET /products/new(.:format) products#new
edit_product GET /products/:id/edit(.:format) products#edit
product GET /products/:id(.:format) products#show
PUT /products/:id(.:format) products#update
DELETE /products/:id(.:format) products#destroy
@tcannonfodder
tcannonfodder / gist:9939717
Last active August 29, 2015 13:58
Basic Controller
def new
@model = Model.new
@Title = "New Model"
end
def create
@model = Model.new(params[:model])
if @model.save
redirect_to model_path(@model), :flash => {:success => "Model Created"}
@tcannonfodder
tcannonfodder / freckle_recurring_budgets.rb
Created April 14, 2014 14:23
Sample script to create recurring project budgets for specific projects in your Freckle account using the API.
# Hey there!
#
# This is a basic script that shows how to give projects an "allowance", like
# 5 hours every month. First, it looks at how many hours you want to budget for
# each project. Then, it establishes a connection with the Freckle API, using your
# API token. It then loops through all the projects you listed, finding out how many
# minutes it needs to add or remove from the existing project budget. Finally, it
# updates the project and goes onto the next one.
#
# If you want to set a monthly budget, you would run this script once every month.
@tcannonfodder
tcannonfodder / gist:9ca5d465b92d59e43799
Created July 16, 2014 23:50
Freckle API v2 Error Message Example
{
"message": "you don't have permission to filter by imports",
"errors": [
{
"resource": "Entry",
"code": "insufficent_permissions",
"field": "import_ids"
}
]
}
@tcannonfodder
tcannonfodder / Gemfile
Created July 27, 2014 20:24
Sinatra Boilerplate
source 'https://rubygems.org'
gem 'sinatra'
gem 'sinatra-contrib'
gem 'debugger', :require => false
gem 'mysql'
gem 'dbd-mysql'
gem 'dbi'
@tcannonfodder
tcannonfodder / backport.rb
Created July 31, 2014 19:07
Running Rail 2.3 LTS Performance Tests using Minitest
# include this in your test_helper.rb. It monkeypatches
# The methods used to actually run any performance tests
# subclassed from ActionController::PerformanceTest
# based on: https://github.com/rails/rails/blob/3-2-stable/activesupport/lib/active_support/testing/performance.rb#L44
module ActiveSupport
module Testing
module Performance
def run(runner)
@tcannonfodder
tcannonfodder / add_allow_switch.rb
Last active August 29, 2015 14:05
Add test-spec's `add_allow_switch` to a MiniTest suite.
# Port of test-spec's `add_allow_switch` to MiniTest.
# This was originally written by @madrobby for Freckle: https://letsfreckle.com
# Make sure to rename `YourApp` to the namespace of your app.
module YourApp
class AddAllowSwitchCalledTwiceError < StandardError
# By overriding this method, we can provide a sort of default exception message
def self.exception(message)
super("Called add_allow_switch(#{message}) twice! Make sure you don't require your test helper twice.")
end
@tcannonfodder
tcannonfodder / deprecated_helpers.rb
Created August 24, 2014 21:48
Deprecated Helpers when porting from test-spec to Minitest
# Deprecation warnings for common test-spec helpers, useful when porting tests
# to MiniTest by showing you what to replace it with.
# This was originally written by @madrobby for Freckle: https://letsfreckle.com
# remember to replace `YourApp` with the namespace of your app.
module YourApp::Assertions
mattr_accessor :deprecation_warnings
@@deprecation_warnings = []
class SpecResponder
@tcannonfodder
tcannonfodder / fix_nested_describes_in_controller_tests.rb
Created August 24, 2014 21:52
Fix nested describes in controller tests in Rails 2.3
# fixes nested describes in controller tests
# this is a Rails bug apparently fixed in newer Rails versions
# https://github.com/rails/rails/issues/7743
# This was originally written by @madrobby for Freckle: https://letsfreckle.com
class ActionController::TestCase
def self.determine_default_controller_class(name)
name.split('::').reverse.map { |n|
safe_constantize(n.sub(/Test$/, ''))
}.compact.first
@tcannonfodder
tcannonfodder / standardized-bug-report-template.md
Last active August 29, 2015 22:22
Standardized Bug Report Template Example: built from years of simultaneously working development and support