Created
January 2, 2013 11:10
-
-
Save pixeltrix/4433870 to your computer and use it in GitHub Desktop.
Simple script to reproduce segfaults with Active Record in ruby-1.9.3p362. This style of scope is used by the kaminari gem to define its page scope - using a class method to define default_scope doesn't segfault.
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 'active_record' | |
ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :database => ":memory:") | |
ActiveRecord::Schema.define(:version => 1) do | |
create_table :posts do |t| | |
t.string :title | |
t.timestamps | |
end | |
end | |
class Post < ActiveRecord::Base | |
default_scope { where(:published => true) } | |
scope :page, Proc.new { |num| limit(10).offset(10 * (num - 1)) } do | |
def current_page | |
return 1 if limit_value.nil? | |
(offset_value / limit_value) + 1 | |
end | |
end | |
end | |
30.times do |i| | |
Post.create! do |p| | |
p.title = "Post #{i}" | |
end | |
end | |
# Segfaults | |
Post.page(1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment