Skip to content

Commit

Permalink
Action Plan should only include approved stories
Browse files Browse the repository at this point in the history
Closes #321
  • Loading branch information
JuanVqz committed Jan 22, 2024
1 parent 76d3e74 commit d0eb2ee
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 12 deletions.
2 changes: 1 addition & 1 deletion 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
@project_stories = @project.stories.approved.by_position
@children = Project.sub_projects_with_ordered_stories(@project.id)
end
end
1 change: 1 addition & 0 deletions app/models/project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class Project < ApplicationRecord
scope :sub_projects_with_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: 2, 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: 3, 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)
FactoryBot.create(:story, :rejected, title: "Rejected task", description: "Rejected description", position: 3, project: project)
end
end

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

describe ".with_ordered_descendents" do
describe ".sub_projects_with_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)
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_ordered_stories(parent.id)

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

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

expect(Story.approved).to eq(approved_stories)
end
end
end

0 comments on commit d0eb2ee

Please sign in to comment.