Skip to content

Commit

Permalink
ROAD-607: Action Plan should only include approved stories (#322)
Browse files Browse the repository at this point in the history
* Action Plan should only include approved stories

Closes #321

* Update scope's name

* VLT-1: Improve specs related to approved stories.

---------

Co-authored-by: Francois Buys <buys.fran@gmail.com>
  • Loading branch information
JuanVqz and fbuys committed Jan 23, 2024
1 parent 76d3e74 commit 7b52e9f
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 15 deletions.
4 changes: 2 additions & 2 deletions app/controllers/action_plans_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ class ActionPlansController < ApplicationController

def show
@project = Project.find(params[:project_id])
@project_stories = @project.stories.by_position
@children = Project.sub_projects_with_ordered_stories(@project.id)
@project_stories = @project.stories.approved.by_position
@children = Project.sub_projects_with_approved_and_ordered_stories(@project.id)
end
end
3 changes: 2 additions & 1 deletion app/models/project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ class Project < ApplicationRecord

scope :active, -> { where.not(status: "archived").or(where(status: nil)) }
scope :parents, -> { where(parent: nil) }
scope :sub_projects_with_ordered_stories, ->(project_id) {
scope :sub_projects_with_approved_and_ordered_stories, ->(project_id) {
where(parent_id: project_id)
.includes(:stories).references(:stories)
.where(stories: {status: :approved})
.order("projects.position ASC, stories.position ASC NULLS FIRST")
}

Expand Down
10 changes: 6 additions & 4 deletions spec/features/action_plan_generate_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,17 @@

let!(:project) do
FactoryBot.create(:project, parent: parent).tap do |project|
FactoryBot.create(:story, title: "Second Story", description: "Second", position: 2, project: project, extra_info: "Extra Information")
FactoryBot.create(:story, title: "First Story", description: "First", position: 1, project: project)
FactoryBot.create(:story, :approved, title: "Second Story", description: "Second", position: 3, project: project, extra_info: "Extra Information")
FactoryBot.create(:story, :approved, title: "First Story", description: "First", position: 1, project: project)
FactoryBot.create(:story, :pending, title: "Pending task", description: "Pending description", position: 2, project: project)
FactoryBot.create(:story, :rejected, title: "Rejected task", description: "Rejected description", position: 4, project: project)
end
end

let!(:project2) do
FactoryBot.create(:project, parent: parent).tap do |project|
FactoryBot.create(:story, title: "Third Story", description: "Third", position: 2, project: project)
FactoryBot.create(:story, title: "Forth Story", description: "Forth", position: 1, project: project)
FactoryBot.create(:story, :approved, title: "Third Story", description: "Third", position: 2, project: project)
FactoryBot.create(:story, :approved, title: "Forth Story", description: "Forth", position: 1, project: project)
end
end

Expand Down
17 changes: 9 additions & 8 deletions spec/models/project_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,19 @@
expect(sub_project2.position).to eq 2
end

describe ".with_ordered_descendents" do
describe ".sub_projects_with_approved_and_ordered_stories" do
it "orders sub projects properly" do
parent = FactoryBot.create(:project)
sub_project1 = FactoryBot.create(:project, parent: parent, position: 2)
story_5 = FactoryBot.create(:story, project: sub_project1, position: 2)
story_4 = FactoryBot.create(:story, project: sub_project1, position: 1)
story_6 = FactoryBot.create(:story, project: sub_project1, position: 3)
story_5 = FactoryBot.create(:story, :approved, project: sub_project1, position: 2)
story_4 = FactoryBot.create(:story, :approved, project: sub_project1, position: 1)
story_6 = FactoryBot.create(:story, :approved, project: sub_project1, position: 3)

sub_project2 = FactoryBot.create(:project, parent: parent, position: 1)
story_3 = FactoryBot.create(:story, project: sub_project2, position: 3)
story_1 = FactoryBot.create(:story, project: sub_project2, position: 1)
story_2 = FactoryBot.create(:story, project: sub_project2, position: 2)
sub_projects = Project.sub_projects_with_ordered_stories(parent.id)
story_3 = FactoryBot.create(:story, :approved, project: sub_project2, position: 3)
story_1 = FactoryBot.create(:story, :approved, project: sub_project2, position: 1)
story_2 = FactoryBot.create(:story, :approved, project: sub_project2, position: 2)
sub_projects = Project.sub_projects_with_approved_and_ordered_stories(parent.id)

expect(sub_projects.count).to eq 2
expect(sub_projects[0].id).to eq sub_project2.id
Expand Down
10 changes: 10 additions & 0 deletions spec/models/story_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -115,4 +115,14 @@
end
end
end

describe ".approved" do
it "returns only approved stories" do
approved_stories = FactoryBot.create_list(:story, 2, :approved)
FactoryBot.create(:story, :rejected)
FactoryBot.create(:story, :pending)

expect(Story.approved.map(&:id).sort).to eq(approved_stories.map(&:id).sort)
end
end
end

0 comments on commit 7b52e9f

Please sign in to comment.