Skip to content

Commit

Permalink
ROAD-609: Export approved stories only
Browse files Browse the repository at this point in the history
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
  • Loading branch information
fbuys committed Jan 23, 2024
1 parent 7b52e9f commit 54f2758
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
1 change: 1 addition & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,7 @@ GEM

PLATFORMS
x86_64-darwin-21
x86_64-darwin-22
x86_64-linux

DEPENDENCIES
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/stories_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand All @@ -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
Expand Down
16 changes: 10 additions & 6 deletions spec/controllers/stories_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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)

Expand All @@ -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)
Expand Down

0 comments on commit 54f2758

Please sign in to comment.