diff options
author | Rémy Coutable <remy@rymai.me> | 2017-05-17 18:00:14 +0000 |
---|---|---|
committer | Rémy Coutable <remy@rymai.me> | 2017-05-17 18:00:14 +0000 |
commit | d4d9b731c41cdb4a8b933edff34bd9c9ddf1403a (patch) | |
tree | bc6c9af3d218b0f32f75b19744e4314f05141be6 | |
parent | 17e799980f6aaa6b378469f3e237c713f293e079 (diff) | |
parent | d1bce8ea75df00970f3d4a67587ceb64bf4ec905 (diff) | |
download | gitlab-ce-d4d9b731c41cdb4a8b933edff34bd9c9ddf1403a.tar.gz |
Merge branch 'dm-changelog-viewer' into 'master'
Add auxiliary blob viewer for CHANGELOG
See merge request !11365
-rw-r--r-- | app/models/blob.rb | 3 | ||||
-rw-r--r-- | app/models/blob_viewer/base.rb | 2 | ||||
-rw-r--r-- | app/models/blob_viewer/changelog.rb | 16 | ||||
-rw-r--r-- | app/models/blob_viewer/license.rb | 2 | ||||
-rw-r--r-- | app/views/projects/blob/viewers/_changelog.html.haml | 4 | ||||
-rw-r--r-- | spec/models/blob_viewer/changelog_spec.rb | 27 |
6 files changed, 52 insertions, 2 deletions
diff --git a/app/models/blob.rb b/app/models/blob.rb index e0c539a17cf..5ae35d3ab08 100644 --- a/app/models/blob.rb +++ b/app/models/blob.rb @@ -41,7 +41,8 @@ class Blob < SimpleDelegator BlobViewer::RouteMap, BlobViewer::License, - BlobViewer::Contributing + BlobViewer::Contributing, + BlobViewer::Changelog ].freeze attr_reader :project diff --git a/app/models/blob_viewer/base.rb b/app/models/blob_viewer/base.rb index c7b8fbfc56a..26a3778c2a3 100644 --- a/app/models/blob_viewer/base.rb +++ b/app/models/blob_viewer/base.rb @@ -11,6 +11,8 @@ module BlobViewer attr_reader :blob attr_accessor :override_max_size + delegate :project, to: :blob + def initialize(blob) @blob = blob end diff --git a/app/models/blob_viewer/changelog.rb b/app/models/blob_viewer/changelog.rb new file mode 100644 index 00000000000..0464ae27f71 --- /dev/null +++ b/app/models/blob_viewer/changelog.rb @@ -0,0 +1,16 @@ +module BlobViewer + class Changelog < Base + include Auxiliary + include Static + + self.partial_name = 'changelog' + self.file_types = %i(changelog) + self.binary = false + + def render_error + return if project.repository.tag_count > 0 + + :no_tags + end + end +end diff --git a/app/models/blob_viewer/license.rb b/app/models/blob_viewer/license.rb index 6751ea15a5d..57355f2c3aa 100644 --- a/app/models/blob_viewer/license.rb +++ b/app/models/blob_viewer/license.rb @@ -8,7 +8,7 @@ module BlobViewer self.binary = false def license - blob.project.repository.license + project.repository.license end def render_error diff --git a/app/views/projects/blob/viewers/_changelog.html.haml b/app/views/projects/blob/viewers/_changelog.html.haml new file mode 100644 index 00000000000..53921e63b5f --- /dev/null +++ b/app/views/projects/blob/viewers/_changelog.html.haml @@ -0,0 +1,4 @@ += icon('history fw') += succeed '.' do + To find the state of this project's repository at the time of any of these versions, check out + = link_to "the tags", namespace_project_tags_path(viewer.project.namespace, viewer.project) diff --git a/spec/models/blob_viewer/changelog_spec.rb b/spec/models/blob_viewer/changelog_spec.rb new file mode 100644 index 00000000000..9066c5a05ac --- /dev/null +++ b/spec/models/blob_viewer/changelog_spec.rb @@ -0,0 +1,27 @@ +require 'spec_helper' + +describe BlobViewer::Changelog, model: true do + include FakeBlobHelpers + + let(:project) { create(:project, :repository) } + let(:blob) { fake_blob(path: 'CHANGELOG') } + subject { described_class.new(blob) } + + describe '#render_error' do + context 'when there are no tags' do + before do + allow(project.repository).to receive(:tag_count).and_return(0) + end + + it 'returns :no_tags' do + expect(subject.render_error).to eq(:no_tags) + end + end + + context 'when there are tags' do + it 'returns nil' do + expect(subject.render_error).to be_nil + end + end + end +end |