Skip to content

Instantly share code, notes, and snippets.

@kianw
kianw / gist:392d7e7c2227dc65c3d1
Last active February 10, 2023 18:34
Git Cheat Sheet
Git Cheatsheet
=== ==========
--- BASICS, PUSH, PULL, MERGE, REBASE --
git init (create a new, empty git repo in current directory)
git clone <url_or_path> (clone a new repo from the given repo)
git pull origin <full-branch-path>
git push origin <full-branch-path>
@kianw
kianw / gist:352f371b224a54655f39
Created August 15, 2014 17:22
Atom snippets for ruby / rails / rspec
'.source.ruby':
'context':
"prefix": "ctx",
"body": "context \"${1}\" do\n\t$2\nend",
'describe':
"prefix": "dsc",
"body": "describe \"${1}\" do\n\t$2\nend"
'before-each':
@kianw
kianw / discoveries.md
Last active December 29, 2015 14:19
Things I wish I had known before I wasted an hour figuring them out...

Models

accepts_nested_attributes_for Update Problems

If you can't update a nested object, getting a message like:

Failed to remove the existing associated parent. 
The record failed to save after its foreign key was set to nil

you're probably not permitting the nested ID parameter to be used. Check your strong parameters #permit to ensure that you're permitting the :id parameter on the nested attributes.

Views

@kianw
kianw / gist:5085085
Last active December 14, 2015 12:18
Thorough Testing of Association Validations --- RSpec examples that will test that a child object is correctly validating its association with a parent object. ActiveRecord will assign a project_id to the task if you assign a saved Project to project. If you assign an unsaved/new Project to project, it will leave project_id blank. Thus, we want …
# Examples
context "validations" do
let(:child) { FactoryGirl.build(:child) } # Fill in enough to ensure that the Child is valid except for the association
it "should not fail if an associated valid Parent is present" do
child.parent = FactoryGirl.build(:parent)
child.valid?.should be_true
child.errors.should be_empty
end