Skip to content

Instantly share code, notes, and snippets.

How do solo developers practice code review?

Thanks for the question, Danny! I can't answer this from experience, but I have some ideas:

1. Ask a friend

This was your idea, and it's a good one. The only problem is you're going to have to have some good friends to jump into this for you, but you'll both be better for it :).

2. Pair programming

describe 'time' do
it 'fails here' do
time1 = Time.now
sleep(0.1)
time2 = Time.now
expect(time1).to be_within(0.1).of(time2)
end
it 'passes here' do
time1 = Time.now
#########################
# .gitignore file for Xcode4 / OS X Source projects
#
# Version 2.0
# For latest version, see: http://stackoverflow.com/questions/49478/git-ignore-file-for-xcode-projects
#
# 2013 updates:
# - fixed the broken "save personal Schemes"
#
# NB: if you are storing "built" products, this WILL NOT WORK,
» bin/rake routes
Prefix Verb URI Pattern Controller#Action
api_articles GET /api/articles(.:format) api/v1/articles#index
POST /api/articles(.:format) api/v1/articles#create
new_api_article GET /api/articles/new(.:format) api/v1/articles#new
edit_api_article GET /api/articles/:id/edit(.:format) api/v1/articles#edit
api_article GET /api/articles/:id(.:format) api/v1/articles#show
PATCH /api/articles/:id(.:format) api/v1/articles#update
PUT /api/articles/:id(.:format) api/v1/articles#update
DELETE /api/articles/:id(.:format) api/v1/articles#destroy
module Api
module V1
class ArticlesController < ApplicationController
def index
articles = [
{ id: 1, name: 'The Things' },
]
render json: articles
end
end

Farticles API

This is an example of a versioned Rails API using HTTP "accept" headers rather than including the version in resource URIs.

Getting started

Requirements

Adding Versions to a Rails API

When you create an application programming interface, you're establishing a contract with everyone who uses it. This too is true for web service APIs. As soon as someone begins using an API cost is incurred to change it. In order to allow breaking changes to an interface we can version it so clients may specify exactly what representation they expect for their requests.

An example API

# https://github.com/iamvery/rails-api-example/blob/b21a0a918c65892376ccbebaf96057051795afc0/app/controllers/v1/articles_controller.rb
module V1
class ArticlesController < ApplicationController
def index
articles = [
{ id: 123, name: 'The Things' },
]
respond_to do |format|
format.json do
# https://github.com/iamvery/rails-api-example/blob/b21a0a918c65892376ccbebaf96057051795afc0/config/routes.rb
Rails.application.routes.draw do
scope module: :v1 do
resources :articles, only: :index
end
end
# https://github.com/iamvery/rails-api-example/blob/5d304f1983107c4cb609d83a5b6b209ba4064287/app/constraints/api_constraint.rb
class ApiConstraint
attr_reader :version
def initialize(options)
@version = options.fetch(:version)
end
def matches?(request)
request