Merge pull request #40 from opf/rubocop

Rubocop issues
pull/6827/head
Stefan Botzenhart 9 years ago
commit bb4c609524
  1. 940
      .rubocop.yml
  2. 24
      app/controllers/documents_controller.rb
  3. 6
      app/mailers/documents_mailer.rb
  4. 8
      app/models/activity/document_activity_provider.rb
  5. 12
      app/models/document.rb
  6. 6
      app/models/document_category.rb
  7. 1
      app/models/document_category_custom_field.rb
  8. 1
      app/models/document_observer.rb
  9. 2
      config/routes.rb
  10. 22
      lib/open_project/documents/engine.rb
  11. 2
      lib/open_project/documents/hooks.rb
  12. 6
      lib/open_project/documents/patches/custom_fields_helper_patch.rb
  13. 2
      lib/open_project/documents/patches/project_patch.rb
  14. 17
      lib/open_project/documents/patches/text_formatting_patch.rb
  15. 38
      spec/application_helper_spec.rb
  16. 80
      spec/controllers/documents_controller_spec.rb
  17. 2
      spec/factories/document_factory.rb
  18. 2
      spec/lib/acts_as_journalized/journaled_spec.rb
  19. 13
      spec/mailers/documents_mailer_spec.rb
  20. 15
      spec/models/document_category_spec.rb
  21. 2
      spec/models/document_observer_spec.rb
  22. 12
      spec/models/document_spec.rb
  23. 56
      spec/routing/documents_routing_spec.rb

File diff suppressed because it is too large Load Diff

@ -33,10 +33,10 @@
class DocumentsController < ApplicationController class DocumentsController < ApplicationController
default_search_scope :documents default_search_scope :documents
model_object Document model_object Document
before_filter :find_project_by_project_id, :only => [:index, :new, :create] before_action :find_project_by_project_id, only: [:index, :new, :create]
before_filter :find_model_object, :except => [:index, :new, :create] before_action :find_model_object, except: [:index, :new, :create]
before_filter :find_project_from_association, :except => [:index, :new, :create] before_action :find_project_from_association, except: [:index, :new, :create]
before_filter :authorize before_action :authorize
def index def index
@ -52,7 +52,7 @@ class DocumentsController < ApplicationController
else else
@grouped = documents.includes(:category).group_by(&:category) @grouped = documents.includes(:category).group_by(&:category)
end end
render :layout => false if request.xhr? render layout: false if request.xhr?
end end
def show def show
@ -68,12 +68,12 @@ class DocumentsController < ApplicationController
@document = @project.documents.build @document = @project.documents.build
@document.attributes = document_params @document.attributes = document_params
if @document.save if @document.save
attachments = Attachment.attach_files(@document, params[:attachments]) Attachment.attach_files(@document, params[:attachments])
render_attachment_warning_if_needed(@document) render_attachment_warning_if_needed(@document)
flash[:notice] = l(:notice_successful_create) flash[:notice] = l(:notice_successful_create)
redirect_to project_documents_path(@project) redirect_to project_documents_path(@project)
else else
render :action => 'new' render action: 'new'
end end
end end
@ -85,15 +85,15 @@ class DocumentsController < ApplicationController
@document.attributes = document_params @document.attributes = document_params
if @document.save if @document.save
flash[:notice] = l(:notice_successful_update) flash[:notice] = l(:notice_successful_update)
redirect_to :action => 'show', :id => @document redirect_to action: 'show', id: @document
else else
render :action => 'edit' render action: 'edit'
end end
end end
def destroy def destroy
@document.destroy @document.destroy
redirect_to :controller => '/documents', :action => 'index', :project_id => @project redirect_to controller: '/documents', action: 'index', project_id: @project
end end
def add_attachment def add_attachment
@ -106,10 +106,10 @@ class DocumentsController < ApplicationController
UserMailer.attachments_added(user, attachments[:files]).deliver UserMailer.attachments_added(user, attachments[:files]).deliver
end end
end end
redirect_to :action => 'show', :id => @document redirect_to action: 'show', id: @document
end end
private private
def document_params def document_params
params.require(:document).permit('category_id', 'title', 'description') params.require(:document).permit('category_id', 'title', 'description')
end end

