Merge pull request #178 from jjnevis/add-delete-tag-feature

Add delete tag feature
This commit is contained in:
Todd Werth
2015-02-01 10:50:38 -08:00
3 changed files with 34 additions and 2 deletions

View File

@@ -32,6 +32,16 @@ module RubyMotionQuery
end
end
# *Do not* use this, use {RMQ#untag} instead:
# @example
# rmq(my_view).untag(:foo, :bar)
# Do nothing if no tag supplied or tag not present
def untag(*tag_or_tags)
tag_or_tags.flatten.each do |tag_name|
tags.delete tag_name
end
end
# Check if this view contains a specific tag
#
# @param tag_name name of tag to check

View File

@@ -20,6 +20,13 @@ module RubyMotionQuery
self
end
def untag(*tag_or_tags)
selected.each do |view|
view.rmq_data.untag(tag_or_tags)
end
self
end
# @return [RMQ]
def clear_tags
selected.each do |view|

View File

@@ -4,19 +4,34 @@ describe 'tags' do
@root_view = @vc.view
end
it 'should tag a view with a single tag' do
it 'should tag and untag a view with a single tag' do
@vc.rmq.append(UIView).tap do |q|
q.tag(:foo)
q.get.rmq_data.tags.should.include :foo
q.get.rmq_data.tags.should.not.include :bar
q.untag(:foo)
q.get.rmq_data.tags.should.not.include :foo
end
end
it 'should tag a view with a multiple tags' do
it 'should tag and untag a view with a multiple tags' do
@vc.rmq.append(UIView).tap do |q|
q.tag(:foo, :bar)
q.get.rmq_data.tags.should.include :foo
q.get.rmq_data.tags.should.include :bar
q.untag(:foo, :bar)
q.get.rmq_data.tags.should.not.include :foo
q.get.rmq_data.tags.should.not.include :bar
end
end
it 'should only untag if tag exists' do
@vc.rmq.append(UIView).tap do |q|
q.tag(:foo)
q.untag(:bar)
q.untag(:bar, :baz)
q.untag
q.get.rmq_data.tag_names.should == [:foo]
end
end