rails / activerecord-deprecated_finders

MIT License
68 stars 22 forks source link

tests fail under ruby2.3 #27

Open terceiro opened 8 years ago

terceiro commented 8 years ago

Hi,

I tried running the tests under Ruby 2.3 and they fail like this:

$ ruby -v
ruby 2.3.0p0 (2015-12-25) [x86_64-linux-gnu]
$ bundle show
Gems included by the bundle:
  * actionmailer (4.2.5.2)
  * actionpack (4.2.5.2)
  * actionview (4.2.5.2)
  * activejob (4.2.5.2)
  * activemodel (4.2.5.2)
  * activerecord (4.2.5.2)
  * activerecord-deprecated_finders (1.0.4)
  * activesupport (4.2.5.2)
  * arel (6.0.3)
  * builder (3.2.2)
  * bundler (1.11.2)
  * concurrent-ruby (1.0.1)
  * erubis (2.7.0)
  * globalid (0.3.6)
  * i18n (0.7.0)
  * json (1.8.3)
  * loofah (2.0.3)
  * mail (2.6.3)
  * mime-types (2.99.1)
  * mini_portile2 (2.0.0)
  * minitest (5.8.4)
  * nokogiri (1.6.7.2)
  * rack (1.6.4)
  * rack-test (0.6.3)
  * rails (4.2.5.2)
  * rails-deprecated_sanitizer (1.0.3)
  * rails-dom-testing (1.0.7)
  * rails-html-sanitizer (1.0.3)
  * railties (4.2.5.2)
  * rake (10.5.0)
  * sprockets (3.5.2)
  * sprockets-rails (3.0.4)
  * sqlite3 (1.3.11)
  * thor (0.19.1)
  * thread_safe (0.3.5)
  * tzinfo (1.2.2)
$ bundle exec rake
/usr/lib/ruby/vendor_ruby/debian_ruby_standalone.rb:24: warning: method redefined; discarding old user_dir
/usr/lib/ruby/2.3.0/rubygems/defaults.rb:76: warning: previous definition of user_dir was here
/usr/lib/ruby/vendor_ruby/debian_ruby_standalone_config.rb:2: warning: method redefined; discarding old ruby
/usr/lib/ruby/2.3.0/rubygems.rb:797: warning: previous definition of ruby was here
Run options: --seed 34515

# Running:

..............................E.EE..................................

Finished in 0.351114s, 193.6695 runs/s, 350.3140 assertions/s.

  1) Error:
