Permalink
Browse files

No longer blowing away groups and classes when updating node

Fixes bug in reports:import that empties groups and classes when importing a node's report
  • Loading branch information...
1 parent 0667504 commit da48338cc8fe0fa4d016c8ff85379741b8d0a93f @reinh reinh committed Mar 12, 2010
Showing with 17 additions and 0 deletions.
  1. +2 −0 app/models/node.rb
  2. +15 −0 spec/models/node_spec.rb
View
@@ -102,12 +102,14 @@ def status_class
attr_accessor :node_class_names
after_save :assign_node_classes
def assign_node_classes
+ return unless @node_group_names
self.node_classes = (@node_class_names || []).map{|name| NodeClass.find_by_name(name)}
end
attr_accessor :node_group_names
after_save :assign_node_groups
def assign_node_groups
+ return unless @node_group_names
self.node_groups = (@node_group_names || []).map{|name| NodeGroup.find_by_name(name)}
end
end
@@ -190,4 +190,19 @@
end
end
+ describe "assigning nodes and groups" do
+ it "should not remove classes if node_class_names is unspecified" do
+ @node = Node.generate!
+ @node.node_classes << NodeClass.generate!
+ lambda {@node.update_attribute(:name, 'new_name')}.should_not change{@node.node_classes.size}
+ end
+
+ it "should not remove groups if node_group_names is unspecified" do
+ @node = Node.generate!
+ @node.node_groups << NodeGroup.generate!
+ lambda {@node.update_attribute(:name, 'new_name')}.should_not change{@node.node_groups.size}
+ end
+
+ end
+
end

0 comments on commit da48338

Please sign in to comment.