1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121
|
require 'spec_helper'
describe OpenIDConnect::ResponseObject::UserInfo do
let(:klass) { OpenIDConnect::ResponseObject::UserInfo }
let(:instance) { klass.new attributes }
subject { instance }
describe 'attributes' do
subject { klass }
its(:required_attributes) { should == [] }
its(:optional_attributes) do
should == [
:sub,
:name,
:given_name,
:family_name,
:middle_name,
:nickname,
:preferred_username,
:profile,
:picture,
:website,
:email,
:email_verified,
:gender,
:birthdate,
:zoneinfo,
:locale,
:phone_number,
:phone_number_verified,
:address,
:updated_at
]
end
end
describe 'validations' do
subject do
_instance_ = instance
_instance_.valid?
_instance_
end
context 'when all attributes are blank' do
let :attributes do
{}
end
its(:valid?) { should == false }
its(:errors) { should include :base }
end
context 'when email is invalid' do
let :attributes do
{email: 'nov@localhost'}
end
its(:valid?) { should == false }
its(:errors) { should include :email }
end
[:email_verified, :zoneinfo].each do |one_of_list|
context "when #{one_of_list} is invalid" do
let :attributes do
{one_of_list => 'Out of List'}
end
its(:valid?) { should == false }
its(:errors) { should include one_of_list }
end
end
#context "when locale is invalid" do
# it :TODO
#end
[:profile, :picture, :website].each do |url|
context "when #{url} is invalid" do
let :attributes do
{url => 'Invalid'}
end
its(:valid?) { should == false }
its(:errors) { should include url }
end
end
context 'when address is blank' do
let :attributes do
{address: {}}
end
its(:valid?) { should == false }
its(:errors) { should include :address }
end
end
describe '#address=' do
context 'when Hash is given' do
let :attributes do
{address: {}}
end
its(:address) { should be_a OpenIDConnect::ResponseObject::UserInfo::Address }
end
context 'when Address is given' do
let :attributes do
{address: OpenIDConnect::ResponseObject::UserInfo::Address.new}
end
its(:address) { should be_a OpenIDConnect::ResponseObject::UserInfo::Address }
end
end
describe '#to_json' do
let :attributes do
{
sub: 'nov.matake#12345',
address: {
formatted: 'Tokyo, Japan'
}
}
end
its(:to_json) { should include '"sub":"nov.matake#12345"'}
its(:to_json) { should include '"address":{"formatted":"Tokyo, Japan"}'}
end
end
|