Skip to content

Instantly share code, notes, and snippets.

@senny
senny / totp.rb
Last active October 24, 2017 09:05 — forked from thibaudgg/totp.rb
class TOTP
attr_reader :secret, :digits, :digest, :interval
DEFAULT_INTERVAL = 30
DEFAULT_DIGITS = 6
def initialize(s, options = {})
@interval = options[:interval] || DEFAULT_INTERVAL
@digits = options[:digits] || DEFAULT_DIGITS
@digest = options[:digest] || "sha1"
<p>bullet deeply nested</p>
<ul>
<li>lorem ipsum</li>
<li>
consectetur adipiscing elit
<ul>
<li>
sed do eiusmod tempor incididunt ut labore et dolore magna aliqua
<ul>
<li>Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo <u>consequat</u>. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</li>
@senny
senny / description.md
Last active August 29, 2015 14:27
`Array#flatten` ignores `respond_to_missing?` when calling `to_ary`

This issue was reported on bugs.ruby-lang.org: https://bugs.ruby-lang.org/issues/11465

The issue appears when using Array#flatten on an instance of Array containing instances of a Class that implements method_missing. Ruby still calls #to_ary even when said class implements respond_to_missing? and returns false for to_ary. Everything works when the class also overwrites respond_to?.

Questions:

  1. Is it expected that respond_to_missing? has no effect in the scenario above?
  2. Should a possible workaround rather define a respond_to? method or overwrite to_ary and return nil?
diff --git a/activerecord/lib/active_record/explain.rb b/activerecord/lib/active_record/explain.rb
index 727a9be..1d9dde0 100644
--- a/activerecord/lib/active_record/explain.rb
+++ b/activerecord/lib/active_record/explain.rb
@@ -16,14 +16,14 @@ module ActiveRecord
# Makes the adapter execute EXPLAIN for the tuples of queries and bindings.
# Returns a formatted string ready to be logged.
def exec_explain(queries) # :nodoc:
- str = queries.map do |sql, bind|
+ str = queries.map do |sql, bind, connection_id|
@senny
senny / env
Last active August 29, 2015 14:16
Ruby 2.2.1 bug
$ ruby --version
ruby 2.2.1p85 (2015-02-26 revision 49769) [x86_64-darwin14]
diff --git a/test/fixtures/high_scores.yml b/test/fixtures/high_scores.yml
index 0c3721e..9d3b342 100644
--- a/test/fixtures/high_scores.yml
+++ b/test/fixtures/high_scores.yml
@@ -1,5 +1,7 @@
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
+<% require Rails.root + "test/support/fixture_helper" %>
+
one:
E, [2015-02-12T03:25:25.223244 #32185] ERROR -- : Actor crashed!
Errno::EHOSTDOWN: Host is down @ dir_initialize - <THE/DIRECTORY/LISTEN/WATCHES>
/usr/local/rbenv/versions/2.1.5/lib/ruby/2.1.0/pathname.rb:425:in `open'
/usr/local/rbenv/versions/2.1.5/lib/ruby/2.1.0/pathname.rb:425:in `foreach'
/usr/local/rbenv/versions/2.1.5/lib/ruby/2.1.0/pathname.rb:425:in `children'
/path/to/app/vendor/bundle/ruby/2.1.0/gems/listen-2.8.3/lib/listen/directory.rb:14:in `scan'
/path/to/app/vendor/bundle/ruby/2.1.0/gems/listen-2.8.3/lib/listen/change.rb:38:in `change'
/path/to/app/vendor/bundle/ruby/2.1.0/gems/celluloid-0.16.0/lib/celluloid/calls.rb:26:in `public_send'
/path/to/app/vendor/bundle/ruby/2.1.0/gems/celluloid-0.16.0/lib/celluloid/calls.rb:26:in `dispatch'
/path/to/app/vendor/bundle/ruby/2.1.0/gems/celluloid-0.16.0/lib/celluloid/calls.rb:63:in `dispatch'
begin
require 'bundler/setup'
rescue LoadError
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
end
require 'rdoc/task'
RDoc::Task.new(:rdoc) do |rdoc|
rdoc.rdoc_dir = 'rdoc'
diff --git a/guides/source/testing.md b/guides/source/testing.md
index 32140be..f2e0f82 100644
--- a/guides/source/testing.md
+++ b/guides/source/testing.md
@@ -223,7 +223,16 @@ Every test must contain at least one assertion, with no restriction as to how ma
### Maintaining the test database schema
-In order to run your tests, your test database will need to have the current structure. The test helper checks whether your test database has any pending migrations. If so, it will try to load your `db/schema.rb` or `db/structure.sql` into the test database. If migrations are still pending, an error will be raised.
+In order to run your tests, your test database will need to have the current
@senny
senny / 1test.rb
Last active August 29, 2015 14:10
require 'bundler'
Bundler.setup(:default)
require 'active_record'
require 'minitest/autorun'
require 'logger'
# This connection will do for database-independent bug reports.
ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: ':memory:')
ActiveRecord::Base.logger = Logger.new(STDOUT)