debian-mirror-gitlab/spec/lib/gitlab/view/presenter/factory_spec.rb

42 lines
1.1 KiB
Ruby
Raw Normal View History

2019-12-04 20:38:33 +05:30
# frozen_string_literal: true
2017-08-17 22:00:37 +05:30
require 'spec_helper'
2020-07-28 23:09:34 +05:30
RSpec.describe Gitlab::View::Presenter::Factory do
2017-08-17 22:00:37 +05:30
let(:build) { Ci::Build.new }
describe '#initialize' do
context 'without optional parameters' do
it 'takes a subject and optional params' do
presenter = described_class.new(build)
expect { presenter }.not_to raise_error
end
end
context 'with optional parameters' do
it 'takes a subject and optional params' do
presenter = described_class.new(build, user: 'user')
expect { presenter }.not_to raise_error
end
end
end
describe '#fabricate!' do
it 'detects the presenter based on the given subject' do
presenter = described_class.new(build).fabricate!
expect(presenter).to be_a(Ci::BuildPresenter)
end
2018-03-17 18:26:18 +05:30
it 'uses the presenter_class if given on #initialize' do
2020-05-24 23:13:21 +05:30
my_custom_presenter = Class.new(described_class)
2018-03-17 18:26:18 +05:30
2020-05-24 23:13:21 +05:30
presenter = described_class.new(build, presenter_class: my_custom_presenter).fabricate!
2018-03-17 18:26:18 +05:30
2020-05-24 23:13:21 +05:30
expect(presenter).to be_a(my_custom_presenter)
2018-03-17 18:26:18 +05:30
end
2017-08-17 22:00:37 +05:30
end
end