Fix/replace deprecations (#5533)

* replace alias_method_chain

* remove deprecation silencing

* bump controller-testing

* introduce permitted params for settings

* replace various deprecations in controllers

* remove deprecation silencing for legacy_specs

* remove `puts` from spec

* replace deprecated access to errors

* remove unnecessary AR::Parameters usage in spec

* specify error to expect

* replace deprecations

* replace deprecated action calls in legacy function specs

* replace deprecations in functional controller tests

* replace deprecations in controllers/controller_specs

* remove params parser which does not seem to be in effect

It is registered for the content type :exclude which makes no sense as it should deal with :json. The desired behaviour of the api dealing with parsing errors is working with or without the code.

* replace deprecations in unit specs

* replace alias_method_chain

[ci skip]
This commit is contained in:
ulferts
2017-07-19 21:17:37 +02:00
committed by Oliver Günther
parent 668306b12f
commit c0b709530c
77 changed files with 1181 additions and 884 deletions
+1 -4
View File
@@ -188,10 +188,7 @@ group :test do
gem 'rspec-legacy_formatters', '~> 1.0.1', require: false
# brings back testing for 'assigns' and 'assert_template' extracted in rails 5
# TODO: 1.0.1 still contains an issue that breaks helper inclusion in view specs
# Constrain value once new version released.
# More information: https://github.com/rspec/rspec-rails/issues/1644
gem 'rails-controller-testing', git: 'https://github.com/rails/rails-controller-testing/'
gem 'rails-controller-testing', '~> 1.0.2'
gem 'aws-sdk', '~> 2.10.1'
gem 'capybara', '~> 2.13.0'
+5 -10
View File
@@ -77,15 +77,6 @@ GIT
rails-angular-xss (0.3.0.pre.pre)
rails (>= 5.0.0, < 5.1)
GIT
remote: https://github.com/rails/rails-controller-testing/
revision: d942a5d239a4b34cf93e86ca35e49f464e516ede
specs:
rails-controller-testing (1.0.1)
actionpack (~> 5.x)
actionview (~> 5.x)
activesupport (~> 5.x)
GIT
remote: https://github.com/rspec/rspec-activemodel-mocks
revision: 5cd4c9d552bcc75d60ea4b7dda96e7377197ab8d
@@ -436,6 +427,10 @@ GEM
bundler (>= 1.3.0, < 2.0)
railties (= 5.0.4)
sprockets-rails (>= 2.0.0)
rails-controller-testing (1.0.2)
actionpack (~> 5.x, >= 5.0.1)
actionview (~> 5.x, >= 5.0.1)
activesupport (~> 5.x)
rails-dom-testing (2.0.3)
activesupport (>= 4.2.0)
nokogiri (>= 1.6)
@@ -685,7 +680,7 @@ DEPENDENCIES
rack_session_access
rails (~> 5.0.4)
rails-angular-xss!
rails-controller-testing!
rails-controller-testing (~> 1.0.2)
rails_12factor
rails_autolink (~> 1.1.6)
rdoc (>= 2.4.2)
@@ -40,6 +40,7 @@ module Api
.visible_by_user(User.current)
.includes(:projects, :types)
.order(:id)
other_fields = CustomField.where("type != 'WorkPackageCustomField'")
.order(:type, :id)
+1 -1
View File
@@ -105,7 +105,7 @@ class ApplicationController < ActionController::Base
end
rescue_from ActionController::ParameterMissing do |exception|
render text: "Required parameter missing: #{exception.param}",
render body: "Required parameter missing: #{exception.param}",
status: :bad_request
end
+4 -3
View File
@@ -1,4 +1,5 @@
#-- encoding: UTF-8
#-- copyright
# OpenProject is a project management system.
# Copyright (C) 2012-2017 the OpenProject Foundation (OPF)
@@ -39,9 +40,9 @@ class MailHandlerController < ActionController::Base
options = params.dup
email = options.delete(:email)
if MailHandler.receive(email, options)
render nothing: true, status: :created
head :created
else
render nothing: true, status: :unprocessable_entity
head :unprocessable_entity
end
end
@@ -50,7 +51,7 @@ class MailHandlerController < ActionController::Base
def check_credential
User.current = nil
unless Setting.mail_handler_api_enabled? && params[:key].to_s == Setting.mail_handler_api_key
render text: 'Access denied. Incoming emails WS is disabled or key is invalid.', status: 403
render plain: 'Access denied. Incoming emails WS is disabled or key is invalid.', status: 403
end
end
end
+2 -1
View File
@@ -1,4 +1,5 @@
#-- encoding: UTF-8
#-- copyright
# OpenProject is a project management system.
# Copyright (C) 2012-2017 the OpenProject Foundation (OPF)
@@ -244,7 +245,7 @@ class MyController < ApplicationController
@user.pref[:my_page_layout] = layout
@user.pref.save
render nothing: true
head :ok
end
def default_breadcrumb
+4 -2
View File
@@ -117,12 +117,14 @@ class ProjectsController < ApplicationController
cond = @project.project_condition(Setting.display_subprojects_work_packages?)
@open_issues_by_type = WorkPackage.visible.group(:type)
@open_issues_by_type = WorkPackage
.visible.group(:type)
.includes(:project, :status, :type)
.where(["(#{cond}) AND #{Status.table_name}.is_closed=?", false])
.references(:projects, :statuses, :types)
.count
@total_issues_by_type = WorkPackage.visible.group(:type)
@total_issues_by_type = WorkPackage
.visible.group(:type)
.includes(:project, :status, :type)
.where(cond)
.references(:projects, :statuses, :types)
+2 -17
View File
@@ -39,12 +39,8 @@ class SettingsController < ApplicationController
def edit
@notifiables = Redmine::Notifiable.all
if request.post? && params[:settings] && params[:settings].is_a?(ActionController::Parameters)
settings = (params[:settings] || {}).dup.symbolize_keys.tap do |set|
set.except! *password_settings if OpenProject::Configuration.disable_password_login?
end
settings.each do |name, value|
if request.post? && params[:settings]
permitted_params.settings.to_h.each do |name, value|
if value.is_a?(Array)
# remove blank values in array settings
value.delete_if(&:blank?)
@@ -90,15 +86,4 @@ class SettingsController < ApplicationController
def show_local_breadcrumb
true
end
private
##
# Returns all password-login related setting keys.
def password_settings
[
:password_min_length, :password_active_rules, :password_min_adhered_rules,
:password_days_valid, :password_count_former_banned, :lost_password
]
end
end
+3 -3
View File
@@ -45,7 +45,7 @@ class SysController < ActionController::Base
render json: p.to_json(include: :repository)
end
format.any(:html, :xml) do
render xml: p.to_xml(include: :repository), content_type: Mime::XML
render xml: p.to_xml(include: :repository), content_type: Mime[:xml]
end
end
end
@@ -68,9 +68,9 @@ class SysController < ActionController::Base
project.repository.fetch_changesets
end
end
render nothing: true, status: 200
head 200
rescue ActiveRecord::RecordNotFound
render nothing: true, status: 404
head 404
end
def repo_auth
+3 -3
View File
@@ -137,7 +137,7 @@ class TimelogController < ApplicationController
respond_to do |format|
# TODO: Implement html response
format.html do
render nothing: true, status: 406
head 406
end
end
end
@@ -173,7 +173,7 @@ class TimelogController < ApplicationController
respond_to do |format|
format.html do
flash[:notice] = l(:notice_successful_delete)
redirect_to :back
redirect_back fallback_location: { action: 'index', project_id: @time_entry.project }
end
format.json do
render json: { text: l(:notice_successful_delete) }
@@ -183,7 +183,7 @@ class TimelogController < ApplicationController
respond_to do |format|
format.html do
flash[:error] = l(:notice_unable_delete_time_entry)
redirect_to :back
redirect_back fallback_location: { action: 'index', project_id: @time_entry.project }
end
format.json do
render json: { isError: true, text: l(:notice_unable_delete_time_entry) }
+4 -2
View File
@@ -166,7 +166,7 @@ class UsersController < ApplicationController
respond_to do |format|
format.html do
flash[:notice] = l(:notice_successful_update)
redirect_to :back
redirect_back(fallback_location: edit_user_path(@user))
end
end
else
@@ -176,7 +176,9 @@ class UsersController < ApplicationController
@user.password = @user.password_confirmation = nil
respond_to do |format|
format.html do render action: :edit end
format.html do
render action: :edit
end
end
end
rescue ::ActionController::RedirectBackError
+4 -4
View File
@@ -114,7 +114,7 @@ class WikiController < ApplicationController
@content.author = User.current
if @page.save
attachments = Attachment.attach_files(@page, params[:attachments])
attachments = Attachment.attach_files(@page, permitted_params.attachments.to_h)
render_attachment_warning_if_needed(@page)
call_hook(:controller_wiki_edit_after_save, params: params, page: @page)
flash[:notice] = l(:notice_successful_create)
@@ -192,7 +192,7 @@ class WikiController < ApplicationController
@content.comments = nil
if !@page.new_record? && params[:content].present? && @content.text == params[:content][:text]
attachments = Attachment.attach_files(@page, params[:attachments])
attachments = Attachment.attach_files(@page, permitted_params.attachments.to_h)
render_attachment_warning_if_needed(@page)
# don't save if text wasn't changed
redirect_to_show
@@ -203,7 +203,7 @@ class WikiController < ApplicationController
@content.add_journal User.current, params['content']['comments']
# if page is new @page.save will also save content, but not if page isn't a new record
if @page.new_record? ? @page.save : @content.save
attachments = Attachment.attach_files(@page, params[:attachments])
attachments = Attachment.attach_files(@page, permitted_params.attachments.to_h)
render_attachment_warning_if_needed(@page)
call_hook(:controller_wiki_edit_after_save, params: params, page: @page)
flash[:notice] = l(:notice_successful_update)
@@ -359,7 +359,7 @@ class WikiController < ApplicationController
def add_attachment
return render_403 unless editable?
attachments = Attachment.attach_files(@page, params[:attachments])
attachments = Attachment.attach_files(@page, permitted_params.attachments.to_h)
render_attachment_warning_if_needed(@page)
redirect_to action: 'show', id: @page, project_id: @project
end
+1 -1
View File
@@ -43,7 +43,7 @@ class WorkflowsController < ApplicationController
@type = ::Type.find_by(id: params[:type_id])
if request.post?
Workflow.destroy_all(['role_id=? and type_id=?', @role.id, @type.id])
Workflow.where(role_id: @role.id, type_id: @type.id).delete_all
(params[:status] || []).each do |status_id, transitions|
transitions.each { |new_status_id, options|
author = options.is_a?(Array) && options.include?('author') && !options.include?('always')
+32 -1
View File
@@ -190,6 +190,24 @@ class PermittedParams
params.require(:status).permit(*self.class.permitted_attributes[:status])
end
def settings
permitted_params = params.require(:settings).permit
all_setting_keys = Setting.available_settings.keys
all_valid_keys = if OpenProject::Configuration.disable_password_login?
all_setting_keys - %w(password_min_length
password_active_rules
password_min_adhered_rules
password_days_valid
password_count_former_banned
lost_password)
else
all_setting_keys
end
permitted_params.merge(params[:settings].to_unsafe_hash.slice(*all_valid_keys))
end
def user
permitted_params = params.require(:user).permit(*self.class.permitted_attributes[:user])
permitted_params = permitted_params.merge(custom_field_values(:user))
@@ -198,7 +216,8 @@ class PermittedParams
end
def user_register_via_omniauth
permitted_params = params.require(:user) \
permitted_params = params
.require(:user)
.permit(:login, :firstname, :lastname, :mail, :language)
permitted_params = permitted_params.merge(custom_field_values(:user))
@@ -241,6 +260,14 @@ class PermittedParams
params.require(:type).permit(*self.class.permitted_attributes[:move_to])
end
def timelog
params.permit(:period,
:period_type,
:from,
:to,
criterias: [])
end
def search
params.permit(*self.class.permitted_attributes[:search])
end
@@ -416,6 +443,10 @@ class PermittedParams
:reported_project_status_comment)
end
def repository_diff
params.permit(:rev, :rev_to, :project, :action, :controller)
end
def membership
params.require(:membership).permit(*self.class.permitted_attributes[:membership])
end
+4 -1
View File
@@ -112,6 +112,9 @@ class Status < ActiveRecord::Base
# Deletes associated workflows
def delete_workflows
Workflow.delete_all(['old_status_id = :id OR new_status_id = :id', { id: id }])
Workflow
.where(old_status_id: id)
.or(Workflow.where(new_status_id: id))
.delete_all
end
end
+2 -2
View File
@@ -38,10 +38,10 @@ See doc/COPYRIGHT.rdoc for more details.
<% end %>
<% cache(@cache_key) do -%>
<%= render partial: 'common/diff', locals: {diff: @diff, diff_type: @diff_type} %>
<%= render partial: 'common/diff', locals: { diff: @diff, diff_type: @diff_type } %>
<% end -%>
<%= other_formats_links do |f| %>
<%= f.link_to 'Diff', url: params, caption: 'Unified diff' %>
<%= f.link_to 'Diff', url: permitted_params.repository_diff.to_h, caption: 'Unified diff' %>
<% end %>
<% html_title(h(with_leading_slash(@path)), 'Diff') -%>
+1 -1
View File
@@ -147,7 +147,7 @@ See doc/COPYRIGHT.rdoc for more details.
</div>
<%= other_formats_links do |f| %>
<%= f.link_to 'CSV', url: params %>
<%= f.link_to 'CSV', url: permitted_params.timelog.to_h %>
<% end %>
<% end %>
<% end %>
+2 -2
View File
@@ -56,8 +56,8 @@ See doc/COPYRIGHT.rdoc for more details.
<modal-loading></modal-loading>
<%= other_formats_links do |f| %>
<%= f.link_to 'Atom', url: params.merge({issue_id: @issue, key: User.current.rss_key}) %>
<%= f.link_to 'CSV', url: params %>
<%= f.link_to 'Atom', url: permitted_params.timelog.to_h.merge({issue_id: @issue, key: User.current.rss_key}) %>
<%= f.link_to 'CSV', url: permitted_params.timelog.to_h %>
<% end %>
<% end %>
</div>
-10
View File
@@ -48,10 +48,6 @@ end
require 'rails/all'
if Rails.env.production? || (Rails.env.test? && ENV['CI'])
ActiveSupport::Deprecation.behavior = :silence
end
if defined?(Bundler)
# lib directory has to be added to the load path so that
# the open_project/plugins files can be found (places under lib).
@@ -71,7 +67,6 @@ if defined?(Bundler)
end
require File.dirname(__FILE__) + '/../lib/open_project/configuration'
require File.dirname(__FILE__) + '/../app/middleware/params_parser_with_exclusion'
require File.dirname(__FILE__) + '/../app/middleware/reset_current_user'
module OpenProject
@@ -95,11 +90,6 @@ module OpenProject
content_type != 'application/x-gzip'
}
config.middleware.use ::ParamsParserWithExclusion,
exclude: -> (env) {
env['PATH_INFO'] =~ /\/api\/v3/
}
config.middleware.use Rack::Attack
# Ensure that tempfiles are cleared after request
# http://stackoverflow.com/questions/4590229
-92
View File
@@ -41,90 +41,6 @@ module ActiveRecord
end
end
module ActiveModel
class Errors
##
# ActiveRecord errors do provide no means to access the symbols initially used to create an
# error. E.g. errors.add :foo, :bar instantly translates :bar, making it hard to write code
# dependent on specific errors (which we use in the APIv3).
# We therefore add a second information store containing pairs of [symbol, translated_message].
def add_with_storing_error_symbols(attribute, message = :invalid, options = {})
error_symbol = options.fetch(:error_symbol) { message }
add_without_storing_error_symbols(attribute, message, options)
if store_new_symbols?
if error_symbol.is_a?(Symbol)
symbol = error_symbol
partial_message = normalize_message(attribute, message, options)
full_message = full_message(attribute, partial_message)
else
symbol = :unknown
full_message = message
end
writable_symbols_and_messages_for(attribute) << [symbol, full_message, partial_message]
end
end
alias_method_chain :add, :storing_error_symbols
def symbols_and_messages_for(attribute)
writable_symbols_and_messages_for(attribute).dup
end
def symbols_for(attribute)
symbols_and_messages_for(attribute).map(&:first)
end
def full_message(attribute, message)
return message if attribute == :base
# if a model acts_as_customizable it will inject attributes like 'custom_field_1' into itself
# using attr_name_override we resolve names of such attributes.
# The rest of the method should reflect the original method implementation of ActiveModel
attr_name_override = nil
match = /\Acustom_field_(?<id>\d+)\z/.match(attribute)
if match
attr_name_override = CustomField.find_by(id: match[:id]).name
end
attr_name = attribute.to_s.gsub('.', '_').humanize
attr_name = @base.class.human_attribute_name(attribute, default: attr_name)
I18n.t(:"errors.format", default: '%{attribute} %{message}',
attribute: attr_name_override || attr_name,
message: message)
end
# Need to do the house keeping along with AR::Errors
# so that the symbols are removed when a new validation round starts
def clear_with_storing_error_symbols
clear_without_storing_error_symbols
@error_symbols = Hash.new
end
alias_method_chain :clear, :storing_error_symbols
private
def error_symbols
@error_symbols ||= Hash.new
end
def writable_symbols_and_messages_for(attribute)
error_symbols[attribute.to_sym] ||= []
end
# Kind of a hack: We need the possibility to temporarily disable symbol storing in the subclass
# Reform::Contract::Errors, because otherwise we end up with duplicate entries
# I feel dirty for doing that, but on the other hand I see no other way out... Please, stop me!
def store_new_symbols?
@store_new_symbols = true if @store_new_symbols.nil?
@store_new_symbols
end
end
end
module ActionView
module Helpers
module Tags
@@ -219,14 +135,6 @@ module ActionView
end
end
end
module AssetTagHelper
def auto_discovery_link_tag_with_no_atom_feeds(type = :rss, url_options = {}, tag_options = {})
return if (type == :atom) && Setting.table_exists? && !Setting.feeds_enabled?
auto_discovery_link_tag_without_no_atom_feeds(type, url_options, tag_options)
end
alias_method_chain :auto_discovery_link_tag, :no_atom_feeds
end
end
end
@@ -1,3 +1,5 @@
#-- encoding: UTF-8
#-- copyright
# OpenProject is a project management system.
# Copyright (C) 2012-2017 the OpenProject Foundation (OPF)
@@ -26,18 +28,12 @@
# See doc/COPYRIGHT.rdoc for more details.
#++
class ParamsParserWithExclusion < ::ActionDispatch::ParamsParser
def initialize(app, options = {})
super(app)
module OpenProject::ActionViewHelpersAssetTagHelperPatch
def auto_discovery_link_tag(type = :rss, url_options = {}, tag_options = {})
return if (type == :atom) && Setting.table_exists? && !Setting.feeds_enabled?
@exclude = options[:exclude]
end
def call(env)
if @exclude && @exclude.call(env)
@app.call(env)
else
super(env)
end
super
end
end
ActionView::Helpers::AssetTagHelper.prepend(OpenProject::ActionViewHelpersAssetTagHelperPatch)
@@ -0,0 +1,109 @@
#-- encoding: UTF-8
#-- copyright
# OpenProject is a project management system.
# Copyright (C) 2012-2017 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-2017 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.
#++
module OpenProject::ActiveModelErrorsPatch
##
# ActiveRecord errors do provide no means to access the symbols initially used to create an
# error. E.g. errors.add :foo, :bar instantly translates :bar, making it hard to write code
# dependent on specific errors (which we use in the APIv3).
# We therefore add a second information store containing pairs of [symbol, translated_message].
def add(attribute, message = :invalid, options = {})
error_symbol = options.fetch(:error_symbol) { message }
super(attribute, message, options)
if store_new_symbols?
if error_symbol.is_a?(Symbol)
symbol = error_symbol
partial_message = normalize_message(attribute, message, options)
full_message = full_message(attribute, partial_message)
else
symbol = :unknown
full_message = message
end
writable_symbols_and_messages_for(attribute) << [symbol, full_message, partial_message]
end
end
def symbols_and_messages_for(attribute)
writable_symbols_and_messages_for(attribute).dup
end
def symbols_for(attribute)
symbols_and_messages_for(attribute).map(&:first)
end
def full_message(attribute, message)
return message if attribute == :base
# if a model acts_as_customizable it will inject attributes like 'custom_field_1' into itself
# using attr_name_override we resolve names of such attributes.
# The rest of the method should reflect the original method implementation of ActiveModel
attr_name_override = nil
match = /\Acustom_field_(?<id>\d+)\z/.match(attribute)
if match
attr_name_override = CustomField.find_by(id: match[:id]).name
end
attr_name = attribute.to_s.tr('.', '_').humanize
attr_name = @base.class.human_attribute_name(attribute, default: attr_name)
I18n.t(:"errors.format", default: '%{attribute} %{message}',
attribute: attr_name_override || attr_name,
message: message)
end
# Need to do the house keeping along with AR::Errors
# so that the symbols are removed when a new validation round starts
def clear
super
@error_symbols = Hash.new
end
private
def error_symbols
@error_symbols ||= Hash.new
end
def writable_symbols_and_messages_for(attribute)
error_symbols[attribute.to_sym] ||= []
end
# Kind of a hack: We need the possibility to temporarily disable symbol storing in the subclass
# Reform::Contract::Errors, because otherwise we end up with duplicate entries
# I feel dirty for doing that, but on the other hand I see no other way out... Please, stop me!
def store_new_symbols?
@store_new_symbols = true if @store_new_symbols.nil?
@store_new_symbols
end
end
ActiveModel::Errors.prepend(OpenProject::ActiveModelErrorsPatch)
+17 -10
View File
@@ -1,4 +1,5 @@
#-- encoding: UTF-8
#-- copyright
# OpenProject is a project management system.
# Copyright (C) 2012-2017 the OpenProject Foundation (OPF)
@@ -34,22 +35,28 @@
# this patch has been added which is based on
# https://github.com/rails/rails/issues/15185#issuecomment-142230234
module OpenProject::Patches
module ActiveRecordJoinPartPatch
def instantiate(row, aliases)
if base_klass == WorkPackage && row.has_key?('hours')
aliases_with_hours = aliases + [['hours', 'hours']]
super(row, aliases_with_hours)
else
super(row, aliases)
end
end
end
end
require 'active_record'
module ActiveRecord
module Associations
class JoinDependency
JoinBase && class JoinPart
def instantiate_with_hours(row, aliases)
if base_klass == WorkPackage && row.has_key?('hours')
aliases_with_hours = aliases + [['hours', 'hours']]
instantiate_without_hours(row, aliases_with_hours)
else
instantiate_without_hours(row, aliases)
end
end; alias_method_chain :instantiate, :hours
end
prepend OpenProject::Patches::ActiveRecordJoinPartPatch
end
end
end
end
@@ -1,4 +1,5 @@
#-- encoding: UTF-8
#-- copyright
# OpenProject is a project management system.
# Copyright (C) 2012-2017 the OpenProject Foundation (OPF)
@@ -30,64 +31,54 @@
require 'redcloth3'
module RedCloth3Patch
def self.included(base)
base.send(:include, InstanceMethods)
private
base.class_eval do
alias_method_chain :block_textile_prefix, :numbering
end
def block_textile_prefix(text)
text.replace(prepend_number_to_heading(text))
super(text)
end
module InstanceMethods
private
HEADING = /^h(\d)\.(.*)$/ unless defined? HEADING
NUMBERED_HEADING = /^h(\d)#\.(.*)$/ unless defined? NUMBERED_HEADING
def block_textile_prefix_with_numbering(text)
text.replace(prepend_number_to_heading(text))
def prepend_number_to_heading(text)
if text =~ NUMBERED_HEADING
level = $1.to_i
block_textile_prefix_without_numbering(text)
number = get_next_number_or_start_new_numbering level
new_text = "h#{level}. #{number}#{$2}"
elsif text =~ HEADING
reset_numbering
end
HEADING = /^h(\d)\.(.*)$/ unless defined? HEADING
NUMBERED_HEADING = /^h(\d)#\.(.*)$/ unless defined? NUMBERED_HEADING
new_text.nil? ? text : new_text
end
def prepend_number_to_heading(text)
if text =~ NUMBERED_HEADING
level = $1.to_i
number = get_next_number_or_start_new_numbering level
new_text = "h#{level}. #{number}#{$2}"
elsif text =~ HEADING
reset_numbering
end
new_text.nil? ? text : new_text
def get_next_number_or_start_new_numbering(level)
begin
number = get_number_for_level level
rescue ArgumentError
reset_numbering
number = get_number_for_level level
end
def get_next_number_or_start_new_numbering(level)
begin
number = get_number_for_level level
rescue ArgumentError
reset_numbering
number = get_number_for_level level
end
number
end
number
end
def get_number_for_level(level)
@numbering_provider ||= Redcloth3::NumberingStack.new level
def get_number_for_level(level)
@numbering_provider ||= Redcloth3::NumberingStack.new level
@numbering_provider.get_next_numbering_for_level level
end
@numbering_provider.get_next_numbering_for_level level
end
def reset_numbering
@numbering_provider = nil
end
def reset_numbering
@numbering_provider = nil
end
end
RedCloth3.send(:include, RedCloth3Patch)
RedCloth3.send(:prepend, RedCloth3Patch)
module Redcloth3
class NumberingStack
+1 -1
View File
@@ -47,6 +47,6 @@ module ExtendedHTTP
#
# This is especially useful for successful update actions.
def no_content
render html: '', status: :no_content
render body: '', status: :no_content
end
end
@@ -134,7 +134,7 @@ module Redmine
return nil unless user && user.is_a?(User)
watchers_to_delete = watchers.find_all { |watcher| watcher.user == user }
watchers_to_delete.each(&:delete)
watchers(true)
watchers.reload
watchers_to_delete.count
end
+1 -1
View File
@@ -107,7 +107,7 @@ describe MembersController, type: :controller do
end
describe '#autocomplete_for_member' do
let(:params) { ActionController::Parameters.new('project_id' => project.identifier.to_s) }
let(:params) { { 'project_id' => project.identifier.to_s } }
before do
login_as(user)
@@ -80,9 +80,9 @@ describe RepositoriesController, type: :controller do
context 'with #edit' do
before do
xhr :get,
:edit,
params: { scm_vendor: 'subversion' }
get :edit,
params: { scm_vendor: 'subversion' },
xhr: true
end
it_behaves_like 'successful settings response'
@@ -91,7 +91,7 @@ describe RepositoriesController, type: :controller do
context 'with #destroy' do
before do
allow(repository).to receive(:destroy).and_return(true)
xhr :delete, :destroy
delete :destroy, xhr: true
end
it 'redirects to settings' do
@@ -101,7 +101,7 @@ describe RepositoriesController, type: :controller do
context 'with #update' do
before do
xhr :put, :update
put :update, xhr: true
end
it_behaves_like 'successful settings response'
@@ -109,13 +109,13 @@ describe RepositoriesController, type: :controller do
context 'with #create' do
before do
xhr :post,
:create,
params: {
scm_vendor: 'subversion',
scm_type: 'local',
url: 'file:///tmp/repo.svn/'
}
post :create,
params: {
scm_vendor: 'subversion',
scm_type: 'local',
url: 'file:///tmp/repo.svn/'
},
xhr: true
end
it 'renders a JS redirect' do
+7 -7
View File
@@ -102,7 +102,7 @@ describe Member, type: :model do
end
it('member should be destroyed') { expect(member.destroyed?).to eq(true) }
context(:roles) { it { expect(member.roles(true)).to be_empty } }
context(:roles) { it { expect(member.roles.reload).to be_empty } }
end
end
@@ -114,7 +114,7 @@ describe Member, type: :model do
member.reload
# Use member_roles(true) to make sure that all member roles are loaded,
# otherwise ActiveRecord doesn't notice mark_for_destruction.
member_role = member.member_roles(true).first
member_role = member.member_roles.reload.first
member.mark_member_role_for_destruction(member_role)
member.save!
member.reload
@@ -126,7 +126,7 @@ describe Member, type: :model do
context 'before saving the member when removing the last role' do
before do
member_role = member.member_roles(true).first
member_role = member.member_roles.reload.first
member.mark_member_role_for_destruction(member_role)
end
@@ -143,7 +143,7 @@ describe Member, type: :model do
#
# Order is important here to ensure we destroy the existing
# member_role and not the one added by adding second_role.
member_role = member.member_roles(true).first
member_role = member.member_roles.reload.first
member.add_and_save_role(second_role)
@@ -152,18 +152,18 @@ describe Member, type: :model do
it('member should not be destroyed') { expect(member.destroyed?).to eq(false) }
context(:roles) do
it { expect(member.roles(true)).to eq [second_role] }
it { expect(member.roles.reload).to eq [second_role] }
end
end
context 'when removing the last member role' do
before do
member_role = member.member_roles(true).first
member_role = member.member_roles.reload.first
member.remove_member_role_and_destroy_member_if_last(member_role)
end
it('member should be destroyed') { expect(member.destroyed?).to eq(true) }
context(:roles) { it { expect(member.roles(true)).to be_empty } }
context(:roles) { it { expect(member.roles.reload).to be_empty } }
end
end
end
+55
View File
@@ -880,6 +880,61 @@ describe PermittedParams, type: :model do
end
end
describe '#settings' do
let (:attribute) { :settings }
describe 'with password login enabled' do
before do
allow(OpenProject::Configuration)
.to receive(:disable_password_login?)
.and_return(false)
end
let(:hash) do
{
'sendmail_arguments' => 'value',
'brute_force_block_after_failed_logins' => 'value',
'password_active_rules' => ['value'],
'default_projects_modules' => ['value', 'value'],
'emails_footer' => { 'en' => 'value' }
}
end
it_behaves_like 'allows params'
end
describe 'with password login disabld' do
include_context 'prepare params comparison'
before do
allow(OpenProject::Configuration)
.to receive(:disable_password_login?)
.and_return(true)
end
let(:hash) do
{
'sendmail_arguments' => 'value',
'brute_force_block_after_failed_logins' => 'value',
'password_active_rules' => ['value'],
'default_projects_modules' => ['value', 'value'],
'emails_footer' => { 'en' => 'value' }
}
end
let(:permitted_hash) do
{
'sendmail_arguments' => 'value',
'brute_force_block_after_failed_logins' => 'value',
'default_projects_modules' => ['value', 'value'],
'emails_footer' => { 'en' => 'value' }
}
end
it { expect(subject).to eq(permitted_hash) }
end
end
describe '#enumerations' do
let (:attribute) { :enumerations }
+2 -2
View File
@@ -89,10 +89,10 @@ describe ::Type, type: :model do
it 'raises an exception for invalid structure' do
# Exampel for invalid structure:
type.attribute_groups = ['foo']
expect { type.save }.to raise_exception
expect { type.save }.to raise_exception(NoMethodError)
# Exampel for invalid structure:
type.attribute_groups = [[]]
expect { type.save }.to raise_exception
expect { type.save }.to raise_exception(NoMethodError)
# Exampel for invalid group name:
type.attribute_groups = [['', ['date']]]
expect(type).not_to be_valid
@@ -29,14 +29,14 @@
require 'spec_helper'
describe WorkPackage, type: :model do
let(:work_package) {
let(:work_package) do
FactoryGirl.create(:work_package, project: project,
status: status)
}
let(:work_package2) {
end
let(:work_package2) do
FactoryGirl.create(:work_package, project: project2,
status: status)
}
end
let(:user) { FactoryGirl.create(:user) }
let(:type) { FactoryGirl.create(:type_standard) }
@@ -44,25 +44,25 @@ describe WorkPackage, type: :model do
let(:project2) { FactoryGirl.create(:project, types: [type]) }
let(:role) { FactoryGirl.create(:role) }
let(:role2) { FactoryGirl.create(:role) }
let(:member) {
let(:member) do
FactoryGirl.create(:member, principal: user,
roles: [role])
}
let(:member2) {
end
let(:member2) do
FactoryGirl.create(:member, principal: user,
roles: [role2],
project: work_package2.project)
}
end
let(:status) { FactoryGirl.create(:status) }
let(:priority) { FactoryGirl.create(:priority) }
let(:time_entry) {
let(:time_entry) do
FactoryGirl.build(:time_entry, work_package: work_package,
project: work_package.project)
}
let(:time_entry2) {
end
let(:time_entry2) do
FactoryGirl.build(:time_entry, work_package: work_package2,
project: work_package2.project)
}
end
describe '#cleanup_action_required_before_destructing?' do
describe 'w/ the work package having a time entry' do
@@ -191,7 +191,12 @@ describe WorkPackage, type: :model do
w/ reassigning to a valid work_package' do
context 'with a single work package' do
let(:action) { WorkPackage.cleanup_associated_before_destructing_if_required(work_package, user, action: 'reassign', reassign_to_id: work_package2.id) }
let(:action) do
WorkPackage.cleanup_associated_before_destructing_if_required(work_package,
user,
action: 'reassign',
reassign_to_id: work_package2.id)
end
before do
work_package2.save!
@@ -219,7 +224,12 @@ describe WorkPackage, type: :model do
end
context 'with a collection of work packages' do
let(:action) { WorkPackage.cleanup_associated_before_destructing_if_required([work_package], user, action: 'reassign', reassign_to_id: work_package2.id) }
let(:action) do
WorkPackage.cleanup_associated_before_destructing_if_required([work_package],
user,
action: 'reassign',
reassign_to_id: work_package2.id)
end
before do
work_package2.save!
@@ -250,7 +260,12 @@ describe WorkPackage, type: :model do
describe 'w/ "reassign" as action
w/ reassigning to a work_package the user is not allowed to see' do
let(:action) { WorkPackage.cleanup_associated_before_destructing_if_required([work_package], user, action: 'reassign', reassign_to_id: work_package2.id) }
let(:action) do
WorkPackage.cleanup_associated_before_destructing_if_required([work_package],
user,
action: 'reassign',
reassign_to_id: work_package2.id)
end
before do
work_package2.save!
@@ -270,7 +285,12 @@ describe WorkPackage, type: :model do
describe 'w/ "reassign" as action
w/ reassigning to a non existing work package' do
let(:action) { WorkPackage.cleanup_associated_before_destructing_if_required([work_package], user, action: 'reassign', reassign_to_id: 0) }
let(:action) do
WorkPackage.cleanup_associated_before_destructing_if_required([work_package],
user,
action: 'reassign',
reassign_to_id: 0)
end
it 'should return true' do
expect(action).to be_falsey
@@ -286,13 +306,18 @@ describe WorkPackage, type: :model do
it 'should set an error on work packages' do
action
expect(work_package.errors.get(:base)).to eq([I18n.t(:'activerecord.errors.models.work_package.is_not_a_valid_target_for_time_entries', id: 0)])
expect(work_package.errors[:base])
.to eq([I18n.t(:'activerecord.errors.models.work_package.is_not_a_valid_target_for_time_entries', id: 0)])
end
end
describe 'w/ "reassign" as action
w/o providing a reassignment id' do
let(:action) { WorkPackage.cleanup_associated_before_destructing_if_required([work_package], user, action: 'reassign') }
let(:action) do
WorkPackage.cleanup_associated_before_destructing_if_required([work_package],
user,
action: 'reassign')
end
it 'should return true' do
expect(action).to be_falsey
@@ -308,12 +333,17 @@ describe WorkPackage, type: :model do
it 'should set an error on work packages' do
action
expect(work_package.errors.get(:base)).to eq([I18n.t(:'activerecord.errors.models.work_package.is_not_a_valid_target_for_time_entries', id: nil)])
expect(work_package.errors[:base])
.to eq([I18n.t(:'activerecord.errors.models.work_package.is_not_a_valid_target_for_time_entries', id: nil)])
end
end
describe 'w/ an invalid option' do
let(:action) { WorkPackage.cleanup_associated_before_destructing_if_required([work_package], user, action: 'bogus') }
let(:action) do
WorkPackage.cleanup_associated_before_destructing_if_required([work_package],
user,
action: 'bogus')
end
it 'should return false' do
expect(action).to be_falsey
@@ -321,7 +351,11 @@ describe WorkPackage, type: :model do
end
describe 'w/ nil as invalid option' do
let(:action) { WorkPackage.cleanup_associated_before_destructing_if_required([work_package], user, nil) }
let(:action) do
WorkPackage.cleanup_associated_before_destructing_if_required([work_package],
user,
nil)
end
it 'should return false' do
expect(action).to be_falsey
@@ -69,7 +69,7 @@ describe API::V3::Activities::ActivitiesByWorkPackageAPI, type: :request do
shared_context 'create activity' do
before do
post (api_v3_paths.work_package_activities work_package.id),
post api_v3_paths.work_package_activities(work_package.id),
params: { comment: { raw: comment } }.to_json,
headers: { 'CONTENT_TYPE' => 'application/json' }
end
@@ -78,8 +78,6 @@ describe 'account/register', type: :view do
context 'without auth source' do
it 'should not show a login field' do
puts rendered
expect(rendered).not_to include('user[login]')
end
@@ -1,4 +1,5 @@
#-- encoding: UTF-8
#-- copyright
# OpenProject is a project management system.
# Copyright (C) 2012-2017 the OpenProject Foundation (OPF)
@@ -26,7 +27,7 @@
#
# See doc/COPYRIGHT.rdoc for more details.
#++
require 'legacy_spec_helper'
require_relative '../legacy_spec_helper'
require 'account_controller'
describe AccountController, type: :controller do
@@ -39,7 +40,7 @@ describe AccountController, type: :controller do
end
it 'should login with wrong password' do
post :login, username: 'admin', password: 'bad'
post :login, params: { username: 'admin', password: 'bad' }
assert_response :success
assert_template 'login'
assert_select 'div.flash.error.icon.icon-error', /Invalid user or password/
@@ -53,7 +54,7 @@ describe AccountController, type: :controller do
it 'should login should reset session' do
expect(@controller).to receive(:reset_session).once
post :login, username: 'jsmith', password: 'jsmith'
post :login, params: { username: 'jsmith', password: 'jsmith' }
assert_response 302
end
@@ -1,4 +1,5 @@
#-- encoding: UTF-8
#-- copyright
# OpenProject is a project management system.
# Copyright (C) 2012-2017 the OpenProject Foundation (OPF)
@@ -27,7 +28,7 @@
# See doc/COPYRIGHT.rdoc for more details.
#++
require 'legacy_spec_helper'
require_relative '../legacy_spec_helper'
describe ActivitiesController, type: :controller do
fixtures :all
@@ -36,7 +37,6 @@ describe ActivitiesController, type: :controller do
it 'project index' do
Journal.delete_all
project = Project.find(1)
public_project = FactoryGirl.create :public_project
issue = FactoryGirl.create :work_package,
project: public_project,
@@ -62,21 +62,24 @@ describe ActivitiesController, type: :controller do
type_id: issue.type_id,
project_id: issue.project_id)
get :index, id: 1, with_subprojects: 0
get :index, params: { id: 1, with_subprojects: 0 }
assert_response :success
assert_template 'index'
refute_nil assigns(:events_by_day)
assert_select 'h3',
content: /#{1.day.ago.to_date.day}/,
sibling: { tag: 'dl',
child: { tag: 'dt',
attributes: { class: /work_package/ },
child: { tag: 'a',
content: /#{ERB::Util.h(Status.find(2).name)}/
}
}
}
content: /#{1.day.ago.to_date.day}/,
sibling: {
tag: 'dl',
child: {
tag: 'dt',
attributes: { class: /work_package/ },
child: {
tag: 'a',
content: /#{ERB::Util.h(Status.find(2).name)}/
}
}
}
end
it 'previous project index' do
@@ -90,21 +93,24 @@ describe ActivitiesController, type: :controller do
type_id: issue.type_id,
project_id: issue.project_id)
get :index, id: 1, from: 3.days.ago.to_date
get :index, params: { id: 1, from: 3.days.ago.to_date }
assert_response :success
assert_template 'index'
refute_nil assigns(:events_by_day)
assert_select 'h3',
content: /#{3.day.ago.to_date.day}/,
sibling: { tag: 'dl',
child: { tag: 'dt',
attributes: { class: /work_package/ },
child: { tag: 'a',
content: /#{ERB::Util.h(issue.subject)}/
}
}
}
content: /#{3.day.ago.to_date.day}/,
sibling: {
tag: 'dl',
child: {
tag: 'dt',
attributes: { class: /work_package/ },
child: {
tag: 'a',
content: /#{ERB::Util.h(issue.subject)}/
}
}
}
end
it 'user index' do
@@ -119,20 +125,23 @@ describe ActivitiesController, type: :controller do
type_id: issue.type_id,
project_id: issue.project_id)
get :index, user_id: 2
get :index, params: { user_id: 2 }
assert_response :success
assert_template 'index'
refute_nil assigns(:events_by_day)
assert_select 'h3',
content: /#{3.day.ago.to_date.day}/,
sibling: { tag: 'dl',
child: { tag: 'dt',
attributes: { class: /work_package/ },
child: { tag: 'a',
content: /#{ERB::Util.h(WorkPackage.find(1).subject)}/
}
}
}
content: /#{3.day.ago.to_date.day}/,
sibling: {
tag: 'dl',
child: {
tag: 'dt',
attributes: { class: /work_package/ },
child: {
tag: 'a',
content: /#{ERB::Util.h(WorkPackage.find(1).subject)}/
}
}
}
end
end
@@ -1,4 +1,5 @@
#-- encoding: UTF-8
#-- copyright
# OpenProject is a project management system.
# Copyright (C) 2012-2017 the OpenProject Foundation (OPF)
@@ -26,7 +27,7 @@
#
# See doc/COPYRIGHT.rdoc for more details.
#++
require 'legacy_spec_helper'
require_relative '../legacy_spec_helper'
require 'admin_controller'
describe AdminController, type: :controller do
@@ -51,11 +52,11 @@ describe AdminController, type: :controller do
assert_template 'projects'
refute_nil assigns(:projects)
# active projects only
assert_nil assigns(:projects).detect { |u| !u.active? }
assert_nil(assigns(:projects).detect { |u| !u.active? })
end
it 'should projects with name filter' do
get :projects, name: 'store', status: ''
get :projects, params: { name: 'store', status: '' }
assert_response :success
assert_template 'projects'
projects = assigns(:projects)
@@ -118,8 +119,9 @@ describe AdminController, type: :controller do
get :projects
assert_response :success
assert_select 'a', attributes: { href: '/projects' },
content: 'Test'
assert_select 'a',
attributes: { href: '/projects' },
content: 'Test'
Redmine::MenuManager.map :admin_menu do |menu|
menu.delete :test_admin_menu_plugin_extension
@@ -26,7 +26,7 @@
#
# See doc/COPYRIGHT.rdoc for more details.
#++
require 'legacy_spec_helper'
require_relative '../legacy_spec_helper'
require 'application_controller'
describe ApplicationController, type: :controller do
@@ -1,4 +1,5 @@
#-- encoding: UTF-8
#-- copyright
# OpenProject is a project management system.
# Copyright (C) 2012-2017 the OpenProject Foundation (OPF)
@@ -27,7 +28,7 @@
# See doc/COPYRIGHT.rdoc for more details.
#++
require 'legacy_spec_helper'
require_relative '../legacy_spec_helper'
require 'attachments_controller'
describe AttachmentsController, type: :controller do
@@ -40,28 +41,28 @@ describe AttachmentsController, type: :controller do
end
it 'should download other' do
get :download, id: 6
get :download, params: { id: 6 }
assert_equal 'application/zip', response.content_type
end
it 'should download text file' do
get :download, id: 4
get :download, params: { id: 4 }
assert_response :success
assert_equal 'text/x-ruby', response.content_type
end
it 'should download missing file' do
get :download, id: 2
get :download, params: { id: 2 }
assert_response 404
end
it 'should anonymous on private private' do
get :download, id: 7
get :download, params: { id: 7 }
assert_redirected_to '/login?back_url=http%3A%2F%2Ftest.host%2Fattachments%2F7'
end
it 'should destroy without permission' do
delete :destroy, id: 3
delete :destroy, params: { id: 3 }
assert_redirected_to '/login?back_url=http%3A%2F%2Ftest.host%2Fattachments%2F3'
assert Attachment.find_by(id: 3)
end
@@ -1,4 +1,5 @@
#-- encoding: UTF-8
#-- copyright
# OpenProject is a project management system.
# Copyright (C) 2012-2017 the OpenProject Foundation (OPF)
@@ -26,7 +27,7 @@
#
# See doc/COPYRIGHT.rdoc for more details.
#++
require 'legacy_spec_helper'
require_relative '../legacy_spec_helper'
require 'boards_controller'
describe BoardsController, type: :controller do
@@ -37,7 +38,7 @@ describe BoardsController, type: :controller do
end
it 'should index' do
get :index, project_id: 1
get :index, params: { project_id: 1 }
assert_response :success
assert_template 'index'
refute_nil assigns(:boards)
@@ -45,7 +46,7 @@ describe BoardsController, type: :controller do
end
it 'should index not found' do
get :index, project_id: 97
get :index, params: { project_id: 97 }
assert_response 404
end
@@ -53,7 +54,7 @@ describe BoardsController, type: :controller do
boards = Project.find(1).boards
boards.take(boards.count - 1).each(&:destroy)
get :index, project_id: 1
get :index, params: { project_id: 1 }
assert_response :success
assert_template 'show'
refute_nil assigns(:topics)
@@ -62,13 +63,13 @@ describe BoardsController, type: :controller do
it 'should create' do
session[:user_id] = 2
assert_difference 'Board.count' do
post :create, project_id: 1, board: { name: 'Testing', description: 'Testing board creation' }
post :create, params: { project_id: 1, board: { name: 'Testing', description: 'Testing board creation' } }
end
assert_redirected_to '/projects/ecookbook/settings/boards'
end
it 'should show' do
get :show, project_id: 1, id: 1
get :show, params: { project_id: 1, id: 1 }
assert_response :success
assert_template 'show'
refute_nil assigns(:board)
@@ -77,7 +78,7 @@ describe BoardsController, type: :controller do
end
it 'should show atom' do
get :show, project_id: 1, id: 1, format: 'atom'
get :show, params: { project_id: 1, id: 1, format: 'atom' }
assert_response :success
assert_template 'common/feed'
refute_nil assigns(:board)
@@ -88,7 +89,7 @@ describe BoardsController, type: :controller do
it 'should update' do
session[:user_id] = 2
assert_no_difference 'Board.count' do
put :update, project_id: 1, id: 2, board: { name: 'Testing', description: 'Testing board update' }
put :update, params: { project_id: 1, id: 2, board: { name: 'Testing', description: 'Testing board update' } }
end
assert_redirected_to '/projects/ecookbook/settings/boards'
assert_equal 'Testing', Board.find(2).name
@@ -97,7 +98,7 @@ describe BoardsController, type: :controller do
it 'should post destroy' do
session[:user_id] = 2
assert_difference 'Board.count', -1 do
post :destroy, project_id: 1, id: 2
post :destroy, params: { project_id: 1, id: 2 }
end
assert_redirected_to '/projects/ecookbook/settings/boards'
assert_nil Board.find_by(id: 2)
@@ -106,7 +107,7 @@ describe BoardsController, type: :controller do
it 'should index should 404 with no board' do
Project.find(1).boards.each(&:destroy)
get :index, project_id: 1
get :index, params: { project_id: 1 }
assert_response 404
end
end
@@ -1,4 +1,5 @@
#-- encoding: UTF-8
#-- copyright
# OpenProject is a project management system.
# Copyright (C) 2012-2017 the OpenProject Foundation (OPF)
@@ -26,7 +27,7 @@
#
# See doc/COPYRIGHT.rdoc for more details.
#++
require 'legacy_spec_helper'
require_relative '../legacy_spec_helper'
require 'enumerations_controller'
describe EnumerationsController, type: :controller do
@@ -43,13 +44,13 @@ describe EnumerationsController, type: :controller do
end
it 'should destroy enumeration not in use' do
post :destroy, id: 7
post :destroy, params: { id: 7 }
assert_redirected_to enumerations_path
assert_nil Enumeration.find_by(id: 7)
end
it 'should destroy enumeration in use' do
post :destroy, id: 4
post :destroy, params: { id: 4 }
assert_response :success
assert_template 'destroy'
refute_nil Enumeration.find_by(id: 4)
@@ -57,7 +58,7 @@ describe EnumerationsController, type: :controller do
it 'should destroy enumeration in use with reassignment' do
issue = WorkPackage.find_by(priority_id: 4)
post :destroy, id: 4, reassign_to_id: 6
post :destroy, params: { id: 4, reassign_to_id: 6 }
assert_redirected_to enumerations_path
assert_nil Enumeration.find_by(id: 4)
# check that the issue was reassign
@@ -1,4 +1,5 @@
#-- encoding: UTF-8
#-- copyright
# OpenProject is a project management system.
# Copyright (C) 2012-2017 the OpenProject Foundation (OPF)
@@ -26,7 +27,7 @@
#
# See doc/COPYRIGHT.rdoc for more details.
#++
require 'legacy_spec_helper'
require_relative '../legacy_spec_helper'
require 'groups_controller'
describe GroupsController, type: :controller do
@@ -44,7 +45,7 @@ describe GroupsController, type: :controller do
end
it 'should show' do
get :show, id: 10
get :show, params: { id: 10 }
assert_response :success
assert_template 'show'
end
@@ -57,61 +58,61 @@ describe GroupsController, type: :controller do
it 'should create' do
assert_difference 'Group.count' do
post :create, group: { lastname: 'New group' }
post :create, params: { group: { lastname: 'New group' } }
end
assert_redirected_to groups_path
end
it 'should edit' do
get :edit, id: 10
get :edit, params: { id: 10 }
assert_response :success
assert_template 'edit'
end
it 'should update' do
put :update, id: 10, group: { lastname: 'new name' }
put :update, params: { id: 10, group: { lastname: 'new name' } }
assert_redirected_to groups_path
end
it 'should destroy' do
assert_difference 'Group.count', -1 do
delete :destroy, id: 10
delete :destroy, params: { id: 10 }
end
assert_redirected_to groups_path
end
it 'should add users' do
assert_difference 'Group.find(10).users.count', 2 do
post :add_users, id: 10, user_ids: ['2', '3']
post :add_users, params: { id: 10, user_ids: ['2', '3'] }
end
end
it 'should remove user' do
assert_difference 'Group.find(10).users.count', -1 do
delete :remove_user, id: 10, user_id: '8'
delete :remove_user, params: { id: 10, user_id: '8' }
end
end
it 'should create membership' do
assert_difference 'Group.find(10).members.count' do
post :create_memberships, id: 10, membership: { project_id: 2, role_ids: ['1', '2'] }
post :create_memberships, params: { id: 10, membership: { project_id: 2, role_ids: ['1', '2'] } }
end
end
it 'should edit membership' do
assert_no_difference 'Group.find(10).members.count' do
put :edit_membership, id: 10, membership_id: 6, membership: { role_ids: ['1', '3'] }
put :edit_membership, params: { id: 10, membership_id: 6, membership: { role_ids: ['1', '3'] } }
end
end
it 'should destroy membership' do
assert_difference 'Group.find(10).members.count', -1 do
delete :destroy_membership, id: 10, membership_id: 6
delete :destroy_membership, params: { id: 10, membership_id: 6 }
end
end
it 'should autocomplete for user' do
get :autocomplete_for_user, id: 10, q: 'mis'
get :autocomplete_for_user, params: { id: 10, q: 'mis' }
assert_response :success
users = assigns(:users)
refute_nil users
@@ -1,4 +1,5 @@
#-- encoding: UTF-8
#-- copyright
# OpenProject is a project management system.
# Copyright (C) 2012-2017 the OpenProject Foundation (OPF)
@@ -27,7 +28,7 @@
# See doc/COPYRIGHT.rdoc for more details.
#++
require 'legacy_spec_helper'
require_relative '../legacy_spec_helper'
describe HelpController, type: :controller do
render_views
@@ -1,4 +1,5 @@
#-- encoding: UTF-8
#-- copyright
# OpenProject is a project management system.
# Copyright (C) 2012-2017 the OpenProject Foundation (OPF)
@@ -26,7 +27,7 @@
#
# See doc/COPYRIGHT.rdoc for more details.
#++
require 'legacy_spec_helper'
require_relative '../legacy_spec_helper'
require 'mail_handler_controller'
describe MailHandlerController, type: :controller do
@@ -43,7 +44,7 @@ describe MailHandlerController, type: :controller do
Setting.mail_handler_api_enabled = 1
Setting.mail_handler_api_key = 'secret'
post :index, key: 'secret', email: IO.read(File.join(FIXTURES_PATH, 'ticket_on_given_project.eml'))
post :index, params: { key: 'secret', email: IO.read(File.join(FIXTURES_PATH, 'ticket_on_given_project.eml')) }
assert_response 201
end
@@ -52,7 +53,7 @@ describe MailHandlerController, type: :controller do
Setting.mail_handler_api_enabled = 0
Setting.mail_handler_api_key = 'secret'
post :index, key: 'secret', email: IO.read(File.join(FIXTURES_PATH, 'ticket_on_given_project.eml'))
post :index, params: { key: 'secret', email: IO.read(File.join(FIXTURES_PATH, 'ticket_on_given_project.eml')) }
assert_response 403
end
end
@@ -1,4 +1,5 @@
#-- encoding: UTF-8
#-- copyright
# OpenProject is a project management system.
# Copyright (C) 2012-2017 the OpenProject Foundation (OPF)
@@ -26,7 +27,7 @@
#
# See doc/COPYRIGHT.rdoc for more details.
#++
require 'legacy_spec_helper'
require_relative '../legacy_spec_helper'
require 'messages_controller'
describe MessagesController, type: :controller do
@@ -39,7 +40,7 @@ describe MessagesController, type: :controller do
end
it 'should show' do
get :show, board_id: 1, id: 1
get :show, params: { board_id: 1, id: 1 }
assert_response :success
assert_template 'show'
refute_nil assigns(:board)
@@ -56,7 +57,7 @@ describe MessagesController, type: :controller do
message.children << m
end
end
get :show, board_id: 1, id: 1, per_page: 100, r: message.children.order('id').last.id
get :show, params: { board_id: 1, id: 1, per_page: 100, r: message.children.order('id').last.id }
assert_response :success
assert_template 'show'
replies = assigns(:replies)
@@ -67,21 +68,22 @@ describe MessagesController, type: :controller do
it 'should show with reply permission' do
session[:user_id] = 2
get :show, board_id: 1, id: 1
get :show, params: { board_id: 1, id: 1 }
assert_response :success
assert_template 'show'
assert_select 'div', attributes: { id: 'reply' },
descendant: { tag: 'textarea', attributes: { id: 'reply_content' } }
assert_select 'div',
attributes: { id: 'reply' },
descendant: { tag: 'textarea', attributes: { id: 'reply_content' } }
end
it 'should show message not found' do
get :show, board_id: 1, id: 99999
get :show, params: { board_id: 1, id: 99999 }
assert_response 404
end
it 'should get new' do
session[:user_id] = 2
get :new, board_id: 1
get :new, params: { board_id: 1 }
assert_response :success
assert_template 'new'
end
@@ -90,9 +92,14 @@ describe MessagesController, type: :controller do
session[:user_id] = 2
allow(Setting).to receive(:notified_events).and_return ['message_posted']
post :create, board_id: 1,
message: { subject: 'Test created message',
content: 'Message body' }
post :create,
params: {
board_id: 1,
message: {
subject: 'Test created message',
content: 'Message body'
}
}
message = Message.find_by(subject: 'Test created message')
refute_nil message
assert_redirected_to topic_path(message)
@@ -106,7 +113,8 @@ describe MessagesController, type: :controller do
mail = mails_to_author.first
assert mail.to.include?('jsmith@somenet.foo')
assert_kind_of Mail::Message, mail
assert_equal "[#{message.board.project.name} - #{message.board.name} - msg#{message.root.id}] Test created message", mail.subject
assert_equal "[#{message.board.project.name} - #{message.board.name} - msg#{message.root.id}] Test created message",
mail.subject
assert mail.body.encoded.include?('Message body')
# project member
@@ -117,16 +125,21 @@ describe MessagesController, type: :controller do
it 'should get edit' do
session[:user_id] = 2
get :edit, id: 1
get :edit, params: { id: 1 }
assert_response :success
assert_template 'edit'
end
it 'should put update' do
session[:user_id] = 2
put :update, id: 1,
message: { subject: 'New subject',
content: 'New body' }
put :update,
params: {
id: 1,
message: {
subject: 'New subject',
content: 'New body'
}
}
message = Message.find(1)
assert_redirected_to topic_path(message)
assert_equal 'New subject', message.subject
@@ -135,7 +148,7 @@ describe MessagesController, type: :controller do
it 'should reply' do
session[:user_id] = 2
post :reply, board_id: 1, id: 1, reply: { content: 'This is a test reply', subject: 'Test reply' }
post :reply, params: { board_id: 1, id: 1, reply: { content: 'This is a test reply', subject: 'Test reply' } }
reply = Message.order('id DESC').first
assert_redirected_to topic_path(1, r: reply)
assert Message.find_by(subject: 'Test reply')
@@ -143,14 +156,14 @@ describe MessagesController, type: :controller do
it 'should destroy topic' do
session[:user_id] = 2
delete :destroy, id: 1
delete :destroy, params: { id: 1 }
assert_redirected_to project_board_path('ecookbook', 1)
assert_nil Message.find_by(id: 1)
end
it 'should quote' do
session[:user_id] = 2
xhr :get, :quote, board_id: 1, id: 3
get :quote, params: { board_id: 1, id: 3 }, xhr: true
assert_response :success
assert_template 'quote'
end
+7 -4
View File
@@ -1,4 +1,5 @@
#-- encoding: UTF-8
#-- copyright
# OpenProject is a project management system.
# Copyright (C) 2012-2017 the OpenProject Foundation (OPF)
@@ -26,7 +27,7 @@
#
# See doc/COPYRIGHT.rdoc for more details.
#++
require 'legacy_spec_helper'
require_relative '../legacy_spec_helper'
require 'my_controller'
describe MyController, type: :controller do
@@ -64,19 +65,21 @@ describe MyController, type: :controller do
end
it 'should add block' do
xhr :post, :add_block, block: 'issuesreportedbyme'
post :add_block, params: { block: 'issuesreportedbyme' }, xhr: true
assert_response :success
assert User.find(2).pref[:my_page_layout]['top'].include?('issuesreportedbyme')
end
it 'should remove block' do
xhr :post, :remove_block, block: 'issuesassignedtome'
post :remove_block, params: { block: 'issuesassignedtome' }, xhr: true
assert_response :success
assert !User.find(2).pref[:my_page_layout].values.flatten.include?('issuesassignedtome')
end
it 'should order blocks' do
xhr :post, :order_blocks, target: 'left', 'target_ordered_children' => ['documents', 'calendar', 'latestnews']
post :order_blocks,
params: { target: 'left', 'target_ordered_children' => ['documents', 'calendar', 'latestnews'] },
xhr: true
assert_response :success
assert_equal ['documents', 'calendar', 'latestnews'], User.find(2).pref[:my_page_layout]['left']
end
@@ -1,4 +1,5 @@
#-- encoding: UTF-8
#-- copyright
# OpenProject is a project management system.
# Copyright (C) 2012-2017 the OpenProject Foundation (OPF)
@@ -27,7 +28,7 @@
# See doc/COPYRIGHT.rdoc for more details.
#++
require 'legacy_spec_helper'
require_relative '../legacy_spec_helper'
describe ProjectEnumerationsController, type: :controller do
fixtures :all
@@ -41,13 +42,21 @@ describe ProjectEnumerationsController, type: :controller do
session[:user_id] = 2 # manager
billable_field = TimeEntryActivityCustomField.find_by(name: 'Billable')
put :update, project_id: 1, enumerations: {
'9' => { 'parent_id' => '9', 'custom_field_values' => { '7' => '1' }, 'active' => '0' }, # Design, De-activate
'10' => { 'parent_id' => '10', 'custom_field_values' => { '7' => '0' }, 'active' => '1' }, # Development, Change custom value
'14' => { 'parent_id' => '14', 'custom_field_values' => { '7' => '1' }, 'active' => '1' }, # Inactive Activity, Activate with custom value
'11' => { 'parent_id' => '11', 'custom_field_values' => { '7' => '1' }, 'active' => '1' } # QA, no changes
params = {
project_id: 1,
enumerations: {
# Design, De-activate
'9' => { 'parent_id' => '9', 'custom_field_values' => { '7' => '1' }, 'active' => '0' },
# Development, Change custom value
'10' => { 'parent_id' => '10', 'custom_field_values' => { '7' => '0' }, 'active' => '1' },
# Inactive Activity, Activate with custom value
'14' => { 'parent_id' => '14', 'custom_field_values' => { '7' => '1' }, 'active' => '1' },
'11' => { 'parent_id' => '11', 'custom_field_values' => { '7' => '1' }, 'active' => '1' } # QA, no changes
}
}
put :update, params: params
assert_response :redirect
assert_redirected_to '/projects/ecookbook/settings/activities'
@@ -105,11 +114,16 @@ describe ProjectEnumerationsController, type: :controller do
)
assert project_activity_two.save
put :update, project_id: 1, enumerations: {
project_activity.id => { 'custom_field_values' => { '7' => '1' }, 'active' => '0' }, # De-activate
project_activity_two.id => { 'custom_field_values' => { '7' => '1' }, 'active' => '0' } # De-activate
params = {
project_id: 1,
enumerations: {
project_activity.id => { 'custom_field_values' => { '7' => '1' }, 'active' => '0' }, # De-activate
project_activity_two.id => { 'custom_field_values' => { '7' => '1' }, 'active' => '0' } # De-activate
}
}
put :update, params: params
assert_response :redirect
assert_redirected_to '/projects/ecookbook/settings/activities'
@@ -132,16 +146,24 @@ describe ProjectEnumerationsController, type: :controller do
assert_equal 3, TimeEntry.where(activity_id: 9, project_id: 1).size
session[:user_id] = 2 # manager
put :update, project_id: 1, enumerations: {
'9' => { 'parent_id' => '9', 'custom_field_values' => { '7' => '1' }, 'active' => '0' } # Design, De-activate
params = {
project_id: 1,
enumerations: {
'9' => { 'parent_id' => '9', 'custom_field_values' => { '7' => '1' }, 'active' => '0' } # Design, De-activate
}
}
put :update, params: params
assert_response :redirect
# No more TimeEntries using the system activity
assert_equal 0, TimeEntry.where(activity_id: 9, project_id: 1).size, 'Time Entries still assigned to system activities'
# All TimeEntries using project activity
project_specific_activity = TimeEntryActivity.find_by(parent_id: 9, project_id: 1)
assert_equal 3, TimeEntry.where(activity_id: project_specific_activity.id, project_id: 1).size, 'No Time Entries assigned to the project activity'
assert_equal 3,
TimeEntry.where(activity_id: project_specific_activity.id, project_id: 1).size,
'No Time Entries assigned to the project activity'
end
it 'update when creating new activities will not convert existing data if an exception is raised' do
@@ -165,16 +187,27 @@ describe ProjectEnumerationsController, type: :controller do
session[:user_id] = 2 # manager
put :update, project_id: 1,
enumerations: { '9' => { 'parent_id' => parent.id,
'custom_field_values' => { '7' => '1' },
'active' => '0' } }
params = {
project_id: 1,
enumerations: {
'9' => { 'parent_id' => parent.id,
'custom_field_values' => { '7' => '1' },
'active' => '0' }
}
}
put :update, params: params
assert_response :redirect
# TimeEntries shouldn't have been reassigned on the failed record
assert_equal 3, TimeEntry.where(activity_id: 9, project_id: 1).size, 'Time Entries are not assigned to system activities'
assert_equal 3,
TimeEntry.where(activity_id: 9, project_id: 1).size,
'Time Entries are not assigned to system activities'
# TimeEntries shouldn't have been reassigned on the saved record either
assert_equal 1, TimeEntry.where(activity_id: 10, project_id: 1).size, 'Time Entries are not assigned to system activities'
assert_equal 1,
TimeEntry.where(activity_id: 10, project_id: 1).size,
'Time Entries are not assigned to system activities'
end
it 'destroy' do
@@ -194,7 +227,7 @@ describe ProjectEnumerationsController, type: :controller do
)
assert project_activity_two.save
delete :destroy, project_id: 1
delete :destroy, params: { project_id: 1 }
assert_response :redirect
assert_redirected_to '/projects/ecookbook/settings/activities'
@@ -215,12 +248,16 @@ describe ProjectEnumerationsController, type: :controller do
.update_all("activity_id = '#{project_activity.id}'")
assert_equal 3, TimeEntry.where(activity_id: project_activity.id, project_id: 1).size
delete :destroy, project_id: 1
delete :destroy, params: { project_id: 1 }
assert_response :redirect
assert_redirected_to '/projects/ecookbook/settings/activities'
assert_nil TimeEntryActivity.find_by(id: project_activity.id)
assert_equal 0, TimeEntry.where(activity_id: project_activity.id, project_id: 1).size, 'TimeEntries still assigned to project specific activity'
assert_equal 3, TimeEntry.where(activity_id: 9, project_id: 1).size, 'TimeEntries still assigned to project specific activity'
assert_equal 0,
TimeEntry.where(activity_id: project_activity.id, project_id: 1).size,
'TimeEntries still assigned to project specific activity'
assert_equal 3,
TimeEntry.where(activity_id: 9, project_id: 1).size,
'TimeEntries still assigned to project specific activity'
end
end
+159 -108
View File
@@ -1,4 +1,5 @@
#-- encoding: UTF-8
#-- copyright
# OpenProject is a project management system.
# Copyright (C) 2012-2017 the OpenProject Foundation (OPF)
@@ -47,16 +48,20 @@ describe ProjectsController, type: :controller do
assert_template 'index'
refute_nil assigns(:projects)
assert_select 'ul', child: { tag: 'li',
descendant: { tag: 'a', content: 'eCookbook' },
child: { tag: 'ul',
descendant: { tag: 'a',
content: 'Child of private child'
}
}
}
assert_select 'ul',
child: {
tag: 'li',
descendant: { tag: 'a', content: 'eCookbook' },
child: {
tag: 'ul',
descendant: {
tag: 'a',
content: 'Child of private child'
}
}
}
assert_select('a', {content: /Private child of eCookbook/}, false)
assert_select('a', { content: /Private child of eCookbook/ }, false)
end
it 'should index atom' do
@@ -78,7 +83,7 @@ describe ProjectsController, type: :controller do
it 'should not show overall spent time link' do
get :index
assert_template 'index'
assert_select('a', {attributes: { href: '/time_entries' }}, false)
assert_select('a', { attributes: { href: '/time_entries' } }, false)
end
end
end
@@ -106,7 +111,7 @@ describe ProjectsController, type: :controller do
get :new
assert_response :success
assert_template 'new'
assert_select('select', {attributes: { name: 'project[parent_id]' }}, false)
assert_select('select', { attributes: { name: 'project[parent_id]' } }, false)
end
end
@@ -118,15 +123,20 @@ describe ProjectsController, type: :controller do
end
it 'should accept get' do
get :new, parent_id: 'ecookbook'
get :new, params: { parent_id: 'ecookbook' }
assert_response :success
assert_template 'new'
# parent project selected
assert_select 'select', attributes: { name: 'project[parent_id]' },
child: { tag: 'option', attributes: { value: '1', selected: 'selected' } }
assert_select 'select',
attributes: { name: 'project[parent_id]' },
child: { tag: 'option', attributes: { value: '1', selected: 'selected' } }
# no empty value
assert_select('select', {attributes: { name: 'project[parent_id]' },
child: { tag: 'option', attributes: { value: '' } }}, false)
assert_select('select',
{
attributes: { name: 'project[parent_id]' },
child: { tag: 'option', attributes: { value: '' } }
},
false)
end
end
end
@@ -139,16 +149,18 @@ describe ProjectsController, type: :controller do
it 'should create a new project' do
post :create,
project: {
name: 'blog',
description: 'weblog',
identifier: 'blog',
is_public: 1,
custom_field_values: { :'3' => '5' },
type_ids: ['1', '3'],
# an issue custom field that is not for all project
work_package_custom_field_ids: ['9'],
enabled_module_names: ['work_package_tracking', 'news', 'repository']
params: {
project: {
name: 'blog',
description: 'weblog',
identifier: 'blog',
is_public: 1,
custom_field_values: { '3': '5' },
type_ids: ['1', '3'],
# an issue custom field that is not for all project
work_package_custom_field_ids: ['9'],
enabled_module_names: ['work_package_tracking', 'news', 'repository']
}
}
assert_redirected_to '/projects/blog/work_packages'
@@ -165,13 +177,17 @@ describe ProjectsController, type: :controller do
end
it 'should create a new subproject' do
post :create, project: { name: 'blog',
description: 'weblog',
identifier: 'blog',
is_public: 1,
custom_field_values: { '3' => '5' },
parent_id: 1
}
post :create,
params: {
project: {
name: 'blog',
description: 'weblog',
identifier: 'blog',
is_public: 1,
custom_field_values: { '3' => '5' },
parent_id: 1
}
}
assert_redirected_to '/projects/blog/work_packages'
project = Project.find_by(name: 'blog')
@@ -187,14 +203,18 @@ describe ProjectsController, type: :controller do
end
it 'should accept create a Project' do
post :create, project: { name: 'blog',
description: 'weblog',
identifier: 'blog',
is_public: 1,
custom_field_values: { '3' => '5' },
type_ids: ['1', '3'],
enabled_module_names: ['work_package_tracking', 'news', 'repository']
}
post :create,
params: {
project: {
name: 'blog',
description: 'weblog',
identifier: 'blog',
is_public: 1,
custom_field_values: { '3' => '5' },
type_ids: ['1', '3'],
enabled_module_names: ['work_package_tracking', 'news', 'repository']
}
}
assert_redirected_to '/projects/blog/work_packages'
@@ -212,13 +232,17 @@ describe ProjectsController, type: :controller do
it 'should fail with parent_id' do
assert_no_difference 'Project.count' do
post :create, project: { name: 'blog',
description: 'weblog',
identifier: 'blog',
is_public: 1,
custom_field_values: { '3' => '5' },
parent_id: 1
}
post :create,
params: {
project: {
name: 'blog',
description: 'weblog',
identifier: 'blog',
is_public: 1,
custom_field_values: { '3' => '5' },
parent_id: 1
}
}
end
assert_response :success
project = assigns(:project)
@@ -235,25 +259,32 @@ describe ProjectsController, type: :controller do
end
it 'should create a project with a parent_id' do
post :create, project: { name: 'blog',
description: 'weblog',
identifier: 'blog',
is_public: 1,
custom_field_values: { '3' => '5' },
parent_id: 1
}
post :create,
params: {
project: {
name: 'blog',
description: 'weblog',
identifier: 'blog',
is_public: 1,
custom_field_values: { '3' => '5' },
parent_id: 1
}
}
assert_redirected_to '/projects/blog/work_packages'
project = Project.find_by(name: 'blog')
end
it 'should fail without parent_id' do
assert_no_difference 'Project.count' do
post :create, project: { name: 'blog',
description: 'weblog',
identifier: 'blog',
is_public: 1,
custom_field_values: { '3' => '5' }
}
post :create,
params: {
project: {
name: 'blog',
description: 'weblog',
identifier: 'blog',
is_public: 1,
custom_field_values: { '3' => '5' }
}
}
end
assert_response :success
project = assigns(:project)
@@ -264,13 +295,17 @@ describe ProjectsController, type: :controller do
it 'should fail with unauthorized parent_id' do
assert !User.find(2).member_of?(Project.find(6))
assert_no_difference 'Project.count' do
post :create, project: { name: 'blog',
description: 'weblog',
identifier: 'blog',
is_public: 1,
custom_field_values: { '3' => '5' },
parent_id: 6
}
post :create,
params: {
project: {
name: 'blog',
description: 'weblog',
identifier: 'blog',
is_public: 1,
custom_field_values: { '3' => '5' },
parent_id: 6
}
}
end
assert_response :success
project = assigns(:project)
@@ -285,11 +320,14 @@ describe ProjectsController, type: :controller do
it 'should create should preserve modules on validation failure' do
session[:user_id] = 1
assert_no_difference 'Project.count' do
post :create, project: {
name: 'blog',
identifier: '',
enabled_module_names: %w(work_package_tracking news)
}
post :create,
params: {
project: {
name: 'blog',
identifier: '',
enabled_module_names: %w(work_package_tracking news)
}
}
end
assert_response :success
project = assigns(:project)
@@ -298,14 +336,14 @@ describe ProjectsController, type: :controller do
end
it 'should show by id' do
get :show, id: 1
get :show, params: { id: 1 }
assert_response :success
assert_template 'show'
refute_nil assigns(:project)
end
it 'should show by identifier' do
get :show, id: 'ecookbook'
get :show, params: { id: 'ecookbook' }
assert_response :success
assert_template 'show'
refute_nil assigns(:project)
@@ -316,18 +354,18 @@ describe ProjectsController, type: :controller do
it 'should show should not display hidden custom fields' do
ProjectCustomField.find_by(name: 'Development status').update_attribute :visible, false
get :show, id: 'ecookbook'
get :show, params: { id: 'ecookbook' }
assert_response :success
assert_template 'show'
refute_nil assigns(:project)
assert_select('li', {content: /Development status/}, false)
assert_select('li', { content: /Development status/ }, false)
end
it 'should show should not fail when custom values are nil' do
project = Project.find_by(identifier: 'ecookbook')
project.custom_values.first.update_attribute(:value, nil)
get :show, id: 'ecookbook'
get :show, params: { id: 'ecookbook' }
assert_response :success
assert_template 'show'
refute_nil assigns(:project)
@@ -338,22 +376,22 @@ describe ProjectsController, type: :controller do
project = Project.find_by(identifier: 'ecookbook')
project.archive!
get :show, id: 'ecookbook'
get :show, params: { id: 'ecookbook' }
assert_response 403
assert_nil assigns(:project)
assert_select 'p', content: /archived/
end
it 'should private subprojects hidden' do
get :show, id: 'ecookbook'
get :show, params: { id: 'ecookbook' }
assert_response :success
assert_template 'show'
assert_select('a', {content: /Private child/}, false)
assert_select('a', { content: /Private child/ }, false)
end
it 'should private subprojects visible' do
session[:user_id] = 2 # manager who is a member of the private subproject
get :show, id: 'ecookbook'
get :show, params: { id: 'ecookbook' }
assert_response :success
assert_template 'show'
assert_select 'a', content: /Private child/
@@ -361,15 +399,21 @@ describe ProjectsController, type: :controller do
it 'should settings' do
session[:user_id] = 2 # manager
get :settings, id: 1
get :settings, params: { id: 1 }
assert_response :success
assert_template 'settings'
end
it 'should update' do
session[:user_id] = 2 # manager
put :update, id: 1, project: { name: 'Test changed name',
issue_custom_field_ids: [''] }
put :update,
params: {
id: 1,
project: {
name: 'Test changed name',
issue_custom_field_ids: ['']
}
}
assert_redirected_to '/projects/ecookbook/settings'
project = Project.find(1)
assert_equal 'Test changed name', project.name
@@ -379,14 +423,14 @@ describe ProjectsController, type: :controller do
session[:user_id] = 2
Project.find(1).enabled_module_names = ['work_package_tracking', 'news']
put :modules, id: 1, project: { enabled_module_names: ['work_package_tracking', 'repository'] }
put :modules, params: { id: 1, project: { enabled_module_names: ['work_package_tracking', 'repository'] } }
assert_redirected_to '/projects/ecookbook/settings/modules'
assert_equal ['repository', 'work_package_tracking'], Project.find(1).enabled_module_names.sort
end
it 'should get destroy info' do
session[:user_id] = 1 # admin
get :destroy_info, id: 1
get :destroy_info, params: { id: 1 }
assert_response :success
assert_template 'destroy_info'
refute_nil Project.find_by(id: 1)
@@ -394,14 +438,14 @@ describe ProjectsController, type: :controller do
it 'should post destroy' do
session[:user_id] = 1 # admin
delete :destroy, id: 1, confirm: 1
delete :destroy, params: { id: 1, confirm: 1 }
assert_redirected_to '/admin/projects'
assert_nil Project.find_by(id: 1)
end
it 'should archive' do
session[:user_id] = 1 # admin
put :archive, id: 1
put :archive, params: { id: 1 }
assert_redirected_to '/admin/projects'
assert !Project.find(1).active?
end
@@ -409,42 +453,49 @@ describe ProjectsController, type: :controller do
it 'should unarchive' do
session[:user_id] = 1 # admin
Project.find(1).archive
put :unarchive, id: 1
put :unarchive, params: { id: 1 }
assert_redirected_to '/admin/projects'
assert Project.find(1).active?
end
it 'should jump should redirect to active tab' do
get :show, id: 1, jump: 'work_packages'
get :show, params: { id: 1, jump: 'work_packages' }
assert_redirected_to controller: :work_packages, action: :index, project_id: 'ecookbook'
end
it 'should jump should not redirect to inactive tab' do
get :show, id: 3, jump: 'news'
get :show, params: { id: 3, jump: 'news' }
assert_response :success
assert_template 'show'
end
it 'should jump should not redirect to unknown tab' do
get :show, id: 3, jump: 'foobar'
get :show, params: { id: 3, jump: 'foobar' }
assert_response :success
assert_template 'show'
end
# A hook that is manually registered later
class ProjectBasedTemplate < Redmine::Hook::ViewListener
def view_layouts_base_html_head(context)
context[:controller].send(:render, text: '<p id="hookselector">Hello from hook!</p>')
context 'with hooks' do
# A hook that is manually registered later
class ProjectBasedTemplate < Redmine::Hook::ViewListener
def view_layouts_base_html_head(context)
context[:controller].send(:render, html: '<p id="hookselector">Hello from hook!</p>'.html_safe)
end
end
before do
# Don't use this hook now
Redmine::Hook.clear_listeners
end
after do
Redmine::Hook.clear_listeners
end
it 'should hook response' do
Redmine::Hook.add_listener(ProjectBasedTemplate)
get :show, params: { id: 1 }
assert_select('p#hookselector')
end
end
# Don't use this hook now
Redmine::Hook.clear_listeners
it 'should hook response' do
Redmine::Hook.add_listener(ProjectBasedTemplate)
get :show, id: 1
assert_select('p#hookselector')
Redmine::Hook.clear_listeners
end
end
@@ -1,4 +1,5 @@
#-- encoding: UTF-8
#-- copyright
# OpenProject is a project management system.
# Copyright (C) 2012-2017 the OpenProject Foundation (OPF)
@@ -26,7 +27,7 @@
#
# See doc/COPYRIGHT.rdoc for more details.
#++
require 'legacy_spec_helper'
require_relative '../legacy_spec_helper'
require 'repositories_controller'
describe RepositoriesController, type: :controller do
@@ -50,52 +51,57 @@ describe RepositoriesController, type: :controller do
end
it 'should revisions' do
get :revisions, project_id: 1
get :revisions, params: { project_id: 1 }
assert_response :success
assert_template 'revisions'
refute_nil assigns(:changesets)
end
it 'should revision' do
get :revision, project_id: 1, rev: 1
get :revision, params: { project_id: 1, rev: 1 }
assert_response :success
refute_nil assigns(:changeset)
assert_equal '1', assigns(:changeset).revision
end
it 'should revision with before nil and after normal' do
get :revision, project_id: 1, rev: 1
get :revision, params: { project_id: 1, rev: 1 }
assert_response :success
assert_template 'revision'
assert_select('ul',
{attributes: { class: 'toolbar-items' },
descendant: { tag: 'a',
attributes: {
href: @controller.url_for(
only_path: true,
controller: 'repositories',
action: 'revision',
project_id: 'ecookbook',
rev: '0'
)
}}}, false)
assert_select('ul',
{
attributes: { class: 'toolbar-items' },
descendant: {
tag: 'a',
attributes: {
href: @controller.url_for(
only_path: true,
controller: 'repositories',
action: 'revision',
project_id: 'ecookbook',
rev: '0'
)
}
}
}, false)
assert_select 'ul',
attributes: { class: 'toolbar-items' },
descendant: { tag: 'a',
attributes: {
href: @controller.url_for(
only_path: true,
controller: 'repositories',
action: 'revision',
project_id: 'ecookbook',
rev: '2'
)
}
}
attributes: { class: 'toolbar-items' },
descendant: {
tag: 'a',
attributes: {
href: @controller.url_for(
only_path: true,
controller: 'repositories',
action: 'revision',
project_id: 'ecookbook',
rev: '2'
)
}
}
end
it 'should graph commits per month' do
get :graph, project_id: 1, graph: 'commits_per_month'
get :graph, params: { project_id: 1, graph: 'commits_per_month' }
assert_response :success
assert_equal 'image/svg+xml', response.content_type
end
@@ -111,24 +117,27 @@ describe RepositoriesController, type: :controller do
comments: 'Committed by foo.'
)
get :committers, project_id: 1
get :committers, params: { project_id: 1 }
assert_response :success
assert_template 'committers'
assert_select 'td',
content: 'foo',
sibling: {
tag: 'td',
child: { tag: 'select',
attributes: { name: %r{^committers\[\d+\]\[\]$} }
}
}
assert_select('td',
{content: 'foo',
content: 'foo',
sibling: {
tag: 'td',
descendant: { tag: 'option', attributes: { selected: 'selected' } }
}}, false)
child: {
tag: 'select',
attributes: { name: %r{^committers\[\d+\]\[\]$} }
}
}
assert_select('td',
{
content: 'foo',
sibling: {
tag: 'td',
descendant: { tag: 'option', attributes: { selected: 'selected' } }
}
}, false)
end
it 'should map committers' do
@@ -142,8 +151,12 @@ describe RepositoriesController, type: :controller do
comments: 'Committed by foo.'
)
assert_no_difference "Changeset.where('user_id = 3').count" do
post :committers, project_id: 1,
committers: { '0' => ['foo', '2'], '1' => ['dlopper', '3'] }
post :committers,
params: {
project_id: 1,
committers: { '0' => ['foo', '2'],
'1' => ['dlopper', '3'] }
}
assert_redirected_to '/projects/ecookbook/repository/committers'
assert_equal User.find(2), c.reload.user
end
@@ -26,7 +26,7 @@
#
# See doc/COPYRIGHT.rdoc for more details.
#++
require 'legacy_spec_helper'
require_relative '../legacy_spec_helper'
require 'repositories_controller'
describe RepositoriesController, 'Git', type: :controller do
@@ -64,7 +64,7 @@ describe RepositoriesController, 'Git', type: :controller do
it 'should browse root' do
@repository.fetch_changesets
@repository.reload
get :show, project_id: 3
get :show, params: { project_id: 3 }
assert_response :success
assert_template 'show'
refute_nil assigns(:entries)
@@ -85,7 +85,7 @@ describe RepositoriesController, 'Git', type: :controller do
it 'should browse branch' do
@repository.fetch_changesets
@repository.reload
get :show, project_id: 3, rev: 'test_branch'
get :show, params: { project_id: 3, rev: 'test_branch' }
assert_response :success
assert_template 'show'
refute_nil assigns(:entries)
@@ -105,7 +105,7 @@ describe RepositoriesController, 'Git', type: :controller do
'tag00.lightweight',
'tag01.annotated',
].each do |t1|
get :show, project_id: 3, rev: t1
get :show, params: { project_id: 3, rev: t1 }
assert_response :success
assert_template 'show'
refute_nil assigns(:entries)
@@ -118,7 +118,7 @@ describe RepositoriesController, 'Git', type: :controller do
it 'should browse directory' do
@repository.fetch_changesets
@repository.reload
get :show, project_id: 3, path: 'images'
get :show, params: { project_id: 3, path: 'images' }
assert_response :success
assert_template 'show'
refute_nil assigns(:entries)
@@ -134,7 +134,7 @@ describe RepositoriesController, 'Git', type: :controller do
it 'should browse at given revision' do
@repository.fetch_changesets
@repository.reload
get :show, project_id: 3, path: 'images', rev: '7234cb2750b63f47bff735edc50a1c0a433c2518'
get :show, params: { project_id: 3, path: 'images', rev: '7234cb2750b63f47bff735edc50a1c0a433c2518' }
assert_response :success
assert_template 'show'
refute_nil assigns(:entries)
@@ -144,7 +144,7 @@ describe RepositoriesController, 'Git', type: :controller do
end
it 'should changes' do
get :changes, project_id: 3, path: 'images/edit.png'
get :changes, params: { project_id: 3, path: 'images/edit.png' }
assert_response :success
assert_template 'changes'
assert_select 'div',
@@ -153,25 +153,25 @@ describe RepositoriesController, 'Git', type: :controller do
end
it 'should entry show' do
get :entry, project_id: 3, path: 'sources/watchers_controller.rb'
get :entry, params: { project_id: 3, path: 'sources/watchers_controller.rb' }
assert_response :success
assert_template 'entry'
# Line 19
assert_select 'th',
content: /11/,
attributes: { class: /line-num/ },
sibling: { tag: 'td', content: /WITHOUT ANY WARRANTY/ }
content: /11/,
attributes: { class: /line-num/ },
sibling: { tag: 'td', content: /WITHOUT ANY WARRANTY/ }
end
it 'should entry download' do
get :entry, project_id: 3, path: 'sources/watchers_controller.rb', format: 'raw'
get :entry, params: { project_id: 3, path: 'sources/watchers_controller.rb', format: 'raw' }
assert_response :success
# File content
assert response.body.include?('WITHOUT ANY WARRANTY')
end
it 'should directory entry' do
get :entry, project_id: 3, path: 'sources'
get :entry, params: { project_id: 3, path: 'sources' }
assert_response :success
assert_template 'show'
refute_nil assigns(:entry)
@@ -183,7 +183,7 @@ describe RepositoriesController, 'Git', type: :controller do
@repository.reload
# Full diff of changeset 2f9c0091
get :diff, project_id: 3, rev: '2f9c0091c754a91af7a9c478e36556b4bde8dcf7'
get :diff, params: { project_id: 3, rev: '2f9c0091c754a91af7a9c478e36556b4bde8dcf7' }
assert_response :success
assert_template 'diff'
# Line 22 removed
@@ -199,8 +199,8 @@ describe RepositoriesController, 'Git', type: :controller do
@repository.fetch_changesets
@repository.reload
get :diff, project_id: 3, rev: '61b685fbe55ab05b5ac68402d5720c1a6ac973d1',
rev_to: '2f9c0091c754a91af7a9c478e36556b4bde8dcf7'
get :diff, params: { project_id: 3, rev: '61b685fbe55ab05b5ac68402d5720c1a6ac973d1',
rev_to: '2f9c0091c754a91af7a9c478e36556b4bde8dcf7' }
assert_response :success
assert_template 'diff'
@@ -210,7 +210,7 @@ describe RepositoriesController, 'Git', type: :controller do
end
it 'should annotate' do
get :annotate, project_id: 3, path: 'sources/watchers_controller.rb'
get :annotate, params: { project_id: 3, path: 'sources/watchers_controller.rb' }
assert_response :success
assert_template 'annotate'
# Line 23, changeset 2f9c0091
@@ -223,7 +223,7 @@ describe RepositoriesController, 'Git', type: :controller do
it 'should annotate at given revision' do
@repository.fetch_changesets
@repository.reload
get :annotate, project_id: 3, rev: 'deff7', path: 'sources/watchers_controller.rb'
get :annotate, params: { project_id: 3, rev: 'deff7', path: 'sources/watchers_controller.rb' }
assert_response :success
assert_template 'annotate'
assert_select 'div',
@@ -232,7 +232,7 @@ describe RepositoriesController, 'Git', type: :controller do
end
it 'should annotate binary file' do
get :annotate, project_id: 3, path: 'images/edit.png'
get :annotate, params: { project_id: 3, path: 'images/edit.png' }
assert_response 200
assert_select 'p', attributes: { class: /nodata/ },
@@ -243,7 +243,7 @@ describe RepositoriesController, 'Git', type: :controller do
@repository.fetch_changesets
@repository.reload
['61b685fbe55ab05b5ac68402d5720c1a6ac973d1', '61b685f'].each do |r|
get :revision, project_id: 3, rev: r
get :revision, params: { project_id: 3, rev: r }
assert_response :success
assert_template 'revision'
end
@@ -253,7 +253,7 @@ describe RepositoriesController, 'Git', type: :controller do
@repository.fetch_changesets
@repository.reload
['', ' ', nil].each do |r|
get :revision, project_id: 3, rev: r
get :revision, params: { project_id: 3, rev: r }
assert_response 404
assert_error_tag content: /was not found/
end
@@ -26,7 +26,7 @@
#
# See doc/COPYRIGHT.rdoc for more details.
#++
require 'legacy_spec_helper'
require_relative '../legacy_spec_helper'
require 'repositories_controller'
describe RepositoriesController, 'Subversion', type: :controller do
@@ -61,7 +61,7 @@ describe RepositoriesController, 'Subversion', type: :controller do
it 'should show' do
@repository.fetch_changesets
@repository.reload
get :show, project_id: PRJ_ID
get :show, params: { project_id: PRJ_ID }
assert_response :success
assert_template 'show'
refute_nil assigns(:entries)
@@ -71,7 +71,7 @@ describe RepositoriesController, 'Subversion', type: :controller do
it 'should browse root' do
@repository.fetch_changesets
@repository.reload
get :show, project_id: PRJ_ID
get :show, params: { project_id: PRJ_ID }
assert_response :success
assert_template 'show'
refute_nil assigns(:entries)
@@ -82,7 +82,7 @@ describe RepositoriesController, 'Subversion', type: :controller do
it 'should browse directory' do
@repository.fetch_changesets
@repository.reload
get :show, project_id: PRJ_ID, path: 'subversion_test'
get :show, params: { project_id: PRJ_ID, path: 'subversion_test' }
assert_response :success
assert_template 'show'
refute_nil assigns(:entries)
@@ -96,7 +96,7 @@ describe RepositoriesController, 'Subversion', type: :controller do
it 'should browse at given revision' do
@repository.fetch_changesets
@repository.reload
get :show, project_id: PRJ_ID, path: 'subversion_test', rev: 4
get :show, params: { project_id: PRJ_ID, path: 'subversion_test', rev: 4 }
assert_response :success
assert_template 'show'
refute_nil assigns(:entries)
@@ -106,7 +106,7 @@ describe RepositoriesController, 'Subversion', type: :controller do
it 'should file changes' do
@repository.fetch_changesets
@repository.reload
get :changes, project_id: PRJ_ID, path: 'subversion_test/folder/helloworld.rb'
get :changes, params: { project_id: PRJ_ID, path: 'subversion_test/folder/helloworld.rb' }
assert_response :success
assert_template 'changes'
@@ -128,7 +128,7 @@ describe RepositoriesController, 'Subversion', type: :controller do
it 'should directory changes' do
@repository.fetch_changesets
@repository.reload
get :changes, project_id: PRJ_ID, path: 'subversion_test/folder'
get :changes, params: { project_id: PRJ_ID, path: 'subversion_test/folder' }
assert_response :success
assert_template 'changes'
@@ -140,7 +140,7 @@ describe RepositoriesController, 'Subversion', type: :controller do
it 'should entry' do
@repository.fetch_changesets
@repository.reload
get :entry, project_id: PRJ_ID, path: 'subversion_test/helloworld.c'
get :entry, params: { project_id: PRJ_ID, path: 'subversion_test/helloworld.c' }
assert_response :success
assert_template 'entry'
end
@@ -151,7 +151,7 @@ describe RepositoriesController, 'Subversion', type: :controller do
it 'should entry should send if too big' do
@repository.fetch_changesets
@repository.reload
get :entry, project_id: PRJ_ID, path: 'subversion_test/helloworld.c'
get :entry, params: { project_id: PRJ_ID, path: 'subversion_test/helloworld.c' }
assert_response :success
assert_template nil
assert_equal 'attachment; filename="helloworld.c"', response.headers['Content-Disposition']
@@ -161,7 +161,7 @@ describe RepositoriesController, 'Subversion', type: :controller do
it 'should entry at given revision' do
@repository.fetch_changesets
@repository.reload
get :entry, project_id: PRJ_ID, path: 'subversion_test/helloworld.rb', rev: 2
get :entry, params: { project_id: PRJ_ID, path: 'subversion_test/helloworld.rb', rev: 2 }
assert_response :success
assert_template 'entry'
# this line was removed in r3 and file was moved in r6
@@ -172,7 +172,7 @@ describe RepositoriesController, 'Subversion', type: :controller do
it 'should entry not found' do
@repository.fetch_changesets
@repository.reload
get :entry, project_id: PRJ_ID, path: 'subversion_test/zzz.c'
get :entry, params: { project_id: PRJ_ID, path: 'subversion_test/zzz.c' }
assert_select 'div', attributes: { id: /errorExplanation/ },
content: /The entry or revision was not found in the repository/
end
@@ -180,7 +180,7 @@ describe RepositoriesController, 'Subversion', type: :controller do
it 'should entry download' do
@repository.fetch_changesets
@repository.reload
get :entry, project_id: PRJ_ID, path: 'subversion_test/helloworld.c', format: 'raw'
get :entry, params: { project_id: PRJ_ID, path: 'subversion_test/helloworld.c', format: 'raw' }
assert_response :success
assert_template nil
assert_equal 'attachment; filename="helloworld.c"', response.headers['Content-Disposition']
@@ -189,7 +189,7 @@ describe RepositoriesController, 'Subversion', type: :controller do
it 'should directory entry' do
@repository.fetch_changesets
@repository.reload
get :entry, project_id: PRJ_ID, path: 'subversion_test/folder'
get :entry, params: { project_id: PRJ_ID, path: 'subversion_test/folder' }
assert_response :success
assert_template 'show'
refute_nil assigns(:entry)
@@ -200,7 +200,7 @@ describe RepositoriesController, 'Subversion', type: :controller do
it 'should revision' do
@repository.fetch_changesets
@repository.reload
get :revision, project_id: 1, rev: 2
get :revision, params: { project_id: 1, rev: 2 }
assert_response :success
assert_template 'revision'
assert_select 'ul',
@@ -220,13 +220,13 @@ describe RepositoriesController, 'Subversion', type: :controller do
it 'should invalid revision' do
@repository.fetch_changesets
@repository.reload
get :revision, project_id: PRJ_ID, rev: 'something_weird'
get :revision, params: { project_id: PRJ_ID, rev: 'something_weird' }
assert_response 404
assert_error_tag content: /was not found/
end
it 'should invalid revision diff' do
get :diff, project_id: PRJ_ID, rev: '1', rev_to: 'something_weird'
get :diff, params: { project_id: PRJ_ID, rev: '1', rev_to: 'something_weird' }
assert_response 404
assert_error_tag content: /was not found/
end
@@ -235,7 +235,7 @@ describe RepositoriesController, 'Subversion', type: :controller do
@repository.fetch_changesets
@repository.reload
['', ' ', nil].each do |r|
get :revision, project_id: PRJ_ID, rev: r
get :revision, params: { project_id: PRJ_ID, rev: r }
assert_response 404
assert_error_tag content: /was not found/
end
@@ -247,7 +247,7 @@ describe RepositoriesController, 'Subversion', type: :controller do
# Changes repository url to a subdirectory
r.update_attribute :url, (r.url + '/subversion_test/folder/')
get :revision, project_id: 1, rev: 2
get :revision, params: { project_id: 1, rev: 2 }
assert_response :success
assert_template 'revision'
assert_select 'ul',
@@ -267,7 +267,7 @@ describe RepositoriesController, 'Subversion', type: :controller do
it 'should revision diff' do
@repository.fetch_changesets
@repository.reload
get :diff, project_id: PRJ_ID, rev: 3
get :diff, params: { project_id: PRJ_ID, rev: 3 }
assert_response :success
assert_template 'diff'
@@ -277,7 +277,7 @@ describe RepositoriesController, 'Subversion', type: :controller do
it 'should directory diff' do
@repository.fetch_changesets
@repository.reload
get :diff, project_id: PRJ_ID, rev: 6, rev_to: 2, path: 'subversion_test/folder'
get :diff, params: { project_id: PRJ_ID, rev: 6, rev_to: 2, path: 'subversion_test/folder' }
assert_response :success
assert_template 'diff'
@@ -292,7 +292,7 @@ describe RepositoriesController, 'Subversion', type: :controller do
it 'should annotate' do
@repository.fetch_changesets
@repository.reload
get :annotate, project_id: PRJ_ID, path: 'subversion_test/helloworld.c'
get :annotate, params: { project_id: PRJ_ID, path: 'subversion_test/helloworld.c' }
assert_response :success
assert_template 'annotate'
end
@@ -300,7 +300,7 @@ describe RepositoriesController, 'Subversion', type: :controller do
it 'should annotate at given revision' do
@repository.fetch_changesets
@repository.reload
get :annotate, project_id: PRJ_ID, rev: 8, path: 'subversion_test/helloworld.c'
get :annotate, params: { project_id: PRJ_ID, rev: 8, path: 'subversion_test/helloworld.c' }
assert_response :success
assert_template 'annotate'
assert_select 'div',
+56 -31
View File
@@ -1,4 +1,5 @@
#-- encoding: UTF-8
#-- copyright
# OpenProject is a project management system.
# Copyright (C) 2012-2017 the OpenProject Foundation (OPF)
@@ -47,8 +48,9 @@ describe RolesController, type: :controller do
refute_nil assigns(:roles)
assert_equal Role.order('builtin, position').to_a, assigns(:roles)
assert_select 'a', attributes: { href: edit_role_path(1) },
content: 'Manager'
assert_select 'a',
attributes: { href: edit_role_path(1) },
content: 'Manager'
end
it 'should get new' do
@@ -58,9 +60,14 @@ describe RolesController, type: :controller do
end
it 'should post new with validaton failure' do
post :create, role: { name: '',
permissions: ['add_work_packages', 'edit_work_packages', 'log_time', ''],
assignable: '0' }
post :create,
params: {
role: {
name: '',
permissions: ['add_work_packages', 'edit_work_packages', 'log_time', ''],
assignable: '0'
}
}
assert_response :success
assert_template 'new'
@@ -68,9 +75,14 @@ describe RolesController, type: :controller do
end
it 'should post new without workflow copy' do
post :create, role: { name: 'RoleWithoutWorkflowCopy',
permissions: ['add_work_packages', 'edit_work_packages', 'log_time'],
assignable: '0' }
post :create,
params: {
role: {
name: 'RoleWithoutWorkflowCopy',
permissions: ['add_work_packages', 'edit_work_packages', 'log_time'],
assignable: '0'
}
}
assert_redirected_to roles_path
role = Role.find_by(name: 'RoleWithoutWorkflowCopy')
@@ -80,10 +92,15 @@ describe RolesController, type: :controller do
end
it 'should post new with workflow copy' do
post :create, role: { name: 'RoleWithWorkflowCopy',
permissions: ['add_work_packages', 'edit_work_packages', 'log_time'],
assignable: '0' },
copy_workflow_from: '1'
post :create,
params: {
role: {
name: 'RoleWithWorkflowCopy',
permissions: ['add_work_packages', 'edit_work_packages', 'log_time'],
assignable: '0'
},
copy_workflow_from: '1'
}
assert_redirected_to roles_path
role = Role.find_by(name: 'RoleWithWorkflowCopy')
@@ -92,17 +109,22 @@ describe RolesController, type: :controller do
end
it 'should get edit' do
get :edit, id: 1
get :edit, params: { id: 1 }
assert_response :success
assert_template 'edit'
assert_equal Role.find(1), assigns(:role)
end
it 'should put update' do
put :update, id: 1,
role: { name: 'Manager',
permissions: ['edit_project'],
assignable: '0' }
put :update,
params: {
id: 1,
role: {
name: 'Manager',
permissions: ['edit_project'],
assignable: '0'
}
}
assert_redirected_to roles_path
role = Role.find(1)
@@ -113,13 +135,13 @@ describe RolesController, type: :controller do
r = Role.new(name: 'ToBeDestroyed', permissions: [:view_wiki_pages])
assert r.save
delete :destroy, id: r
delete :destroy, params: { id: r }
assert_redirected_to roles_path
assert_nil Role.find_by(id: r.id)
end
it 'should destroy role in use' do
delete :destroy, id: 1
delete :destroy, params: { id: 1 }
assert_redirected_to roles_path
assert flash[:error] == 'This role is in use and cannot be deleted.'
refute_nil Role.find_by(id: 1)
@@ -134,18 +156,21 @@ describe RolesController, type: :controller do
assert_equal Role.order('builtin, position'), assigns(:roles)
assert_select 'input', attributes: { type: 'checkbox',
name: 'permissions[3][]',
value: 'add_work_packages',
checked: 'checked' }
name: 'permissions[3][]',
value: 'add_work_packages',
checked: 'checked' }
assert_select 'input', attributes: { type: 'checkbox',
name: 'permissions[3][]',
value: 'delete_work_packages',
checked: nil }
name: 'permissions[3][]',
value: 'delete_work_packages',
checked: nil }
end
it 'should put bulk update' do
put :bulk_update, permissions: { '0' => '', '1' => ['edit_work_packages'], '3' => ['add_work_packages', 'delete_work_packages'] }
put :bulk_update,
params: {
permissions: { '0' => '', '1' => ['edit_work_packages'], '3' => ['add_work_packages', 'delete_work_packages'] }
}
assert_redirected_to roles_path
assert_equal [:edit_work_packages], Role.find(1).permissions
@@ -154,33 +179,33 @@ describe RolesController, type: :controller do
end
it 'should clear all permissions' do
put :bulk_update, permissions: { '0' => '' }
put :bulk_update, params: { permissions: { '0' => '' } }
assert_redirected_to roles_path
assert Role.find(1).permissions.empty?
end
it 'should move highest' do
put :update, id: 3, role: { move_to: 'highest' }
put :update, params: { id: 3, role: { move_to: 'highest' } }
assert_redirected_to roles_path
assert_equal 1, Role.find(3).position
end
it 'should move higher' do
position = Role.find(3).position
put :update, id: 3, role: { move_to: 'higher' }
put :update, params: { id: 3, role: { move_to: 'higher' } }
assert_redirected_to roles_path
assert_equal position - 1, Role.find(3).position
end
it 'should move lower' do
position = Role.find(2).position
put :update, id: 2, role: { move_to: 'lower' }
put :update, params: { id: 2, role: { move_to: 'lower' } }
assert_redirected_to roles_path
assert_equal position + 1, Role.find(2).position
end
it 'should move lowest' do
put :update, id: 2, role: { move_to: 'lowest' }
put :update, params: { id: 2, role: { move_to: 'lowest' } }
assert_redirected_to roles_path
assert_equal Role.count, Role.find(2).position
end
@@ -1,4 +1,5 @@
#-- encoding: UTF-8
#-- copyright
# OpenProject is a project management system.
# Copyright (C) 2012-2017 the OpenProject Foundation (OPF)
@@ -27,7 +28,7 @@
# See doc/COPYRIGHT.rdoc for more details.
#++
require 'legacy_spec_helper'
require_relative '../legacy_spec_helper'
require 'search_controller'
describe SearchController, type: :controller do
@@ -40,7 +41,7 @@ describe SearchController, type: :controller do
end
it 'should search all projects' do
get :index, q: 'recipe subproject commit', submit: 'Search'
get :index, params: { q: 'recipe subproject commit', submit: 'Search' }
assert_response :success
assert_template 'index'
@@ -54,7 +55,7 @@ describe SearchController, type: :controller do
end
it 'should search project and subprojects' do
get :index, project_id: 1, q: 'recipe subproject', scope: 'subprojects', submit: 'Search'
get :index, params: { project_id: 1, q: 'recipe subproject', scope: 'subprojects', submit: 'Search' }
assert_response :success
assert_template 'index'
assert assigns(:results).include?(WorkPackage.find(1))
@@ -64,18 +65,18 @@ describe SearchController, type: :controller do
it 'should search without searchable custom fields' do
CustomField.update_all "searchable = #{ActiveRecord::Base.connection.quoted_false}"
get :index, project_id: 1
get :index, params: { project_id: 1 }
assert_response :success
assert_template 'index'
refute_nil assigns(:project)
get :index, project_id: 1, q: 'can'
get :index, params: { project_id: 1, q: 'can' }
assert_response :success
assert_template 'index'
end
it 'should search with searchable custom fields' do
get :index, project_id: 1, q: 'stringforcustomfield'
get :index, params: { project_id: 1, q: 'stringforcustomfield' }
assert_response :success
results = assigns(:results)
refute_nil results
@@ -85,7 +86,7 @@ describe SearchController, type: :controller do
it 'should search all words' do
# 'all words' is on by default
get :index, project_id: 1, q: 'recipe updating saving'
get :index, params: { project_id: 1, q: 'recipe updating saving' }
results = assigns(:results)
refute_nil results
assert_equal 1, results.size
@@ -93,7 +94,7 @@ describe SearchController, type: :controller do
end
it 'should search one of the words' do
get :index, project_id: 1, q: 'recipe updating saving', submit: 'Search'
get :index, params: { project_id: 1, q: 'recipe updating saving', submit: 'Search' }
results = assigns(:results)
refute_nil results
assert_equal 3, results.size
@@ -101,45 +102,45 @@ describe SearchController, type: :controller do
end
it 'should search titles only without result' do
get :index, project_id: 1, q: 'recipe updating saving', all_words: '1', titles_only: '1', submit: 'Search'
get :index, params: { project_id: 1, q: 'recipe updating saving', all_words: '1', titles_only: '1', submit: 'Search' }
results = assigns(:results)
refute_nil results
assert_equal 0, results.size
end
it 'should search titles only' do
get :index, project_id: 1, q: 'recipe', titles_only: '1', submit: 'Search'
get :index, params: { project_id: 1, q: 'recipe', titles_only: '1', submit: 'Search' }
results = assigns(:results)
refute_nil results
assert_equal 2, results.size
end
it 'should search with invalid project id' do
get :index, project_id: 195, q: 'recipe'
get :index, params: { project_id: 195, q: 'recipe' }
assert_response 404
assert_nil assigns(:results)
end
it 'should quick jump to work packages' do
# work_package of a public project
get :index, q: '3'
get :index, params: { q: '3' }
assert_redirected_to '/work_packages/3'
end
it 'should not jump to an invisible WP' do
get :index, q: '4'
get :index, params: { q: '4' }
assert_response :success
assert_template 'index'
end
it 'should large integer' do
get :index, q: '4615713488'
get :index, params: { q: '4615713488' }
assert_response :success
assert_template 'index'
end
it 'should tokens with quotes' do
get :index, project_id: 1, q: '"good bye" hello "bye bye"'
get :index, params: { project_id: 1, q: '"good bye" hello "bye bye"' }
assert_equal ['good bye', 'hello', 'bye bye'], assigns(:tokens)
end
end
@@ -1,4 +1,5 @@
#-- encoding: UTF-8
#-- copyright
# OpenProject is a project management system.
# Copyright (C) 2012-2017 the OpenProject Foundation (OPF)
@@ -27,7 +28,7 @@
# See doc/COPYRIGHT.rdoc for more details.
#++
require 'legacy_spec_helper'
require_relative '../legacy_spec_helper'
require 'settings_controller'
describe SettingsController, type: :controller do
@@ -51,11 +52,15 @@ describe SettingsController, type: :controller do
end
it 'should post edit notifications' do
post :edit, settings: { mail_from: 'functional@test.foo',
bcc_recipients: '0',
notified_events: %w(work_package_added work_package_updated news_added),
emails_footer: 'Test footer'
}
post :edit,
params: {
settings: {
mail_from: 'functional@test.foo',
bcc_recipients: '0',
notified_events: %w(work_package_added work_package_updated news_added),
emails_footer: 'Test footer'
}
}
assert_redirected_to '/settings/edit'
assert_equal 'functional@test.foo', Setting.mail_from
assert !Setting.bcc_recipients?
@@ -27,7 +27,7 @@
# See doc/COPYRIGHT.rdoc for more details.
#++
require 'legacy_spec_helper'
require_relative '../legacy_spec_helper'
require 'sys_controller'
describe SysController, type: :controller do
@@ -44,7 +44,7 @@ describe SysController, type: :controller do
get :projects
assert_response :success
assert_equal 'application/xml', response.content_type
assert_select 'projects', children: { count: Project.active.has_module(:repository).count }
assert_select 'projects', children: { count: Project.active.has_module(:repository).count }
end
it 'should fetch changesets' do
@@ -55,23 +55,23 @@ describe SysController, type: :controller do
it 'should fetch changesets one project' do
expect_any_instance_of(Repository::Subversion).to receive(:fetch_changesets).and_return(true)
get :fetch_changesets, id: 'ecookbook'
get :fetch_changesets, params: { id: 'ecookbook' }
assert_response :success
end
it 'should fetch changesets unknown project' do
get :fetch_changesets, id: 'unknown'
get :fetch_changesets, params: { id: 'unknown' }
assert_response 404
end
describe 'api key', with_settings: { sys_api_key: 'my_secret_key' } do
it 'should api key' do
get :projects, key: 'my_secret_key'
get :projects, params: { key: 'my_secret_key' }
assert_response :success
end
it 'should wrong key should respond with 403 error' do
get :projects, key: 'wrong_key'
get :projects, params: { key: 'wrong_key' }
assert_response 403
end
end
@@ -1,4 +1,5 @@
#-- encoding: UTF-8
#-- copyright
# OpenProject is a project management system.
# Copyright (C) 2012-2017 the OpenProject Foundation (OPF)
@@ -27,7 +28,7 @@
# See doc/COPYRIGHT.rdoc for more details.
#++
require 'legacy_spec_helper'
require_relative '../../legacy_spec_helper'
describe TimeEntries::ReportsController, type: :controller do
render_views
@@ -35,11 +36,11 @@ describe TimeEntries::ReportsController, type: :controller do
fixtures :all
it 'should report at project level' do
get :show, project_id: 'ecookbook'
get :show, params: { project_id: 'ecookbook' }
assert_response :success
assert_template 'time_entries/reports/show'
assert_select 'form',
attributes: { action: '/projects/ecookbook/time_entries/report', id: 'query_form' }
attributes: { action: '/projects/ecookbook/time_entries/report', id: 'query_form' }
end
it 'should report all projects' do
@@ -47,7 +48,7 @@ describe TimeEntries::ReportsController, type: :controller do
assert_response :success
assert_template 'time_entries/reports/show'
assert_select 'form',
attributes: { action: '/time_entries/report', id: 'query_form' }
attributes: { action: '/time_entries/report', id: 'query_form' }
end
it 'should report all projects denied' do
@@ -59,7 +60,7 @@ describe TimeEntries::ReportsController, type: :controller do
end
it 'should report all projects one criteria' do
get :show, columns: 'week', from: '2007-04-01', to: '2007-04-30', criterias: ['project']
get :show, params: { columns: 'week', from: '2007-04-01', to: '2007-04-30', criterias: ['project'] }
assert_response :success
assert_template 'time_entries/reports/show'
refute_nil assigns(:total_hours)
@@ -67,7 +68,7 @@ describe TimeEntries::ReportsController, type: :controller do
end
it 'should report all time' do
get :show, project_id: 1, criterias: ['project', 'issue']
get :show, params: { project_id: 1, criterias: ['project', 'issue'] }
assert_response :success
assert_template 'time_entries/reports/show'
refute_nil assigns(:total_hours)
@@ -75,7 +76,7 @@ describe TimeEntries::ReportsController, type: :controller do
end
it 'should report all time by day' do
get :show, project_id: 1, criterias: ['project', 'issue'], columns: 'day'
get :show, params: { project_id: 1, criterias: ['project', 'issue'], columns: 'day' }
assert_response :success
assert_template 'time_entries/reports/show'
refute_nil assigns(:total_hours)
@@ -84,7 +85,7 @@ describe TimeEntries::ReportsController, type: :controller do
end
it 'should report one criteria' do
get :show, project_id: 1, columns: 'week', from: '2007-04-01', to: '2007-04-30', criterias: ['project']
get :show, params: { project_id: 1, columns: 'week', from: '2007-04-01', to: '2007-04-30', criterias: ['project'] }
assert_response :success
assert_template 'time_entries/reports/show'
refute_nil assigns(:total_hours)
@@ -92,7 +93,11 @@ describe TimeEntries::ReportsController, type: :controller do
end
it 'should report two criterias' do
get :show, project_id: 1, columns: 'month', from: '2007-01-01', to: '2007-12-31', criterias: ['member', 'activity']
get :show, params: { project_id: 1,
columns: 'month',
from: '2007-01-01',
to: '2007-12-31',
criterias: ['member', 'activity'] }
assert_response :success
assert_template 'time_entries/reports/show'
refute_nil assigns(:total_hours)
@@ -100,7 +105,7 @@ describe TimeEntries::ReportsController, type: :controller do
end
it 'should report one day' do
get :show, project_id: 1, columns: 'day', from: '2007-03-23', to: '2007-03-23', criterias: ['member', 'activity']
get :show, params: { project_id: 1, columns: 'day', from: '2007-03-23', to: '2007-03-23', criterias: ['member', 'activity'] }
assert_response :success
assert_template 'time_entries/reports/show'
refute_nil assigns(:total_hours)
@@ -108,17 +113,22 @@ describe TimeEntries::ReportsController, type: :controller do
end
it 'should report at issue level' do
get :show, project_id: 1, work_package_id: 1, columns: 'month', from: '2007-01-01', to: '2007-12-31', criterias: ['member', 'activity']
get :show, params: { project_id: 1,
work_package_id: 1,
columns: 'month',
from: '2007-01-01',
to: '2007-12-31',
criterias: ['member', 'activity'] }
assert_response :success
assert_template 'time_entries/reports/show'
refute_nil assigns(:total_hours)
assert_equal '154.25', '%.2f' % assigns(:total_hours)
assert_select 'form',
attributes: { action: work_package_time_entries_report_path(1), id: 'query_form' }
attributes: { action: work_package_time_entries_report_path(1), id: 'query_form' }
end
it 'should report custom field criteria' do
get :show, project_id: 1, criterias: ['project', 'cf_1', 'cf_7']
get :show, params: { project_id: 1, criterias: ['project', 'cf_1', 'cf_7'] }
assert_response :success
assert_template 'time_entries/reports/show'
refute_nil assigns(:total_hours)
@@ -128,16 +138,17 @@ describe TimeEntries::ReportsController, type: :controller do
# Custom field column
assert_select 'th', descendant: { content: /\s*Database\s*/ }
# Custom field row
assert_select 'td', content: 'MySQL',
sibling: { tag: 'td', attributes: { class: 'hours' },
child: { tag: 'span', attributes: { class: 'hours hours-int' },
content: '1' } }
assert_select 'td',
content: 'MySQL',
sibling: { tag: 'td', attributes: { class: 'hours' },
child: { tag: 'span', attributes: { class: 'hours hours-int' },
content: '1' } }
# Second custom field column
assert_select 'th', descendant: { content: /\s*Billable\s*/ }
end
it 'should report one criteria no result' do
get :show, project_id: 1, columns: 'week', from: '1998-04-01', to: '1998-04-30', criterias: ['project']
get :show, params: { project_id: 1, columns: 'week', from: '1998-04-01', to: '1998-04-30', criterias: ['project'] }
assert_response :success
assert_template 'time_entries/reports/show'
refute_nil assigns(:total_hours)
@@ -145,7 +156,11 @@ describe TimeEntries::ReportsController, type: :controller do
end
it 'should report all projects csv export' do
get :show, columns: 'month', from: '2007-01-01', to: '2007-06-30', criterias: ['project', 'member', 'activity'], format: 'csv'
get :show, params: { columns: 'month',
from: '2007-01-01',
to: '2007-06-30',
criterias: ['project', 'member', 'activity'],
format: 'csv' }
assert_response :success
assert_match(/text\/csv/, response.content_type)
lines = response.body.chomp.split("\n")
@@ -156,7 +171,12 @@ describe TimeEntries::ReportsController, type: :controller do
end
it 'should report csv export' do
get :show, project_id: 1, columns: 'month', from: '2007-01-01', to: '2007-06-30', criterias: ['project', 'member', 'activity'], format: 'csv'
get :show, params: { project_id: 1,
columns: 'month',
from: '2007-01-01',
to: '2007-06-30',
criterias: ['project', 'member', 'activity'],
format: 'csv' }
assert_response :success
assert_match(/text\/csv/, response.content_type)
lines = response.body.chomp.split("\n")
@@ -27,7 +27,7 @@
# See doc/COPYRIGHT.rdoc for more details.
#++
require 'legacy_spec_helper'
require_relative '../legacy_spec_helper'
require 'timelog_controller'
describe TimelogController, type: :controller do
@@ -37,25 +37,26 @@ describe TimelogController, type: :controller do
it 'should get new' do
session[:user_id] = 3
get :new, project_id: 1
get :new, params: { project_id: 1 }
assert_response :success
assert_template 'edit'
# Default activity selected
assert_select 'option', attributes: { selected: 'selected' },
content: 'Development'
assert_select 'option',
attributes: { selected: 'selected' },
content: 'Development'
end
it 'should get new should only show active time entry activities' do
session[:user_id] = 3
get :new, project_id: 1
get :new, params: { project_id: 1 }
assert_response :success
assert_template 'edit'
assert_select('option', {content: 'Inactive Activity'}, false)
assert_select('option', { content: 'Inactive Activity' }, false)
end
it 'should get edit existing time' do
session[:user_id] = 2
get :edit, id: 2, project_id: nil
get :edit, params: { id: 2, project_id: nil }
assert_response :success
assert_template 'edit'
# Default activity selected
@@ -68,7 +69,7 @@ describe TimelogController, type: :controller do
te.save!
session[:user_id] = 1
get :edit, project_id: 1, id: 1
get :edit, params: { project_id: 1, id: 1 }
assert_response :success
assert_template 'edit'
# Blank option since nothing is pre-selected
@@ -79,13 +80,13 @@ describe TimelogController, type: :controller do
# TODO: should POST to issues time log instead of project. change form
# and routing
session[:user_id] = 3
post :create, project_id: 1,
time_entry: { comments: 'Some work on TimelogControllerTest',
# Not the default activity
activity_id: '11',
spent_on: '2008-03-14',
work_package_id: '1',
hours: '7.3' }
post :create, params: { project_id: 1,
time_entry: { comments: 'Some work on TimelogControllerTest',
# Not the default activity
activity_id: '11',
spent_on: '2008-03-14',
work_package_id: '1',
hours: '7.3' } }
assert_redirected_to action: 'index', project_id: 'ecookbook'
i = WorkPackage.find(1)
@@ -102,13 +103,13 @@ describe TimelogController, type: :controller do
# TODO: should POST to issues time log instead of project. change form
# and routing
session[:user_id] = 3
post :create, project_id: 1,
time_entry: { comments: 'Some work on TimelogControllerTest',
# Not the default activity
activity_id: '11',
work_package_id: '',
spent_on: '2008-03-14',
hours: '7.3' }
post :create, params: { project_id: 1,
time_entry: { comments: 'Some work on TimelogControllerTest',
# Not the default activity
activity_id: '11',
work_package_id: '',
spent_on: '2008-03-14',
hours: '7.3' } }
assert_redirected_to action: 'index', project_id: 'ecookbook'
t = TimeEntry.find_by(comments: 'Some work on TimelogControllerTest')
@@ -124,9 +125,9 @@ describe TimelogController, type: :controller do
assert_equal 2, entry.user_id
session[:user_id] = 1
put :update, id: 1,
time_entry: { work_package_id: '2',
hours: '8' }
put :update, params: { id: 1,
time_entry: { work_package_id: '2',
hours: '8' } }
assert_redirected_to action: 'index', project_id: 'ecookbook'
entry.reload
@@ -137,7 +138,7 @@ describe TimelogController, type: :controller do
it 'should destroy' do
session[:user_id] = 2
delete :destroy, id: 1
delete :destroy, params: { id: 1 }
assert_redirected_to action: 'index', project_id: 'ecookbook'
assert_equal I18n.t(:notice_successful_delete), flash[:notice]
assert_nil TimeEntry.find_by(id: 1)
@@ -151,7 +152,7 @@ describe TimelogController, type: :controller do
end
session[:user_id] = 2
delete :destroy, id: 1
delete :destroy, params: { id: 1 }
assert_redirected_to action: 'index', project_id: 'ecookbook'
assert_equal I18n.t(:notice_unable_delete_time_entry), flash[:error]
refute_nil TimeEntry.find_by(id: 1)
@@ -171,7 +172,7 @@ describe TimelogController, type: :controller do
end
it 'should index at project level' do
get :index, project_id: 'ecookbook'
get :index, params: { project_id: 'ecookbook' }
assert_response :success
assert_template 'index'
refute_nil assigns(:entries)
@@ -188,7 +189,7 @@ describe TimelogController, type: :controller do
end
it 'should index at project level with date range' do
get :index, project_id: 'ecookbook', from: '2007-03-20', to: '2007-04-30'
get :index, params: { project_id: 'ecookbook', from: '2007-03-20', to: '2007-04-30' }
assert_response :success
assert_template 'index'
refute_nil assigns(:entries)
@@ -202,7 +203,7 @@ describe TimelogController, type: :controller do
end
it 'should index at project level with period' do
get :index, project_id: 'ecookbook', period: '7_days'
get :index, params: { project_id: 'ecookbook', period: '7_days' }
assert_response :success
assert_template 'index'
refute_nil assigns(:entries)
@@ -214,7 +215,7 @@ describe TimelogController, type: :controller do
end
it 'should index one day' do
get :index, project_id: 'ecookbook', from: '2007-03-23', to: '2007-03-23'
get :index, params: { project_id: 'ecookbook', from: '2007-03-23', to: '2007-03-23' }
assert_response :success
assert_template 'index'
refute_nil assigns(:total_hours)
@@ -224,7 +225,7 @@ describe TimelogController, type: :controller do
end
it 'should index at issue level' do
get :index, work_package_id: 1
get :index, params: { work_package_id: 1 }
assert_response :success
assert_template 'index'
refute_nil assigns(:entries)
@@ -241,7 +242,7 @@ describe TimelogController, type: :controller do
it 'should index atom feed' do
TimeEntry.all.each(&:recreate_initial_journal!)
get :index, project_id: 1, format: 'atom'
get :index, params: { project_id: 1, format: 'atom' }
assert_response :success
assert_equal 'application/atom+xml', response.content_type
refute_nil assigns(:items)
@@ -54,16 +54,14 @@ describe TypesController, type: :controller do
end
it 'should post create' do
post :create, tab: "settings", type: {
name: 'New type'
}
post :create, params: { tab: "settings", type: { name: 'New type' } }
type = ::Type.find_by(name: 'New type')
assert_redirected_to action: 'edit', tab: 'settings', id: type.id
assert_equal 0, type.workflows.count
end
it 'should post create with workflow copy' do
post :create, type: { name: 'New type' }, copy_workflow_from: 1
post :create, params: { type: { name: 'New type' }, copy_workflow_from: 1 }
type = ::Type.find_by(name: 'New type')
assert_redirected_to action: 'edit', tab: 'settings', id: type.id
assert_equal 0, type.projects.count
@@ -73,7 +71,7 @@ describe TypesController, type: :controller do
it 'should get edit' do
::Type.find(1).project_ids = [1, 3]
get :edit, id: 1, tab: 'settings'
get :edit, params: { id: 1, tab: 'settings' }
assert_response :success
assert_template 'edit'
assert_template 'types/form/_settings'
@@ -92,33 +90,33 @@ describe TypesController, type: :controller do
end
it 'should post update name' do
post :update, id: 1, tab: "settings", type: { name: 'Renamed' }
post :update, params: { id: 1, tab: "settings", type: { name: 'Renamed' } }
assert_equal "Renamed", ::Type.find(1).name
assert_redirected_to action: 'edit'
end
it 'should post update projects' do
post :update, id: 1, tab: "projects", type: { project_ids: ['1', '2', ''] }
post :update, params: { id: 1, tab: "projects", type: { project_ids: ['1', '2', ''] } }
assert_redirected_to action: 'edit'
assert_equal [1, 2], ::Type.find(1).project_ids.sort
end
it 'should post update without projects' do
post :update, id: 1, tab: "projects", type: { project_ids: [''] }
post :update, params: { id: 1, tab: "projects", type: { project_ids: [''] } }
assert_redirected_to action: 'edit'
assert ::Type.find(1).project_ids.empty?
end
it 'should move lower' do
type = ::Type.find_by(position: 1)
post :move, id: 1, type: { move_to: 'lower' }
post :move, params: { id: 1, type: { move_to: 'lower' } }
assert_equal 2, type.reload.position
end
it 'should destroy' do
type = ::Type.create!(name: 'Destroyable')
assert_difference '::Type.count', -1 do
post :destroy, id: type.id
post :destroy, params: { id: type.id }
end
assert_redirected_to action: 'index'
assert_nil flash[:error]
@@ -126,7 +124,7 @@ describe TypesController, type: :controller do
it 'should destroy type in use' do
assert_no_difference '::Type.count' do
post :destroy, id: 1
post :destroy, params: { id: 1 }
end
assert_redirected_to action: 'index'
refute_nil flash[:error]
+1 -1
View File
@@ -26,7 +26,7 @@
# See doc/COPYRIGHT.rdoc for more details.
#++
require 'legacy_spec_helper'
require_relative '../legacy_spec_helper'
describe UserMailer, type: :mailer do
include ::Rails::Dom::Testing::Assertions::SelectorAssertions
+36 -29
View File
@@ -1,4 +1,5 @@
#-- encoding: UTF-8
#-- copyright
# OpenProject is a project management system.
# Copyright (C) 2012-2017 the OpenProject Foundation (OPF)
@@ -27,7 +28,7 @@
# See doc/COPYRIGHT.rdoc for more details.
#++
require 'legacy_spec_helper'
require_relative '../legacy_spec_helper'
require 'users_controller'
describe UsersController, type: :controller do
@@ -52,11 +53,11 @@ describe UsersController, type: :controller do
assert_template 'index'
refute_nil assigns(:users)
# active users only
assert_nil assigns(:users).detect { |u| !u.active? }
assert_nil(assigns(:users).detect { |u| !u.active? })
end
it 'should index with name filter' do
get :index, name: 'john'
get :index, params: { name: 'john' }
assert_response :success
assert_template 'index'
users = assigns(:users)
@@ -66,7 +67,7 @@ describe UsersController, type: :controller do
end
it 'should index with group filter' do
get :index, group_id: '10'
get :index, params: { group_id: '10' }
assert_response :success
assert_template 'index'
users = assigns(:users)
@@ -77,7 +78,7 @@ describe UsersController, type: :controller do
it 'should show should not display hidden custom fields' do
session[:user_id] = nil
UserCustomField.find_by(name: 'Phone number').update_attribute :visible, false
get :show, id: 2
get :show, params: { id: 2 }
assert_response :success
assert_template 'show'
refute_nil assigns(:user)
@@ -93,34 +94,34 @@ describe UsersController, type: :controller do
# Create a custom field to illustrate the issue
custom_field = CustomField.create!(name: 'Testing', field_format: 'text')
custom_value = user.custom_values.build(custom_field: custom_field).save!
user.custom_values.build(custom_field: custom_field).save!
get :show, id: 2
get :show, params: { id: 2 }
assert_response :success
end
it 'should show inactive' do
session[:user_id] = nil
get :show, id: 5
get :show, params: { id: 5 }
assert_response 404
end
it 'should show should not reveal users with no visible activity or project' do
session[:user_id] = nil
get :show, id: 9
get :show, params: { id: 9 }
assert_response 404
end
it 'should show inactive by admin' do
session[:user_id] = 1
get :show, id: 5
get :show, params: { id: 5 }
assert_response 200
refute_nil assigns(:user)
end
it 'should show displays memberships based on project visibility' do
session[:user_id] = 1
get :show, id: 2
get :show, params: { id: 2 }
assert_response :success
memberships = assigns(:memberships)
refute_nil memberships
@@ -130,13 +131,13 @@ describe UsersController, type: :controller do
it 'should show current should require authentication' do
session[:user_id] = nil
get :show, id: 'current'
get :show, params: { id: 'current' }
assert_response 302
end
it 'should show current' do
session[:user_id] = 2
get :show, id: 'current'
get :show, params: { id: 'current' }
assert_response :success
assert_template 'show'
assert_equal User.find(2), assigns(:user)
@@ -156,16 +157,18 @@ describe UsersController, type: :controller do
assert_difference 'User.count' do
assert_difference 'ActionMailer::Base.deliveries.size' do
post :create,
user: {
firstname: 'John',
lastname: 'Doe',
login: 'jdoe',
password: 'adminADMIN!',
password_confirmation: 'adminADMIN!',
mail: 'jdoe@gmail.com',
mail_notification: 'none'
},
pref: { }
params: {
user: {
firstname: 'John',
lastname: 'Doe',
login: 'jdoe',
password: 'adminADMIN!',
password_confirmation: 'adminADMIN!',
mail: 'jdoe@gmail.com',
mail_notification: 'none'
},
pref: {}
}
end
end
@@ -185,7 +188,8 @@ describe UsersController, type: :controller do
activation_link = Regexp.new(
"http://#{Setting.host_name}/account/activate\\?token=[a-f0-9]+",
Regexp::MULTILINE)
Regexp::MULTILINE
)
assert(mail.body.encoded =~ activation_link)
end
@@ -195,7 +199,7 @@ describe UsersController, type: :controller do
# Provide at least one user field, otherwise strong_parameters regards the user parameter
# as non-existent and raises ActionController::ParameterMissing, which in turn
# results in a 400.
post :create, user: { login: 'jdoe' }
post :create, params: { user: { login: 'jdoe' } }
end
assert_response :success
@@ -203,7 +207,7 @@ describe UsersController, type: :controller do
end
it 'should edit' do
get :edit, id: 2
get :edit, params: { id: 2 }
assert_response :success
assert_template 'edit'
@@ -212,7 +216,7 @@ describe UsersController, type: :controller do
it 'should update with failure' do
assert_no_difference 'User.count' do
put :update, id: 2, user: { firstname: '' }
put :update, params: { id: 2, user: { firstname: '' } }
end
assert_response :success
@@ -220,7 +224,7 @@ describe UsersController, type: :controller do
end
it 'should update with group ids should assign groups' do
put :update, id: 2, user: { group_ids: ['10'] }
put :update, params: { id: 2, user: { group_ids: ['10'] } }
user = User.find(2)
assert_equal [10], user.group_ids
@@ -229,7 +233,10 @@ describe UsersController, type: :controller do
it 'should update with password change should send a notification' do
Setting.bcc_recipients = '1'
put :update, id: 2, user: { password: 'newpassPASS!', password_confirmation: 'newpassPASS!' }, send_information: '1'
put :update, params: { id: 2,
user: { password: 'newpassPASS!',
password_confirmation: 'newpassPASS!' },
send_information: '1' }
u = User.find(2)
assert u.check_password?('newpassPASS!')
+75 -74
View File
@@ -1,4 +1,5 @@
#-- encoding: UTF-8
#-- copyright
# OpenProject is a project management system.
# Copyright (C) 2012-2017 the OpenProject Foundation (OPF)
@@ -26,7 +27,7 @@
#
# See doc/COPYRIGHT.rdoc for more details.
#++
require 'legacy_spec_helper'
require_relative '../legacy_spec_helper'
require 'wiki_controller'
describe WikiController, type: :controller do
@@ -47,7 +48,7 @@ describe WikiController, type: :controller do
end
it 'should show start page' do
get :show, project_id: 'ecookbook'
get :show, params: { project_id: 'ecookbook' }
assert_response :success
assert_template 'show'
assert_select 'h1', content: /CookBook documentation/
@@ -60,7 +61,7 @@ describe WikiController, type: :controller do
end
it 'should show page with name' do
get :show, project_id: 1, id: 'Another page'
get :show, params: { project_id: 1, id: 'Another page' }
assert_response :success
assert_template 'show'
assert_select 'h1', content: /Another page/
@@ -75,30 +76,30 @@ describe WikiController, type: :controller do
page.content = WikiContent.new(text: 'Side bar content for test_show_with_sidebar')
page.save!
get :show, project_id: 1, id: 'Another page'
get :show, params: { project_id: 1, id: 'Another page' }
assert_response :success
assert_select 'div', attributes: { id: 'sidebar' },
content: /Side bar content for test_show_with_sidebar/
end
it 'should show unexistent page without edit right' do
get :show, project_id: 1, id: 'Unexistent page'
get :show, params: { project_id: 1, id: 'Unexistent page' }
assert_response 404
end
it 'should show unexistent page with edit right' do
session[:user_id] = 2
get :show, project_id: 1, id: 'Unexistent page'
get :show, params: { project_id: 1, id: 'Unexistent page' }
assert_response :success
assert_template 'edit'
end
it 'should create page' do
session[:user_id] = 2
put :update, project_id: 1,
id: 'New page',
content: { comments: 'Created the page',
text: "h1. New page\n\nThis is a new page" }
put :update, params: { project_id: 1,
id: 'New page',
content: { comments: 'Created the page',
text: "h1. New page\n\nThis is a new page" } }
assert_redirected_to action: 'show', project_id: 'ecookbook', id: 'new-page'
page = wiki.find_page('New page')
assert !page.new_record?
@@ -110,12 +111,12 @@ describe WikiController, type: :controller do
session[:user_id] = 2
assert_difference 'WikiPage.count' do
assert_difference 'Attachment.count' do
put :update, project_id: 1,
id: 'New page',
content: { comments: 'Created the page',
text: "h1. New page\n\nThis is a new page",
lock_version: 0 },
attachments: { '1' => { 'file' => uploaded_test_file('testfile.txt', 'text/plain') } }
put :update, params: { project_id: 1,
id: 'New page',
content: { comments: 'Created the page',
text: "h1. New page\n\nThis is a new page",
lock_version: 0 },
attachments: { '1' => { 'file' => uploaded_test_file('testfile.txt', 'text/plain') } } }
end
end
page = wiki.find_page('New page')
@@ -131,13 +132,13 @@ describe WikiController, type: :controller do
assert_no_difference 'WikiPage.count' do
assert_no_difference 'WikiContent.count' do
assert_difference 'Journal.count' do
put :update, project_id: 1,
id: 'Another page',
content: {
comments: 'my comments',
text: 'edited',
lock_version: 1
}
put :update, params: { project_id: 1,
id: 'Another page',
content: {
comments: 'my comments',
text: 'edited',
lock_version: 1
} }
end
end
end
@@ -154,13 +155,13 @@ describe WikiController, type: :controller do
assert_no_difference 'WikiPage.count' do
assert_no_difference 'WikiContent.count' do
assert_no_difference 'Journal.count' do
put :update, project_id: 1,
id: 'Another page',
content: {
comments: 'a' * 300, # failure here, comment is too long
text: 'edited',
lock_version: 1
}
put :update, params: { project_id: 1,
id: 'Another page',
content: {
comments: 'a' * 300, # failure here, comment is too long
text: 'edited',
lock_version: 1
} }
end
end
end
@@ -190,26 +191,26 @@ describe WikiController, type: :controller do
assert_no_difference 'WikiPage.count' do
assert_no_difference 'WikiContent.count' do
assert_no_difference 'Journal.count' do
put :update, project_id: 1,
id: 'Another page',
content: {
comments: 'My comments',
text: 'Text should not be lost',
lock_version: 1
}
put :update, params: { project_id: 1,
id: 'Another page',
content: {
comments: 'My comments',
text: 'Text should not be lost',
lock_version: 1
} }
end
end
end
assert_response :success
assert_template 'edit'
assert_select 'div',
attributes: { class: /error/ },
content: /Information has been updated by at least one other user in the meantime/
attributes: { class: /error/ },
content: /Information has been updated by at least one other user in the meantime/
assert_select 'textarea',
attributes: { name: 'content[text]' },
content: /Text should not be lost/
attributes: { name: 'content[text]' },
content: /Text should not be lost/
assert_select 'input',
attributes: { name: 'content[comments]', value: 'My comments' }
attributes: { name: 'content[comments]', value: 'My comments' }
c.reload
assert_equal 'Previous text', c.text
@@ -230,7 +231,7 @@ describe WikiController, type: :controller do
data: FactoryGirl.build(:journal_wiki_content_journal,
text: "h1. CookBook documentation\nSome updated [[documentation]] here...")
get :history, project_id: 1, id: 'CookBook documentation'
get :history, params: { project_id: 1, id: 'CookBook documentation' }
assert_response :success
assert_template 'history'
refute_nil assigns(:versions)
@@ -243,7 +244,7 @@ describe WikiController, type: :controller do
journable_id: 2,
data: FactoryGirl.build(:journal_wiki_content_journal,
text: "h1. Another page\n\n\nthis is a link to ticket: #2")
get :history, project_id: 1, id: 'Another page'
get :history, params: { project_id: 1, id: 'Another page' }
assert_response :success
assert_template 'history'
refute_nil assigns(:versions)
@@ -261,7 +262,7 @@ describe WikiController, type: :controller do
data: FactoryGirl.build(:journal_wiki_content_journal,
text: "h1. CookBook documentation\n\n\nSome updated [[documentation]] here...")
get :diff, project_id: 1, id: 'CookBook documentation', version: journal_to.version, version_from: journal_from.version
get :diff, params: { project_id: 1, id: 'CookBook documentation', version: journal_to.version, version_from: journal_from.version }
assert_response :success
assert_template 'diff'
assert_select 'ins', attributes: { class: 'diffins' },
@@ -278,7 +279,7 @@ describe WikiController, type: :controller do
data: FactoryGirl.build(:journal_wiki_content_journal,
text: "h1. CookBook documentation\n\n\nSome [[documentation]] here...")
get :annotate, project_id: 1, id: 'CookBook documentation', version: journal_to.version
get :annotate, params: { project_id: 1, id: 'CookBook documentation', version: journal_to.version }
assert_response :success
assert_template 'annotate'
# Line 1
@@ -293,23 +294,23 @@ describe WikiController, type: :controller do
it 'should get rename' do
session[:user_id] = 2
get :rename, project_id: 1, id: 'Another page'
get :rename, params: { project_id: 1, id: 'Another page' }
assert_response :success
assert_template 'rename'
end
it 'should get rename child page' do
session[:user_id] = 2
get :rename, project_id: 1, id: 'Child 1'
get :rename, params: { project_id: 1, id: 'Child 1' }
assert_response :success
assert_template 'rename'
end
it 'should rename with redirect' do
session[:user_id] = 2
patch :rename, project_id: 1, id: 'Another page',
page: { title: 'Another renamed page',
redirect_existing_links: 1 }
patch :rename, params: { project_id: 1, id: 'Another page',
page: { title: 'Another renamed page',
redirect_existing_links: 1 } }
assert_redirected_to action: 'show', project_id: 'ecookbook', id: 'another-renamed-page'
# Check redirects
refute_nil wiki.find_page('Another page')
@@ -318,9 +319,9 @@ describe WikiController, type: :controller do
it 'should rename without redirect' do
session[:user_id] = 2
patch :rename, project_id: 1, id: 'another-page',
page: { title: 'Another renamed page',
redirect_existing_links: '0' }
patch :rename, params: { project_id: 1, id: 'another-page',
page: { title: 'Another renamed page',
redirect_existing_links: '0' } }
assert_redirected_to action: 'show', project_id: 'ecookbook', id: 'another-renamed-page'
# Check that there's no redirects
assert_nil wiki.find_page('Another page')
@@ -328,14 +329,14 @@ describe WikiController, type: :controller do
it 'should destroy child' do
session[:user_id] = 2
delete :destroy, project_id: 1, id: 'Child 1'
delete :destroy, params: { project_id: 1, id: 'Child 1' }
assert_redirected_to action: 'index', project_id: 'ecookbook', id: redirect_page
end
it 'should destroy parent' do
session[:user_id] = 2
assert_no_difference('WikiPage.count') do
delete :destroy, project_id: 1, id: 'Another page'
delete :destroy, params: { project_id: 1, id: 'Another page' }
end
assert_response :success
assert_template 'destroy'
@@ -344,7 +345,7 @@ describe WikiController, type: :controller do
it 'should destroy parent with nullify' do
session[:user_id] = 2
assert_difference('WikiPage.count', -1) do
delete :destroy, project_id: 1, id: 'Another page', todo: 'nullify'
delete :destroy, params: { project_id: 1, id: 'Another page', todo: 'nullify' }
end
assert_redirected_to action: 'index', project_id: 'ecookbook', id: redirect_page
assert_nil WikiPage.find_by(id: 2)
@@ -353,7 +354,7 @@ describe WikiController, type: :controller do
it 'should destroy parent with cascade' do
session[:user_id] = 2
assert_difference('WikiPage.count', -3) do
delete :destroy, project_id: 1, id: 'Another page', todo: 'destroy'
delete :destroy, params: { project_id: 1, id: 'Another page', todo: 'destroy' }
end
assert_redirected_to action: 'index', project_id: 'ecookbook', id: redirect_page
assert_nil WikiPage.find_by(id: 2)
@@ -363,7 +364,7 @@ describe WikiController, type: :controller do
it 'should destroy parent with reassign' do
session[:user_id] = 2
assert_difference('WikiPage.count', -1) do
delete :destroy, project_id: 1, id: 'Another page', todo: 'reassign', reassign_to_id: 1
delete :destroy, params: { project_id: 1, id: 'Another page', todo: 'reassign', reassign_to_id: 1 }
end
assert_redirected_to action: 'index', project_id: 'ecookbook', id: redirect_page
assert_nil WikiPage.find_by(id: 2)
@@ -371,7 +372,7 @@ describe WikiController, type: :controller do
end
it 'should index' do
get :index, project_id: 'ecookbook'
get :index, params: { project_id: 'ecookbook' }
assert_response :success
assert_template 'index'
pages = assigns(:pages)
@@ -391,7 +392,7 @@ describe WikiController, type: :controller do
end
it 'should index should include atom link' do
get :index, project_id: 'ecookbook'
get :index, params: { project_id: 'ecookbook' }
assert_select 'a', attributes: { href: '/projects/ecookbook/activity.atom?show_wiki_edits=1' }
end
@@ -399,7 +400,7 @@ describe WikiController, type: :controller do
context 'with an authorized user to export the wiki' do
before do
session[:user_id] = 2
get :export, project_id: 'ecookbook'
get :export, params: { project_id: 'ecookbook' }
end
it { is_expected.to respond_with :success }
@@ -414,7 +415,7 @@ describe WikiController, type: :controller do
context 'with an unauthorized user' do
before do
get :export, project_id: 'ecookbook'
get :export, params: { project_id: 'ecookbook' }
it { is_expected.to respond_with :redirect }
it { is_expected.to redirect_to('wiki index') { { action: 'show', project_id: @project, id: nil } } }
@@ -424,7 +425,7 @@ describe WikiController, type: :controller do
context 'GET :date_index' do
before do
get :date_index, project_id: 'ecookbook'
get :date_index, params: { project_id: 'ecookbook' }
end
it { is_expected.to respond_with :success }
@@ -438,7 +439,7 @@ describe WikiController, type: :controller do
end
it 'should not found' do
get :show, project_id: 999
get :show, params: { project_id: 999 }
assert_response 404
end
@@ -446,7 +447,7 @@ describe WikiController, type: :controller do
page = WikiPage.find_by(wiki_id: 1, title: 'Another page')
assert !page.protected?
session[:user_id] = 2
post :protect, project_id: 1, id: page.title, protected: '1'
post :protect, params: { project_id: 1, id: page.title, protected: '1' }
assert_redirected_to action: 'show', project_id: 'ecookbook', id: 'another-page'
assert page.reload.protected?
end
@@ -455,14 +456,14 @@ describe WikiController, type: :controller do
page = WikiPage.find_by(wiki_id: 1, title: 'CookBook documentation')
assert page.protected?
session[:user_id] = 2
post :protect, project_id: 1, id: page.title, protected: '0'
post :protect, params: { project_id: 1, id: page.title, protected: '0' }
assert_redirected_to action: 'show', project_id: 'ecookbook', id: 'cookbook-documentation'
assert !page.reload.protected?
end
it 'should show page with edit link' do
session[:user_id] = 2
get :show, project_id: 1
get :show, params: { project_id: 1 }
assert_response :success
assert_template 'show'
assert_select 'a', attributes: { href: '/projects/1/wiki/CookBook+documentation/edit' }
@@ -470,16 +471,16 @@ describe WikiController, type: :controller do
it 'should show page without edit link' do
session[:user_id] = 4
get :show, project_id: 1
get :show, params: { project_id: 1 }
assert_response :success
assert_template 'show'
assert_select('a', {attributes: { href: '/projects/1/wiki/CookBook+documentation/edit' }}, false)
assert_select('a', { attributes: { href: '/projects/1/wiki/CookBook+documentation/edit' } }, false)
end
it 'should edit unprotected page' do
# Non members can edit unprotected wiki pages
session[:user_id] = 4
get :edit, project_id: 1, id: 'Another page'
get :edit, params: { project_id: 1, id: 'Another page' }
assert_response :success
assert_template 'edit'
end
@@ -487,19 +488,19 @@ describe WikiController, type: :controller do
it 'should edit protected page by nonmember' do
# Non members can't edit protected wiki pages
session[:user_id] = 4
get :edit, project_id: 1, id: 'CookBook documentation'
get :edit, params: { project_id: 1, id: 'CookBook documentation' }
assert_response 403
end
it 'should edit protected page by member' do
session[:user_id] = 2
get :edit, project_id: 1, id: 'CookBook documentation'
get :edit, params: { project_id: 1, id: 'CookBook documentation' }
assert_response :success
assert_template 'edit'
end
it 'should history of non existing page should return 404' do
get :history, project_id: 1, id: 'Unknown page'
get :history, params: { project_id: 1, id: 'Unknown page' }
assert_response 404
end
end
@@ -1,4 +1,5 @@
#-- encoding: UTF-8
#-- copyright
# OpenProject is a project management system.
# Copyright (C) 2012-2017 the OpenProject Foundation (OPF)
@@ -26,7 +27,7 @@
#
# See doc/COPYRIGHT.rdoc for more details.
#++
require 'legacy_spec_helper'
require_relative '../legacy_spec_helper'
require 'workflows_controller'
describe WorkflowsController, type: :controller do
@@ -46,7 +47,7 @@ describe WorkflowsController, type: :controller do
count = Workflow.where('role_id = 1 AND type_id = 2').count
assert_select 'a', content: count.to_s,
attributes: { href: '/workflows/edit?role_id=1&amp;type_id=2' }
attributes: { href: '/workflows/edit?role_id=1&amp;type_id=2' }
end
it 'should get edit' do
@@ -62,7 +63,7 @@ describe WorkflowsController, type: :controller do
Workflow.create!(role_id: 1, type_id: 1, old_status_id: 2, new_status_id: 3)
Workflow.create!(role_id: 2, type_id: 1, old_status_id: 3, new_status_id: 5)
get :edit, role_id: 2, type_id: 1
get :edit, params: { role_id: 2, type_id: 1 }
assert_response :success
assert_template 'edit'
@@ -72,23 +73,23 @@ describe WorkflowsController, type: :controller do
# allowed transitions
assert_select 'input', attributes: { type: 'checkbox',
name: 'status[3][5][]',
value: 'always',
checked: 'checked' }
name: 'status[3][5][]',
value: 'always',
checked: 'checked' }
# not allowed
assert_select 'input', attributes: { type: 'checkbox',
name: 'status[3][2][]',
value: 'always',
checked: nil }
name: 'status[3][2][]',
value: 'always',
checked: nil }
# unused
assert_select('input', {attributes: { type: 'checkbox',
name: 'status[1][1][]' }}, false)
assert_select('input', { attributes: { type: 'checkbox',
name: 'status[1][1][]' } }, false)
end
it 'should get edit with role and type and all statuses' do
Workflow.delete_all
get :edit, role_id: 2, type_id: 1, used_statuses_only: '0'
get :edit, params: { role_id: 2, type_id: 1, used_statuses_only: '0' }
assert_response :success
assert_template 'edit'
@@ -96,17 +97,17 @@ describe WorkflowsController, type: :controller do
assert_equal Status.count, assigns(:statuses).size
assert_select 'input', attributes: { type: 'checkbox',
name: 'status[1][1][]',
value: 'always',
checked: nil }
name: 'status[1][1][]',
value: 'always',
checked: nil }
end
it 'should post edit' do
post :edit, role_id: 2, type_id: 1,
status: {
'4' => { '5' => ['always'] },
'3' => { '1' => ['always'], '2' => ['always'] }
}
post :edit, params: { role_id: 2, type_id: 1,
status: {
'4' => { '5' => ['always'] },
'3' => { '1' => ['always'], '2' => ['always'] }
} }
assert_redirected_to '/workflows/edit?role_id=2&type_id=1'
assert_equal 3, Workflow.where(type_id: 1, role_id: 2).count
@@ -115,11 +116,11 @@ describe WorkflowsController, type: :controller do
end
it 'should post edit with additional transitions' do
post :edit, role_id: 2, type_id: 1,
status: {
'4' => { '5' => ['always'] },
'3' => { '1' => ['author'], '2' => ['assignee'], '4' => ['author', 'assignee'] }
}
post :edit, params: { role_id: 2, type_id: 1,
status: {
'4' => { '5' => ['always'] },
'3' => { '1' => ['author'], '2' => ['assignee'], '4' => ['author', 'assignee'] }
} }
assert_redirected_to '/workflows/edit?role_id=2&type_id=1'
assert_equal 4, Workflow.where(type_id: 1, role_id: 2).count
@@ -141,7 +142,7 @@ describe WorkflowsController, type: :controller do
it 'should clear workflow' do
assert Workflow.where(type_id: 1, role_id: 2).count > 0
post :edit, role_id: 2, type_id: 1
post :edit, params: { role_id: 2, type_id: 1 }
assert_equal 0, Workflow.where(type_id: 1, role_id: 2).count
end
@@ -154,8 +155,8 @@ describe WorkflowsController, type: :controller do
it 'should post copy one to one' do
source_transitions = status_transitions(type_id: 1, role_id: 2)
post :copy, source_type_id: '1', source_role_id: '2',
target_type_ids: ['3'], target_role_ids: ['1']
post :copy, params: { source_type_id: '1', source_role_id: '2',
target_type_ids: ['3'], target_role_ids: ['1'] }
assert_response 302
assert_equal source_transitions, status_transitions(type_id: 3, role_id: 1)
end
@@ -163,8 +164,8 @@ describe WorkflowsController, type: :controller do
it 'should post copy one to many' do
source_transitions = status_transitions(type_id: 1, role_id: 2)
post :copy, source_type_id: '1', source_role_id: '2',
target_type_ids: ['2', '3'], target_role_ids: ['1', '3']
post :copy, params: { source_type_id: '1', source_role_id: '2',
target_type_ids: ['2', '3'], target_role_ids: ['1', '3'] }
assert_response 302
assert_equal source_transitions, status_transitions(type_id: 2, role_id: 1)
assert_equal source_transitions, status_transitions(type_id: 3, role_id: 1)
@@ -176,8 +177,8 @@ describe WorkflowsController, type: :controller do
source_t2 = status_transitions(type_id: 2, role_id: 2)
source_t3 = status_transitions(type_id: 3, role_id: 2)
post :copy, source_type_id: 'any', source_role_id: '2',
target_type_ids: ['2', '3'], target_role_ids: ['1', '3']
post :copy, params: { source_type_id: 'any', source_role_id: '2',
target_type_ids: ['2', '3'], target_role_ids: ['1', '3'] }
assert_response 302
assert_equal source_t2, status_transitions(type_id: 2, role_id: 1)
assert_equal source_t3, status_transitions(type_id: 3, role_id: 1)
@@ -187,7 +188,8 @@ describe WorkflowsController, type: :controller do
# Returns an array of status transitions that can be compared
def status_transitions(conditions)
Workflow.where(conditions)
Workflow
.where(conditions)
.order('type_id, role_id, old_status_id, new_status_id')
.map { |w| [w.old_status, w.new_status_id] }
end
@@ -27,7 +27,7 @@
# See doc/COPYRIGHT.rdoc for more details.
#++
require 'legacy_spec_helper'
require_relative '../../legacy_spec_helper'
describe 'ApiTest: DisabledRestApiTest', type: :request do
fixtures :all
@@ -62,7 +62,7 @@ describe 'ApiTest: DisabledRestApiTest', type: :request do
before do
@user = FactoryGirl.create(:user, password: 'adminADMIN!', password_confirmation: 'adminADMIN!')
@authorization = ActionController::HttpAuthentication::Basic.encode_credentials(@user.login, 'adminADMIN!')
get '/api/v2/projects.xml', nil, authorization: @authorization
get '/api/v2/projects.xml', params: { authorization: @authorization }
end
it { is_expected.to respond_with :unauthorized }
@@ -77,7 +77,7 @@ describe 'ApiTest: DisabledRestApiTest', type: :request do
@user = FactoryGirl.create(:user)
@token = FactoryGirl.create(:token, user: @user, action: 'api')
@authorization = ActionController::HttpAuthentication::Basic.encode_credentials(@token.value, 'X')
get '/api/v2/projects.xml', nil, authorization: @authorization
get '/api/v2/projects.xml', params: { authorization: @authorization }
end
it { is_expected.to respond_with :unauthorized }
@@ -107,7 +107,7 @@ describe 'ApiTest: DisabledRestApiTest', type: :request do
before do
@user = FactoryGirl.create(:user, password: 'adminADMIN!', password_confirmation: 'adminADMIN!')
@authorization = ActionController::HttpAuthentication::Basic.encode_credentials(@user.login, 'adminADMIN!')
get '/api/v2/projects.json', nil, authorization: @authorization
get '/api/v2/projects.json', params: { authorization: @authorization }
end
it { is_expected.to respond_with :unauthorized }
@@ -122,7 +122,7 @@ describe 'ApiTest: DisabledRestApiTest', type: :request do
@user = FactoryGirl.create(:user)
@token = FactoryGirl.create(:token, user: @user, action: 'api')
@authorization = ActionController::HttpAuthentication::Basic.encode_credentials(@token.value, 'DoesNotMatter')
get '/api/v2/projects.json', nil, authorization: @authorization
get '/api/v2/projects.json', params: { authorization: @authorization }
end
it { is_expected.to respond_with :unauthorized }
@@ -27,7 +27,7 @@
# See doc/COPYRIGHT.rdoc for more details.
#++
require 'legacy_spec_helper'
require_relative '../../legacy_spec_helper'
describe 'ApiTest: HttpAcceptAuthTest', type: :request do
fixtures :all
@@ -27,7 +27,7 @@
# See doc/COPYRIGHT.rdoc for more details.
#++
require 'legacy_spec_helper'
require_relative '../../legacy_spec_helper'
describe 'ApiTest: HttpBasicLoginTest', type: :request do
fixtures :all
@@ -27,7 +27,7 @@
# See doc/COPYRIGHT.rdoc for more details.
#++
require 'legacy_spec_helper'
require_relative '../../legacy_spec_helper'
describe 'ApiTest: HttpBasicLoginWithApiToken', type: :request do
fixtures :all
@@ -1,4 +1,5 @@
#-- encoding: UTF-8
#-- copyright
# OpenProject is a project management system.
# Copyright (C) 2012-2017 the OpenProject Foundation (OPF)
@@ -27,7 +28,7 @@
# See doc/COPYRIGHT.rdoc for more details.
#++
require 'legacy_spec_helper'
require_relative '../../legacy_spec_helper'
describe 'ApiTest: TokenAuthentication', type: :request do
fixtures :all
+3 -2
View File
@@ -1,4 +1,5 @@
#-- encoding: UTF-8
#-- copyright
# OpenProject is a project management system.
# Copyright (C) 2012-2017 the OpenProject Foundation (OPF)
@@ -42,13 +43,13 @@ describe 'Application', with_settings: { login_required?: false } do
allow(Setting).to receive(:default_language).and_return 'en'
# a french user
get '/projects', {}, 'HTTP_ACCEPT_LANGUAGE' => 'de,de-de;q=0.8,en-us;q=0.5,en;q=0.3'
get '/projects', params: {}, headers: { 'HTTP_ACCEPT_LANGUAGE' => 'de,de-de;q=0.8,en-us;q=0.5,en;q=0.3' }
assert_response :success
assert_select 'h2', content: 'Projekte'
assert_equal :de, current_language
# not a supported language: default language should be used
get '/projects', {}, 'HTTP_ACCEPT_LANGUAGE' => 'zz'
get '/projects', params: {}, headers: { 'HTTP_ACCEPT_LANGUAGE' => 'zz' }
assert_response :success
assert_select 'h2', content: 'Projects'
end
+1 -1
View File
@@ -27,7 +27,7 @@
# See doc/COPYRIGHT.rdoc for more details.
#++
require 'legacy_spec_helper'
require_relative '../legacy_spec_helper'
describe 'Layout' do
fixtures :all
@@ -1,4 +1,5 @@
#-- encoding: UTF-8
#-- copyright
# OpenProject is a project management system.
# Copyright (C) 2012-2017 the OpenProject Foundation (OPF)
@@ -26,7 +27,7 @@
#
# See doc/COPYRIGHT.rdoc for more details.
#++
require 'legacy_spec_helper'
require_relative '../../../legacy_spec_helper'
describe 'MenuManager', with_settings: { login_required: 0 } do
include Redmine::I18n
@@ -39,7 +40,7 @@ describe 'MenuManager', with_settings: { login_required: 0 } do
it 'project menu with specific locale' do
Setting.available_languages = [:de, :en]
get '/projects/ecookbook', {}, 'HTTP_ACCEPT_LANGUAGE' => 'de,de-de;q=0.8,en-us;q=0.5,en;q=0.3'
get '/projects/ecookbook', params: {}, headers: { 'HTTP_ACCEPT_LANGUAGE' => 'de,de-de;q=0.8,en-us;q=0.5,en;q=0.3' }
assert_select 'div', attributes: { id: 'main-menu' },
descendant: { tag: 'li', child: { tag: 'a', content: ll('de', :label_activity),
+1 -1
View File
@@ -26,7 +26,7 @@
#
# See doc/COPYRIGHT.rdoc for more details.
#++
require 'legacy_spec_helper'
require_relative '../legacy_spec_helper'
describe 'routing', type: :routing do
before do
-9
View File
@@ -86,15 +86,6 @@ RSpec.configure do |config|
I18n.locale = 'en'
end
if ENV['CI']
$stderr.puts <<-EOS
WARNING
Silencing all ActiveSupport::Deprecation message output due to CI=true.
EOS
ActiveSupport::Deprecation.behavior = :silence
end
# colorized rspec output
config.color = true
config.formatter = 'progress'
+9 -9
View File
@@ -262,7 +262,7 @@ module LegacyAssertionsAndHelpers
context "should not send www authenticate when header accept auth is session #{http_method} #{url}" do
context 'without credentials' do
before do
send(http_method, url, parameters, 'HTTP_X_AUTHENTICATION_SCHEME' => 'Session')
send(http_method, url, params: parameters, headers: { 'HTTP_X_AUTHENTICATION_SCHEME' => 'Session' })
end
it { should respond_with failure_code }
it { should_respond_with_content_type_based_on_url(url) }
@@ -291,7 +291,7 @@ module LegacyAssertionsAndHelpers
before do
@user = FactoryGirl.create(:user, password: 'adminADMIN!', password_confirmation: 'adminADMIN!', admin: true) # Admin so they can access the project
send(http_method, url, parameters, credentials(@user.login, 'adminADMIN!'))
send(http_method, url, params: parameters, headers: credentials(@user.login, 'adminADMIN!'))
end
it { should respond_with success_code }
it { should_respond_with_content_type_based_on_url(url) }
@@ -304,7 +304,7 @@ module LegacyAssertionsAndHelpers
before do
@user = FactoryGirl.create(:user)
send(http_method, url, parameters, credentials(@user.login, 'wrong_password'))
send(http_method, url, params: parameters, headers: credentials(@user.login, 'wrong_password'))
end
it { should respond_with failure_code }
it { should_respond_with_content_type_based_on_url(url) }
@@ -315,7 +315,7 @@ module LegacyAssertionsAndHelpers
context 'without credentials' do
before do
send(http_method, url, parameters)
send(http_method, url, params: parameters)
end
it { should respond_with failure_code }
it { should_respond_with_content_type_based_on_url(url) }
@@ -344,7 +344,7 @@ module LegacyAssertionsAndHelpers
@user = FactoryGirl.create(:user, admin: true)
@token = FactoryGirl.create(:token, user: @user, action: 'api')
send(http_method, url, parameters, credentials(@token.value, 'X'))
send(http_method, url, params: parameters, headers: credentials(@token.value, 'X'))
end
it { should respond_with success_code }
it { should_respond_with_content_type_based_on_url(url) }
@@ -359,7 +359,7 @@ module LegacyAssertionsAndHelpers
@user = FactoryGirl.create(:user)
@token = FactoryGirl.create(:token, user: @user, action: 'feeds')
send(http_method, url, parameters, credentials(@token.value, 'X'))
send(http_method, url, params: parameters, headers: credentials(@token.value, 'X'))
end
it { should respond_with failure_code }
it { should_respond_with_content_type_based_on_url(url) }
@@ -393,7 +393,7 @@ module LegacyAssertionsAndHelpers
else
url + "?key=#{@token.value}"
end
send(http_method, request_url, parameters)
send(http_method, request_url, params: parameters)
end
it { should respond_with success_code }
it { should_respond_with_content_type_based_on_url(url) }
@@ -413,7 +413,7 @@ module LegacyAssertionsAndHelpers
else
url + "?key=#{@token.value}"
end
send(http_method, request_url, parameters)
send(http_method, request_url, params: parameters)
end
it { should respond_with failure_code }
it { should_respond_with_content_type_based_on_url(url) }
@@ -427,7 +427,7 @@ module LegacyAssertionsAndHelpers
before do
@user = FactoryGirl.create(:user, admin: true)
@token = FactoryGirl.create(:token, user: @user, action: 'api')
send(http_method, url, {}, {'X-OpenProject-API-Key' => @token.value.to_s})
send(http_method, url, params: {}, headers: { 'X-OpenProject-API-Key' => @token.value.to_s })
end
it { should respond_with success_code }
it { should_respond_with_content_type_based_on_url(url) }
+1 -1
View File
@@ -26,7 +26,7 @@
#
# See doc/COPYRIGHT.rdoc for more details.
#++
require 'legacy_spec_helper'
require_relative '../../../legacy_spec_helper'
describe 'Redmine::Hook::Manager' do # FIXME: naming (RSpec-port)
fixtures :all
+1 -1
View File
@@ -128,7 +128,7 @@ describe 'Search' do # FIXME: naming (RSpec-port)
it 'should search_issue_with_multiple_hits_in_journals' do
i = WorkPackage.find(1)
Journal.delete_all journable_id: i.id
Journal.where(journable_id: i.id).delete_all
i.add_journal User.current, 'Journal notes'
i.save!
i.add_journal User.current, 'Some notes with Redmine links: #2, r2.'
+3 -1
View File
@@ -1,4 +1,5 @@
#-- encoding: UTF-8
#-- copyright
# OpenProject is a project management system.
# Copyright (C) 2012-2017 the OpenProject Foundation (OPF)
@@ -26,7 +27,8 @@
#
# See doc/COPYRIGHT.rdoc for more details.
#++
require 'legacy_spec_helper'
require_relative '../legacy_spec_helper'
describe Status, type: :model do
fixtures :all
+1 -1
View File
@@ -114,7 +114,7 @@ describe WikiPage, type: :model do
# make sure that page content and its history are deleted
assert WikiContent.where(page_id: 1).empty?
content_ids.each do |wiki_content_id|
assert Journal.where(journable_type: WikiContent,
assert Journal.where(journable_type: 'WikiContent',
journable_id: wiki_content_id)
end
end