Commit 90696194 authored by Sean McGivern's avatar Sean McGivern

Merge branch 'issue_27212-ee' into 'master'

CE Backport - Add closed_at field to issues

See merge request !1452
parents f1924d2b 77b8bac1
...@@ -63,6 +63,14 @@ class Issue < ActiveRecord::Base ...@@ -63,6 +63,14 @@ class Issue < ActiveRecord::Base
state :opened state :opened
state :reopened state :reopened
state :closed state :closed
before_transition any => :closed do |issue|
issue.closed_at = Time.zone.now
end
before_transition closed: any do |issue|
issue.closed_at = nil
end
end end
def hook_attrs def hook_attrs
......
---
title: Add closed_at field to issues
merge_request:
author:
class AddClosedAtToIssues < ActiveRecord::Migration
DOWNTIME = false
def change
add_column :issues, :closed_at, :datetime
end
end
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20170313133418) do ActiveRecord::Schema.define(version: 20170315194013) do
# These are extensions that must be enabled in order to support this database # These are extensions that must be enabled in order to support this database
enable_extension "plpgsql" enable_extension "plpgsql"
...@@ -530,6 +530,7 @@ ActiveRecord::Schema.define(version: 20170313133418) do ...@@ -530,6 +530,7 @@ ActiveRecord::Schema.define(version: 20170313133418) do
t.text "description_html" t.text "description_html"
t.integer "time_estimate" t.integer "time_estimate"
t.integer "relative_position" t.integer "relative_position"
t.datetime "closed_at"
end end
add_index "issues", ["assignee_id"], name: "index_issues_on_assignee_id", using: :btree add_index "issues", ["assignee_id"], name: "index_issues_on_assignee_id", using: :btree
......
...@@ -15,6 +15,7 @@ Issue: ...@@ -15,6 +15,7 @@ Issue:
- updated_by_id - updated_by_id
- confidential - confidential
- deleted_at - deleted_at
- closed_at
- due_date - due_date
- moved_to_id - moved_to_id
- lock_version - lock_version
......
...@@ -37,6 +37,30 @@ describe Issue, models: true do ...@@ -37,6 +37,30 @@ describe Issue, models: true do
end end
end end
describe '#closed_at' do
after do
Timecop.return
end
let!(:now) { Timecop.freeze(Time.now) }
it 'sets closed_at to Time.now when issue is closed' do
issue = create(:issue, state: 'opened')
issue.close
expect(issue.closed_at).to eq(now)
end
it 'sets closed_at to nil when issue is reopened' do
issue = create(:issue, state: 'closed')
issue.reopen
expect(issue.closed_at).to be_nil
end
end
describe '#to_reference' do describe '#to_reference' do
let(:namespace) { build(:namespace, path: 'sample-namespace') } let(:namespace) { build(:namespace, path: 'sample-namespace') }
let(:project) { build(:empty_project, name: 'sample-project', namespace: namespace) } let(:project) { build(:empty_project, name: 'sample-project', namespace: namespace) }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment