From 54f2758eb2888e2b335209cb4e835aa717349c86 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 ++++++++++------ 3 files changed, 13 insertions(+), 8 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)