Merge branch 'release/8.0' into dev

pull/6760/head
Jens Ulferts 6 years ago
commit 462e075447
No known key found for this signature in database
GPG Key ID: 3CAA4B1182CF5308
  1. 2
      app/models/custom_field.rb
  2. 2
      spec/lib/custom_field_form_builder_spec.rb
  3. 93
      spec/models/custom_field_spec.rb
  4. 12
      spec/models/work_package_custom_field_spec.rb
  5. 59
      spec_legacy/unit/custom_field_spec.rb

@ -260,7 +260,7 @@ class CustomField < ActiveRecord::Base
def possible_version_values_options(obj)
mapped_with_deduced_project(obj) do |project|
if project
project.versions
project.shared_versions
else
Version.systemwide
end

@ -284,7 +284,7 @@ describe CustomFieldFormBuilder do
resource.custom_field.field_format = 'version'
resource.customized = project
allow(project)
.to receive(:versions)
.to receive(:shared_versions)
.and_return([version1, version2])
end

@ -244,6 +244,88 @@ describe CustomField, type: :model do
[option2.value, option2.id.to_s]]
end
end
context 'for a version custom field' do
let(:versions) { [FactoryBot.build_stubbed(:version), FactoryBot.build_stubbed(:version)] }
before do
field.field_format = 'version'
end
context 'with a project provided' do
it 'returns the project\'s shared_versions' do
allow(project)
.to receive(:shared_versions)
.and_return(versions)
expect(field.possible_values_options(project))
.to eql(versions.sort.map { |u| [u.name, u.id.to_s] })
end
end
context 'with a time entry provided' do
let(:time_entry) { FactoryBot.build_stubbed(:time_entry, project: project) }
it 'returns the project\'s shared_versions' do
allow(project)
.to receive(:shared_versions)
.and_return(versions)
expect(field.possible_values_options(project))
.to eql(versions.sort.map { |u| [u.name, u.id.to_s] })
end
end
context 'with nothing provided' do
it 'returns the systemwide versions' do
allow(Version)
.to receive(:systemwide)
.and_return(versions)
expect(field.possible_values_options)
.to eql(versions.sort.map { |u| [u.name, u.id.to_s] })
end
end
end
end
describe '#possible_values' do
context 'on a list custom field' do
let(:field) { CustomField.new field_format: "list" }
context 'on providing an array' do
before do
field.possible_values = ['One value', 'Two values', '']
end
it 'accepts the values' do
expect(field.possible_values.map(&:value))
.to match_array(['One value', 'Two values'])
end
end
context 'on providing a string' do
before do
field.possible_values = 'One value'
end
it 'accepts the values' do
expect(field.possible_values.map(&:value))
.to match_array(['One value'])
end
end
context 'on providing a multiline string' do
before do
field.possible_values = "One value\nTwo values \r\n \n"
end
it 'accepts the values' do
expect(field.possible_values.map(&:value))
.to match_array(['One value', 'Two values'])
end
end
end
end
describe 'nested attributes for custom options' do
@ -284,4 +366,15 @@ describe CustomField, type: :model do
it_behaves_like 'saving updates field\'s updated_at'
end
end
describe '#destroy' do
it 'removes the cf' do
field.save!
field.destroy
expect(CustomField.where(id: field.id).exists?)
.to be_falsey
end
end
end

@ -30,13 +30,13 @@ require 'spec_helper'
describe WorkPackageCustomField, type: :model do
describe '.summable' do
let (:custom_field) {
let (:custom_field) do
FactoryBot.create(:work_package_custom_field,
name: 'Database',
field_format: 'list',
possible_values: ['MySQL', 'PostgreSQL', 'Oracle'],
is_required: true)
}
name: 'Database',
field_format: 'list',
possible_values: %w(MySQL PostgreSQL Oracle),
is_required: true)
end
before do
custom_field.save!

@ -1,59 +0,0 @@
#-- encoding: UTF-8
#-- copyright
# OpenProject is a project management system.
# Copyright (C) 2012-2018 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 docs/COPYRIGHT.rdoc for more details.
#++
require_relative '../legacy_spec_helper'
describe CustomField, type: :model do
it 'should create' do
field = UserCustomField.new(name: 'Money money money', field_format: 'float')
assert field.save
end
it 'should possible values should accept an array' do
field = CustomField.new field_format: "list"
field.possible_values = ['One value', '']
assert_equal ['One value'], field.possible_values.map(&:value)
end
it 'should possible values should accept a string' do
field = CustomField.new field_format: "list"
field.possible_values = 'One value'
assert_equal ['One value'], field.possible_values.map(&:value)
end
it 'should possible values should accept a multiline string' do
field = CustomField.new field_format: "list"
field.possible_values = "One value\nAnd another one \r\n \n"
assert_equal ['One value', 'And another one'], field.possible_values.map(&:value)
end
it 'should destroy' do
field = FactoryBot.create :custom_field
assert field.destroy
end
end
Loading…
Cancel
Save