Merge branch 'issue_27212' into 'master'

Add closed_at field to issues

Closes #27212

See merge request !9977
This commit is contained in:
Sean McGivern 2017-03-20 15:34:09 +00:00
commit df0778a4a1
6 changed files with 46 additions and 1 deletions

View file

@ -55,6 +55,14 @@ class Issue < ActiveRecord::Base
state :opened
state :reopened
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
def hook_attrs

View file

@ -0,0 +1,4 @@
---
title: Add closed_at field to issues
merge_request:
author:

View file

@ -0,0 +1,7 @@
class AddClosedAtToIssues < ActiveRecord::Migration
DOWNTIME = false
def change
add_column :issues, :closed_at, :datetime
end
end

View file

@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20170315174634) do
ActiveRecord::Schema.define(version: 20170315194013) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@ -445,6 +445,7 @@ ActiveRecord::Schema.define(version: 20170315174634) do
t.text "description_html"
t.integer "time_estimate"
t.integer "relative_position"
t.datetime "closed_at"
end
add_index "issues", ["assignee_id"], name: "index_issues_on_assignee_id", using: :btree

View file

@ -15,6 +15,7 @@ Issue:
- updated_by_id
- confidential
- deleted_at
- closed_at
- due_date
- moved_to_id
- lock_version

View file

@ -37,6 +37,30 @@ describe Issue, models: true do
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
let(:namespace) { build(:namespace, path: 'sample-namespace') }
let(:project) { build(:empty_project, name: 'sample-project', namespace: namespace) }