Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions README.rdoc
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 5 additions & 1 deletion lib/dag/standard.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -59,4 +63,4 @@ module NonPolyEdgeInstanceMethods
end

end
end
end
3 changes: 1 addition & 2 deletions lib/dag/validators.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -55,4 +54,4 @@ def direct_indirect(record)
end
end

end
end
32 changes: 19 additions & 13 deletions test/dag_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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!
Expand Down Expand Up @@ -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
Expand Down