This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
karthik@cloud:~/MyRubyProjects/beach_projects/dashboard$ bundle install | |
/home/karthik/.rvm/gems/ruby-1.9.2-p0@rails3/gems/bundler-1.0.7/lib/bundler/ui.rb:56:in '<class:UI>': uninitialized constant Gem::SilentUI (NameError) | |
from /home/karthik/.rvm/gems/ruby-1.9.2-p0@rails3/gems/bundler-1.0.7/lib/bundler/ui.rb:2:in `<module:Bundler>' | |
from /home/karthik/.rvm/gems/ruby-1.9.2-p0@rails3/gems/bundler-1.0.7/lib/bundler/ui.rb:1:in `<top (required)>' | |
from /home/karthik/.rvm/gems/ruby-1.9.2-p0@rails3/gems/bundler-1.0.7/lib/bundler/cli.rb:16:in `initialize' | |
from /home/karthik/.rvm/gems/ruby-1.9.2-p0@rails3/gems/bundler-1.0.7/lib/bundler/vendor/thor.rb:246:in `new' | |
from /home/karthik/.rvm/gems/ruby-1.9.2-p0@rails3/gems/bundler-1.0.7/lib/bundler/vendor/thor.rb:246:in `dispatch' | |
from /home/karthik/.rvm/gems/ruby-1.9.2-p0@rails3/gems/bundler-1.0.7/lib/bundler/vendor/thor/base.rb:389:in `start' | |
from /home/karthik/.rvm/gems/ruby-1.9.2-p0@rails3/gems/bundler-1.0.7/bin/bundle:13:in `<top (required)>' | |
from /home/karthik/. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Fixnum | |
def crime | |
end | |
end | |
p 2.method(:crime) | |
#<Method: Fixnum#crime> #crime() defined in Fixnum class is invoked | |
module Loser | |
def crime | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require File.expand_path('../boot', __FILE__) | |
require 'rails/all' | |
# If you have a Gemfile, require the gems listed there, including any gems | |
# you've limited to :test, :development, or :production. | |
Bundler.require(:default, Rails.env) if defined?(Bundler) | |
module MyRails3App | |
class Application < Rails::Application |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# RSpec 2.0 syntax Cheet Sheet by http://ApproachE.com | |
# defining spec within a module will automatically pick Player::MovieList as a 'subject' (see below) | |
module Player | |
describe MovieList, "with optional description" do | |
it "is pending example, so that you can write ones quickly" | |
it "is already working example that we want to suspend from failing temporarily" do | |
pending("working on another feature that temporarily breaks this one") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### Terminal Output showing spec failure ### | |
Failures: | |
1) CurrencyConverter#validations | |
Failure/Error: it { should validate_uniqueness_of(:from).scoped_to(:to) } | |
Can't find first CurrencyConverter | |
# ./spec/models/currency_converter_spec.rb:4:in `block (3 levels) in <top (required)>' | |
########################################### | |
### The Solution ### |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
################################################################################ | |
################################## Yucky code ################################## | |
find_by_name name | |
User.all( :conditions => "first_name LIKE #{name}% OR last_name LIKE #{name}%") #prone to SQL injection. Imagine the parameter name = "1; drop table users;" | |
end | |
############################################################################################################################ | |
# For Active Record to sanitize the input parameters from SQL Injection of sorts, you may adopt one of the following styles: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
describe Address do | |
describe "#validations" do | |
it "must have a city" do | |
a = Address.new | |
a.should_not be_valid | |
a.errors_on(:city).should_not be_nil | |
end | |
it "must have a state" do | |
a = Address.new |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
describe Address do | |
describe "#validations" do | |
it "must have a city" do | |
a = Address.new | |
a.should_not be_valid | |
a.errors_on(:city).should_not be_nil | |
end | |
it "must have a state" do | |
a = Address.new |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
describe Address do | |
describe "#validations" do | |
before(:each) do | |
@a = Address.new | |
@a.should_not be_valid | |
end | |
it "must have a city" do | |
@a.errors_on(:city).should_not be_nil | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
describe Address do | |
describe "#validations" do | |
before(:all) do | |
@a = Address.new | |
@a.should_not be_valid | |
end | |
%w(:city :state :country).each do |attr| | |
it "must have a #{attr}" do | |
@a.errors_on(attr).should_not be_nil |
OlderNewer