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
end
return link
end
def add_config_to_app(appname, config_hash)
begin
config = Noah::Configuration.find_or_create(config_hash)
......
......@@ -8,8 +8,8 @@ module Noah
def delete
self.members.each_value do |member_array|
member_array.each do |member|
member.tags.key.srem "#{self.id}"
member_array.each do |mem|
delete_member(mem)
end
end
super
......@@ -40,11 +40,18 @@ module Noah
def delete_member(node)
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}")
node.untag!(self.name) unless node.tags.member?(self) == false
node.untag!(self.name) if node.tags.include?(self)
self.save
end
self.save
end
def to_hash
......
......@@ -24,18 +24,10 @@ module Noah::Taggable
case tag_name.class.to_s
when "Array"
tag_name.each do |t|
my_tag = ::Noah::Tag.find(:name => t).first
if self.tags.member?(my_tag)
self.tags.key.srem "#{my_tag.id}"
my_tag.delete_member(self)
end
remove_tag(t)
end
else
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
remove_tag(tag_name)
end
self.save
end
......@@ -45,4 +37,13 @@ module Noah::Taggable
self.tags.sort.each {|t| tag_arr << t.name} if self.tags.size != 0
super.merge(:tags => tag_arr)
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
......@@ -60,6 +60,31 @@ describe "Using the Tag Model", :reset_redis => true do
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
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