Commit 349e759b authored by John E. Vincent's avatar John E. Vincent

untag fully working via Ruby API

parent b3fc82de
...@@ -91,6 +91,7 @@ module Noah ...@@ -91,6 +91,7 @@ module Noah
end end
return link return link
end end
def add_config_to_app(appname, config_hash) def add_config_to_app(appname, config_hash)
begin begin
config = Noah::Configuration.find_or_create(config_hash) config = Noah::Configuration.find_or_create(config_hash)
......
...@@ -8,8 +8,8 @@ module Noah ...@@ -8,8 +8,8 @@ module Noah
def delete def delete
self.members.each_value do |member_array| self.members.each_value do |member_array|
member_array.each do |member| member_array.each do |mem|
member.tags.key.srem "#{self.id}" delete_member(mem)
end end
end end
super super
...@@ -40,11 +40,18 @@ module Noah ...@@ -40,11 +40,18 @@ module Noah
def delete_member(node) def delete_member(node)
nc = class_to_lower(node.class.to_s)+"s" nc = class_to_lower(node.class.to_s)+"s"
if self.members[nc.to_sym].member?(node) # Need to refactor. Essentially there are conditions we need to check for before trying to delete a member
# Are there any members at all?
# Are there any members of a given class?
# Not pretty but it works for now
if self.members.size == 0 || self.members.has_key?(nc.to_sym) == false
# no match so save and be done with it
self.save
elsif self.members[nc.to_sym].include?(node)
Ohm.redis.srem("#{self.key}:members", "#{node.key}") Ohm.redis.srem("#{self.key}:members", "#{node.key}")
node.untag!(self.name) unless node.tags.member?(self) == false node.untag!(self.name) if node.tags.include?(self)
self.save
end end
self.save
end end
def to_hash def to_hash
......
...@@ -24,18 +24,10 @@ module Noah::Taggable ...@@ -24,18 +24,10 @@ module Noah::Taggable
case tag_name.class.to_s case tag_name.class.to_s
when "Array" when "Array"
tag_name.each do |t| tag_name.each do |t|
my_tag = ::Noah::Tag.find(:name => t).first remove_tag(t)
if self.tags.member?(my_tag)
self.tags.key.srem "#{my_tag.id}"
my_tag.delete_member(self)
end
end end
else else
my_tag = ::Noah::Tag.find(:name => tag_name).first remove_tag(tag_name)
if self.tags.member?(my_tag)
self.tags.key.srem "#{my_tag.id}"
my_tag.delete_member(self)
end
end end
self.save self.save
end end
...@@ -45,4 +37,13 @@ module Noah::Taggable ...@@ -45,4 +37,13 @@ module Noah::Taggable
self.tags.sort.each {|t| tag_arr << t.name} if self.tags.size != 0 self.tags.sort.each {|t| tag_arr << t.name} if self.tags.size != 0
super.merge(:tags => tag_arr) super.merge(:tags => tag_arr)
end end
protected
def remove_tag(tag_name)
my_tag = ::Noah::Tag.find(:name => tag_name).first
if self.tags.member?(my_tag)
self.tags.key.srem "#{my_tag.id}"
my_tag.delete_member(self)
end
end
end end
...@@ -60,6 +60,31 @@ describe "Using the Tag Model", :reset_redis => true do ...@@ -60,6 +60,31 @@ describe "Using the Tag Model", :reset_redis => true do
end end
end end
end end
it "should untag! a single tag from an object" do
@application.tag! "foobarspec"
t = Noah::Tag.find(:name => 'foobarspec').first
t.nil?.should == false
@application.tags.size.should == 1
@application.tags.include?(t).should == true
t.members.size.should == 1
t.members[:applications].include?(@application).should == true
@application.untag! "foobarspec"
@application.tags.size.should == 0
t.members.size.should == 0
end
it "should untag! an array of tags from an object" do
tagz = %w{foo bar baz bang}
@application.tag! tagz
@application.tags.size.should == tagz.size
@application.untag! tagz
@application.tags.size.should == 0
tagz.each do |tag|
t = Noah::Tag.find(:name => tag).first
t.nil?.should == false
Noah::Tag.all.size.should == tagz.size
t.members.has_key?(:applications).should == false
end
end
end end
describe "should not" do describe "should not" do
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment