test/slim_attributes_test.rb in ghazel-slim-attributes-0.6.3.1 vs test/slim_attributes_test.rb in ghazel-slim-attributes-0.7.6.1
- old
+ new
@@ -2,11 +2,11 @@
# http://pennysmalls.com
require 'rubygems'
require 'active_record'
require 'active_record/version'
-require 'slim_attributes'
+require File.dirname(__FILE__) + '/../lib/slim_attributes'
require 'test/unit'
require File.dirname(__FILE__) + "/products"
require File.dirname(__FILE__) + "/slim_db_test_utils"
class SlimAttributesTest < Test::Unit::TestCase
@@ -14,10 +14,15 @@
SlimDbTestUtils.connect_and_create_db
Product.create_product_table
Product.make_some_products
end
+ def test_slim_attributes_is_proxying_results
+ x = Product.find(:first)
+ assert_equal Mysql::Result::RowHash, x.instance_variable_get(:@attributes).class
+ end
+
def test_finds_all
items = Product.find(:all)
assert items.size == 100, "must find all 100 items"
end
@@ -136,22 +141,25 @@
assert_equal "product_0", item2.name, "name must be original from cached query"
item3 = Product.find_by_id(1)
item1.name = "bar"
assert_equal "product_0", item3.name, "name must be original from cached query"
item2.name << "_test"
-# unmodified rails fails this test - but does it matter either way?
+# unmodified rails fails this test because the attributes are not dupped, only the
+# hash containing them is
+# but this test is useful - it shows that the rowhash has not been made
+# into a real hash before dup in called in the query cache code
check_attributes_for(item3, 0)
end
end
def test_accessing_destroyed_object_attributes
item1 = Product.find_by_id(1)
assert_equal false, item1.frozen?
item1.destroy # object is frozen
assert_equal true, item1.frozen?
check_attributes_for(item1, 0)
- assert_raises(TypeError) {item1.name = "another product"}
+ assert_raises(RUBY_VERSION >= "1.9" ? RuntimeError : TypeError) {item1.name = "another product"}
end
def teardown
SlimDbTestUtils.remove_db
end
@@ -161,9 +169,9 @@
def check_attributes_for(item, i)
assert_equal "product_#{i}", item.name, "item name must be right"
assert_equal i, item.number, "item number must be right"
assert_equal i + 1, item.id, "item id must be right"
assert_equal "Made by the test suite", item.comment, "item comment must be right"
- assert ((1.minute.ago)..(Time.now)) === item.created_at, "item created_at must be reasonable"
+ assert item.created_at <= Time.now && item.created_at > Time.now - 30, "item created_at must be reasonable"
assert_nil item.nil_test, "nil_test must be nil"
end
end