summaryrefslogtreecommitdiff
path: root/spec/helpers/user_helper_spec.rb
blob: e6e6ab402598e481cd85c749b7473c39df547888 (plain)
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
require 'spec_helper'

describe UserHelper do
  describe 'user_avatar_url' do
    let (:user) { User.new({'avatar_url' => avatar_url}) }

    context 'no avatar' do
      let (:avatar_url) { nil }

      it 'should return a generic avatar' do
        expect(user_avatar_url(user)).to eq 'no_avatar.png'
      end
    end

    context 'plain gravatar' do
      let (:base_url) { 'http://www.gravatar.com/avatar/abcdefgh' }
      let (:avatar_url) { "#{base_url}?s=40&d=mm" }

      it 'should return gravatar with default size' do
        expect(user_avatar_url(user)).to eq "#{base_url}?s=40&d=identicon"
      end

      it 'should return gravatar with custom size' do
        expect(user_avatar_url(user, 120)).to eq "#{base_url}?s=120&d=identicon"
      end
    end

    context 'secure gravatar' do
      let (:base_url) { 'https://secure.gravatar.com/avatar/abcdefgh' }
      let (:avatar_url) { "#{base_url}?s=40&d=mm" }

      it 'should return gravatar with default size' do
        expect(user_avatar_url(user)).to eq "#{base_url}?s=40&d=identicon"
      end

      it 'should return gravatar with custom size' do
        expect(user_avatar_url(user, 120)).to eq "#{base_url}?s=120&d=identicon"
      end
    end

    context 'custom avatar' do
      let (:avatar_url) { 'http://example.local/avatar.png' }

      it 'should return custom avatar' do
        expect(user_avatar_url(user)).to eq avatar_url
      end
    end
  end
end