|
|
|
@ -50,121 +50,104 @@ describe AvatarHelper, type: :helper do |
|
|
|
|
"#{host}/avatar/#{digest}?secure=#{ssl}" |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
describe 'ssl dependent on protocol settings' do |
|
|
|
|
it "should be set to secure if protocol is 'https'" do |
|
|
|
|
with_settings protocol: 'https' do |
|
|
|
|
expect(described_class.secure?).to be true |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
it "should be set to unsecure if protocol is 'http'" do |
|
|
|
|
with_settings protocol: 'http' do |
|
|
|
|
expect(described_class.secure?).to be false |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
before do |
|
|
|
|
AvatarHelper.configure! |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
describe 'default avatar dependent on settings' do |
|
|
|
|
it 'should be set to value of setting' do |
|
|
|
|
with_settings gravatar_default: 'Wavatars' do |
|
|
|
|
expect(described_class.default).to eq 'Wavatars' |
|
|
|
|
describe 'avatar' do |
|
|
|
|
context 'when enabled', with_settings: { gravatar_enabled?: true } do |
|
|
|
|
|
|
|
|
|
describe 'ssl dependent on protocol settings' do |
|
|
|
|
context 'with https protocol', with_settings: { protocol: 'https' } do |
|
|
|
|
it "should be set to secure if protocol is 'https'" do |
|
|
|
|
expect(described_class.secure?).to be true |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
context 'with http protocol', with_settings: { protocol: 'http' } do |
|
|
|
|
it "should be set to unsecure if protocol is 'http'" do |
|
|
|
|
expect(described_class.secure?).to be false |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
it "should be set to unsecure if protocol is 'http'" do |
|
|
|
|
with_settings gravatar_default: '' do |
|
|
|
|
expect(described_class.default).to be_nil |
|
|
|
|
describe 'default avatar dependent on settings' do |
|
|
|
|
context 'with wavatars', with_settings: { gravatar_default: 'Wavatars' } do |
|
|
|
|
it 'should be set to value of setting' do |
|
|
|
|
expect(described_class.default).to eq 'Wavatars' |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
context 'when empty' do |
|
|
|
|
it "should be set to unsecure if protocol is 'http'" do |
|
|
|
|
expect(described_class.default).to be_nil |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
describe '#avatar' do |
|
|
|
|
it 'should return a gravatar image tag if a user is provided' do |
|
|
|
|
digest = Digest::MD5.hexdigest(user.mail) |
|
|
|
|
context 'with http', with_settings: { protocol: 'http' } do |
|
|
|
|
it 'should return a gravatar image tag if a user is provided' do |
|
|
|
|
digest = Digest::MD5.hexdigest(user.mail) |
|
|
|
|
expect(helper.avatar(user)).to be_html_eql(expected_image_tag(digest)) |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
with_settings gravatar_enabled: '1', protocol: 'http' do |
|
|
|
|
expect(helper.avatar(user)).to be_html_eql(expected_image_tag(digest)) |
|
|
|
|
it 'should return a gravatar url if a user is provided' do |
|
|
|
|
digest = Digest::MD5.hexdigest(user.mail) |
|
|
|
|
expect(helper.avatar_url(user)).to eq(expected_url(digest)) |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
it 'should return a gravatar image tag with ssl if the request was ssl required' do |
|
|
|
|
digest = Digest::MD5.hexdigest(user.mail) |
|
|
|
|
context 'with https', with_settings: { protocol: 'https' } do |
|
|
|
|
it 'should return a gravatar image tag with ssl if the request was ssl required' do |
|
|
|
|
digest = Digest::MD5.hexdigest(user.mail) |
|
|
|
|
expect(helper.avatar(user)).to be_html_eql(expected_image_tag(digest, ssl: true)) |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
with_settings gravatar_enabled: '1', protocol: 'https' do |
|
|
|
|
expect(helper.avatar(user)).to be_html_eql(expected_image_tag(digest, ssl: true)) |
|
|
|
|
it 'should return a gravatar image tag with ssl if the request was ssl required' do |
|
|
|
|
digest = Digest::MD5.hexdigest(user.mail) |
|
|
|
|
expect(helper.avatar_url(user)).to eq(expected_url(digest, ssl: true)) |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
it 'should return an empty string if a non parsable (e-mail) string is provided' do |
|
|
|
|
with_settings gravatar_enabled: '1' do |
|
|
|
|
it 'should return an empty string if a non parsable (e-mail) string is provided' do |
|
|
|
|
expect(helper.avatar('just the name')).to eq('') |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
it 'should return an empty string if nil is provided' do |
|
|
|
|
with_settings gravatar_enabled: '1' do |
|
|
|
|
it 'should return an empty string if nil is provided' do |
|
|
|
|
expect(helper.avatar(nil)).to eq('') |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
it 'should return an empty string if gravatar is disabled' do |
|
|
|
|
with_settings gravatar_enabled: '0' do |
|
|
|
|
expect(helper.avatar(user)).to eq('') |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
it 'should return a gravatar image tag if a parsable e-mail string is provided' do |
|
|
|
|
with_settings gravatar_enabled: '1' do |
|
|
|
|
it 'should return a gravatar image tag if a parsable e-mail string is provided' do |
|
|
|
|
mail = '<e-mail@mail.de>' |
|
|
|
|
digest = Digest::MD5.hexdigest('e-mail@mail.de') |
|
|
|
|
|
|
|
|
|
expect(helper.avatar(mail)).to be_html_eql(expected_image_tag(digest, title: nil)) |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
describe '#avatar_url' do |
|
|
|
|
it 'should return a gravatar url if a user is provided' do |
|
|
|
|
digest = Digest::MD5.hexdigest(user.mail) |
|
|
|
|
|
|
|
|
|
with_settings gravatar_enabled: '1', protocol: 'http' do |
|
|
|
|
expect(helper.avatar_url(user)).to eq(expected_url(digest)) |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
it 'should return a gravatar image tag with ssl if the request was ssl required' do |
|
|
|
|
digest = Digest::MD5.hexdigest(user.mail) |
|
|
|
|
it 'should return a gravatar image tag if a parsable e-mail string is provided' do |
|
|
|
|
mail = '<e-mail@mail.de>' |
|
|
|
|
digest = Digest::MD5.hexdigest('e-mail@mail.de') |
|
|
|
|
|
|
|
|
|
with_settings gravatar_enabled: '1', protocol: 'https' do |
|
|
|
|
expect(helper.avatar_url(user)).to eq(expected_url(digest, ssl: true)) |
|
|
|
|
expect(helper.avatar_url(mail)).to eq(expected_url(digest)) |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
it 'should return an empty string if a non parsable (e-mail) string is provided' do |
|
|
|
|
with_settings gravatar_enabled: '1' do |
|
|
|
|
it 'should return an empty string if a non parsable (e-mail) string is provided' do |
|
|
|
|
expect(helper.avatar_url('just the name')).to eq('') |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
it 'should return an empty string if nil is provided' do |
|
|
|
|
with_settings gravatar_enabled: '1' do |
|
|
|
|
it 'should return an empty string if nil is provided' do |
|
|
|
|
expect(helper.avatar_url(nil)).to eq('') |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
context 'when disabled', with_settings: { gravatar_enabled?: false } do |
|
|
|
|
it 'should return an empty string if gravatar is disabled' do |
|
|
|
|
with_settings gravatar_enabled: '0' do |
|
|
|
|
expect(helper.avatar_url(user)).to eq('') |
|
|
|
|
end |
|
|
|
|
expect(helper.avatar(user)).to eq('') |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
it 'should return a gravatar image tag if a parsable e-mail string is provided' do |
|
|
|
|
with_settings gravatar_enabled: '1' do |
|
|
|
|
mail = '<e-mail@mail.de>' |
|
|
|
|
digest = Digest::MD5.hexdigest('e-mail@mail.de') |
|
|
|
|
|
|
|
|
|
expect(helper.avatar_url(mail)).to eq(expected_url(digest)) |
|
|
|
|
end |
|
|
|
|
it 'should return an empty string if gravatar is disabled' do |
|
|
|
|
expect(helper.avatar_url(user)).to eq('') |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|