Skip to content

Instantly share code, notes, and snippets.

View mbhnyc's full-sized avatar

Matthew Hensrud mbhnyc

  • New York, NY
  • 03:48 (UTC -04:00)
  • X @mbhnyc
View GitHub Profile
@mbhnyc
mbhnyc / gist:5944282
Created July 7, 2013 17:43
1 Way to store constants on the model and use in a view
# In model:
STATUS_CHOICES = {
default: "Ask me",
single: "Single",
relationship: "Relationship",
married: "Married",
divorced: "Divorced",
complicated: "Takes some explaining",
open: "Open Relationship",
@mbhnyc
mbhnyc / minitest_helper.rb
Created October 16, 2012 01:08
Sample test suite for an API
ENV["RAILS_ENV"] = "test"
require File.expand_path('../../config/environment', __FILE__)
require "minitest/autorun"
require "minitest/rails"
require "minitest/rails/capybara"
require "database_cleaner"
require "factory_girl"
require "carrierwave/test/matchers"
@mbhnyc
mbhnyc / home_integration_test.rb
Created August 8, 2012 15:53
Why are my integration tests running twice?
require 'minitest_helper'
describe "Home integration" do
it "has content" do
visit root_path
assert page.has_content?("Be the first to know")
end
it "is possible to log in and log out" do
provider = create(:provider)
@mbhnyc
mbhnyc / gist:2781841
Created May 24, 2012 14:19
Scripts in views sample
/ layout (see last line)
!!! 5
-html_tag class: "no-js", lang: "en" do
= render "head", stylesheet_partial: "stylesheets"
%body{ class: "#{controller.controller_name}" }
#wrapper
#main
@mbhnyc
mbhnyc / gist:2137965
Created March 20, 2012 16:32
Routing Question
# index.html.haml
- if !@flags_profiles.empty?
= simple_form_for( f, remote: true, method: :put, url: admins_moderations_confirm_flag_path, html: { style: 'line-height: 1'} ) do |g|
= g.hidden_field :id, :value => f.id
= g.submit "Confirm Flag", html_options: {class: "moderate-photo-button", style: "color: green;"}
# routes.rb
namespace :admins do
resources :moderations
match 'moderations/confirm_flag' => 'moderations#confirm_flag', :via => :put
@mbhnyc
mbhnyc / gist:1393651
Created November 25, 2011 14:34
Test Params
{"utf8"=>"✓",
"_method"=>"put",
"authenticity_token"=>"mwSXSnnkNo37wsC7juyHXTlCYKJRLRn1vr26+uiHYJs=",
"profile"=>{"username"=>"blah",
"email"=>"blah@gmail.com",
"datingprofile_attributes"=>{"birthday(1i)"=>"1977",
"birthday(2i)"=>"12",
"birthday(3i)"=>"27",
"gender"=>"M",
"orientation"=>"",