Skip to content

Commit 7b52e9f

Browse files
JuanVqzfbuys
andauthored
ROAD-607: Action Plan should only include approved stories (#322)
* 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 <[email protected]>
1 parent 76d3e74 commit 7b52e9f

File tree

5 files changed

+29
-15
lines changed

5 files changed

+29
-15
lines changed

app/controllers/action_plans_controller.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ class ActionPlansController < ApplicationController
33

44
def show
55
@project = Project.find(params[:project_id])
6-
@project_stories = @project.stories.by_position
7-
@children = Project.sub_projects_with_ordered_stories(@project.id)
6+
@project_stories = @project.stories.approved.by_position
7+
@children = Project.sub_projects_with_approved_and_ordered_stories(@project.id)
88
end
99
end

app/models/project.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@ class Project < ApplicationRecord
1313

1414
scope :active, -> { where.not(status: "archived").or(where(status: nil)) }
1515
scope :parents, -> { where(parent: nil) }
16-
scope :sub_projects_with_ordered_stories, ->(project_id) {
16+
scope :sub_projects_with_approved_and_ordered_stories, ->(project_id) {
1717
where(parent_id: project_id)
1818
.includes(:stories).references(:stories)
19+
.where(stories: {status: :approved})
1920
.order("projects.position ASC, stories.position ASC NULLS FIRST")
2021
}
2122

spec/features/action_plan_generate_spec.rb

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,17 @@
88

99
let!(:project) do
1010
FactoryBot.create(:project, parent: parent).tap do |project|
11-
FactoryBot.create(:story, title: "Second Story", description: "Second", position: 2, project: project, extra_info: "Extra Information")
12-
FactoryBot.create(:story, title: "First Story", description: "First", position: 1, project: project)
11+
FactoryBot.create(:story, :approved, title: "Second Story", description: "Second", position: 3, project: project, extra_info: "Extra Information")
12+
FactoryBot.create(:story, :approved, title: "First Story", description: "First", position: 1, project: project)
13+
FactoryBot.create(:story, :pending, title: "Pending task", description: "Pending description", position: 2, project: project)
14+
FactoryBot.create(:story, :rejected, title: "Rejected task", description: "Rejected description", position: 4, project: project)
1315
end
1416
end
1517

1618
let!(:project2) do
1719
FactoryBot.create(:project, parent: parent).tap do |project|
18-
FactoryBot.create(:story, title: "Third Story", description: "Third", position: 2, project: project)
19-
FactoryBot.create(:story, title: "Forth Story", description: "Forth", position: 1, project: project)
20+
FactoryBot.create(:story, :approved, title: "Third Story", description: "Third", position: 2, project: project)
21+
FactoryBot.create(:story, :approved, title: "Forth Story", description: "Forth", position: 1, project: project)
2022
end
2123
end
2224

spec/models/project_spec.rb

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,19 @@
2121
expect(sub_project2.position).to eq 2
2222
end
2323

24-
describe ".with_ordered_descendents" do
24+
describe ".sub_projects_with_approved_and_ordered_stories" do
2525
it "orders sub projects properly" do
2626
parent = FactoryBot.create(:project)
2727
sub_project1 = FactoryBot.create(:project, parent: parent, position: 2)
28-
story_5 = FactoryBot.create(:story, project: sub_project1, position: 2)
29-
story_4 = FactoryBot.create(:story, project: sub_project1, position: 1)
30-
story_6 = FactoryBot.create(:story, project: sub_project1, position: 3)
28+
story_5 = FactoryBot.create(:story, :approved, project: sub_project1, position: 2)
29+
story_4 = FactoryBot.create(:story, :approved, project: sub_project1, position: 1)
30+
story_6 = FactoryBot.create(:story, :approved, project: sub_project1, position: 3)
31+
3132
sub_project2 = FactoryBot.create(:project, parent: parent, position: 1)
32-
story_3 = FactoryBot.create(:story, project: sub_project2, position: 3)
33-
story_1 = FactoryBot.create(:story, project: sub_project2, position: 1)
34-
story_2 = FactoryBot.create(:story, project: sub_project2, position: 2)
35-
sub_projects = Project.sub_projects_with_ordered_stories(parent.id)
33+
story_3 = FactoryBot.create(:story, :approved, project: sub_project2, position: 3)
34+
story_1 = FactoryBot.create(:story, :approved, project: sub_project2, position: 1)
35+
story_2 = FactoryBot.create(:story, :approved, project: sub_project2, position: 2)
36+
sub_projects = Project.sub_projects_with_approved_and_ordered_stories(parent.id)
3637

3738
expect(sub_projects.count).to eq 2
3839
expect(sub_projects[0].id).to eq sub_project2.id

spec/models/story_spec.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,4 +115,14 @@
115115
end
116116
end
117117
end
118+
119+
describe ".approved" do
120+
it "returns only approved stories" do
121+
approved_stories = FactoryBot.create_list(:story, 2, :approved)
122+
FactoryBot.create(:story, :rejected)
123+
FactoryBot.create(:story, :pending)
124+
125+
expect(Story.approved.map(&:id).sort).to eq(approved_stories.map(&:id).sort)
126+
end
127+
end
118128
end

0 commit comments

Comments
 (0)