<commit_before>require File.join(File.dirname(__FILE__), *%w[.. .. .. spec_helper])
require File.join(File.dirname(__FILE__), *%w[.. .. .. fixtures pubsub])

describe 'Blather::Stanza::PubSub::Affiliations' do
  it 'registers itself' do
    XMPPNode.class_from_registration(:pubsub_affiliations, 'http://jabber.org/protocol/pubsub').must_equal Stanza::PubSub::Affiliations
  end

  it 'ensures an affiliations node is present on create' do
    affiliations = Stanza::PubSub::Affiliations.new
    affiliations.pubsub.children.detect { |n| n.element_name == 'affiliations' }.wont_be_nil
  end

  it 'ensures an affiliations node exists when calling #affiliations' do
    affiliations = Stanza::PubSub::Affiliations.new
    affiliations.pubsub.remove_child :affiliations
    affiliations.pubsub.children.detect { |n| n.element_name == 'affiliations' }.must_be_nil

    affiliations.affiliations.wont_be_nil
    affiliations.pubsub.children.detect { |n| n.element_name == 'affiliations' }.wont_be_nil    
  end

  it 'defaults to a get node' do
    aff = Stanza::PubSub::Affiliations.new
    aff.type.must_equal :get
  end

  it 'sets the host if requested' do
    aff = Stanza::PubSub::Affiliations.new :get, 'pubsub.jabber.local'
    aff.to.must_equal JID.new('pubsub.jabber.local')
  end

  it 'can import an affiliates result node' do
    node = XML::Document.string(affiliations_xml).root

    affiliations = Stanza::PubSub::Affiliations.new.inherit node
    affiliations.size.must_equal 5
    affiliations.list.must_equal({
      :owner => ['node1', 'node2'],
      :publisher => ['node3'],
      :outcast => ['node4'],
      :member => ['node5'],
      :none => ['node6']
    })
  end
end<commit_msg>fully spec out the affiliations node<commit_after>require File.join(File.dirname(__FILE__), *%w[.. .. .. spec_helper])
require File.join(File.dirname(__FILE__), *%w[.. .. .. fixtures pubsub])

def control_affiliations
  { :owner => ['node1', 'node2'],
    :publisher => ['node3'],
    :outcast => ['node4'],
    :member => ['node5'],
    :none => ['node6'] }
end

describe 'Blather::Stanza::PubSub::Affiliations' do
  it 'registers itself' do
    XMPPNode.class_from_registration(:pubsub_affiliations, 'http://jabber.org/protocol/pubsub').must_equal Stanza::PubSub::Affiliations
  end

  it 'ensures an affiliations node is present on create' do
    affiliations = Stanza::PubSub::Affiliations.new
    affiliations.pubsub.children.detect { |n| n.element_name == 'affiliations' }.wont_be_nil
  end

  it 'ensures an affiliations node exists when calling #affiliations' do
    affiliations = Stanza::PubSub::Affiliations.new
    affiliations.pubsub.remove_child :affiliations
    affiliations.pubsub.children.detect { |n| n.element_name == 'affiliations' }.must_be_nil

    affiliations.affiliations.wont_be_nil
    affiliations.pubsub.children.detect { |n| n.element_name == 'affiliations' }.wont_be_nil    
  end

  it 'defaults to a get node' do
    aff = Stanza::PubSub::Affiliations.new
    aff.type.must_equal :get
  end

  it 'sets the host if requested' do
    aff = Stanza::PubSub::Affiliations.new :get, 'pubsub.jabber.local'
    aff.to.must_equal JID.new('pubsub.jabber.local')
  end

  it 'can import an affiliates result node' do
    node = XML::Document.string(affiliations_xml).root

    affiliations = Stanza::PubSub::Affiliations.new.inherit node
    affiliations.size.must_equal 5
    affiliations.list.must_equal(control_affiliations)
  end

  it 'will iterate over each affiliation' do
    node = XML::Document.string(affiliations_xml).root
    affiliations = Stanza::PubSub::Affiliations.new.inherit node
    affiliations.each do |type, nodes|
      nodes.must_equal control_affiliations[type]
    end
  end

  it 'can be accessed via "[]"' do
    node = XML::Document.string(affiliations_xml).root
    affiliations = Stanza::PubSub::Affiliations.new.inherit node
    [:owner, :publisher, :outcast, :member, :none].each do |type|
      affiliations[type].must_equal control_affiliations[type]
    end
  end
end
{'fraction_non_alphanumeric': 0.12748015873015872, 'fraction_numerical': 0.003472222222222222, 'mean_word_length': 4.157289002557545, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1554287', 'n_tokens_mistral': 1366, 'n_tokens_neox': 1350, 'n_words': 287}