Skip to content

Instantly share code, notes, and snippets.

@simi
Last active November 27, 2015 19:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save simi/e47d0257dde5fc242577 to your computer and use it in GitHub Desktop.
Save simi/e47d0257dde5fc242577 to your computer and use it in GitHub Desktop.
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'
gem 'rails', '4.2.5'
gem 'sqlite3'
end
require 'active_record'
require 'minitest/autorun'
require 'logger'
ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: ':memory:')
ActiveRecord::Base.logger = Logger.new(STDOUT)
ActiveRecord::Schema.define do
create_table :products do |t|
t.decimal :price, precision: 12, scale: 2
t.references :content
end
create_table :contents do |t|
end
end
class Product < ActiveRecord::Base
belongs_to :content
end
class Content < ActiveRecord::Base
has_one :product
end
class BugTest < Minitest::Test
def setup
Content.delete_all; Product.delete_all;
end
def test_negative_price
Content.create(product: Product.create(price: -0.9))
joined_product = Content.joins(:product).select('products.*').first
product = Product.first
assert_equal product.price?, joined_product.price?
end
def test_positive_price
Content.create(product: Product.create(price: 0.9))
joined_product = Content.joins(:product).select('products.*').first
product = Product.first
assert_equal product.price?, joined_product.price?
end
def test_nil_price
Content.create(product: Product.create)
joined_product = Content.joins(:product).select('products.*').first
product = Product.first
assert_equal product.price?, joined_product.price?
end
def test_zero_price
Content.create(product: Product.create(price: 0))
joined_product = Content.joins(:product).select('products.*').first
product = Product.first
assert_equal product.price?, joined_product.price?
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment