This file contains 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
it do | |
expect{ | |
@return_result = foo() | |
}.to change(Foo, :count).from(1).to(0) | |
expect(@return_result).to eq(true) | |
end |
This file contains 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
# This is generated using toy_scaffold, | |
# and is meant for learning purposes only. | |
# It aims for more clarity for beginners, therefore | |
# sacrifices some best practices and DRY principle. | |
class BooksController < ApplicationController | |
# GET /books | |
# View file is at app/views/books/index.html.erb | |
def index | |
@books = Book.all |
This file contains 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
start_time = Time.now.to_f | |
time_elapsed = lambda { ((Time.now.to_f - start_time) * 1000).to_i } | |
logger.info "#{msg} 404 Not Found (#{time_elapsed.call}ms)" |
This file contains 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
#<Rack::BodyProxy: @body= | |
#<Rack::BodyProxy: @body= | |
#<Rack::BodyProxy: @body= | |
#<Rack::BodyProxy: @body= | |
#<Rack::BodyProxy: @body= | |
#<Rack::BodyProxy: @body= | |
#<Sprockets::StaticAsset |
This file contains 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
book.errors.keys | |
[:title] | |
book.errors[:base].present? | |
false | |
book.errors.keys | |
[:title, :base] | |
# and someone does this | |
if book.errors.keys.include?(:base) | |
boom!() |
This file contains 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
login(user) | |
expect(page).to have_content("Logged in") | |
visit foo_path |
This file contains 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
foo.save | |
foo.end_at.strftime('%H:%M:%S.%L') | |
"20:38:34.447" | |
foo.reload.end_at.strftime('%H:%M:%S.%L') | |
"20:38:34.000" |
This file contains 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 'nokogiri' | |
require 'open-uri' | |
(1..91).each do |i| | |
f = Fountain.create(issue:i, title:i) | |
end | |
(1..91).each do |i| | |
f = Fountain.find_by(issue:i) | |
i_s = "%02d" % i |
This file contains 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
# controller | |
@open_id = params[:open].to_i | |
# spec | |
expect(assigns(:open_id)).to eq(@params[:open].to_i) |
This file contains 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
irb(main):016:0> Money.new(1.5) == 0.015.to_money | |
=> true | |
irb(main):017:0> Money.new(1.5).instance_variable_get(:@fractional).to_s | |
=> "1.5" | |
irb(main):018:0> 0.015.to_money.instance_variable_get(:@fractional).to_s | |
=> "2.0" |