Skip to content

Instantly share code, notes, and snippets.

@stevenyap
stevenyap / Capybara.md
Created October 23, 2013 05:03
Capybara Cheatsheet

Refer to: https://github.com/jnicklas/capybara

Note: Capybara does not show exceptions created by app. It will instead only tell you that the element you are searching for is not found.

Setup

  • Gemfile setup
gem "capybara"
gem 'selenium-webdriver' # requires for live browser demostration
@stevenyap
stevenyap / Simple Form.md
Created October 26, 2013 04:25
Simple Form Cheatsheet

Gemfile

gem 'simple_form'

Installation

rails generate simple_form:install
@stevenyap
stevenyap / Github Flavored Markdown.md
Last active March 28, 2024 17:42
Github Flavored Markdown cheatsheet

Github Flavored Markdown (GFMD) is based on Markdown Syntax Guide with some overwriting as described at Github Flavored Markdown

Text Writing

It is easy to write in GFMD. Just write simply like text and use the below simple "tagging" to mark the text and you are good to go!

To specify a paragraph, leave 2 spaces at the end of the line

Headings

@stevenyap
stevenyap / Rails Controller.md
Created October 19, 2013 13:58
Rails controller cheatsheet

Flash

# supports only notice and alert by default
# the rest has to go into flash hash
redirect_to :index, notice: "success"
redirect_to :new, notice: "errors"
redirect_to :new, flash: { success: "yeah" }
flash[:info] = "updated"
@stevenyap
stevenyap / Capistrano 3.md
Created February 21, 2014 08:52
Capistrano 3 Setup

This guide explains the way to setup a production server using Capistrano.

Setup Capistrano on LOCAL

  • Capistrano is a development gem which assist the developer to run commands on the production server (something like a Heroku toolbelt)
  • Hence, it is installed and configured on developer's computer
# Gemfile

# Use Capistrano for deployment
@stevenyap
stevenyap / Git Reset-Revert.md
Created November 17, 2013 09:50
Git reset and revert: Undoing changs

Difference between reset and revert

  • Reset rewinds history (files + commits) back to the previous commits
  • Revert rewinds your files back to the previous commits by adding a new commit to show this
  • You should use revert (especially if you have pushed) as it does not rewrite history

Git Reset

# If you are pulling, rebasing or your new code is a mess, and you want to return to the last committed point:
@stevenyap
stevenyap / Git Branching.md
Created November 16, 2013 09:55
Git Branching

Git Branching

Problem

  • You have pushed your code to production and you are going to work on a major story.
  • Halfway through, the client called to ask you to fix a major bug immediately.
  • Your current code base is half-way, but the bug is urgent. How to resolve this?

Branching and Merging to the rescus

  • You should work on the new story on a new branch
  • In the happy event (where there is no sudden issues), you can simply merge back the new branch into master just like normal pushing
@stevenyap
stevenyap / Rake Database.md
Last active April 13, 2023 09:42
List of rake commands to manage database

Create database

rake db:create

Create database table

This will creates a migration file in /db/migrate without table definition.

rails g migration create_<TABLE>
@stevenyap
stevenyap / Rspec.md
Created October 18, 2013 13:28
Rspec testing cheatsheet

Precaution

  • Example groups are executed in random orders so setting let must be taken care of
  • before(:all) does not rollback transaction! Test data created remains in the test database! However, running rspec (on cmd line) will clear the test database.
    rake db:test:prepare will also clear the test database.

Testing samples:

Feature testing:

@stevenyap
stevenyap / vcr_timecop.md
Last active December 19, 2022 18:36
Optimizing time-sensitive and HTTP-based test case using VCR and Timecop

Problem

You need to get the last hour data from an API but your test case runs too slow with the connections to API or test cases fail consistently with VCR due to different HTTP request sent in the params.

For example, expect(api.latest_data_time).eq 1.hour.ago in which 1.hour.ago will be different each time you execute the test case and the api http request param of the time will also change according to the current system time like http://api.com?starting_time=<new_current_time>

Solution

We need VCR to record the HTTP request and we use Timecop to freeze the system so that the HTTP request remains the same.