summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuke "Jared" Bennett <lbennett@gitlab.com>2017-05-17 17:09:03 +0100
committerLuke "Jared" Bennett <lbennett@gitlab.com>2017-05-18 09:51:58 +0100
commit1f8a9b558d552925a176e1dd6ba6ef54fc2ee20a (patch)
tree4052308af3a436aa055c2c7c6c6775c2a41fd784
parent6dd88474bed70c2aa70c7fdf7ba6dbdc29dc8998 (diff)
downloadgitlab-ce-1f8a9b558d552925a176e1dd6ba6ef54fc2ee20a.tar.gz
Added editable concern spec Snippet include Editable
-rw-r--r--app/controllers/projects/issues_controller.rb3
-rw-r--r--app/helpers/application_helper.rb4
-rw-r--r--app/helpers/editable_helper.rb5
-rw-r--r--app/models/concerns/editable.rb7
-rw-r--r--app/models/concerns/issuable.rb1
-rw-r--r--app/models/note.rb1
-rw-r--r--app/models/snippet.rb1
-rw-r--r--app/views/projects/issues/show.html.haml2
-rw-r--r--spec/models/concerns/editable_spec.rb11
9 files changed, 24 insertions, 11 deletions
diff --git a/app/controllers/projects/issues_controller.rb b/app/controllers/projects/issues_controller.rb
index 5dfe00a35cd..7b1e4a70232 100644
--- a/app/controllers/projects/issues_controller.rb
+++ b/app/controllers/projects/issues_controller.rb
@@ -5,7 +5,6 @@ class Projects::IssuesController < Projects::ApplicationController
include ToggleAwardEmoji
include IssuableCollections
include SpammableActions
- include EditableHelper
prepend_before_action :authenticate_user!, only: [:new]
@@ -212,7 +211,7 @@ class Projects::IssuesController < Projects::ApplicationController
issue_number: @issue.iid,
}
- if is_edited?(@issue)
+ if @issue.is_edited?
response[:updated_at] = @issue.updated_at
response[:updated_by_name] = @issue.last_edited_by.name
response[:updated_by_path] = user_path(@issue.last_edited_by)
diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb
index 16734fe4c75..8c74d36ad81 100644
--- a/app/helpers/application_helper.rb
+++ b/app/helpers/application_helper.rb
@@ -2,8 +2,6 @@ require 'digest/md5'
require 'uri'
module ApplicationHelper
- include EditableHelper
-
# Check if a particular controller is the current one
#
# args - One or more controller names to check
@@ -183,7 +181,7 @@ module ApplicationHelper
end
def edited_time_ago_with_tooltip(object, placement: 'top', html_class: 'time_ago', exclude_author: false)
- return unless is_edited?(object)
+ return unless object.is_edited?
content_tag :small, class: 'edited-text' do
output = content_tag(:span, 'Edited ')
diff --git a/app/helpers/editable_helper.rb b/app/helpers/editable_helper.rb
deleted file mode 100644
index 78d9998b97e..00000000000
--- a/app/helpers/editable_helper.rb
+++ /dev/null
@@ -1,5 +0,0 @@
-module EditableHelper
- def is_edited?(object)
- !object.last_edited_at.blank? && object.last_edited_at != object.created_at
- end
-end
diff --git a/app/models/concerns/editable.rb b/app/models/concerns/editable.rb
new file mode 100644
index 00000000000..c62c7e1e936
--- /dev/null
+++ b/app/models/concerns/editable.rb
@@ -0,0 +1,7 @@
+module Editable
+ extend ActiveSupport::Concern
+
+ def is_edited?
+ last_edited_at.present? && last_edited_at != created_at
+ end
+end
diff --git a/app/models/concerns/issuable.rb b/app/models/concerns/issuable.rb
index 075ec575f9d..ea10d004c9c 100644
--- a/app/models/concerns/issuable.rb
+++ b/app/models/concerns/issuable.rb
@@ -15,6 +15,7 @@ module Issuable
include Taskable
include TimeTrackable
include Importable
+ include Editable
# This object is used to gather issuable meta data for displaying
# upvotes, downvotes, notes and closing merge requests count for issues and merge requests
diff --git a/app/models/note.rb b/app/models/note.rb
index 46d0a4f159f..4cb3c6f062a 100644
--- a/app/models/note.rb
+++ b/app/models/note.rb
@@ -13,6 +13,7 @@ class Note < ActiveRecord::Base
include AfterCommitQueue
include ResolvableNote
include IgnorableColumn
+ include Editable
ignore_column :original_discussion_id
diff --git a/app/models/snippet.rb b/app/models/snippet.rb
index 882e2fa0594..6c3358685fe 100644
--- a/app/models/snippet.rb
+++ b/app/models/snippet.rb
@@ -8,6 +8,7 @@ class Snippet < ActiveRecord::Base
include Awardable
include Mentionable
include Spammable
+ include Editable
cache_markdown_field :title, pipeline: :single_line
cache_markdown_field :content
diff --git a/app/views/projects/issues/show.html.haml b/app/views/projects/issues/show.html.haml
index 144233b54bb..0ad615535d7 100644
--- a/app/views/projects/issues/show.html.haml
+++ b/app/views/projects/issues/show.html.haml
@@ -53,7 +53,7 @@
.detail-page-description.content-block
.issue-title-data.hidden{ "data" => { "endpoint" => rendered_title_namespace_project_issue_path(@project.namespace, @project, @issue),
"can-update-tasks-class" => can?(current_user, :update_issue, @issue) ? 'js-task-list-container' : '',
- "is-edited": is_edited?(@issue),
+ "is-edited": @issue.is_edited?,
} }
.issue-title-entrypoint
diff --git a/spec/models/concerns/editable_spec.rb b/spec/models/concerns/editable_spec.rb
new file mode 100644
index 00000000000..cd73af3b480
--- /dev/null
+++ b/spec/models/concerns/editable_spec.rb
@@ -0,0 +1,11 @@
+require 'spec_helper'
+
+describe Editable do
+ describe '#is_edited?' do
+ let(:issue) { create(:issue, last_edited_at: nil) }
+ let(:edited_issue) { create(:issue, created_at: 3.days.ago, last_edited_at: 2.days.ago) }
+
+ it { expect(issue.is_edited?).to eq(false) }
+ it { expect(edited_issue.is_edited?).to eq(true) }
+ end
+end