require 'spec_helper' describe Commit do let(:project) { create(:project) } let(:commit) { project.commit } describe 'modules' do subject { described_class } it { is_expected.to include_module(Mentionable) } it { is_expected.to include_module(Participable) } it { is_expected.to include_module(Referable) } it { is_expected.to include_module(StaticModel) } end describe '#to_reference' do it 'returns a String reference to the object' do expect(commit.to_reference).to eq commit.id end it 'supports a cross-project reference' do cross = double('project') expect(commit.to_reference(cross)).to eq "#{project.to_reference}@#{commit.id}" end end describe '#title' do it "returns no_commit_message when safe_message is blank" do allow(commit).to receive(:safe_message).and_return('') expect(commit.title).to eq("--no commit message") end it "truncates a message without a newline at 80 characters" do message = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec sodales id felis id blandit. Vivamus egestas lacinia lacus, sed rutrum mauris.' allow(commit).to receive(:safe_message).and_return(message) expect(commit.title).to eq("#{message[0..79]}…") end it "truncates a message with a newline before 80 characters at the newline" do message = commit.safe_message.split(" ").first allow(commit).to receive(:safe_message).and_return(message + "\n" + message) expect(commit.title).to eq(message) end it "does not truncates a message with a newline after 80 but less 100 characters" do message =<(txt) { allow(subject).to receive(:safe_message).and_return(txt) } end # Include the subject in the repository stub. let(:extra_commits) { [subject] } end end