BigW Consortium Gitlab

base_spec.rb 1.27 KB
Newer Older
1 2 3 4 5 6 7 8
require 'spec_helper'

describe Gitlab::View::Presenter::Base do
  let(:project) { double(:project) }
  let(:presenter_class) do
    Struct.new(:subject).include(described_class)
  end

9 10 11 12 13 14
  describe '.presenter?' do
    it 'returns true' do
      presenter = presenter_class.new(project)

      expect(presenter.class).to be_presenter
    end
15 16 17 18 19
  end

  describe '.presents' do
    it 'exposes #subject with the given keyword' do
      presenter_class.presents(:foo)
20
      presenter = presenter_class.new(project)
21

22
      expect(presenter.foo).to eq(project)
23 24 25 26 27 28
    end
  end

  describe '#can?' do
    context 'user is not allowed' do
      it 'returns false' do
29 30 31
        presenter = presenter_class.new(build_stubbed(:empty_project))

        expect(presenter.can?(nil, :read_project)).to be_falsy
32 33 34 35
      end
    end

    context 'user is allowed' do
36 37
      it 'returns true' do
        presenter = presenter_class.new(build_stubbed(:empty_project, :public))
38

39 40 41 42 43
        expect(presenter.can?(nil, :read_project)).to be_truthy
      end
    end

    context 'subject is overriden' do
44
      it 'returns true' do
45 46 47
        presenter = presenter_class.new(build_stubbed(:empty_project, :public))

        expect(presenter.can?(nil, :read_project, build_stubbed(:empty_project))).to be_falsy
48 49 50 51
      end
    end
  end
end