Merge branch 'release/5.0' into dev

pull/6827/head
Oliver Günther 9 years ago
commit 9282a7946a
  1. 111
      .travis.yml
  2. 7
      Gemfile.plugins
  3. 6
      app/controllers/documents_controller.rb
  4. 4
      app/models/document_category.rb
  5. 4
      app/models/document_observer.rb
  6. 2
      app/views/documents/edit.html.erb
  7. 2
      app/views/documents/new.html.erb
  8. 4
      app/views/documents/show.html.erb
  9. 6
      config/routes.rb
  10. 2
      lib/open_project/documents/engine.rb
  11. 2
      lib/open_project/documents/patches/custom_fields_helper_patch.rb
  12. 47
      spec/controllers/documents_controller_spec.rb
  13. 7
      spec/models/document_observer_spec.rb

@ -0,0 +1,111 @@
#-- copyright
# OpenProject is a project management system.
# Copyright (C) 2012-2015 the OpenProject Foundation (OPF)
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License version 3.
#
# 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.
#
# See doc/COPYRIGHT.rdoc for more details.
#++
# Travis configuration based on the respective OpenProject core configuration.
# Everything save for the matrix section and additional `before_install`
# instructions is copied and pasted from the core.
language: ruby
rvm:
- 2.2.3
sudo: false
cache:
- bundler: true
- directories:
- frontend/node_modules
- frontend/bower_components
bundler_args: --without development production
branches:
only:
- master
- dev
- /^(stable|release)\/.*$/
env:
global:
- CI=true
- RAILS_ENV=test
- COVERAGE=true
matrix:
- "TEST_SUITE=plugins:spec DB=mysql"
- "TEST_SUITE=plugins:cucumber DB=mysql"
before_install:
# Custom plugin instructions follow.
# Move the plugin into a subfolder. The plugin-provided Gemfile.plugins
# must refer to this folder.
- mkdir -p plugins/this
- echo `ls -a | tail -n+3 | grep -v plugins` plugins/this/ | xargs mv
# Get OpenProject.
# Doing the fetch detour as you cannot clone into the current directory.
- git init
- git remote add openproject https://github.com/opf/openproject.git
- git fetch --depth=1 openproject
- git checkout openproject/stable/5
# End of custom plugin instructions.
- "echo `firefox -v`"
- "export DISPLAY=:99.0"
- "/sbin/start-stop-daemon --start -v --pidfile ./tmp/custom_xvfb_99.pid --make-pidfile --background --exec /usr/bin/Xvfb -- :99 -ac -screen 0 1920x1080x16"
- "echo `xdpyinfo -display :99 | grep 'dimensions' | awk '{ print $2 }'`"
- travis_retry npm install
# We need phantomjs 2.0 to get tests passing
- mkdir travis-phantomjs
- wget https://s3.amazonaws.com/travis-phantomjs/phantomjs-2.0.0-ubuntu-12.04.tar.bz2 -O $PWD/travis-phantomjs/phantomjs-2.0.0-ubuntu-12.04.tar.bz2
- tar -xvf $PWD/travis-phantomjs/phantomjs-2.0.0-ubuntu-12.04.tar.bz2 -C $PWD/travis-phantomjs
- export PATH=$PWD/travis-phantomjs:$PATH
before_script:
- sh script/ci_setup.sh $DB
script:
- sh script/ci_runner.sh $TEST_SUITE $GROUP_SIZE $GROUP
notifications:
email: false
slack:
secure: "a+I0uMgXgrDd3aitr2yhXrh7g/UOUTwoDVElunY7gYdrM+gpZ6RE1AP4/Q++hERBCs7rUBzmb//zxGTcc8Nw4nGqZOmPOMIsAoD49UupGLUzHbxzKlpwdBcwh77fq3rYwkjZjE/H1qiElPT7v6qyWMSdNGlj/bAB74eD7Zl3S5cMRvZ1whbSg2GA2v6ZqtXaKfrSFrPRzsIOBXs99OxWNWAsUGpEwTYac7wb6rdMJkBbzosp4gP99mGvQArEzo0nrIQgRH8W4Q6iLnrpX0g5uKccWl1u/G2bmH8L4F50ce4uuUE+TtHO/nfNFnb2KuDR4QyoccQQbGHXL/jaaAZXG/gzs5Hmru2Thaym43fSwxos80xmZs1vqB/rXE+Rg9qXcCKyyX31zjSI/iW4wS015fz8MKVX6qDg49epaw1ovn0AOYrvTd94GV6RX6eJ3/l+KJJHSKaaLP/713h11LWx/S27tiB40fboXQ68YzIQCuahRUEHUfhU3P10Wf9y2fdDsthtHHSrOJMQ3Ii/Jm3KQm6bE5RWORdHvc/sF2WLfLmJ627j9JhWYYi5mDKJ9AeMWtZNHreU0mM27OUgfhiW11ItKgpwQPEiiicrlYRrMmK+9hc9cym+8tRM+wEth1xhIkfgQFtngONKjv361Wt3JifxM79+bn0IyF72vAVNy8k="
addons:
firefox: "38.0esr"
postgresql: "9.3"
# Disabling coverage reporting until CodeClimate supports merging results from multiple partial tests
# code_climate:
# repo_token:
# secure: "W/lyd8Ud18GRASuVShsIKa2MRHhxjh8WICMQ4WKr68qt0X0Tlp7Bclv4ReiEgiQeKsIoJJy5FfJfINdAT8A4sy2JbrLeISShcIU7Kqpfh6DSLNoRAuLz5P7EXMNFns1gBKCmrSzcB+9ksuTLyTCKkjUcj1NbJzGqpB4jSTecAdg="