associations#test_0007_supports proc where values which access the owner:
ArgumentError: wrong number of arguments (given 0, expected 1)
    /home/terceiro/.ruby-standalone/gems/ruby/2.3.0/gems/activerecord-4.2.5.2/lib/active_record/relation/spawn_methods.rb:41:in `instance_exec'
    /home/terceiro/.ruby-standalone/gems/ruby/2.3.0/gems/activerecord-4.2.5.2/lib/active_record/relation/spawn_methods.rb:41:in `merge!'
    /tmp/activerecord-deprecated_finders/lib/active_record/deprecated_finders/association_builder.rb:22:in `block in to_proc'
    /home/terceiro/.ruby-standalone/gems/ruby/2.3.0/gems/activerecord-4.2.5.2/lib/active_record/associations/association_scope.rb:191:in `instance_exec'
    /home/terceiro/.ruby-standalone/gems/ruby/2.3.0/gems/activerecord-4.2.5.2/lib/active_record/associations/association_scope.rb:191:in `eval_scope'
    /home/terceiro/.ruby-standalone/gems/ruby/2.3.0/gems/activerecord-4.2.5.2/lib/active_record/associations/association_scope.rb:155:in `block (2 levels) in add_constraints'
    /home/terceiro/.ruby-standalone/gems/ruby/2.3.0/gems/activerecord-4.2.5.2/lib/active_record/associations/association_scope.rb:154:in `each'
    /home/terceiro/.ruby-standalone/gems/ruby/2.3.0/gems/activerecord-4.2.5.2/lib/active_record/associations/association_scope.rb:154:in `block in add_constraints'
    /home/terceiro/.ruby-standalone/gems/ruby/2.3.0/gems/activerecord-4.2.5.2/lib/active_record/associations/association_scope.rb:141:in `each'
    /home/terceiro/.ruby-standalone/gems/ruby/2.3.0/gems/activerecord-4.2.5.2/lib/active_record/associations/association_scope.rb:141:in `each_with_index'
    /home/terceiro/.ruby-standalone/gems/ruby/2.3.0/gems/activerecord-4.2.5.2/lib/active_record/associations/association_scope.rb:141:in `add_constraints'
    /home/terceiro/.ruby-standalone/gems/ruby/2.3.0/gems/activerecord-4.2.5.2/lib/active_record/associations/association_scope.rb:39:in `scope'
    /home/terceiro/.ruby-standalone/gems/ruby/2.3.0/gems/activerecord-4.2.5.2/lib/active_record/associations/association_scope.rb:5:in `scope'
    /home/terceiro/.ruby-standalone/gems/ruby/2.3.0/gems/activerecord-4.2.5.2/lib/active_record/associations/association.rb:97:in `association_scope'
    /home/terceiro/.ruby-standalone/gems/ruby/2.3.0/gems/activerecord-4.2.5.2/lib/active_record/associations/association.rb:86:in `scope'
    /home/terceiro/.ruby-standalone/gems/ruby/2.3.0/gems/activerecord-4.2.5.2/lib/active_record/associations/collection_association.rb:423:in `scope'
    /home/terceiro/.ruby-standalone/gems/ruby/2.3.0/gems/activerecord-4.2.5.2/lib/active_record/associations/collection_proxy.rb:37:in `initialize'
    /home/terceiro/.ruby-standalone/gems/ruby/2.3.0/gems/activerecord-4.2.5.2/lib/active_record/relation/delegation.rb:106:in `new'
    /home/terceiro/.ruby-standalone/gems/ruby/2.3.0/gems/activerecord-4.2.5.2/lib/active_record/relation/delegation.rb:106:in `create'
    /home/terceiro/.ruby-standalone/gems/ruby/2.3.0/gems/activerecord-4.2.5.2/lib/active_record/associations/collection_association.rb:39:in `reader'
    /home/terceiro/.ruby-standalone/gems/ruby/2.3.0/gems/activerecord-4.2.5.2/lib/active_record/associations/builder/association.rb:115:in `comments'
    /tmp/activerecord-deprecated_finders/test/associations_test.rb:77:in `block (2 levels) in <top (required)>'

  2) Error:
