2019-08-22 06:57:44 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-01-09 15:46:38 -05:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-24 14:09:03 -04:00
|
|
|
RSpec.describe Gitlab::View::Presenter::Factory do
|
2017-01-10 17:41:04 -05:00
|
|
|
let(:build) { Ci::Build.new }
|
2017-01-09 15:46:38 -05:00
|
|
|
|
|
|
|
describe '#initialize' do
|
|
|
|
context 'without optional parameters' do
|
|
|
|
it 'takes a subject and optional params' do
|
2017-01-10 17:41:04 -05:00
|
|
|
presenter = described_class.new(build)
|
|
|
|
|
|
|
|
expect { presenter }.not_to raise_error
|
2017-01-09 15:46:38 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with optional parameters' do
|
|
|
|
it 'takes a subject and optional params' do
|
2017-01-10 17:41:04 -05:00
|
|
|
presenter = described_class.new(build, user: 'user')
|
|
|
|
|
|
|
|
expect { presenter }.not_to raise_error
|
2017-01-09 15:46:38 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#fabricate!' do
|
|
|
|
it 'detects the presenter based on the given subject' do
|
2017-01-10 17:41:04 -05:00
|
|
|
presenter = described_class.new(build).fabricate!
|
|
|
|
|
|
|
|
expect(presenter).to be_a(Ci::BuildPresenter)
|
2017-01-09 15:46:38 -05:00
|
|
|
end
|
2017-12-05 09:03:16 -05:00
|
|
|
|
|
|
|
it 'uses the presenter_class if given on #initialize' do
|
2020-05-19 20:08:20 -04:00
|
|
|
my_custom_presenter = Class.new(described_class)
|
2017-12-05 09:03:16 -05:00
|
|
|
|
2020-05-19 20:08:20 -04:00
|
|
|
presenter = described_class.new(build, presenter_class: my_custom_presenter).fabricate!
|
2017-12-05 09:03:16 -05:00
|
|
|
|
2020-05-19 20:08:20 -04:00
|
|
|
expect(presenter).to be_a(my_custom_presenter)
|
2017-12-05 09:03:16 -05:00
|
|
|
end
|
2017-01-09 15:46:38 -05:00
|
|
|
end
|
|
|
|
end
|