diff --git a/app/helpers/issues_helper.rb b/app/helpers/issues_helper.rb index 55170cbfa6bfd6841eb4f75933c8c1003f6b331a..e8ea39d7ffc6469e463f91febc5736082f82efa3 100644 --- a/app/helpers/issues_helper.rb +++ b/app/helpers/issues_helper.rb @@ -4,7 +4,7 @@ module IssuesHelper def issue_css_classes(issue) classes = ["issue"] classes << "closed" if issue.closed? - classes << "today" if issue.today? + classes << "today" if issue.new? classes << "user-can-drag" if @sort == 'relative_position' classes.join(' ') end diff --git a/app/models/concerns/issuable.rb b/app/models/concerns/issuable.rb index 46cd9649c2d2dfb5bd28bfde96f6d4437758fac3..a6986029f0d6a164d4a26aebfe4aebeaa7615936 100644 --- a/app/models/concerns/issuable.rb +++ b/app/models/concerns/issuable.rb @@ -385,8 +385,12 @@ def today? Date.today == created_at.to_date end + def created_hours_ago + (Time.now.utc.to_i - created_at.utc.to_i) / 3600 + end + def new? - today? && created_at == updated_at + created_hours_ago < 24 end def open? diff --git a/changelogs/unreleased/dz-improve-new-issue-highlight.yml b/changelogs/unreleased/dz-improve-new-issue-highlight.yml new file mode 100644 index 0000000000000000000000000000000000000000..5b2cc72971a408e2c52b0b296989cfda180c63c4 --- /dev/null +++ b/changelogs/unreleased/dz-improve-new-issue-highlight.yml @@ -0,0 +1,5 @@ +--- +title: Change logic behind new issues highlight +merge_request: 41150 +author: +type: changed diff --git a/spec/models/concerns/issuable_spec.rb b/spec/models/concerns/issuable_spec.rb index 46fe942fec13ea70fa1a2e69eed3aa1ff66a6895..8d2eb3b5e2af52fdb31ed31759fcb0a6c9f9cc84 100644 --- a/spec/models/concerns/issuable_spec.rb +++ b/spec/models/concerns/issuable_spec.rb @@ -295,20 +295,14 @@ end describe "#new?" do - it "returns true when created today and record hasn't been updated" do - allow(issue).to receive(:today?).and_return(true) - expect(issue.new?).to be_truthy - end - - it "returns false when not created today" do - allow(issue).to receive(:today?).and_return(false) + it "returns false when created 30 hours ago" do + allow(issue).to receive(:created_at).and_return(Time.current - 30.hours) expect(issue.new?).to be_falsey end - it "returns false when record has been updated" do - allow(issue).to receive(:today?).and_return(true) - issue.update_attribute(:updated_at, 1.hour.ago) - expect(issue.new?).to be_falsey + it "returns true when created 20 hours ago" do + allow(issue).to receive(:created_at).and_return(Time.current - 20.hours) + expect(issue.new?).to be_truthy end end