associations#test_0005_translates hash scope options into scopes:
ArgumentError: wrong number of arguments (given 0, expected 1)
    /home/terceiro/.ruby-standalone/gems/ruby/2.3.0/gems/activerecord-4.2.5.2/lib/active_record/relation/spawn_methods.rb:41:in `instance_exec'
    /home/terceiro/.ruby-standalone/gems/ruby/2.3.0/gems/activerecord-4.2.5.2/lib/active_record/relation/spawn_methods.rb:41:in `merge!'
    /home/terceiro/.ruby-standalone/gems/ruby/2.3.0/gems/activerecord-4.2.5.2/lib/active_record/relation/spawn_methods.rb:33:in `merge'
    /tmp/activerecord-deprecated_finders/lib/active_record/deprecated_finders/association_builder.rb:24:in `block in to_proc'
    /home/terceiro/.ruby-standalone/gems/ruby/2.3.0/gems/activerecord-4.2.5.2/lib/active_record/associations/association_scope.rb:191:in `instance_exec'
    /home/terceiro/.ruby-standalone/gems/ruby/2.3.0/gems/activerecord-4.2.5.2/lib/active_record/associations/association_scope.rb:191:in `eval_scope'
    /home/terceiro/.ruby-standalone/gems/ruby/2.3.0/gems/activerecord-4.2.5.2/lib/active_record/associations/association_scope.rb:155:in `block (2 levels) in add_constraints'
    /home/terceiro/.ruby-standalone/gems/ruby/2.3.0/gems/activerecord-4.2.5.2/lib/active_record/associations/association_scope.rb:154:in `each'
    /home/terceiro/.ruby-standalone/gems/ruby/2.3.0/gems/activerecord-4.2.5.2/lib/active_record/associations/association_scope.rb:154:in `block in add_constraints'
    /home/terceiro/.ruby-standalone/gems/ruby/2.3.0/gems/activerecord-4.2.5.2/lib/active_record/associations/association_scope.rb:141:in `each'
    /home/terceiro/.ruby-standalone/gems/ruby/2.3.0/gems/activerecord-4.2.5.2/lib/active_record/associations/association_scope.rb:141:in `each_with_index'
    /home/terceiro/.ruby-standalone/gems/ruby/2.3.0/gems/activerecord-4.2.5.2/lib/active_record/associations/association_scope.rb:141:in `add_constraints'
    /home/terceiro/.ruby-standalone/gems/ruby/2.3.0/gems/activerecord-4.2.5.2/lib/active_record/associations/association_scope.rb:39:in `scope'
    /home/terceiro/.ruby-standalone/gems/ruby/2.3.0/gems/activerecord-4.2.5.2/lib/active_record/associations/association_scope.rb:5:in `scope'
    /home/terceiro/.ruby-standalone/gems/ruby/2.3.0/gems/activerecord-4.2.5.2/lib/active_record/associations/association.rb:97:in `association_scope'
    /home/terceiro/.ruby-standalone/gems/ruby/2.3.0/gems/activerecord-4.2.5.2/lib/active_record/associations/association.rb:86:in `scope'
    /home/terceiro/.ruby-standalone/gems/ruby/2.3.0/gems/activerecord-4.2.5.2/lib/active_record/associations/collection_association.rb:423:in `scope'
    /home/terceiro/.ruby-standalone/gems/ruby/2.3.0/gems/activerecord-4.2.5.2/lib/active_record/associations/collection_proxy.rb:37:in `initialize'
    /home/terceiro/.ruby-standalone/gems/ruby/2.3.0/gems/activerecord-4.2.5.2/lib/active_record/relation/delegation.rb:106:in `new'
    /home/terceiro/.ruby-standalone/gems/ruby/2.3.0/gems/activerecord-4.2.5.2/lib/active_record/relation/delegation.rb:106:in `create'
    /home/terceiro/.ruby-standalone/gems/ruby/2.3.0/gems/activerecord-4.2.5.2/lib/active_record/associations/collection_association.rb:39:in `reader'
    /home/terceiro/.ruby-standalone/gems/ruby/2.3.0/gems/activerecord-4.2.5.2/lib/active_record/associations/builder/association.rb:115:in `comments'
    /tmp/activerecord-deprecated_finders/test/associations_test.rb:49:in `block (2 levels) in <top (required)>'

  3) Error:
associations#test_0006_supports proc where values:
ArgumentError: wrong number of arguments (given 0, expected 1)
    /home/terceiro/.ruby-standalone/gems/ruby/2.3.0/gems/activerecord-4.2.5.2/lib/active_record/relation/spawn_methods.rb:41:in `instance_exec'
    /home/terceiro/.ruby-standalone/gems/ruby/2.3.0/gems/activerecord-4.2.5.2/lib/active_record/relation/spawn_methods.rb:41:in `merge!'
    /tmp/activerecord-deprecated_finders/lib/active_record/deprecated_finders/association_builder.rb:22:in `block in to_proc'
    /home/terceiro/.ruby-standalone/gems/ruby/2.3.0/gems/activerecord-4.2.5.2/lib/active_record/associations/association_scope.rb:191:in `instance_exec'
    /home/terceiro/.ruby-standalone/gems/ruby/2.3.0/gems/activerecord-4.2.5.2/lib/active_record/associations/association_scope.rb:191:in `eval_scope'
    /home/terceiro/.ruby-standalone/gems/ruby/2.3.0/gems/activerecord-4.2.5.2/lib/active_record/associations/association_scope.rb:155:in `block (2 levels) in add_constraints'
    /home/terceiro/.ruby-standalone/gems/ruby/2.3.0/gems/activerecord-4.2.5.2/lib/active_record/associations/association_scope.rb:154:in `each'
    /home/terceiro/.ruby-standalone/gems/ruby/2.3.0/gems/activerecord-4.2.5.2/lib/active_record/associations/association_scope.rb:154:in `block in add_constraints'
    /home/terceiro/.ruby-standalone/gems/ruby/2.3.0/gems/activerecord-4.2.5.2/lib/active_record/associations/association_scope.rb:141:in `each'
    /home/terceiro/.ruby-standalone/gems/ruby/2.3.0/gems/activerecord-4.2.5.2/lib/active_record/associations/association_scope.rb:141:in `each_with_index'
    /home/terceiro/.ruby-standalone/gems/ruby/2.3.0/gems/activerecord-4.2.5.2/lib/active_record/associations/association_scope.rb:141:in `add_constraints'
    /home/terceiro/.ruby-standalone/gems/ruby/2.3.0/gems/activerecord-4.2.5.2/lib/active_record/associations/association_scope.rb:39:in `scope'
    /home/terceiro/.ruby-standalone/gems/ruby/2.3.0/gems/activerecord-4.2.5.2/lib/active_record/associations/association_scope.rb:5:in `scope'
    /home/terceiro/.ruby-standalone/gems/ruby/2.3.0/gems/activerecord-4.2.5.2/lib/active_record/associations/association.rb:97:in `association_scope'
    /home/terceiro/.ruby-standalone/gems/ruby/2.3.0/gems/activerecord-4.2.5.2/lib/active_record/associations/association.rb:86:in `scope'
    /home/terceiro/.ruby-standalone/gems/ruby/2.3.0/gems/activerecord-4.2.5.2/lib/active_record/associations/collection_association.rb:423:in `scope'
    /home/terceiro/.ruby-standalone/gems/ruby/2.3.0/gems/activerecord-4.2.5.2/lib/active_record/associations/collection_proxy.rb:37:in `initialize'
    /home/terceiro/.ruby-standalone/gems/ruby/2.3.0/gems/activerecord-4.2.5.2/lib/active_record/relation/delegation.rb:106:in `new'
    /home/terceiro/.ruby-standalone/gems/ruby/2.3.0/gems/activerecord-4.2.5.2/lib/active_record/relation/delegation.rb:106:in `create'
    /home/terceiro/.ruby-standalone/gems/ruby/2.3.0/gems/activerecord-4.2.5.2/lib/active_record/associations/collection_association.rb:39:in `reader'
    /home/terceiro/.ruby-standalone/gems/ruby/2.3.0/gems/activerecord-4.2.5.2/lib/active_record/associations/builder/association.rb:115:in `comments'
    /tmp/activerecord-deprecated_finders/test/associations_test.rb:67:in `block (2 levels) in <top (required)>'

68 runs, 123 assertions, 0 failures, 3 errors, 0 skips
rake aborted!
Command failed with status (1): [ruby -I"test" -w -I"/home/terceiro/.ruby-standalone/gems/ruby/2.3.0/gems/rake-10.5.0/lib" "/home/terceiro/.ruby-standalone/gems/ruby/2.3.0/gems/rake-10.5.0/lib/rake/rake_test_loader.rb" "test/**/*_test.rb" ]

Tasks: TOP => default => test
(See full trace by running task with --trace)

Also, I needed to do the following in order to run the tests at all, because with rails 5.0.0.beta3 the tests crashed during load:

diff --git a/activerecord-deprecated_finders.gemspec b/activerecord-deprecated_finders.gemspec
index 7bf2ebd..fb64ab4 100644
--- a/activerecord-deprecated_finders.gemspec
+++ b/activerecord-deprecated_finders.gemspec
@@ -17,6 +17,6 @@ Gem::Specification.new do |gem|
   gem.require_paths = ["lib"]

   gem.add_development_dependency 'minitest',     '>= 3'
-  gem.add_development_dependency 'activerecord', '>= 4.0.0.beta', '< 5'
+  gem.add_development_dependency 'activerecord', '~> 4.2'
   gem.add_development_dependency 'sqlite3',      '~> 1.3'
 end
terceiro commented 8 years ago

seems to be a rails issue: rails/rails@a98475c2df8ab7d7d353cb29bb3f201c4c7eb9d1

terceiro commented 8 years ago

after I apply that patch to rails locally, it then fails with:

  1) Error:
associations#test_0005_translates hash scope options into scopes:
ArgumentError: invalid value for Integer(): "c"
    /home/terceiro/.ruby-standalone/gems/ruby/2.3.0/gems/activerecord-4.2.5.2/lib/active_record/connection_adapters/abstract/database_statements.rb:324:in `Integer'
    /home/terceiro/.ruby-standalone/gems/ruby/2.3.0/gems/activerecord-4.2.5.2/lib/active_record/connection_adapters/abstract/database_statements.rb:324:in `sanitize_limit'
    /home/terceiro/.ruby-standalone/gems/ruby/2.3.0/gems/activerecord-4.2.5.2/lib/active_record/relation/query_methods.rb:872:in `build_arel'
    /home/terceiro/.ruby-standalone/gems/ruby/2.3.0/gems/activerecord-4.2.5.2/lib/active_record/relation/query_methods.rb:858:in `arel'
    /home/terceiro/.ruby-standalone/gems/ruby/2.3.0/gems/activerecord-4.2.5.2/lib/active_record/relation/delegation.rb:119:in `respond_to?'
    /home/terceiro/.ruby-standalone/gems/ruby/2.3.0/gems/activerecord-4.2.5.2/lib/active_record/relation/spawn_methods.rb:43:in `merge!'
    /home/terceiro/.ruby-standalone/gems/ruby/2.3.0/gems/activerecord-4.2.5.2/lib/active_record/associations/association_scope.rb:158:in `block (2 levels) in add_constraints'
    /home/terceiro/.ruby-standalone/gems/ruby/2.3.0/gems/activerecord-4.2.5.2/lib/active_record/associations/association_scope.rb:154:in `each'
    /home/terceiro/.ruby-standalone/gems/ruby/2.3.0/gems/activerecord-4.2.5.2/lib/active_record/associations/association_scope.rb:154:in `block in add_constraints'
    /home/terceiro/.ruby-standalone/gems/ruby/2.3.0/gems/activerecord-4.2.5.2/lib/active_record/associations/association_scope.rb:141:in `each'
    /home/terceiro/.ruby-standalone/gems/ruby/2.3.0/gems/activerecord-4.2.5.2/lib/active_record/associations/association_scope.rb:141:in `each_with_index'
    /home/terceiro/.ruby-standalone/gems/ruby/2.3.0/gems/activerecord-4.2.5.2/lib/active_record/associations/association_scope.rb:141:in `add_constraints'
    /home/terceiro/.ruby-standalone/gems/ruby/2.3.0/gems/activerecord-4.2.5.2/lib/active_record/associations/association_scope.rb:39:in `scope'
    /home/terceiro/.ruby-standalone/gems/ruby/2.3.0/gems/activerecord-4.2.5.2/lib/active_record/associations/association_scope.rb:5:in `scope'
    /home/terceiro/.ruby-standalone/gems/ruby/2.3.0/gems/activerecord-4.2.5.2/lib/active_record/associations/association.rb:97:in `association_scope'
    /home/terceiro/.ruby-standalone/gems/ruby/2.3.0/gems/activerecord-4.2.5.2/lib/active_record/associations/association.rb:86:in `scope'
    /home/terceiro/.ruby-standalone/gems/ruby/2.3.0/gems/activerecord-4.2.5.2/lib/active_record/associations/collection_association.rb:423:in `scope'
    /home/terceiro/.ruby-standalone/gems/ruby/2.3.0/gems/activerecord-4.2.5.2/lib/active_record/associations/collection_proxy.rb:37:in `initialize'
    /home/terceiro/.ruby-standalone/gems/ruby/2.3.0/gems/activerecord-4.2.5.2/lib/active_record/relation/delegation.rb:106:in `new'
    /home/terceiro/.ruby-standalone/gems/ruby/2.3.0/gems/activerecord-4.2.5.2/lib/active_record/relation/delegation.rb:106:in `create'
    /home/terceiro/.ruby-standalone/gems/ruby/2.3.0/gems/activerecord-4.2.5.2/lib/active_record/associations/collection_association.rb:39:in `reader'
    /home/terceiro/.ruby-standalone/gems/ruby/2.3.0/gems/activerecord-4.2.5.2/lib/active_record/associations/builder/association.rb:115:in `comments'
    /tmp/activerecord-deprecated_finders/test/associations_test.rb:49:in `block (2 levels) in <top (required)>'

and this is easy enough to fix:

diff --git a/test/associations_test.rb b/test/associations_test.rb
index aff9a07..50d9dea 100644
--- a/test/associations_test.rb
+++ b/test/associations_test.rb
@@ -42,7 +42,7 @@ describe 'associations' do

   it 'translates hash scope options into scopes' do
     assert_deprecated do
-      @klass.has_many :comments, readonly: 'a', order: 'b', limit: 'c', group: 'd', having: 'e',
+      @klass.has_many :comments, readonly: 'a', order: 'b', limit: 1, group: 'd', having: 'e',
                                  offset: 'f', select: 'g', uniq: 'h', include: 'i', conditions: 'j'
     end

@@ -50,7 +50,7 @@ describe 'associations' do

     scope.readonly_value.must_equal 'a'
     scope.order_values.must_equal ['b']
-    scope.limit_value.must_equal 'c'
+    scope.limit_value.must_equal 1
     scope.group_values.must_equal ['d']
     scope.having_values.must_equal ['e']
     scope.offset_value.must_equal 'f'

and then it gives me:

# Running:

....................................................................

Finished in 0.356942s, 190.5073 runs/s, 392.2210 assertions/s.

What is the best way forward with this?