Here's an example of a rspec test helper that will let you sign in as a given user.
Create spec/support/helpers/authentication.rb with the following:
module Helpers
module Authentication
def sign_in_as(user)| # As used with CanCan and Devise | |
| class ApplicationController < ActionController::Base | |
| protect_from_forgery | |
| include ErrorResponseActions | |
| rescue_from CanCan::AccessDenied, :with => :authorization_error | |
| rescue_from ActiveRecord::RecordNotFound, :with => :resource_not_found | |
| before_filter :authenticate! |
| HTTP status code symbols for Rails | |
| Thanks to Cody Fauser for this list of HTTP responce codes and their Ruby on Rails symbol mappings. | |
| Status Code Symbol | |
| 1xx Informational | |
| 100 :continue | |
| 101 :switching_protocols | |
| 102 :processing |
| # 1) Create your private key (any password will do, we remove it below) | |
| $ cd ~/.ssh | |
| $ openssl genrsa -des3 -out server.orig.key 2048 | |
| # 2) Remove the password | |
| $ openssl rsa -in server.orig.key -out server.key |
| # Call scopes directly from your URL params: | |
| # | |
| # @products = Product.filter(params.slice(:status, :location, :starts_with)) | |
| module Filterable | |
| extend ActiveSupport::Concern | |
| module ClassMethods | |
| # Call the class methods with names based on the keys in <tt>filtering_params</tt> | |
| # with their associated values. For example, "{ status: 'delayed' }" would call |
| ## | |
| # by SoAwesomeMan | |
| str =<<-EOS.gsub(/^[\s\t]*|[\s\t]*\n/, '') # no space "\s" for new line "\n"; kill tabs too | |
| select awesome, awesome, awesome, awesome, awesome, awesome, | |
| from rad, rad, rad, rad, rad, rad, rad, rad, rad, rad, rad, | |
| where cool cool cool cool cool cool cool cool cool cool cool' | |
| EOS | |
| # => "select awesome, awesome, awesome, awesome, awesome, awesome,from rad, rad, rad, rad, rad, rad, rad, rad, rad, rad, rad,where cool cool cool cool cool cool cool cool cool cool cool'" | |
| str =<<-EOS.gsub(/^[\s\t]*/, '').gsub(/[\s\t]*\n/, ' ').strip # yes space "\s" for new line "\n"; kill tabs too |
Originally published in June 2008
When hiring Ruby on Rails programmers, knowing the right questions to ask during an interview was a real challenge for me at first. In 30 minutes or less, it's difficult to get a solid read on a candidate's skill set without looking at code they've previously written. And in the corporate/enterprise world, I often don't have access to their previous work.
To ensure we hired competent ruby developers at my last job, I created a list of 15 ruby questions -- a ruby measuring stick if you will -- to select the cream of the crop that walked through our doors.
Candidates will typically give you a range of responses based on their experience and personality. So it's up to you to decide the correctness of their answer.
| Object.assign = function( O, dictionary ) { | |
| var target, src; | |
| // Let target be ToObject(O). | |
| target = Object( O ); | |
| // Let src be ToObject(dictionary). | |
| src = Object( dictionary ); | |
| // For each own property of src, let key be the property key |
| #macro(VelListToJSON $list ) | |
| #set($myList = $list )## dereference | |
| { | |
| #foreach($key in $myList.keySet()) | |
| "$key": | |
| #set($x = $myList.get($key)) | |
| #VelToJSON($x) | |
| #if($foreachCount != $myList.keySet().size()) , #end | |
| #end | |
| } |
| brew install git | |
| brew update | |
| brew install readline | |
| brew link readline | |
| brew install python | |
| brew install postgres | |
| brew install tmux | |
| brew install pip | |
| brew install nginx | |
| brew install libevent |