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

Once again: Bug for check attribute #22434

Closed
Sega100500 opened this issue Nov 28, 2015 · 7 comments
Closed

Once again: Bug for check attribute #22434

Sega100500 opened this issue Nov 28, 2015 · 7 comments

Comments

@Sega100500
Copy link

Firstly, please excuse me for #22424
But it really bug

I followed your recommendations:

  1. http://edgeguides.rubyonrails.org/contributing_to_ruby_on_rails.html#create-an-executable-test-case
  2. https://github.com/rails/rails/blob/master/guides/bug_report_templates/active_record_gem.rb

This is my test for you:

begin
  require 'bundler/inline'
rescue LoadError => e
  $stderr.puts 'Bundler version 1.10 or later is required. Please update your Bundler'
  raise e
end

gemfile(true) do
  source 'https://rubygems.org'
  # Activate the gem you are reporting the issue against.
  gem 'activerecord', '~> 4.2.0'
  gem 'sqlite3'
end

require 'active_record'
require 'minitest/autorun'
require 'logger'

# Ensure backward compatibility with Minitest 4
Minitest::Test = MiniTest::Unit::TestCase unless defined?(Minitest::Test)

# This connection will do for database-independent bug reports.
ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: ':memory:')
ActiveRecord::Base.logger = Logger.new(STDOUT)

ActiveRecord::Schema.define do
  create_table :products, force: true do |t|
    t.integer :content_id
    t.decimal :price, precision: 14, scale: 2
  end

  create_table :contents, force: true do |t|
  end
end

class Content < ActiveRecord::Base
  has_one :product
end

class Product < ActiveRecord::Base
  belongs_to :content
end

class BugTest < Minitest::Test
  def test_association_stuff

    content = Content.create!
    product = Product.create!

    content.product = product

    assert_equal 1, content.id
    assert_equal 1, product.id
    assert_equal content.id, Product.first.content_id

    # for nil price
    assert_equal false, product.price?

    # for zero price
    product.price = 0
    assert_equal false, product.price?

    # test for price
    product.price = 0.9
    assert_equal 0.9, product.price
    assert_equal true, product.price?

    # save for latest verify
    product.save!

    # another product - not joined
    product2 = Product.create!
    product2.price = 0

    assert_equal 0, product2.price
    assert_equal false, product2.price?

    # get content with related product
    content_with_product = Content.select('contents.*, products.*, contents.id AS c_id, products.id AS product_id')
                                  .joins('INNER JOIN products ON products.content_id = contents.id')
                                  .where('contents.id = ?', content.id)
                                  .first

    assert_equal content.id, content_with_product.c_id
    assert_equal content.product.id, content_with_product.product_id

    # has a value
    assert_equal 0.9, content_with_product.price

    # !!! BUG
    assert_equal true, content_with_product.price?

    # But that - OK
    content_with_product.price = 1.0
    assert_equal 1.0, content_with_product.price
    assert_equal true, content_with_product.price?

  end
end

Many THANKS for consideration

@Sega100500
Copy link
Author

If we change:

    # test for price
    product.price = 1.0
    assert_equal 1.0, product.price
    assert_equal true, product.price?

then bug not appear by latest verify

    # has a value
    assert_equal 1.0, content_with_product.price

    # !!! BUG - already NOT
    assert_equal true, content_with_product.price?

This bug - wrong verify value of Float values

@Sega100500
Copy link
Author

@rafaelfranca
Of course, you can continue to ignore the issues found me. Motivating those that:
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND

But I try find and report issues.
Because I want ROR to be a better, more reliable and convenient for ALL - The BEST framework!

SORRY again. And THANKS!

@Sega100500
Copy link
Author

@adityashedge
Use this my test instead of that you have written:

adityashedge/test-2.2.3-22424@92bd9e6

https://github.com/adityashedge/test-2.2.3-22424

@simi
Copy link
Contributor

simi commented Nov 28, 2015

I tracked down this already in #22429 probably.

@Sega100500
Copy link
Author

@simi
Issue #22424 was be locked before I was able to place a test there.
Your test point to the same bug, it is right.

@adityashedge
Copy link

@Sega100500 ignore the repo. I couldn't find the template and wasn't able to reproduce the issue. Well now that we have narrowed it down to #22429 we can use this.
@anujaware has already sent a pull request.

This issue can be closed. Duplicate #22429

@Sega100500
Copy link
Author

@adityashedge
MANY THANKS! Really!
I was point to that string in code several times in #22424
But my messages was ignored.

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

No branches or pull requests

3 participants