Commit f01f2d40 authored by James Edwards-Jones's avatar James Edwards-Jones

Moved CSV content tests from feature specs

parent 2ababc97
require 'spec_helper'
describe 'Issues csv', feature: true do
let(:user) { create(:user) }
let(:user) { create(:user) }
let(:project) { create(:empty_project, :public) }
let(:milestone) { create(:milestone, title: 'v1.0', project: project) }
let(:idea_label) { create(:label, project: project, title: 'Idea') }
......@@ -10,7 +10,7 @@ describe 'Issues csv', feature: true do
before { login_as(user) }
def request_csv(params={})
def request_csv(params = {})
visit namespace_project_issues_path(project.namespace, project, params)
click_on 'Download CSV'
click_on 'Request export'
......@@ -20,6 +20,10 @@ describe 'Issues csv', feature: true do
ActionMailer::Base.deliveries.last.attachments.first
end
def csv
CSV.parse(attachment.decode_body, headers: true)
end
it 'triggers an email export' do
expect(ExportCsvWorker).to receive(:perform_async).with(user.id, project.id, hash_including(project_id: project.id))
......@@ -58,18 +62,8 @@ describe 'Issues csv', feature: true do
expect(csv.count).to eq 0
end
def visit_project_csv
#TODO: Move these specs elsewhere
visit export_csv_namespace_project_issues_path(project.namespace, project, method: :post)
end
def csv
CSV.parse(attachment.decode_body, headers: true)
end
it 'avoids excessive database calls' do
control_count = ActiveRecord::QueryRecorder.new{ visit_project_csv }.count
control_count = ActiveRecord::QueryRecorder.new{ request_csv }.count
create_list(:labeled_issue,
10,
project: project,
......@@ -77,68 +71,6 @@ describe 'Issues csv', feature: true do
author: user,
milestone: milestone,
labels: [feature_label, idea_label])
expect{ visit_project_csv }.not_to exceed_query_limit(control_count)
end
context 'includes' do
before do
issue.update!(milestone: milestone,
assignee: user,
description: 'Issue with details',
due_date: DateTime.new(2014, 3, 2),
created_at: DateTime.new(2015, 4, 3, 2, 1, 0),
updated_at: DateTime.new(2016, 5, 4, 3, 2, 1),
labels: [feature_label, idea_label])
visit_project_csv
end
specify 'title' do
expect(csv[0]['Title']).to eq issue.title
end
specify 'description' do
expect(csv[0]['Description']).to eq issue.description
end
specify 'author name' do
expect(csv[0]['Author']).to eq issue.author_name
end
specify 'assignee name' do
expect(csv[0]['Assignee']).to eq issue.assignee_name
end
specify 'confidential' do
expect(csv[0]['Confidential']).to eq 'false'
end
specify 'milestone' do
expect(csv[0]['Milestone']).to eq issue.milestone.title
end
specify 'labels' do
expect(csv[0]['Labels']).to eq 'Feature,Idea'
end
specify 'due_date' do
expect(csv[0]['Due Date']).to eq '2014-03-02'
end
specify 'created_at' do
expect(csv[0]['Created At (UTC)']).to eq '2015-04-03 02:01:00'
end
specify 'updated_at' do
expect(csv[0]['Updated At (UTC)']).to eq '2016-05-04 03:02:01'
end
end
context 'with minimal details' do
it 'renders labels as nil' do
visit_project_csv
expect(csv[0]['Labels']).to eq nil
end
expect{ request_csv }.not_to exceed_query_limit(control_count + 5)
end
end
......@@ -8,11 +8,16 @@ describe Notify do
describe 'csv export email' do
let(:user) { create(:user) }
let(:empty_project) { create(:empty_project) }
subject { Notify.issues_csv_email(user, project, "dummy content") }
subject { Notify.issues_csv_email(user, empty_project, "dummy content", 3) }
it 'attachment has csv mime type' do
attachment = subject.attachments.first
expect(attachment.mime_type).to eq 'text/csv'
end
it 'mentions number of issues and project name' do
expect(subject).to have_content '3'
expect(subject).to have_content empty_project.name
end
end
end
require 'spec_helper'
describe Issues::ExportCsvService, services: true do
let(:project) { create(:project) }
let!(:issues) { create_list(:issue, 2, project: project) }
let(:user) { create(:user) }
let(:project) { create(:empty_project, :public) }
let!(:issue) { create(:issue, project: project, author: user) }
let(:subject) { described_class.new(Issue.all) }
let(:email) { subject.email(user, project) }
it 'renders csv to string' do
expect(subject.render).to be_a String
end
describe '#email' do
let(:user) { double(notification_email: 'notification@example.com') }
it 'emails csv' do
expect{ subject.email(user, project) }.to change(ActionMailer::Base.deliveries, :count)
end
it 'emails csv' do
expect{ email }.to change(ActionMailer::Base.deliveries, :count)
end
end
it 'renders csv to temporary file'
it 'includes relevent details (move from feature spec)'
def csv
attachment = email.attachments[0]
CSV.parse(attachment.decode_body, headers: true)
end
context 'includes' do
let(:milestone) { create(:milestone, title: 'v1.0', project: project) }
let(:idea_label) { create(:label, project: project, title: 'Idea') }
let(:feature_label) { create(:label, project: project, title: 'Feature') }
before do
issue.update!(milestone: milestone,
assignee: user,
description: 'Issue with details',
due_date: DateTime.new(2014, 3, 2),
created_at: DateTime.new(2015, 4, 3, 2, 1, 0),
updated_at: DateTime.new(2016, 5, 4, 3, 2, 1),
labels: [feature_label, idea_label])
end
specify 'title' do
expect(csv[0]['Title']).to eq issue.title
end
specify 'description' do
expect(csv[0]['Description']).to eq issue.description
end
specify 'author name' do
expect(csv[0]['Author']).to eq issue.author_name
end
specify 'assignee name' do
expect(csv[0]['Assignee']).to eq issue.assignee_name
end
specify 'confidential' do
expect(csv[0]['Confidential']).to eq 'false'
end
specify 'milestone' do
expect(csv[0]['Milestone']).to eq issue.milestone.title
end
specify 'labels' do
expect(csv[0]['Labels']).to eq 'Feature,Idea'
end
specify 'due_date' do
expect(csv[0]['Due Date']).to eq '2014-03-02'
end
specify 'created_at' do
expect(csv[0]['Created At (UTC)']).to eq '2015-04-03 02:01:00'
end
specify 'updated_at' do
expect(csv[0]['Updated At (UTC)']).to eq '2016-05-04 03:02:01'
end
end
context 'with minimal details' do
it 'renders labels as nil' do
expect(csv[0]['Labels']).to eq nil
end
end
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