Created
May 17, 2015 02:56
-
-
Save backus/622a5f685a54a15189b8 to your computer and use it in GitHub Desktop.
Surprising return from `parent_name`
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_support' | |
require 'active_support/core_ext' | |
require 'active_record' | |
require 'test/unit' | |
# Setup | |
ActiveRecord::Base.establish_connection( | |
:adapter => "sqlite3", | |
:database => ":memory:" | |
) | |
ActiveRecord::Schema.define do | |
create_table :users do |table| | |
table.column :gender, :string | |
end | |
end | |
class User < ActiveRecord::Base | |
scope :male, -> { where(gender: 'M') } | |
end | |
module M | |
class N | |
end | |
end | |
# Test | |
class ParentNameTest < Test::Unit::TestCase | |
def test_module # passes | |
assert_parent_name M::N, 'M' | |
end | |
def test_ar_scope # fails 4.2 | |
klass = User.male.class | |
name = klass.to_s.split('::').first | |
assert_parent_name klass, name | |
end | |
private | |
def assert_parent_name(klass, expectation) | |
actual = klass.parent_name | |
assert expectation == actual, | |
"Expected #{klass}.parent_name to be #{expectation.inspect} but found #{actual.inspect}" | |
end | |
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
source "https://rubygems.org" | |
case ENV['ACTIVE_VERSION'] | |
when '4.2' | |
gem 'activerecord', '= 4.2.1' | |
gem 'activesupport', '= 4.2.1' | |
when '4.0' | |
gem 'activerecord', '= 4.0.13' | |
gem 'activesupport', '= 4.0.13' | |
else | |
fail 'Specify environment variable ACTIVE_VERSION' | |
end | |
gem 'test-unit', '1.2.3' | |
gem 'sqlite3', '1.3.10' |
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 'rake' | |
rule(/4.\d/) do |t| | |
bundle = "ACTIVE_VERSION=#{t.name} bundle" | |
sh "#{bundle} install && #{bundle} exec ruby 01_test.rb" | |
end | |
task default: %w[4.0 4.2] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment