2019-03-30 03:23:56 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-03-05 12:51:40 -05:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-24 14:09:03 -04:00
|
|
|
RSpec.describe ProjectBadge do
|
2018-03-05 12:51:40 -05:00
|
|
|
let(:placeholder_url) { 'http://www.example.com/%{project_path}/%{project_id}/%{default_branch}/%{commit_sha}' }
|
|
|
|
|
|
|
|
describe 'associations' do
|
|
|
|
it { is_expected.to belong_to(:project) }
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'validations' do
|
|
|
|
it { is_expected.to validate_presence_of(:project) }
|
|
|
|
end
|
|
|
|
|
|
|
|
shared_examples 'rendered_links' do
|
2019-04-05 04:43:27 -04:00
|
|
|
it 'uses the badge project information to populate the url placeholders' do
|
2018-03-05 12:51:40 -05:00
|
|
|
stub_project_commit_info(project)
|
|
|
|
|
|
|
|
expect(badge.public_send("rendered_#{method}")).to eq "http://www.example.com/#{project.full_path}/#{project.id}/master/whatever"
|
|
|
|
end
|
|
|
|
|
|
|
|
def stub_project_commit_info(project)
|
|
|
|
allow(project).to receive(:commit).and_return(double('Commit', sha: 'whatever'))
|
|
|
|
allow(project).to receive(:default_branch).and_return('master')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'methods' do
|
2020-09-04 08:08:27 -04:00
|
|
|
let(:badge) { build_stubbed(:project_badge, link_url: placeholder_url, image_url: placeholder_url) }
|
|
|
|
let(:project) { badge.project }
|
2018-03-05 12:51:40 -05:00
|
|
|
|
2020-02-06 16:08:48 -05:00
|
|
|
describe '#rendered_link_url' do
|
2018-03-05 12:51:40 -05:00
|
|
|
let(:method) { :link_url }
|
|
|
|
|
|
|
|
it_behaves_like 'rendered_links'
|
|
|
|
end
|
|
|
|
|
2020-02-06 16:08:48 -05:00
|
|
|
describe '#rendered_image_url' do
|
2018-03-05 12:51:40 -05:00
|
|
|
let(:method) { :image_url }
|
|
|
|
|
|
|
|
it_behaves_like 'rendered_links'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|