@ -39,7 +39,7 @@ class DocumentsMailer < UserMailer
with_locale_for(user) do with_locale_for(user) do
subject = "[#{@document.project.name}] #{t(:label_document_new)}: #{@document.title}" subject = "[#{@document.project.name}] #{t(:label_document_new)}: #{@document.title}"
mail :to => user.mail, :subject => subject mail to: user.mail, subject: subject
end end
end end
@ -47,11 +47,9 @@ class DocumentsMailer < UserMailer
container = attachments.first.container container = attachments.first.container
@added_to = "#{Document.model_name.human}: #{container.title}" @added_to = "#{Document.model_name.human}: #{container.title}"
@added_to_url = url_for(:controller => '/documents', :action => 'show', :id => container.id) @added_to_url = url_for(controller: '/documents', action: 'show', id: container.id)
super super
end end
end end

@ -40,19 +40,19 @@ class Activity::DocumentActivityProvider < Activity::BaseActivityProvider
] ]
end end
def event_title(event, activity) def event_title(event, _activity)
"#{Document.model_name.human}: #{event['document_title']}" "#{Document.model_name.human}: #{event['document_title']}"
end end
def event_type(event, activity) def event_type(_event, _activity)
'document' 'document'
end end
def event_path(event, activity) def event_path(event, _activity)
url_helpers.project_documents_url(url_helper_parameter(event)) url_helpers.project_documents_url(url_helper_parameter(event))
end end
def event_url(event, activity) def event_url(event, _activity)
url_helpers.project_documents_url(url_helper_parameter(event)) url_helpers.project_documents_url(url_helper_parameter(event))
end end

@ -32,8 +32,8 @@
class Document < ActiveRecord::Base class Document < ActiveRecord::Base
belongs_to :project belongs_to :project
belongs_to :category, :class_name => "DocumentCategory", :foreign_key => "category_id" belongs_to :category, class_name: "DocumentCategory", foreign_key: "category_id"
acts_as_attachable :delete_permission => :manage_documents acts_as_attachable delete_permission: :manage_documents
acts_as_journalized acts_as_journalized
acts_as_event title: Proc.new { |o| "#{Document.model_name.human}: #{o.title}" }, acts_as_event title: Proc.new { |o| "#{Document.model_name.human}: #{o.title}" },
@ -44,12 +44,12 @@ class Document < ActiveRecord::Base
end) end)
acts_as_searchable :columns => ['title', "#{table_name}.description"], acts_as_searchable columns: ['title', "#{table_name}.description"],
:include => :project, include: :project,
references: :projects references: :projects
validates_presence_of :project, :title, :category validates_presence_of :project, :title, :category
validates_length_of :title, :maximum => 60 validates_length_of :title, maximum: 60
scope :visible, lambda { scope :visible, lambda {
includes(:project) includes(:project)

@ -31,12 +31,12 @@
#++ #++
class DocumentCategory < Enumeration class DocumentCategory < Enumeration
has_many :documents, :foreign_key => 'category_id' has_many :documents, foreign_key: 'category_id'
OptionName = :enumeration_doc_categories OPTION_NAME = :enumeration_doc_categories
def option_name def option_name
OptionName OPTION_NAME
end end
def objects_count def objects_count

@ -35,4 +35,3 @@ class DocumentCategoryCustomField < CustomField
:enumeration_doc_categories :enumeration_doc_categories
end end
end end

@ -41,4 +41,3 @@ class DocumentObserver < ActiveRecord::Observer
end end
end end
end end

@ -35,5 +35,3 @@ OpenProject::Application.routes.draw do
resources :documents, shallow: true resources :documents, shallow: true
end end
end end

@ -37,18 +37,20 @@ module OpenProject::Documents
include OpenProject::Plugins::ActsAsOpEngine include OpenProject::Plugins::ActsAsOpEngine
register 'openproject-documents', register 'openproject-documents',
:author_url => "http://www.finn.de", author_url: "http://www.finn.de",
:requires_openproject => ">= 4.0.0" do requires_openproject: ">= 4.0.0" do
menu :project_menu, :documents, menu :project_menu, :documents,
{ :controller => '/documents', :action => 'index' }, { controller: '/documents', action: 'index' },
:param => :project_id, param: :project_id,
:caption => :label_document_plural, caption: :label_document_plural,
:html => { :class => 'icon2 icon-book1' } html: { class: 'icon2 icon-book1' }
project_module :documents do |map| project_module :documents do |_map|
permission :manage_documents, {:documents => [:new, :create, :edit, :update, :destroy, :add_attachment]}, :require => :loggedin permission :manage_documents, {
permission :view_documents, :documents => [:index, :show, :download] documents: [:new, :create, :edit, :update, :destroy, :add_attachment]
}, require: :loggedin
permission :view_documents, documents: [:index, :show, :download]
end end
Redmine::Notifiable.all << Redmine::Notifiable.new('document_added') Redmine::Notifiable.all << Redmine::Notifiable.new('document_added')
@ -68,7 +70,7 @@ module OpenProject::Documents
require 'open_project/documents/hooks' require 'open_project/documents/hooks'
end end
initializer 'documents.register_observers' do |app| initializer 'documents.register_observers' do |_app|
ActiveRecord::Base.observers.push :document_observer ActiveRecord::Base.observers.push :document_observer
end end

@ -32,6 +32,6 @@
module OpenProject::Documents module OpenProject::Documents
class Hooks < Redmine::Hook::ViewListener class Hooks < Redmine::Hook::ViewListener
render_on :activity_index_head, render_on :activity_index_head,
:partial => 'hooks/documents/activity_index_head' partial: 'hooks/documents/activity_index_head'
end end
end end

@ -36,7 +36,11 @@ module OpenProject::Documents::Patches
base.class_eval do base.class_eval do
def custom_fields_tabs_with_documents def custom_fields_tabs_with_documents
custom_fields_tabs_without_documents << {:name => 'DocumentCategoryCustomField', :partial => 'custom_fields/tab', :label => DocumentCategory::OptionName} custom_fields_tabs_without_documents << {
name: 'DocumentCategoryCustomField',
partial: 'custom_fields/tab',
label: DocumentCategory::OptionName
}
end end
alias_method_chain :custom_fields_tabs, :documents alias_method_chain :custom_fields_tabs, :documents

@ -34,7 +34,7 @@ module OpenProject::Documents::Patches
def self.included(base) def self.included(base)
base.class_eval do base.class_eval do
has_many :documents, :dependent => :destroy has_many :documents, dependent: :destroy
end end
end end
end end

@ -36,8 +36,14 @@ module OpenProject::Documents::Patches
base.class_eval do base.class_eval do
def parse_redmine_links_with_documents(text, project, obj, attr, only_path, options) def parse_redmine_links_with_documents(text, project, obj, attr, only_path, options)
text.gsub!(/([\s\(,\-\[\>]|^)(!)?(([a-z0-9\-_]+):)?(document)((#+|r)(\d+)|(:)([^"\s<>][^\s<>]*?|"[^"]+?"))(?=(?=[[:punct:]]\W)|,|\s|\]|<|$)/) do |m| text.gsub!(/([\s\(,\-\[\>]|^)(!)?(([a-z0-9\-_]+):)?(document)((#+|r)(\d+)|(:)([^"\s<>][^\s<>]*?|"[^"]+?"))(?=(?=[[:punct:]]\W)|,|\s|\]|<|$)/) do |_m|
leading, esc, project_prefix, project_identifier, prefix, sep, identifier = $1, $2, $3, $4, $5, $7 || $9, $8 || $10 leading = $1
esc = $2
project_prefix = $3
project_identifier = $4
prefix = $5
sep = $7 || $9
identifier = $8 || $10
link = nil link = nil
if project_identifier if project_identifier
project = Project.visible.find_by_identifier(project_identifier) project = Project.visible.find_by_identifier(project_identifier)
@ -51,8 +57,11 @@ module OpenProject::Documents::Patches
document = project.documents.visible.find_by_title(name) document = project.documents.visible.find_by_title(name)
end end
if document if document
link = link_to document.title, {:only_path => only_path, :controller => '/documents', :action => 'show', :id => document}, link = link_to document.title, {
:class => 'document' only_path: only_path,
controller: '/documents',
action: 'show', id: document },
class: 'document'
end end
end end
leading + (link || "#{project_prefix}#{prefix}#{sep}#{identifier}") leading + (link || "#{project_prefix}#{prefix}#{sep}#{identifier}")

@ -41,14 +41,20 @@ describe ApplicationHelper do
describe ".format_text" do describe ".format_text" do
let(:project) { FactoryGirl.create :valid_project } let(:project) { FactoryGirl.create :valid_project }
let(:identifier) { project.identifier } let(:identifier) { project.identifier }
let(:project_member) { FactoryGirl.create :user, let(:role) {
:member_in_project => project, FactoryGirl.create(:role, permissions: [
:member_through_role => FactoryGirl.create(:role, :view_work_packages, :edit_work_packages, :view_documents, :browse_repository, :view_changesets, :view_wiki_pages
:permissions => [:view_work_packages, :edit_work_packages, ])
:view_documents, :browse_repository, :view_changesets, :view_wiki_pages]) } }
let(:document) { FactoryGirl.create :document, let(:project_member) {
:title => 'Test document', FactoryGirl.create :user, member_in_project: project,
:project => project } member_through_role: role
}
let(:document) {
FactoryGirl.create :document,
title: 'Test document',
project: project
}
before do before do
@project = project @project = project
@ -60,9 +66,11 @@ describe ApplicationHelper do
end end
context "Simple Document links" do context "Simple Document links" do
let(:document_link) { link_to('Test document', let(:document_link) {
{:controller => 'documents', :action => 'show', :id => document.id}, link_to('Test document',
:class => 'document') } { controller: 'documents', action: 'show', id: document.id },
class: 'document')
}
context "Plain link" do context "Plain link" do
subject { format_text("document##{document.id}") } subject { format_text("document##{document.id}") }
@ -93,25 +101,25 @@ describe ApplicationHelper do
let(:the_other_project) { FactoryGirl.create :valid_project } let(:the_other_project) { FactoryGirl.create :valid_project }
context "By name without project" do context "By name without project" do
subject { format_text("document:\"#{document.title}\"", :project => the_other_project) } subject { format_text("document:\"#{document.title}\"", project: the_other_project) }
it { is_expected.to eq('<p>document:"Test document"</p>') } it { is_expected.to eq('<p>document:"Test document"</p>') }
end end
context "By id and given project" do context "By id and given project" do
subject { format_text("#{identifier}:document##{document.id}", :project => the_other_project) } subject { format_text("#{identifier}:document##{document.id}", project: the_other_project) }
it { is_expected.to eq("<p><a class=\"document\" href=\"/documents/#{document.id}\">Test document</a></p>") } it { is_expected.to eq("<p><a class=\"document\" href=\"/documents/#{document.id}\">Test document</a></p>") }
end end
context "By name and given project" do context "By name and given project" do
subject { format_text("#{identifier}:document:\"#{document.title}\"", :project => the_other_project) } subject { format_text("#{identifier}:document:\"#{document.title}\"", project: the_other_project) }
it { is_expected.to eq("<p><a class=\"document\" href=\"/documents/#{document.id}\">Test document</a></p>") } it { is_expected.to eq("<p><a class=\"document\" href=\"/documents/#{document.id}\">Test document</a></p>") }
end end
context "Invalid link" do context "Invalid link" do
subject { format_text("invalid:document:\"Test document\"", :project => the_other_project) } subject { format_text("invalid:document:\"Test document\"", project: the_other_project) }
it { is_expected.to eq('<p>invalid:document:"Test document"</p>') } it { is_expected.to eq('<p>invalid:document:"Test document"</p>') }
end end

@ -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

@ -32,7 +32,7 @@
FactoryGirl.define do FactoryGirl.define do
factory :document do factory :document do
project project
category :factory => :document_category category factory: :document_category
sequence(:description) { |n| "I am a document's description No. #{n}" } sequence(:description) { |n| "I am a document's description No. #{n}" }
sequence(:title) { |n| "I am the document No. #{n}" } sequence(:title) { |n| "I am the document No. #{n}" }
end end

@ -35,7 +35,7 @@ describe "Journalized Objects" do
before(:each) do before(:each) do
@type ||= FactoryGirl.create(:type_feature) @type ||= FactoryGirl.create(:type_feature)
@project ||= FactoryGirl.create(:project_with_types) @project ||= FactoryGirl.create(:project_with_types)
@current = FactoryGirl.create(:user, :login => "user1", :mail => "user1@users.com") @current = FactoryGirl.create(:user, login: "user1", mail: "user1@users.com")
allow(User).to receive(:current).and_return @current allow(User).to receive(:current).and_return @current
end end

@ -32,11 +32,14 @@ require File.dirname(__FILE__) + '/../spec_helper'
describe DocumentsMailer do describe DocumentsMailer do
let(:user) { FactoryGirl.create(:user, firstname: 'Test', lastname: "User", :mail => 'test@test.com') } let(:user) {
let(:project) { FactoryGirl.create(:project, name: "TestProject")} FactoryGirl.create(:user, firstname: 'Test', lastname: "User", mail: 'test@test.com')
let(:document) { FactoryGirl.create(:document, project: project, description: "Test Description", title: "Test Title" )} }
let(:mail) { DocumentsMailer.document_added(user, document) } let(:project) { FactoryGirl.create(:project, name: "TestProject") }
let(:document) {
FactoryGirl.create(:document, project: project, description: "Test Description", title: "Test Title" )
}
let(:mail) { DocumentsMailer.document_added(user, document) }
describe "document added-mail" do describe "document added-mail" do
it "renders the subject" do it "renders the subject" do

@ -40,10 +40,10 @@ describe DocumentCategory do
end end
it "should order documents by the category they are created with" do it "should order documents by the category they are created with" do
uncategorized = FactoryGirl.create :document_category, :name => "Uncategorized", :project => project uncategorized = FactoryGirl.create :document_category, name: "Uncategorized", project: project
user_documentation = FactoryGirl.create :document_category, :name => "User documentation" user_documentation = FactoryGirl.create :document_category, name: "User documentation"
FactoryGirl.create_list :document, 2, :category => uncategorized, :project => project FactoryGirl.create_list :document, 2, category: uncategorized, project: project
expect(DocumentCategory.find_by_name(uncategorized.name).objects_count).to eql 2 expect(DocumentCategory.find_by_name(uncategorized.name).objects_count).to eql 2
expect(DocumentCategory.find_by_name(user_documentation.name).objects_count).to eql 0 expect(DocumentCategory.find_by_name(user_documentation.name).objects_count).to eql 0
@ -51,14 +51,14 @@ describe DocumentCategory do
end end
it "should file the categorizations under the option name :enumeration_doc_categories" do it "should file the categorizations under the option name :enumeration_doc_categories" do
expect(DocumentCategory.new.option_name).to eql :enumeration_doc_categories expect(DocumentCategory.new.option_name).to eql :enumeration_doc_categories
end end
it "should only allow one category to be the default-category" do it "should only allow one category to be the default-category" do
old_default = FactoryGirl.create :document_category, :name => "old default", :project => project, :is_default => true old_default = FactoryGirl.create :document_category, name: "old default", project: project, is_default: true
expect{ expect{
new_default = FactoryGirl.create :document_category, :name => "new default", :project => project, :is_default => true FactoryGirl.create :document_category, name: "new default", project: project, is_default: true
old_default.reload old_default.reload
}.to change{old_default.is_default?}.from(true).to(false) }.to change{old_default.is_default?}.from(true).to(false)
@ -66,6 +66,3 @@ describe DocumentCategory do
end end
end end

@ -33,7 +33,7 @@ require File.dirname(__FILE__) + '/../spec_helper'
describe DocumentObserver do describe DocumentObserver do
let(:user) { FactoryGirl.create(:user, firstname: 'Test', lastname: "User", :mail => 'test@test.com') } let(:user) { FactoryGirl.create(:user, firstname: 'Test', lastname: "User", mail: 'test@test.com') }
let(:project) { FactoryGirl.create(:project, name: "TestProject")} let(:project) { FactoryGirl.create(:project, name: "TestProject")}
let(:mail) do let(:mail) do

@ -33,7 +33,7 @@ require File.dirname(__FILE__) + '/../spec_helper'
describe Document do describe Document do
let(:documentation_category) { FactoryGirl.create :document_category, :name => 'User documentation'} let(:documentation_category) { FactoryGirl.create :document_category, name: 'User documentation'}
let(:project) { FactoryGirl.create :project} let(:project) { FactoryGirl.create :project}
let(:user) { FactoryGirl.create(:user)} let(:user) { FactoryGirl.create(:user)}
let(:admin) { FactoryGirl.create(:admin)} let(:admin) { FactoryGirl.create(:admin)}
@ -76,7 +76,7 @@ describe Document do
end end
it "should set a default-category, if none is given" do it "should set a default-category, if none is given" do
default_category = FactoryGirl.create :document_category, :name => 'Technical documentation', :is_default => true default_category = FactoryGirl.create :document_category, name: 'Technical documentation', is_default: true
document = Document.new(project: project, title: "New Document") document = Document.new(project: project, title: "New Document")
expect(document.category).to eql default_category expect(document.category).to eql default_category
expect{ expect{
@ -102,9 +102,11 @@ describe Document do
end end
describe "acts as event" do describe "acts as event" do
let(:now) { Time.now } let(:now) { Time.zone.now }
let(:document) { FactoryGirl.build(:document, let(:document) {
created_on: now) } FactoryGirl.build(:document,
created_on: now)
}
it { expect(document.event_datetime).to eq(now) } it { expect(document.event_datetime).to eq(now) }
end end

@ -33,32 +33,46 @@ require 'spec_helper'
describe DocumentsController do describe DocumentsController do
describe "routing" do describe "routing" do
it { expect(get('/projects/567/documents')).to route_to(:controller => 'documents', it {
:action => 'index', expect(get('/projects/567/documents')).to route_to(controller: 'documents',
:project_id => '567' ) } action: 'index',
project_id: '567' )
}
it { expect(get('/projects/567/documents/new')).to route_to(:controller => 'documents', it {
:action => 'new', expect(get('/projects/567/documents/new')).to route_to(controller: 'documents',
:project_id => '567' ) } action: 'new',
project_id: '567' )
}
it { expect(get('/documents/22')).to route_to(:controller => 'documents', it {
:action => 'show', expect(get('/documents/22')).to route_to(controller: 'documents',
:id => '22') } action: 'show',
id: '22')
}
it { expect(get('/documents/22/edit')).to route_to(:controller => 'documents', it {
:action => 'edit', expect(get('/documents/22/edit')).to route_to(controller: 'documents',
:id => '22') } action: 'edit',
id: '22')
}
it { expect(post('/projects/567/documents')).to route_to(:controller => 'documents', it {
:action => 'create', expect(post('/projects/567/documents')).to route_to(controller: 'documents',
:project_id => '567') } action: 'create',
project_id: '567')
}
it { expect(put('/documents/567')).to route_to(:controller => 'documents', it {
:action => 'update', expect(put('/documents/567')).to route_to(controller: 'documents',
:id => '567') } action: 'update',
id: '567')
}
it { expect(delete('/documents/567')).to route_to(:controller => 'documents', it {
:action => 'destroy', expect(delete('/documents/567')).to route_to(controller: 'documents',
:id => '567') } action: 'destroy',
id: '567')
}
end end
end end

Loading…
Cancel
Save