Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ReflectionTest#test_read_attribute_names got failure, an extra "wibble" shown #26099

Closed
yahonda opened this issue Aug 10, 2016 · 5 comments
Closed

Comments

@yahonda
Copy link
Member

yahonda commented Aug 10, 2016

Steps to reproduce

$ cd activerecord
$ bundle
$ bundle exec rake test

Expected behavior

All ActiveRecord unit test should finish without failures

Actual behavior

All sqlite3, mysql2 and postgresql adapters get the same failure:

$ cd activerecord
$ bundle exec rake test
... snip ... 
Using mysql2
... snip ... 
  1) Failure:
ReflectionTest#test_read_attribute_names [/home/yahonda/git/rails/activerecord/test/cases/reflection_test.rb:44]:
--- expected
+++ actual
@@ -1 +1 @@
-["approved", "author_email_address", "author_name", "bonus_time", "content", "created_at", "group", "id", "important", "last_read", "parent_id", "parent_title", "replies_count", "title", "type", "unique_replies_count", "updated_at", "written_on"]
+["approved", "author_email_address", "author_name", "bonus_time", "content", "created_at", "group", "id", "important", "last_read", "parent_id", "parent_title", "replies_count", "title", "type", "unique_replies_count", "updated_at", "wibble", "written_on"]


4930 runs, 13610 assertions, 1 failures, 0 errors, 5 skips

... snip ...
Using sqlite3
... snip ...
  1) Failure:
ReflectionTest#test_read_attribute_names [/home/yahonda/git/rails/activerecord/test/cases/reflection_test.rb:44]:
--- expected
+++ actual
@@ -1 +1 @@
-["approved", "author_email_address", "author_name", "bonus_time", "content", "created_at", "group", "id", "important", "last_read", "parent_id", "parent_title", "replies_count", "title", "type", "unique_replies_count", "updated_at", "written_on"]
+["approved", "author_email_address", "author_name", "bonus_time", "content", "created_at", "group", "id", "important", "last_read", "parent_id", "parent_title", "replies_count", "title", "type", "unique_replies_count", "updated_at", "wibble", "written_on"]


4769 runs, 13146 assertions, 1 failures, 0 errors, 3 skips

... snip ... 
Using postgresql
... snip ... 
  1) Failure:
ReflectionTest#test_read_attribute_names [/home/yahonda/git/rails/activerecord/test/cases/reflection_test.rb:44]:
--- expected
+++ actual
@@ -1 +1 @@
-["approved", "author_email_address", "author_name", "bonus_time", "content", "created_at", "group", "id", "important", "last_read", "parent_id", "parent_title", "replies_count", "title", "type", "unique_replies_count", "updated_at", "written_on"]
+["approved", "author_email_address", "author_name", "bonus_time", "content", "created_at", "group", "id", "important", "last_read", "parent_id", "parent_title", "replies_count", "title", "type", "unique_replies_count", "updated_at", "wibble", "written_on"]


5296 runs, 14594 assertions, 1 failures, 0 errors, 1 skips

System configuration

Rails version: master branch

Ruby version:ruby 2.3.1p112 (2016-04-26 revision 54768) [x86_64-linux]

Additional information

  • Minimum steps to reproduce
bundle exec ruby -w -I"lib:test" -I"/home/yahonda/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.1/gems/rake-11.1.2/lib" \
  "/home/yahonda/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/rake-11.1.2/lib/rake/rake_test_loader.rb" \
  "test/cases/validations_test.rb" "test/cases/reflection_test.rb" 

ruby 2.3.1 has been installed by rbenv and ruby-build plugin.

  • git bisect
    According to git bisect these failure reproduces since
    f0ddf87
@yahonda
Copy link
Member Author

yahonda commented Aug 10, 2016

grep wibble and found this test, it adds :wibble here. Still do not know if Topic.reset_column_information should remove attribute (not column) information.

https://github.com/rails/rails/blob/master/activerecord/test/cases/validations_test.rb#L158-L170

  def test_numericality_validation_with_mutation
    Topic.class_eval do
      attribute :wibble, :string
      validates_numericality_of :wibble, only_integer: true
    end

    topic = Topic.new(wibble: "123-4567")
    topic.wibble.gsub!("-", "")

    assert topic.valid?
  ensure
    Topic.reset_column_information
  end

@kamipo
Copy link
Member

kamipo commented Aug 11, 2016

How about it?

  def test_numericality_validation_with_mutation
    klass = Class.new(Topic) do
      attribute :wibble, :string
      validates_numericality_of :wibble, only_integer: true
    end

    topic = klass.new(wibble: "123-4567")
    topic.wibble.gsub!("-", "")

    assert topic.valid?
  end

@yahonda
Copy link
Member Author

yahonda commented Aug 11, 2016

(Sorry pointing another guy since I did not confirm autocomplete)
@kamipo Thanks. It works like a charm.

If I understand correctly (correct me if I'm wrong and if you have some time) test_numericality_validation_with_mutation is creating another new class named Topic instead of changing current Topic class using class_eval then Topic should not affect each other.

Let me open a pull request. Thanks again.

yahonda added a commit to yahonda/rails that referenced this issue Aug 11, 2016
since it affects another test `ReflectionTest#test_read_attribute_names`

Address rails#26099
@yahonda
Copy link
Member Author

yahonda commented Aug 11, 2016

Opened #26124

@yahonda
Copy link
Member Author

yahonda commented Aug 11, 2016

Closed as #26124 has been merged to master.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants