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 24, 2024
1 parent 7b52e9f commit 230be4d
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 9 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
4 changes: 3 additions & 1 deletion spec/features/projects_manage_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 230be4d

Please sign in to comment.