diaspora/diaspora

Appending to a post's tags in tests

hasandiwan opened this issue · 1 comments

I'm attempting to add openpgp-signed StatusUpdates to diaspora, if there's a 'signed' tag:

`

if @s.tag_list.member?('signed') then
pgp_sign @s
end
@s.save!
`

It's quite straightforward to code, but I'd now like to verify this functionality works. What I have so far is:

`

@s.tag_list = ActsAsTaggableOn::TagList.new(:signed)
@s.tag_list
@s.tag_list
=> ["signed"]
@s.save!
@s.reload
@s.tag_list
=> []
`

Huh?

jhass commented

The forum might be a little bit better avenue for such talk than the issue tracker :)

StatusMessage includes Diaspora::Taggable

include Diaspora::Taggable

Which defines a before validation hook

before_validation :build_tags # build tags before validation fixs the too long tag name issue #5737

that sets the tag list from what's parsed from the message body

def build_tags
self.tag_list = tag_strings
end
def tag_strings
MessageRenderer::Processor.normalize(send(self.class.field_with_tags) || "")
.scan(/(?:^|\s)#([#{ActsAsTaggableOn::Tag.tag_text_regexp}]+|<3)/u)
.map(&:first)
.uniq(&:downcase)
end

In other words a message's tags are not meant to be a generic metadata attachment system, they're purely there to support the hashtagging feature.