Permalink
Browse files

Merge branch 'master' into rbtree

  • Loading branch information...
2 parents cb4bf3a + ab46c62 commit d751d26fa52a6ebb18effb2f26874767b4e0d432 @kouno committed Sep 9, 2012
@@ -230,7 +230,10 @@ def assert_instance(constellation, args) #:nodoc:
instances = constellation.instances[self] # All instances of this class in this constellation
instance = instances[key]
# REVISIT: This ignores any additional attribute assignments
- return instance, key if instance # A matching instance of this class
+ if instance
+ raise "Additional role values are ignored when asserting an existing instance" if args[-1].is_a? Hash and !args[-1].empty?
+ return instance, key # A matching instance of this class
+ end
# Now construct each of this object's identifying roles
irns = identifying_role_names
@@ -134,15 +134,25 @@ class Mod::Bar; end
name2 = @constellation.Name("foo")
foo2 = @constellation.LegalEntity("foo")
- acme2 = @constellation.Company("Acme, Inc", :auto_counter_val => :new)
- fred_fly2 = @constellation.Person("fred", "fly", :auto_counter_val => :new)
+ acme2 = @constellation.Company("Acme, Inc") # , :auto_counter_val => :new)
+ fred_fly2 = @constellation.Person("fred", "fly") # , :auto_counter_val => :new)
name1.object_id.should == name2.object_id
foo1.object_id.should == foo2.object_id
acme1.object_id.should == acme2.object_id
fred_fly1.object_id.should == fred_fly2.object_id
end
+ it "should reject re-assertion with additional assignments" do
+ name1 = @constellation.Name("foo")
+ foo1 = @constellation.LegalEntity("foo")
+ acme1 = @constellation.Company("Acme, Inc", :auto_counter_val => :new)
+
+ name2 = @constellation.Name("foo")
+ foo2 = @constellation.LegalEntity("foo")
+ lambda { @constellation.Company("Acme, Inc", :auto_counter_val => :new) }.should raise_error
+ end
+
it "should support methods to assert instances via the class for that type" do
name = foo = acme = fred_fly = nil
lambda {
@@ -0,0 +1,77 @@
+require 'activefacts/api'
+
+module TestMultiPartIdentifierModule
+ class ParentId < AutoCounter
+ value_type
+ end
+
+ class Parent
+ identified_by :parent_id
+ one_to_one :parent_id
+ end
+
+ class Position < Int
+ value_type
+ end
+
+ class Child
+ identified_by :parent, :position
+ has_one :parent
+ has_one :position
+ end
+end
+
+describe "Multi-part identifiers" do
+ include ActiveFacts::API
+ before :each do
+ @c = Constellation.new(TestMultiPartIdentifierModule)
+ @p = @c.Parent(:new)
+ @c0 = @c.Child(@p, 0)
+ @c2 = @c.Child(@p, 2)
+ @c1 = @c.Child(@p, 1)
+ end
+
+ it "should allow children to be found in the instance index" do
+ @c.Child[[@p, 0]].should == @c0
+ @c.Child[[@p, 1]].should == @c1
+ @c.Child[[@p, 2]].should == @c2
+ end
+
+ it "should sort child keys in the instance index" do
+ pending "Key sorting is not supported in this version" unless @p.all_child.respond_to? :keys
+ @c.Child.keys.should == [[[@p.parent_id], 0], [[@p.parent_id], 1], [[@p.parent_id], 2]]
+ @c.Child.map{|k, c| c.position}.should == [@c0.position, @c1.position, @c2.position]
+ end
+
+ it "should index children in the parent's RoleValues" do
+ @p.all_child.size.should == 3
+ end
+
+ it "should allow children to be found in the instance index by the residual key" do
+ pending "RoleValues use the whole key, not the residual key" do
+ @c.Child[[0]].should == @c0
+ @c.Child[[1]].should == @c1
+ @c.Child[[2]].should == @c2
+ end
+ end
+
+ it "should allow children to be found in the instance index by the whole key" do
+ @c.Child[[[@p.parent_id], 0]].should == @c0
+ @c.Child[[[@p.parent_id], 1]].should == @c1
+ @c.Child[[[@p.parent_id], 2]].should == @c2
+ end
+
+ it "should sort children in the parent's RoleValues" do
+ pending "Key sorting is not supported in this version" if @p.all_child.instance_variable_get("@a").kind_of? Array
+ @p.all_child.to_a[0].should == @c0
+ @p.all_child.to_a[1].should == @c1
+ @p.all_child.to_a[2].should == @c2
+ end
+
+ it "should have a correct key for each child in the parent's RoleValues" do
+ pending "Key sorting is not supported in this version" if @p.all_child.instance_variable_get("@a").kind_of? Array
+ @p.all_child.keys[0].should == [[@p.parent_id], 0]
+ @p.all_child.keys[1].should == [[@p.parent_id], 1]
+ @p.all_child.keys[2].should == [[@p.parent_id], 2]
+ end
+end
@@ -54,8 +54,8 @@
bd = Decimal.new("98765432109876543.210")
bd.to_s("F").should == "98765432109876543.21"
bd.to_s("E").should == "0.9876543210987654321E17"
- bd.to_s("3E").should == "0.987 654 321 098 765 432 1E17"
- bd.to_s(3).should == "0.987 654 321 098 765 432 1E17"
+ bd.to_s("3E").should =~ /0.987 654 321 098 765 432 1.*E17/
+ bd.to_s(3).should =~ /0.987 654 321 098 765 432 1.*E17/
bd.to_s("3F").should == "987 654 321 098 765 43.21"
bd.should be_a Decimal
bd.should be_a BigDecimal

0 comments on commit d751d26

Please sign in to comment.