This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Original Rails controller and action | |
| class EmployeesController < ApplicationController | |
| def create | |
| @employee = Employee.new(employee_params) | |
| if @employee.save | |
| redirect_to @employee, notice: "Employee #{@employee.name} created" | |
| else | |
| render :new | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| rails new --skip-javascript --skip-turbolinks --skip-keeps --skip-git --skip-bundle --skip-test --skip-coffee testing-rails $1 | |
| rails new --skip-keeps --skip-git --skip-bundle --skip-test --skip-action-mailer --skip-action-cable testing-rails --api | |
| bundle exec rails new \ | |
| --skip-keeps \ | |
| --skip-git \ | |
| --skip-bundle \ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # app/serializers/customer_serializer_spec.rb | |
| class CustomerSerializer < ActiveModel::Serializer | |
| attributes :customer_number, :email, :username | |
| def customer_number | |
| object.account_number | |
| end | |
| def merchant_id |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'base64' | |
| def base64_url_decode(str) | |
| str += '=' * (4 - str.length.modulo(4)) | |
| Base64.decode64(str.gsub("-", "+").gsub("_", "/")) | |
| end # source: https://github.com/ptarjan/base64url/blob/master/ruby.rb | |
| require 'hmac' | |
| require 'hmac-sha2' ## used to decode facebook return values |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Testing client side app (like BackboneJS) with Capybara, VCR, webmock, factory girl |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Today's little useless tidbit converts a url's query string into a hash | |
| # set of k/v pairs in a way that merges duplicates and massages empty | |
| # querystring values | |
| def qs_to_hash(query_string) | |
| keyvals = query_string.split('&').inject({}) do |result, q| | |
| k,v = q.split('=') | |
| if !v.nil? | |
| result.merge({k => v}) | |
| elsif !result.key?(k) |
NewerOlder