forked from negativecode/vines
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'upstream/master' into core
Conflicts: README.md test/storage/couchdb_test.rb test/storage/ldap_test.rb test/storage/mongodb_test.rb test/storage/redis_test.rb test/storage/sql_test.rb vines.gemspec
- Loading branch information
Showing
46 changed files
with
1,518 additions
and
1,444 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,88 +1,102 @@ | ||
# encoding: UTF-8 | ||
|
||
require 'vines' | ||
require 'ext/nokogiri' | ||
require 'minitest/autorun' | ||
|
||
class ContactTest < MiniTest::Unit::TestCase | ||
def test_equality | ||
alice = Vines::Contact.new(:jid => 'alice@wonderland.lit') | ||
alice2 = Vines::Contact.new(:jid => 'alice@wonderland.lit') | ||
hatter = Vines::Contact.new(:jid => 'hatter@wonderland.lit') | ||
|
||
assert_nil alice <=> 42 | ||
|
||
assert alice == alice2 | ||
assert alice.eql?(alice2) | ||
assert alice.hash == alice2.hash | ||
|
||
refute alice == hatter | ||
refute alice.eql?(hatter) | ||
refute alice.hash == hatter.hash | ||
require 'test_helper' | ||
|
||
describe Vines::Contact do | ||
subject do | ||
Vines::Contact.new( | ||
jid: 'alice@wonderland.lit', | ||
name: "Alice", | ||
groups: %w[Friends Buddies], | ||
subscription: 'from') | ||
end | ||
|
||
def test_initialize_missing_jid_raises | ||
assert_raises(ArgumentError) { Vines::Contact.new } | ||
assert_raises(ArgumentError) { Vines::Contact.new(:jid => '') } | ||
end | ||
describe 'contact equality checks' do | ||
let(:alice) { Vines::Contact.new(jid: 'alice@wonderland.lit') } | ||
let(:hatter) { Vines::Contact.new(jid: 'hatter@wonderland.lit') } | ||
|
||
def test_initialize_domain_only_jid_does_not_raise | ||
contact = Vines::Contact.new(:jid => 'tea.wonderland.lit') | ||
assert_equal 'tea.wonderland.lit', contact.jid.to_s | ||
end | ||
it 'uses class in equality check' do | ||
(subject <=> 42).must_be_nil | ||
end | ||
|
||
def test_to_roster_xml_sorts_groups | ||
contact = Vines::Contact.new( | ||
:jid => 'a@wonderland.lit', | ||
:name => "Contact 1", | ||
:groups => %w[B A]) | ||
it 'is equal to itself' do | ||
assert subject == subject | ||
assert subject.eql?(subject) | ||
assert subject.hash == subject.hash | ||
end | ||
|
||
expected = %q{ | ||
<item jid="a@wonderland.lit" name="Contact 1" subscription="none"> | ||
<group>A</group> | ||
<group>B</group> | ||
</item> | ||
}.strip.gsub(/\n/, '').gsub(/\s{2,}/, '') | ||
it 'is equal to another contact with the same jid' do | ||
assert subject == alice | ||
assert subject.eql?(alice) | ||
assert subject.hash == alice.hash | ||
end | ||
|
||
assert_equal expected, contact.to_roster_xml.to_xml(:indent => 0).gsub(/\n/, '') | ||
it 'is not equal to a different jid' do | ||
refute subject == hatter | ||
refute subject.eql?(hatter) | ||
refute subject.hash == hatter.hash | ||
end | ||
end | ||
|
||
def test_send_roster_push | ||
contact = Vines::Contact.new( | ||
:jid => 'alice@wonderland.lit', | ||
:name => "Alice", | ||
:groups => %w[Friends Buddies], | ||
:subscription => 'from') | ||
|
||
recipient = MiniTest::Mock.new | ||
recipient.expect(:user, Vines::User.new(:jid => 'hatter@wonderland.lit')) | ||
def recipient.nodes; @nodes; end | ||
def recipient.write(node) | ||
@nodes ||= [] | ||
@nodes << node | ||
describe 'initialize' do | ||
it 'raises when not given a jid' do | ||
-> { Vines::Contact.new }.must_raise ArgumentError | ||
-> { Vines::Contact.new(jid: '') }.must_raise ArgumentError | ||
end | ||
|
||
contact.send_roster_push(recipient) | ||
assert recipient.verify | ||
assert_equal 1, recipient.nodes.size | ||
it 'accepts a domain-only jid' do | ||
contact = Vines::Contact.new(jid: 'tea.wonderland.lit') | ||
contact.jid.to_s.must_equal 'tea.wonderland.lit' | ||
end | ||
end | ||
|
||
expected = node(%q{ | ||
<iq to="hatter@wonderland.lit" type="set"> | ||
<query xmlns="jabber:iq:roster"> | ||
describe '#to_roster_xml' do | ||
let(:expected) do | ||
node(%q{ | ||
<item jid="alice@wonderland.lit" name="Alice" subscription="from"> | ||
<group>Buddies</group> | ||
<group>Friends</group> | ||
</item> | ||
</query> | ||
</iq> | ||
}.strip.gsub(/\n/, '').gsub(/\s{2,}/, '')) | ||
recipient.nodes[0].remove_attribute('id') # id is random | ||
assert_equal expected, recipient.nodes[0] | ||
}) | ||
end | ||
|
||
it 'sorts group names' do | ||
subject.to_roster_xml.must_equal expected | ||
end | ||
end | ||
|
||
private | ||
describe '#send_roster_push' do | ||
let(:recipient) { MiniTest::Mock.new } | ||
let(:expected) do | ||
node(%q{ | ||
<iq to="hatter@wonderland.lit" type="set"> | ||
<query xmlns="jabber:iq:roster"> | ||
<item jid="alice@wonderland.lit" name="Alice" subscription="from"> | ||
<group>Buddies</group> | ||
<group>Friends</group> | ||
</item> | ||
</query> | ||
</iq> | ||
}) | ||
end | ||
|
||
def node(xml) | ||
Nokogiri::XML(xml).root | ||
before do | ||
recipient.expect :user, Vines::User.new(jid: 'hatter@wonderland.lit') | ||
class << recipient | ||
attr_accessor :nodes | ||
def write(node) | ||
@nodes ||= [] | ||
@nodes << node | ||
end | ||
end | ||
end | ||
|
||
it '' do | ||
subject.send_roster_push(recipient) | ||
recipient.verify | ||
recipient.nodes.size.must_equal 1 | ||
recipient.nodes.first.remove_attribute('id') # id is random | ||
recipient.nodes.first.must_equal expected | ||
end | ||
end | ||
end |
Oops, something went wrong.