From 230be4d0889edacc46c87cfd11a11e10fa0d5c6c Mon Sep 17 00:00:00 2001 From: Francois Buys Date: Tue, 23 Jan 2024 22:08:21 +0200 Subject: [PATCH] ROAD-609: Export approved stories only We use the CSV tool to export stories to Jira for example. We only want to work on stories that we approved and therefore we only want to export stories from Points that were approved. See: https://ombulabs.atlassian.net/browse/ROAD-609 --- Gemfile.lock | 1 + app/controllers/stories_controller.rb | 4 ++-- spec/controllers/stories_controller_spec.rb | 16 ++++++++++------ spec/features/projects_manage_spec.rb | 4 +++- 4 files changed, 16 insertions(+), 9 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index bb94f31a..f5a7c22e 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -443,6 +443,7 @@ GEM PLATFORMS x86_64-darwin-21 + x86_64-darwin-22 x86_64-linux DEPENDENCIES diff --git a/app/controllers/stories_controller.rb b/app/controllers/stories_controller.rb index 521dbee8..e8463dc4 100644 --- a/app/controllers/stories_controller.rb +++ b/app/controllers/stories_controller.rb @@ -90,7 +90,7 @@ def export csv = if params[:export_with_comments] == "1" CSV.generate(headers: true) do |csv| csv << CSV_HEADERS + ["comment"] - @project.stories.includes(:comments).by_position.each do |story| + @project.stories.includes(:comments).approved.by_position.each do |story| comments = [] story.comments.each do |comment| comments << "#{comment.user.name}: #{comment.body}" @@ -101,7 +101,7 @@ def export else CSV.generate(headers: true) do |csv| csv << CSV_HEADERS - @project.stories.by_position.each do |story| + @project.stories.approved.by_position.each do |story| csv << story.attributes.slice(*CSV_HEADERS) end end diff --git a/spec/controllers/stories_controller_spec.rb b/spec/controllers/stories_controller_spec.rb index 8412f837..49efcd7c 100644 --- a/spec/controllers/stories_controller_spec.rb +++ b/spec/controllers/stories_controller_spec.rb @@ -4,7 +4,7 @@ render_views let!(:project) { FactoryBot.create(:project) } - let!(:story) { FactoryBot.create(:story, project: project) } + let!(:story) { FactoryBot.create(:story, project: project, status: :approved) } before do @request.env["devise.mapping"] = Devise.mappings[:user] @@ -173,7 +173,9 @@ end describe "#export" do - it "exports a CSV file" do + it "exports a CSV file with approved stories only" do + FactoryBot.create(:story, project: project, status: :rejected) + FactoryBot.create(:story, project: project, status: :pending) get :export, params: {project_id: project.id} expect(response).to have_http_status(:ok) @@ -186,11 +188,13 @@ end context "with comments" do - it "exports a CSV file" do + it "exports a CSV file with approved stories only" do user = FactoryBot.create(:user) - story2 = FactoryBot.create(:story, project: project) - story3 = FactoryBot.create(:story, project: project) - story4 = FactoryBot.create(:story, project: project) + story2 = FactoryBot.create(:story, project: project, status: :approved) + story3 = FactoryBot.create(:story, project: project, status: :approved) + story4 = FactoryBot.create(:story, project: project, status: :approved) + FactoryBot.create(:story, project: project, status: :rejected) + FactoryBot.create(:story, project: project, status: :pending) comment1 = FactoryBot.create(:comment, user: user, story: story) comment1_2 = FactoryBot.create(:comment, user: user, story: story) comment2_1 = FactoryBot.create(:comment, user: user, story: story2) diff --git a/spec/features/projects_manage_spec.rb b/spec/features/projects_manage_spec.rb index 1db8e1c2..38e0e992 100644 --- a/spec/features/projects_manage_spec.rb +++ b/spec/features/projects_manage_spec.rb @@ -141,10 +141,12 @@ context "import & Export" do before do - project.stories.create(title: "php upgrade", description: "quick php upgrade") + project.stories.create(title: "php upgrade", description: "quick php upgrade", status: :approved) end it "allows me to export a CSV", js: false do + project.stories.create(title: "pending story", description: "pending stories don't export", status: :pending) + project.stories.create(title: "rejected story", description: "rejected stories don't export", status: :rejected) visit project_path(id: project.id) find("#import-export").click