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 '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 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
| 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 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
| login(user) | |
| expect(page).to have_content("Logged in") | |
| visit foo_path |
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
| 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 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
| #<Rack::BodyProxy: @body= | |
| #<Rack::BodyProxy: @body= | |
| #<Rack::BodyProxy: @body= | |
| #<Rack::BodyProxy: @body= | |
| #<Rack::BodyProxy: @body= | |
| #<Rack::BodyProxy: @body= | |
| #<Sprockets::StaticAsset |
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
| 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 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
| # 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 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
| it do | |
| expect{ | |
| @return_result = foo() | |
| }.to change(Foo, :count).from(1).to(0) | |
| expect(@return_result).to eq(true) | |
| 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
| def foo(role) | |
| if !teacher?(role) | |
| ... | |
| def teacher?(role) | |
| role == :teacher |
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
| # insdie model | |
| def write_attribute(attr_name, value) | |
| super | |
| # Association assignment take effect after super | |
| case attr_name | |
| when 'admin_editing' | |
| pp "Inside write_attribute: #{self.admin_editing}" | |
| end | |
| end |