|
|
@ -28,8 +28,8 @@ |
|
|
|
# |
|
|
|
# |
|
|
|
# See doc/COPYRIGHT.rdoc for more details. |
|
|
|
# See doc/COPYRIGHT.rdoc for more details. |
|
|
|
#++ |
|
|
|
#++ |
|
|
|
require File.dirname(__FILE__) + '/../spec_helper' |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
require File.dirname(__FILE__) + '/../spec_helper' |
|
|
|
|
|
|
|
|
|
|
|
describe DocumentsController do |
|
|
|
describe DocumentsController do |
|
|
|
|
|
|
|
|
|
|
@ -38,10 +38,11 @@ describe DocumentsController do |
|
|
|
let(:admin) { FactoryGirl.create(:admin)} |
|
|
|
let(:admin) { FactoryGirl.create(:admin)} |
|
|
|
let(:project) { FactoryGirl.create(:project, name: "Test Project")} |
|
|
|
let(:project) { FactoryGirl.create(:project, name: "Test Project")} |
|
|
|
let(:user) { FactoryGirl.create(:user)} |
|
|
|
let(:user) { FactoryGirl.create(:user)} |
|
|
|
let(:role) { FactoryGirl.create(:role, :permissions => [:view_documents]) } |
|
|
|
let(:role) { FactoryGirl.create(:role, permissions: [:view_documents]) } |
|
|
|
|
|
|
|
|
|
|
|
let(:default_category){ FactoryGirl.create(:document_category, project: project, name: "Default Category")} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let(:default_category){ |
|
|
|
|
|
|
|
FactoryGirl.create(:document_category, project: project, name: "Default Category") |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
before do |
|
|
|
before do |
|
|
|
allow(User).to receive(:current).and_return admin |
|
|
|
allow(User).to receive(:current).and_return admin |
|
|
@ -49,28 +50,27 @@ describe DocumentsController do |
|
|
|
|
|
|
|
|
|
|
|
describe "index" do |
|
|
|
describe "index" do |
|
|
|
|
|
|
|
|
|
|
|
let(:document) { FactoryGirl.create(:document, title: "Sample Document", project: project, category: default_category) } |
|
|
|
let(:document) { |
|
|
|
|
|
|
|
FactoryGirl.create(:document, title: "Sample Document", project: project, category: default_category) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
before :each do |
|
|
|
before do |
|
|
|
document.update_attributes(description:<<LOREM) |
|
|
|
document.update_attributes(description:<<LOREM) |
|
|
|
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 |
|
|
|
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 |
|
|
|
|
|
|
|
|
|
|
|
Vestibulum non velit mi. Aliquam scelerisque libero ut nulla fringilla a sollicitudin magna rhoncus. Praesent a nunc lorem, ac porttitor eros. Sed ac diam nec neque interdum adipiscing quis quis justo. Donec arcu nunc, fringilla eu dictum at, venenatis ac sem. Vestibulum quis elit urna, ac mattis sapien. Lorem ipsum dolor sit amet, consectetur adipiscing elit. |
|
|
|
Vestibulum non velit mi. Aliquam scelerisque libero ut nulla fringilla a sollicitudin magna rhoncus. Praesent a nunc lorem, ac porttitor eros. Sed ac diam nec neque interdum adipiscing quis quis justo. Donec arcu nunc, fringilla eu dictum at, venenatis ac sem. Vestibulum quis elit urna, ac mattis sapien. Lorem ipsum dolor sit amet, consectetur adipiscing elit. |
|
|
|
LOREM |
|
|
|
LOREM |
|
|
|
|
|
|
|
|
|
|
|
get :index, :project_id => project.identifier |
|
|
|
get :index, project_id: project.identifier |
|
|
|
|
|
|
|
|
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
it "should render the index-template successfully" do |
|
|
|
it "should render the index-template successfully" do |
|
|
|
|
|
|
|
|
|
|
|
expect(response).to be_success |
|
|
|
expect(response).to be_success |
|
|
|
expect(response).to render_template("index") |
|
|
|
expect(response).to render_template("index") |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
it "should group documents by category, if no other sorting is given " do |
|
|
|
it "should group documents by category, if no other sorting is given " do |
|
|
|
|
|
|
|
expect(assigns(:grouped)).not_to be_nil |
|
|
|
expect(assigns(:grouped)).not_to be_nil |
|
|
|
|
|
|
|
expect(assigns(:grouped).keys.map(&:name)).to eql [default_category.name] |
|
|
|
expect(assigns(:grouped).keys.map(&:name)).to eql [default_category.name] |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
@ -79,7 +79,6 @@ LOREM |
|
|
|
expect(response.body).to have_css('.wiki p') |
|
|
|
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: (document.description.split("\n").first + '...')) |
|
|
|
expect(response.body).to have_css('.wiki p', text: /EndOfLineHere.../) |
|
|
|
expect(response.body).to have_css('.wiki p', text: /EndOfLineHere.../) |
|
|
|
|
|
|
|
|
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
end |
|
|
|
end |
|
|
@ -87,20 +86,25 @@ LOREM |
|
|
|
|
|
|
|
|
|
|
|
describe "create" do |
|
|
|
describe "create" do |
|
|
|
|
|
|
|
|
|
|
|
let(:document_attributes) { FactoryGirl.attributes_for(:document, title: "New Document", project_id: project.id, category_id: default_category.id) } |
|
|
|
let(:document_attributes) { |
|
|
|
|
|
|
|
FactoryGirl.attributes_for(:document, title: "New Document", |
|
|
|
|
|
|
|
project_id: project.id, |
|
|
|
|
|
|
|
category_id: default_category.id) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
before :each do |
|
|
|
before do |
|
|
|
ActionMailer::Base.deliveries.clear |
|
|
|
ActionMailer::Base.deliveries.clear |
|
|
|
allow(Setting).to receive(:notified_events).and_return(Setting.notified_events.dup << 'document_added') |
|
|
|
allow(Setting).to receive(:notified_events).and_return(Setting.notified_events.dup << 'document_added') |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
it "should create a new document with valid arguments" do |
|
|
|
it "should create a new document with valid arguments" do |
|
|
|
expect do |
|
|
|
expect do |
|
|
|
post :create, :project_id => project.identifier, |
|
|
|
post :create, project_id: project.identifier, |
|
|
|
:document => FactoryGirl.attributes_for(:document, title: "New Document", project_id: project.id, category_id: default_category.id) |
|
|
|
document: FactoryGirl.attributes_for(:document, title: "New Document", |
|
|
|
#:attachments => {'1' => FactoryGirl.attributes_for(:attachment, :author => admin)} |
|
|
|
project_id: project.id, |
|
|
|
|
|
|
|
category_id: default_category.id |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
end.to change{Document.count}.by 1 |
|
|
|
end.to change{Document.count}.by 1 |
|
|
|
end |
|
|
|
end |
|
|
@ -108,22 +112,24 @@ LOREM |
|
|
|
it "should create a new document with valid arguments" do |
|
|
|
it "should create a new document with valid arguments" do |
|
|
|
expect do |
|
|
|
expect do |
|
|
|
post :create, |
|
|
|
post :create, |
|
|
|
:project_id => project.identifier, |
|
|
|
project_id: project.identifier, |
|
|
|
:document => document_attributes |
|
|
|
document: document_attributes |
|
|
|
|
|
|
|
|
|
|
|
end.to change{Document.count}.by 1 |
|
|
|
end.to change{Document.count}.by 1 |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
describe "with attachments" do |
|
|
|
describe "with attachments" do |
|
|
|
|
|
|
|
|
|
|
|
before :each do |
|
|
|
before do |
|
|
|
notify_project = project |
|
|
|
notify_project = project |
|
|
|
notify_member = FactoryGirl.create(:member, :project => notify_project, :user => user, :roles => [role]) |
|
|
|
FactoryGirl.create(:member, project: notify_project, user: user, roles: [role]) |
|
|
|
|
|
|
|
|
|
|
|
post :create, |
|
|
|
post :create, |
|
|
|
:project_id => notify_project.identifier, |
|
|
|
project_id: notify_project.identifier, |
|
|
|
:document => FactoryGirl.attributes_for(:document, title: "New Document", project_id: notify_project.id, category_id: default_category.id), |
|
|
|
document: FactoryGirl.attributes_for(:document, title: "New Document", |
|
|
|
:attachments => {'1' => {description: "sample file", file: file_attachment}} |
|
|
|
project_id: notify_project.id, |
|
|
|
|
|
|
|
category_id: default_category.id |
|
|
|
|
|
|
|
), |
|
|
|
|
|
|
|
attachments: { '1' => { description: "sample file", file: file_attachment } } |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
it "should add an attachment" do |
|
|
|
it "should add an attachment" do |
|
|
@ -140,28 +146,24 @@ LOREM |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
it "should send out mails with notifications to members of the project with :view_documents-permission" do |
|
|
|
it "should send out mails with notifications to members of the project with :view_documents-permission" do |
|
|
|
|
|
|
|
|
|
|
|
document = Document.last |
|
|
|
|
|
|
|
expect(ActionMailer::Base.deliveries.size).to eql 1 |
|
|
|
expect(ActionMailer::Base.deliveries.size).to eql 1 |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
describe "destroy" do |
|
|
|
describe "destroy" do |
|
|
|
|
|
|
|
|
|
|
|
let(:document) { FactoryGirl.create(:document, title: "Sample Document", project: project, category: default_category) } |
|
|
|
let(:document) { |
|
|
|
|
|
|
|
FactoryGirl.create(:document, title: "Sample Document", project: project, category: default_category) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
before :each do |
|
|
|
before do |
|
|
|
document |
|
|
|
document |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
it "should delete the document and redirect back to documents-page of the project" do |
|
|
|
it "should delete the document and redirect back to documents-page of the project" do |
|
|
|
expect{ |
|
|
|
expect{ |
|
|
|
delete :destroy, :id => document.id |
|
|
|
delete :destroy, id: document.id |
|
|
|
}.to change{Document.count}.by -1 |
|
|
|
}.to change{Document.count}.by -1 |
|
|
|
|
|
|
|
|
|
|
|
expect(response).to redirect_to "/projects/#{project.identifier}/documents" |
|
|
|
expect(response).to redirect_to "/projects/#{project.identifier}/documents" |
|
|
@ -169,16 +171,8 @@ LOREM |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def file_attachment |
|
|
|
def file_attachment |
|
|
|
test_document = "#{OpenProject::Documents::Engine.root}/spec/assets/attachments/testfile.txt" |
|
|
|
test_document = "#{OpenProject::Documents::Engine.root}/spec/assets/attachments/testfile.txt" |
|
|
|
Rack::Test::UploadedFile.new(test_document, "text/plain") |
|
|
|
Rack::Test::UploadedFile.new(test_document, "text/plain") |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|