Skip to content

Instantly share code, notes, and snippets.

# app/controllers/v1/users_controller.rb
class V1::UsersController < V1::ApplicationController
def create
user = SignUpUser.perform(user_params)
render json: user, serializer: AuthenticationSerializer, root: :user
end
private
# config/routes.rb
Rails.application.routes.draw do
api_version(module: 'V1',
header: {
name: 'Accept',
value: 'application/vnd.authentication-demo-app.com; version=1' },
defaults: { format: :json }) do
resources :users, only: :create
end
$ rails g model email password_digest authentication_token authentication_token_expires_at:datetime
RSpec.configure do |config|
# ...
config.include Helpers::Requests, type: :request
config.include JsonSpec::Helpers
# ...
end
# spec/support/helpers/requests.rb
module Helpers
module Requests
def body
response.body
end
def json_value_at_path(path = '')
parse_json(body, path)
# spec/requests/v1/users_requests_spec.rb
require 'rails_helper'
describe 'Users endpoints' do
describe 'POST /users' do
context 'with valid email and password' do
it 'returns JSON for a user' do
user_attributes = {
user: {
oh hai
@hchood
hchood / sinatra-deployment.md
Created December 6, 2014 22:43
Deploying SInatra apps to Heroku

Deploying Sinatra apps to Heroku

Pre-requisites:

  1. Git repo in your app

  2. Create account on heroku.com

  • Add your SSH key to Heroku so you can push to your heroku remote repo. Hopefully you already have an SSH key for GitHub, in which case you can run the following:

$ heroku keys:add

@hchood
hchood / kickoff-mentor-group-presentations.md
Last active August 29, 2015 14:09
Day 1 Mentor Group Presentation Topics

Topics

  • Pair Programming
    • why is it efficient for development?
    • why is it efficient for learning?
    • How do you do it?
  • Test Driven Development
    • why is it efficient for development?
    • How do you do it?
  • How does it make software better?
@hchood
hchood / seeds.rb
Created September 23, 2014 19:51
Bus seeder
timeframes = [
"6-9 AM",
"9-12 PM",
"12-3 PM"
]
direction = [
"inbound",
"outbound"
]