Skip to content

Commit

Permalink
Add tests for coverage.
Browse files Browse the repository at this point in the history
  • Loading branch information
kouno committed Aug 16, 2012
1 parent 63f4e43 commit 7150045
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 17 deletions.
12 changes: 7 additions & 5 deletions lib/activefacts/api/entity.rb
Original file line number Diff line number Diff line change
Expand Up @@ -163,12 +163,14 @@ def identifying_roles
end

def find_inherited_role(role_name)
if !superclass.is_entity_type
false
elsif superclass.roles.has_key?(role_name)
superclass.roles[role_name]
if superclass.is_entity_type
if superclass.roles.has_key?(role_name)
superclass.roles[role_name]
else
superclass.find_inherited_role(role_name)
end
else
superclass.find_inherited_role(role_name)
false
end
end

Expand Down
8 changes: 0 additions & 8 deletions lib/activefacts/api/numeric.rb
Original file line number Diff line number Diff line change
Expand Up @@ -177,14 +177,6 @@ def inspect
"\#<AutoCounter "+to_s+">"
end

def hash #:nodoc:
if self.defined?
@value.hash
else
0
end
end

def <=>(other)
to_s <=> other.to_s
end
Expand Down
4 changes: 0 additions & 4 deletions lib/activefacts/api/role.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,6 @@ def unary?
counterpart == nil
end

def is_inherited?(klass)
klass.supertypes_transitive.include?(@object_type)
end

def counterpart_object_type
# This method is sometimes used when unaries are used in an entity's identifier.
@is_unary ? TrueClass : (counterpart ? counterpart.object_type : nil)
Expand Down
6 changes: 6 additions & 0 deletions spec/fact_type/roles_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ class Employee
# print "object_type: "; p Mod.object_type
end

it "should find inherited roles" do
Mod::Person.find_inherited_role(:name).should be_an_instance_of Role # name is defined on LegalEntity
Mod::Person.find_inherited_role(:family).should be_false # family is defined on Person
Mod::Person.find_inherited_role(:non_existing_role).should be_false
end

it "should associate a role name with a matching existing object_type" do
module Mod
class Existing1 < String
Expand Down
15 changes: 15 additions & 0 deletions spec/identification_scheme/identification_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,21 @@ class Cat
@c.Business[['Acme']].should == @bus
@c.Business.size.should == 1
end

describe "when compared to a subtype" do
before :each do
module Mod
class SubBusiness < Business
end
end
@sub_business = @c.Business('Bcme')
end

it "should not be eql?" do
@business.eql?(@sub_business).should be_false
@sub_business.eql?(@business).should be_false
end
end
end

describe "when the value is changed" do
Expand Down

0 comments on commit 7150045

Please sign in to comment.