diff --git a/README.rdoc b/README.rdoc index 76876a6..8afa053 100644 --- a/README.rdoc +++ b/README.rdoc @@ -137,16 +137,12 @@ Several class methods get added to the link model to make it easier to find and #Finds a link or returns nil self.find_link(ancestor,descendant) - #Returns true if a link exists - self.connected?(ancestor,descendant) #Creates an edge between an ancestor and descendant self.create_edge(ancestor,descendant) - self.connect(ancestor,descendant) #Creates an edge using save! between an ancestor and descendant self.create_edge!(ancestor,descendant) - self.connect!(ancestor,descendant) #Builds an edge between an ancestor and descendant, returning an unsaved edge self.build_edge(ancestor,descendant) diff --git a/lib/dag/standard.rb b/lib/dag/standard.rb index 259f5b8..42509c0 100644 --- a/lib/dag/standard.rb +++ b/lib/dag/standard.rb @@ -12,6 +12,10 @@ def matches?(other) self.id == other.id end + def nil? + self.id.nil? + end + #Factory Construction method that creates an endpoint from a model def self.from_resource(resource) self.new(resource.id) @@ -59,4 +63,4 @@ module NonPolyEdgeInstanceMethods end end -end \ No newline at end of file +end diff --git a/lib/dag/validators.rb b/lib/dag/validators.rb index 2b55b4e..604a32b 100644 --- a/lib/dag/validators.rb +++ b/lib/dag/validators.rb @@ -39,7 +39,6 @@ def check_possible(record) class UpdateCorrectnessValidator < ActiveModel::Validator def validate(record) - record.errors[:base] << "No changes" unless record.changed? record.errors[:base] << "Do not manually change the count value" if manual_change(record) record.errors[:base] << "Cannot make a direct link with count 1 indirect" if direct_indirect(record) end @@ -55,4 +54,4 @@ def direct_indirect(record) end end -end \ No newline at end of file +end diff --git a/test/dag_test.rb b/test/dag_test.rb index 14038a5..9a22677 100644 --- a/test/dag_test.rb +++ b/test/dag_test.rb @@ -122,7 +122,7 @@ def setup #Brings down database def teardown - ActiveRecord::Base.connection.tables.each do |table| + ActiveRecord::Base.connection.data_sources.each do |table| ActiveRecord::Base.connection.drop_table(table) end end @@ -368,9 +368,9 @@ def test_validation_on_create_duplication_catch a = Node.create! b = Node.create! e = Default.create_edge(a, b) - e2 = Default.create_edge(a, b) + e2 = Default.build_edge(a, b).save assert !e2 - assert_raises(ActiveRecord::RecordInvalid) { e3 = Default.create_edge!(a, b) } + assert_raises(ActiveRecord::RecordInvalid) { e3 = Default.build_edge(a, b).save! } end #Tests that we catch reversed links on creation (cycles) @@ -402,15 +402,6 @@ def test_validation_on_update_indirect_catch assert_raises(ActiveRecord::RecordInvalid) { e.save! } end - #Tests that nochanges fails save and save! - def test_validation_on_update_no_change_catch - a = Node.create! - b = Node.create! - e = Default.create_edge!(a, b) - assert !e.save - assert_raises(ActiveRecord::RecordInvalid) { e.save! } - end - #Tests that destroyable? works as required def tests_destroyable a = Node.create! @@ -608,11 +599,26 @@ def test_has_many_parents assert !e.nil? end - def test_has_many_parents_build_assign + # Tests parent added to a new node + def test_has_many_parents_build_assign_save a = Node.create! b = Node.new b.parents << a assert b.valid?, b.errors.full_messages + assert b.save + end + + # Tests creation of a bridging link between a new node and a grandparent + def test_create_parent_with_grandparent + a = Node.create! + b = Node.create! + b.parents << a + c = Node.new + c.parents << b + assert c.save + e = Default.find_link(a, c) + assert e + assert !e.direct? end #Tests leaf? instance method