WpUser specs

This commit is contained in:
erwanlr
2013-03-22 17:57:31 +01:00
parent cb9717f6e7
commit 92414d0c2f
2 changed files with 58 additions and 2 deletions

View File

@@ -3,7 +3,6 @@
require 'wp_user/existable'
class WpUser < WpItem
include WpUser::Existable
attr_accessor :id, :login, :display_name, :password
@@ -23,7 +22,7 @@ class WpUser < WpItem
end
def ==(other)
self === (other)
self === other
end
def ===(other)

View File

@@ -0,0 +1,57 @@
# encoding: UTF-8
require 'spec_helper'
describe WpUser do
subject(:wp_user) { WpUser.new(uri, options) }
let(:uri) { URI.parse('http://example.com') }
let(:options) { {} }
describe '#allowed_options' do
[:id, :login, :display_name, :password].each do |sym|
its(:allowed_options) { should include sym }
end
its(:allowed_options) { should_not include :name }
end
describe '#uri' do
context 'when the id is not set' do
it 'raises an error' do
expect { wp_user.uri }.to raise_error('The id is nil')
end
end
context 'when the id is set' do
it 'returns the uri to the auhor page' do
wp_user.id = 2
wp_user.uri.should == uri.merge('?author=2')
end
end
end
describe '#<=>' do
it 'bases the comparaison on the :id' do
wp_user.id = 1
other = WpUser.new(uri, id: 3)
wp_user.<=>(other).should === 1.<=>(3)
end
end
describe '#===, #==' do
context 'when the :id and :login are the same' do
it 'is ===, and ==' do
WpUser.new(uri, id: 1, name: 'yo').should == WpUser.new(uri, id: 1, name: 'yo')
end
end
context 'when :id and :login are different' do
it 'is not === or ==' do
WpUser.new(uri, id: 1, name: 'yo').should_not == WpUser.new(uri, id: 2, name:'yo')
end
end
end
end