Commit 7538ae81 authored by James Edwards-Jones's avatar James Edwards-Jones

CSV format supported in Issues#index

parent 8800c0da
......@@ -51,6 +51,7 @@ class Projects::IssuesController < Projects::ApplicationController
respond_to do |format|
format.html
format.atom { render layout: false }
format.csv
format.json do
render json: {
html: view_to_html_string("projects/issues/_issues"),
......
columns = {
'Issue ID' => 'iid',
'Title' => 'title',
'State' => 'state',
'Description' => 'description',
'Author Id' => 'author_id',
'Assignee Id' => 'assignee_id',
'Due Date' => 'due_date',
'Created At' => 'created_at',
'Updated At' => 'updated_at'
}
CSV.generate do |csv|
csv << columns.keys
@issues.pluck(*columns.values).each do |row|
csv << row
end
end
require 'spec_helper'
describe 'Issues csv', feature: true do
let(:user) { create(:user) }
let(:project) { create(:project, :public) }
let!(:issue) { create(:issue, project: project) }
before do
login_as(user)
visit namespace_project_issues_path(project.namespace, project, format: :csv)
end
it 'downloads as a file' do
expect(page.response_headers['Content-Type']).to include('csv')
end
it 'includes title' do
expect(csv[0]['Title']).to eq issue.title
end
it 'includes description' do
expect(csv[0]['Description']).to eq issue.description
end
end
module CsvHelpers
def csv
CSV.parse(body, headers: true)
end
end
RSpec.configure do |config|
config.include CsvHelpers, type: :feature
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment