summaryrefslogtreecommitdiff
path: root/spec/helpers/appearances_helper_spec.rb
blob: b8d131dd47c596b2663ba5a54d545224e8ba02be (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
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
# frozen_string_literal: true

require "spec_helper"

describe AppearancesHelper do
  before do
    user = create(:user)
    allow(helper).to receive(:current_user).and_return(user)
  end

  describe "#header_message" do
    it "returns nil when header message field is not set" do
      create(:appearance)

      expect(helper.header_message).to be_nil
    end

    context "when header message is set" do
      it "includes current message" do
        message = "Foo bar"
        create(:appearance, header_message: message)

        expect(helper.header_message).to include(message)
      end
    end
  end

  describe "#footer_message" do
    it "returns nil when footer message field is not set" do
      create(:appearance)

      expect(helper.footer_message).to be_nil
    end

    context "when footer message is set" do
      it "includes current message" do
        message = "Foo bar"
        create(:appearance, footer_message: message)

        expect(helper.footer_message).to include(message)
      end
    end
  end

  describe "#brand_image" do
    let!(:appearance) { create(:appearance, :with_logo) }

    context "when there is a logo" do
      it "returns a path" do
        expect(helper.brand_image).to match(%r{img data-src="/uploads/-/system/appearance/.*png})
      end
    end

    context "when there is a logo but no associated upload" do
      before do
        # Legacy attachments were not tracked in the uploads table
        appearance.logo.upload.destroy
        appearance.reload
      end

      it "falls back to using the original path" do
        expect(helper.brand_image).to match(%r{img data-src="/uploads/-/system/appearance/.*png})
      end
    end
  end

  describe "#brand_title" do
    it "returns the default CE title when no appearance is present" do
      allow(helper)
        .to receive(:current_appearance)
        .and_return(nil)

      expect(helper.brand_title).to eq("GitLab Community Edition")
    end
  end
end