Skip to content

Instantly share code, notes, and snippets.

@MTen
MTen / Rspec instead of TestUnit
Last active April 14, 2020 00:29
This is a flag hack for the "rails new <name_of_app>" command. It needs to be added to your .bash_profile and it will remove TestUnit, add the rspec-rails gem to your Gemfile, change directory into your app, re-bundle, and then generate a rspec folder. The syntax is "rails new <name_of_app> -rspec" I added pg to this and config database.yml
Adding a -rspec flag to rails. Also establishes and
rails() { if [[ $1 == "new" && $3 == "-rspec" ]]; then add_rspec $2; else command rails "$@"; fi; }
function add_rspec(){
command rails new $1 -d postgresql -T; #delete -d postgresql if you don't want pg
command chmod 664 $1/Gemfile;
echo -e "\n#Because rspec is better than Test::Unit. Or so I'm told.\ngem 'rspec-rails'" >> $1/Gemfile;
command chmod 644 $1/Gemfile;
command cd $1;
[1] pry(main)> Book
=> Book(id: integer, title: string, author: string, abstract: text, created_at: datetime, updated_at: datetime)
[2] pry(main)> Book.create title: "Who Stole My Cheese?"
(0.1ms) begin transaction
SQL (5.1ms) INSERT INTO "books" ("created_at", "title", "updated_at") VALUES (?, ?, ?) [["created_at", Tue, 08 Oct 2013 23:14:31 UTC +00:00], ["title", "Who Stole My Cheese?"], ["updated_at", Tue, 08 Oct 2013 23:14:31 UTC +00:00]]
(14.9ms) commit transaction
=> #<Book id: 4, title: "Who Stole My Cheese?", author: nil, abstract: nil, created_at: "2013-10-08 23:14:31", updated_at: "2013-10-08 23:14:31">
[3] pry(main)> Book.find(4)
Book Load (0.3ms) SELECT "books".* FROM "books" WHERE "books"."id" = ? LIMIT 1 [["id", 4]]
=> #<Book id: 4, title: "Who Stole My Cheese?", author: nil, abstract: nil, created_at: "2013-10-08 23:14:31", updated_at: "2013-10-08 23:14:31">
@andywenk
andywenk / import-example.rb
Created November 4, 2012 21:34
csv-import-example
# This is a basic example how to create an import from csv data. This could
# be called in a rake task:
namespace :db do
namespace :import do
desc "Import customer of old shop from csv"
task :customer => :environment do
csv_file = 'db/customer_data.csv'
importer = Import::ImportCustomer.new(IO.read(csv_file))
importer.import
@lucasfais
lucasfais / gist:1207002
Created September 9, 2011 18:46
Sublime Text 2 - Useful Shortcuts

Sublime Text 2 – Useful Shortcuts (Mac OS X)

General

⌘T go to file
⌘⌃P go to project
⌘R go to methods
⌃G go to line
⌘KB toggle side bar
⌘⇧P command prompt
@olivierlacan
olivierlacan / launch_sublime_from_terminal.markdown
Created September 5, 2011 15:50
Launch Sublime Text 2 from the Mac OS X Terminal

Launch Sublime Text 2 from the Mac OS X Terminal

Sublime Text 2 ships with a CLI called subl (why not "sublime", go figure). This utility is hidden in the following folder (assuming you installed Sublime in /Applications like normal folk. If this following line opens Sublime Text for you, then bingo, you're ready.

open /Applications/Sublime\ Text\ 2.app/Contents/SharedSupport/bin/subl

You can find more (official) details about subl here: http://www.sublimetext.com/docs/2/osx_command_line.html

Installation

@zhengjia
zhengjia / capybara cheat sheet
Created June 7, 2010 01:35
capybara cheat sheet
=Navigating=
visit('/projects')
visit(post_comments_path(post))
=Clicking links and buttons=
click_link('id-of-link')
click_link('Link Text')
click_button('Save')
click('Link Text') # Click either a link or a button
click('Button Value')