@ -0,0 +1,7 @@
# Used by travis to bundle this plugin with the OpenProject core.
# The tested plugin will be moved to the path `./plugins/this`
# whereas OpenProject will be checked out to `.`.
gem 'openproject-documents', path: 'plugins/this'
# If the plugin has any dependencies declare them here:

@ -110,12 +110,8 @@ class DocumentsController < ApplicationController
end
private
def document_params
params.require(:document).permit('category_id', 'title', 'description')
end
private
def document_params
params.require(:document).permit('category_id', 'title', 'description')
params.fetch(:document, {}).permit('category_id', 'title', 'description')
end
end

@ -33,10 +33,10 @@
class DocumentCategory < Enumeration
has_many :documents, foreign_key: 'category_id'
OPTION_NAME = :enumeration_doc_categories
OptionName = :enumeration_doc_categories
def option_name
OPTION_NAME
OptionName
end
def objects_count

@ -31,13 +31,11 @@
#++
class DocumentObserver < ActiveRecord::Observer
def after_create(document)
return unless Setting.notified_events.include?('document_added')
document.recipients.each do |user|
DocumentsMailer.document_added(user, document).deliver
DocumentsMailer.document_added(user, document).deliver_now
end
end
end

@ -34,5 +34,5 @@ See doc/COPYRIGHT.rdoc for more details.
<%= labelled_tabular_form_for @document, url: document_path(@document), method: 'PATCH' do |f| -%>
<%= render partial: "documents/form", locals: { f: f } %>
<%= styled_button_tag l(:button_save), class: "-highlight -with-icon icon-yes" %>
<%= styled_button_tag l(:button_save), class: "-highlight -with-icon icon-checkmark" %>
<% end %>

@ -34,7 +34,7 @@ See doc/COPYRIGHT.rdoc for more details.
<%= labelled_tabular_form_for @document, url: project_documents_path(@project), html: { multipart: true } do |f| -%>
<%= render :partial => 'documents/form', locals: { f: f } %>
<%= render :partial => 'attachments/form' %>
<%= styled_button_tag l(:button_create), class: "-highlight -with-icon icon-yes" %>
<%= styled_button_tag l(:button_create), class: "-highlight -with-icon icon-checkmark" %>
<% end %>

@ -58,11 +58,11 @@ See doc/COPYRIGHT.rdoc for more details.
<% if authorize_for('documents', 'add_attachment') %>
<p><%= link_to l(:label_attachment_new), {}, :onclick => "Element.show('add_attachment_form'); Element.hide(this); Element.scrollTo('add_attachment_form'); return false;",
:id => 'attach_files_link' %></p>
<%= form_tag({ :controller => '/documents', :action => 'add_attachment', :id => @document }, :multipart => true, :id => "add_attachment_form", :style => "display:none;") do %>
<%= form_tag(add_attachment_document_path(@document), method: :post, multipart: true, :id => "add_attachment_form", :style => "display:none;") do %>
<div class="box">
<p><%= render :partial => 'attachments/form' %></p>
</div>
<%= styled_button_tag l(:button_add), class: "-highlight -with-icon icon-yes" %>
<%= styled_button_tag l(:button_add), class: "-highlight -with-icon icon-checkmark" %>
<% end %>
<% end %>

@ -32,6 +32,10 @@
OpenProject::Application.routes.draw do
resources :projects do
resources :documents, shallow: true
resources :documents, shallow: true do
member do
post 'add_attachment'
end
end
end
end

@ -44,7 +44,7 @@ module OpenProject::Documents
{ controller: '/documents', action: 'index' },
param: :project_id,
caption: :label_document_plural,
html: { class: 'icon2 icon-book1' }
html: { class: 'icon2 icon-notes' }
project_module :documents do |_map|
permission :manage_documents, {

@ -39,7 +39,7 @@ module OpenProject::Documents::Patches
custom_fields_tabs_without_documents << {
name: 'DocumentCategoryCustomField',
partial: 'custom_fields/tab',
label: DocumentCategory::OPTION_NAME
label: DocumentCategory::OptionName
}
end

@ -44,16 +44,16 @@ describe DocumentsController do
FactoryGirl.create(:document_category, project: project, name: "Default Category")
}
let(:document) {
FactoryGirl.create(:document, title: "Sample Document", project: project, category: default_category)
}
before do
allow(User).to receive(:current).and_return admin
end
describe "index" do
let(:document) {
FactoryGirl.create(:document, title: "Sample Document", project: project, category: default_category)
}
before do
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
@ -83,6 +83,15 @@ LOREM
end
describe 'new' do
before do
get :new, project_id: project.id
end
it 'show the new document form' do
expect(response).to render_template(partial: 'documents/_form')
end
end
describe "create" do
@ -151,12 +160,34 @@ LOREM
end
end
describe "destroy" do
describe 'show' do
before do
document
get :show, id: document.id
end
let(:document) {
FactoryGirl.create(:document, title: "Sample Document", project: project, category: default_category)
}
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,
id: document.id,
attachments: { '1' => { description: "sample file", file: file_attachment } }
end
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
before do
document
end

@ -31,18 +31,15 @@
require File.dirname(__FILE__) + '/../spec_helper'
describe DocumentObserver do
let(:user) { FactoryGirl.create(:user, firstname: 'Test', lastname: "User", mail: 'test@test.com') }
let(:project) { FactoryGirl.create(:project, name: "TestProject")}
let(:mail) do
mock = Object.new
allow(mock).to receive(:deliver)
allow(mock).to receive(:deliver_now)
mock
end
it "is triggered, when a document has been created" do
document = FactoryGirl.build(:document)
#observers are singletons, so any_instance exactly leaves out the singleton
@ -60,6 +57,4 @@ describe DocumentObserver do
document.save
end
end

Loading…
Cancel
Save