Skip to content

Commit

Permalink
dont_delete_done_tasks (#83)
Browse files Browse the repository at this point in the history
* initial commit for dont_delete_done_tasks

* add test

* dont delete done tasks

* Update spec/models/task_spec.rb

Co-authored-by: Daniel Diekmeier <[email protected]>

* Capitalize the status

* migrate status field to citext

* annotate

---------

Co-authored-by: Daniel Diekmeier <[email protected]>
  • Loading branch information
oma-s and danieldiekmeier authored Jan 19, 2024
1 parent a7a4eb5 commit 14c8250
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 7 deletions.
4 changes: 2 additions & 2 deletions app/models/task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# id :uuid not null, primary key
# sprint_id :uuid
# title :string not null
# status :string
# status :citext
# github_id :string
# repository :string
# issue_number :bigint
Expand Down Expand Up @@ -45,7 +45,7 @@ def sync_with_github
end

Task.transaction do
Task.where(github_id: deleted_ids).destroy_all if deleted_ids.any?
Task.where(github_id: deleted_ids).where.not(status: "done").destroy_all if deleted_ids.any?

if tasks.any?
task_ids_by_github_id = Task.upsert_all(tasks, returning: [:github_id, :id], unique_by: [:github_id]).rows.to_h
Expand Down
13 changes: 13 additions & 0 deletions db/migrate/20240119111322_change_field_to_citext.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# frozen_string_literal: true

class ChangeFieldToCitext < ActiveRecord::Migration[6.0]
def up
enable_extension "citext"
change_column :tasks, :status, :citext
end

def down
change_column :tasks, :status, :string
disable_extension "citext"
end
end
5 changes: 3 additions & 2 deletions db/schema.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion spec/fixtures/tasks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# id :uuid not null, primary key
# sprint_id :uuid
# title :string not null
# status :string
# status :citext
# github_id :string
# repository :string
# issue_number :bigint
Expand Down
12 changes: 10 additions & 2 deletions spec/models/task_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# id :uuid not null, primary key
# sprint_id :uuid
# title :string not null
# status :string
# status :citext
# github_id :string
# repository :string
# issue_number :bigint
Expand Down Expand Up @@ -78,13 +78,21 @@
end

it "deletes tasks that are not in the list" do
task = tasks :done
task = tasks :in_progress

Task.sync_with_github

expect(Task.exists?(task.id)).to eq false
end

it "does not delete tasks that are not in the list if they are done" do
task = tasks :done

Task.sync_with_github

expect(Task.exists?(task.id)).to eq true
end

it "only updates finished_storypoints" do
sprint_feedback = sprint_feedbacks(:sprint_feedback_1)
expect(sprint_feedback).to have_attributes finished_storypoints: 8
Expand Down

0 comments on commit 14c8250

Please sign in to comment.