parent
074ff0aafc
commit
5a5e3494f9
@ -0,0 +1,41 @@ |
||||
#-- 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. |
||||
#++ |
||||
|
||||
class Type::AttributeGroup < Type::FormGroup |
||||
def members |
||||
attributes.sort |
||||
end |
||||
|
||||
def active_members(project) |
||||
members.select do |prop| |
||||
type.passes_attribute_constraint?(prop, project: project) |
||||
end |
||||
end |
||||
end |
@ -0,0 +1,60 @@ |
||||
#-- 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. |
||||
#++ |
||||
|
||||
class Type::FormGroup |
||||
attr_accessor :key, |
||||
:attributes, |
||||
:type |
||||
|
||||
def initialize(type, key, attributes) |
||||
self.key = key |
||||
self.attributes = attributes |
||||
self.type = type |
||||
end |
||||
|
||||
## |
||||
# Translate the given attribute group if its internal |
||||
# (== if it's a symbol) |
||||
def translated_key |
||||
if key.is_a? Symbol |
||||
I18n.t(Type.default_groups[key]) |
||||
else |
||||
key |
||||
end |
||||
end |
||||
|
||||
def members |
||||
raise NotImplementedError |
||||
end |
||||
|
||||
def active_members(project) |
||||
raise NotImplementedError |
||||
end |
||||
end |
@ -0,0 +1,41 @@ |
||||
#-- 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. |
||||
#++ |
||||
|
||||
class Type::QueryGroup < Type::FormGroup |
||||
alias :query :attributes |
||||
|
||||
def members |
||||
[attributes] |
||||
end |
||||
|
||||
def active_members(project) |
||||
[members] |
||||
end |
||||
end |
@ -0,0 +1,81 @@ |
||||
#-- 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 'spec_helper' |
||||
|
||||
describe TypesHelper, type: :helper do |
||||
let(:type) { FactoryGirl.build_stubbed(:type) } |
||||
|
||||
describe "#form_configuration_groups" do |
||||
it "returns a Hash with the keys :actives and :inactives Arrays" do |
||||
expect(helper.form_configuration_groups(type)[:actives]).to be_an Array |
||||
expect(helper.form_configuration_groups(type)[:inactives]).to be_an Array |
||||
end |
||||
|
||||
describe ":inactives" do |
||||
subject { helper.form_configuration_groups(type)[:inactives] } |
||||
|
||||
before do |
||||
allow(type) |
||||
.to receive(:attribute_groups) |
||||
.and_return [::Type::AttributeGroup.new(type, 'group one', ["assignee"])] |
||||
end |
||||
|
||||
it 'contains Hashes ordered by key :translation' do |
||||
# The first left over attribute should currently be "date" |
||||
expect(subject.first[:translation]).to be_present |
||||
expect(subject.first[:translation] <= subject.second[:translation]).to be_truthy |
||||
end |
||||
|
||||
# The "assignee" is in "group one". It should not appear in :inactives. |
||||
it 'does not contain attributes that do not exist anymore' do |
||||
expect(subject.map { |inactive| inactive[:key] }).to_not include "assignee" |
||||
end |
||||
end |
||||
|
||||
describe ":actives" do |
||||
subject { helper.form_configuration_groups(type)[:actives] } |
||||
|
||||
before do |
||||
allow(type) |
||||
.to receive(:attribute_groups) |
||||
.and_return [::Type::AttributeGroup.new(type, 'group one', ["date"])] |
||||
end |
||||
|
||||
it 'has a proper structure' do |
||||
# The group's name/key |
||||
expect(subject.first.first.key).to eq "group one" |
||||
|
||||
# The groups attributes |
||||
expect(subject.first.second).to be_an Array |
||||
expect(subject.first.second.first[:key]).to eq "date" |
||||
expect(subject.first.second.first[:translation]).to eq "Date" |
||||
end |
||||
end |
||||
end |
||||
end |
Loading…
Reference in new issue