kanbanworkflowstimelinescrumrubyroadmapproject-planningproject-managementopenprojectangularissue-trackerifcgantt-chartganttbug-trackerboardsbcf
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
227 lines
7.8 KiB
227 lines
7.8 KiB
11 years ago
|
#-- copyright
|
||
11 years ago
|
# OpenProject Documents Plugin
|
||
11 years ago
|
#
|
||
11 years ago
|
# Former OpenProject Core functionality extracted into a plugin.
|
||
|
#
|
||
|
# Copyright (C) 2009-2014 the OpenProject Foundation (OPF)
|
||
11 years ago
|
#
|
||
|
# This program is free software; you can redistribute it and/or
|
||
|
# modify it under the terms of the GNU General Public License version 3.
|
||
|
#
|
||
11 years ago
|
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
|
||
|
# Copyright (C) 2006-2013 Jean-Philippe Lang
|
||
|
# Copyright (C) 2010-2013 the ChiliProject Team
|
||
|
#
|
||
|
# This program is free software; you can redistribute it and/or
|
||
|
# modify it under the terms of the GNU General Public License
|
||
|
# as published by the Free Software Foundation; either version 2
|
||
|
# of the License, or (at your option) any later version.
|
||
|
#
|
||
|
# This program is distributed in the hope that it will be useful,
|
||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
|
# GNU General Public License for more details.
|
||
|
#
|
||
|
# You should have received a copy of the GNU General Public License
|
||
|
# along with this program; if not, write to the Free Software
|
||
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||
|
#
|
||
11 years ago
|
# See doc/COPYRIGHT.rdoc for more details.
|
||
|
#++
|
||
|
|
||
9 years ago
|
require File.dirname(__FILE__) + '/../spec_helper'
|
||
11 years ago
|
|
||
|
describe DocumentsController do
|
||
|
|
||
|
render_views
|
||
|
|
||
7 years ago
|
let(:admin) { FactoryBot.create(:admin)}
|
||
|
let(:project) { FactoryBot.create(:project, name: "Test Project")}
|
||
|
let(:user) { FactoryBot.create(:user)}
|
||
|
let(:role) { FactoryBot.create(:role, permissions: [:view_documents]) }
|
||
11 years ago
|
|
||
9 years ago
|
let(:default_category){
|
||
7 years ago
|
FactoryBot.create(:document_category, project: project, name: "Default Category")
|
||
9 years ago
|
}
|
||
11 years ago
|
|
||
9 years ago
|
let(:document) {
|
||
7 years ago
|
FactoryBot.create(:document, title: "Sample Document", project: project, category: default_category)
|
||
9 years ago
|
}
|
||
|
|
||
11 years ago
|
before do
|
||
10 years ago
|
allow(User).to receive(:current).and_return admin
|
||
11 years ago
|
end
|
||
|
|
||
|
describe "index" do
|
||
9 years ago
|
let(:long_description) {
|
||
|
<<-LOREM.strip_heredoc
|
||
|
Lorem ipsum dolor sit amet, consectetur adipiscing elit.\
|
||
|
Ut egestas, mi vehicula varius varius, ipsum massa fermentum orci,\
|
||
|
eget tristique ante sem vel mi. Nulla facilisi.\
|
||
|
Donec enim libero, luctus ac sagittis sit amet, vehicula sagittis magna.\
|
||
|
Duis ultrices molestie ante, eget scelerisque sem iaculis vitae.\
|
||
|
Etiam fermentum mauris vitae metus pharetra condimentum fermentum est pretium.\
|
||
|
Proin sollicitudin elementum quam quis pharetra.\
|
||
|
Aenean facilisis nunc quis elit volutpat mollis.\
|
||
|
Aenean eleifend varius euismod. Ut dolor est, congue eget dapibus eget, elementum eu odio.\
|
||
|
Integer et lectus neque, nec scelerisque nisi. EndOfLineHere
|
||
11 years ago
|
|
||
9 years ago
|
Praesent a nunc lorem, ac porttitor eros.
|
||
|
LOREM
|
||
|
}
|
||
11 years ago
|
|
||
9 years ago
|
before do
|
||
|
document.update_attributes(description: long_description)
|
||
7 years ago
|
get :index, params: { project_id: project.identifier }
|
||
11 years ago
|
end
|
||
|
|
||
|
it "should render the index-template successfully" do
|
||
|
expect(response).to be_success
|
||
|
expect(response).to render_template("index")
|
||
|
end
|
||
|
|
||
|
it "should group documents by category, if no other sorting is given " do
|
||
9 years ago
|
expect(assigns(:grouped)).not_to be_nil
|
||
11 years ago
|
expect(assigns(:grouped).keys.map(&:name)).to eql [default_category.name]
|
||
|
end
|
||
|
|
||
|
it "should render documents with long descriptions properly" do
|
||
|
|
||
10 years ago
|
expect(response.body).to have_css('.wiki p')
|
||
|
expect(response.body).to have_css('.wiki p', text: (document.description.split("\n").first + '...'))
|
||
|
expect(response.body).to have_css('.wiki p', text: /EndOfLineHere.../)
|
||
11 years ago
|
end
|
||
|
|
||
|
end
|
||
|
|
||
9 years ago
|
describe 'new' do
|
||
|
before do
|
||
7 years ago
|
get :new, params: { project_id: project.id }
|
||
9 years ago
|
end
|
||
|
|
||
|
it 'show the new document form' do
|
||
|
expect(response).to render_template(partial: 'documents/_form')
|
||
|
end
|
||
|
end
|
||
11 years ago
|
|
||
|
describe "create" do
|
||
|
|
||
9 years ago
|
let(:document_attributes) {
|
||
7 years ago
|
FactoryBot.attributes_for(:document, title: "New Document",
|
||
9 years ago
|
project_id: project.id,
|
||
|
category_id: default_category.id)
|
||
|
}
|
||
11 years ago
|
|
||
|
|
||
9 years ago
|
before do
|
||
11 years ago
|
ActionMailer::Base.deliveries.clear
|
||
11 years ago
|
allow(Setting).to receive(:notified_events).and_return(Setting.notified_events.dup << 'document_added')
|
||
11 years ago
|
end
|
||
|
|
||
|
it "should create a new document with valid arguments" do
|
||
|
expect do
|
||
7 years ago
|
post :create, params: { project_id: project.identifier,
|
||
7 years ago
|
document: FactoryBot.attributes_for(:document, title: "New Document",
|
||
7 years ago
|
project_id: project.id,
|
||
|
category_id: default_category.id
|
||
|
) }
|
||
11 years ago
|
|
||
|
end.to change{Document.count}.by 1
|
||
|
end
|
||
|
|
||
|
it "should create a new document with valid arguments" do
|
||
|
expect do
|
||
|
post :create,
|
||
7 years ago
|
params: {
|
||
|
project_id: project.identifier,
|
||
|
document: document_attributes
|
||
|
}
|
||
11 years ago
|
end.to change{Document.count}.by 1
|
||
|
end
|
||
|
|
||
|
describe "with attachments" do
|
||
|
|
||
9 years ago
|
before do
|
||
11 years ago
|
notify_project = project
|
||
7 years ago
|
FactoryBot.create(:member, project: notify_project, user: user, roles: [role])
|
||
11 years ago
|
|
||
|
post :create,
|
||
7 years ago
|
params: {
|
||
|
project_id: notify_project.identifier,
|
||
7 years ago
|
document: FactoryBot.attributes_for(:document, title: "New Document",
|
||
7 years ago
|
project_id: notify_project.id,
|
||
|
category_id: default_category.id
|
||
|
),
|
||
|
attachments: { '1' => { description: "sample file", file: file_attachment } }
|
||
|
}
|
||
11 years ago
|
end
|
||
|
|
||
|
it "should add an attachment" do
|
||
|
document = Document.last
|
||
|
|
||
|
expect(document.attachments.count).to eql 1
|
||
|
attachment = document.attachments.first
|
||
|
expect(attachment.description).to eql "sample file"
|
||
|
expect(attachment.filename).to eql "testfile.txt"
|
||
|
end
|
||
|
|
||
|
it "should redirect to the documents-page" do
|
||
|
expect(response).to redirect_to project_documents_path(project.identifier)
|
||
|
end
|
||
|
|
||
|
it "should send out mails with notifications to members of the project with :view_documents-permission" do
|
||
|
expect(ActionMailer::Base.deliveries.size).to eql 1
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
|
||
9 years ago
|
describe 'show' do
|
||
|
before do
|
||
|
document
|
||
7 years ago
|
get :show, params: { id: document.id }
|
||
9 years ago
|
end
|
||
11 years ago
|
|
||
9 years ago
|
it "should delete the document and redirect back to documents-page of the project" do
|
||
|
expect(response).to be_success
|
||
|
expect(response).to render_template('show')
|
||
|
end
|
||
|
end
|
||
|
|
||
|
describe '#add_attachment' do
|
||
|
before do
|
||
|
document
|
||
|
post :add_attachment,
|
||
7 years ago
|
params: {
|
||
|
id: document.id,
|
||
|
attachments: { '1' => { description: "sample file", file: file_attachment } }
|
||
|
}
|
||
9 years ago
|
end
|
||
11 years ago
|
|
||
9 years ago
|
it "should delete the document and redirect back to documents-page of the project" do
|
||
|
expect(response).to be_redirect
|
||
|
document.reload
|
||
|
expect(document.attachments.length).to eq(1)
|
||
|
end
|
||
|
end
|
||
|
|
||
|
describe "destroy" do
|
||
9 years ago
|
before do
|
||
11 years ago
|
document
|
||
|
end
|
||
|
|
||
|
it "should delete the document and redirect back to documents-page of the project" do
|
||
|
expect{
|
||
7 years ago
|
delete :destroy, params: { id: document.id }
|
||
11 years ago
|
}.to change{Document.count}.by -1
|
||
|
|
||
|
expect(response).to redirect_to "/projects/#{project.identifier}/documents"
|
||
9 years ago
|
expect{Document.find(document.id)}.to raise_error ActiveRecord::RecordNotFound
|
||
11 years ago
|
end
|
||
|
end
|
||
|
|
||
|
def file_attachment
|
||
|
test_document = "#{OpenProject::Documents::Engine.root}/spec/assets/attachments/testfile.txt"
|
||
|
Rack::Test::UploadedFile.new(test_document, "text/plain")
|
||
|
end
|
||
|
end
|