mirror of
https://github.com/opf/openproject.git
synced 2026-06-14 03:30:14 +00:00
Remove plugin tests from lib/ that now are eager loaded
This commit is contained in:
@@ -100,7 +100,7 @@ module OpenProject
|
||||
|
||||
# Custom directories with classes and modules you want to be autoloadable.
|
||||
config.enable_dependency_loading = true
|
||||
config.eager_load_paths << Rails.root.join('lib')
|
||||
config.paths.add Rails.root.join('lib').to_s, eager_load: true
|
||||
|
||||
# Only load the plugins named here, in the order given (default is alphabetical).
|
||||
# :all can be used as a placeholder for all plugins not explicitly named.
|
||||
|
||||
@@ -33,7 +33,7 @@ Dir.glob(File.join(Rails.root, 'lib/plugins/*')).sort.each do |directory|
|
||||
lib = File.join(directory, 'lib')
|
||||
|
||||
$:.unshift lib
|
||||
Rails.configuration.paths.add lib, glob: '*', eager_load: true
|
||||
Rails.configuration.paths.add lib, eager_load: true, glob: "**[^test]/*"
|
||||
|
||||
initializer = File.join(directory, 'init.rb')
|
||||
if File.file?(initializer)
|
||||
|
||||
@@ -1,198 +0,0 @@
|
||||
#-- 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.
|
||||
#++
|
||||
|
||||
#-- encoding: UTF-8
|
||||
require File.join(File.dirname(__FILE__), 'test_helper')
|
||||
|
||||
class ChangesTest < Test::Unit::TestCase
|
||||
context "A journal's changes" do
|
||||
setup do
|
||||
@user = User.create(name: 'Steve Richert')
|
||||
@user.update_attribute(:last_name, 'Jobs')
|
||||
@changes = @user.journals.last.details
|
||||
end
|
||||
|
||||
should 'be a hash' do
|
||||
assert_kind_of Hash, @changes
|
||||
end
|
||||
|
||||
should 'not be empty' do
|
||||
assert !@changes.empty?
|
||||
end
|
||||
|
||||
should 'have string keys' do
|
||||
@changes.keys.each do |key|
|
||||
assert_kind_of String, key
|
||||
end
|
||||
end
|
||||
|
||||
should 'have array values' do
|
||||
@changes.values.each do |value|
|
||||
assert_kind_of Array, value
|
||||
end
|
||||
end
|
||||
|
||||
should 'have two-element values' do
|
||||
@changes.values.each do |value|
|
||||
assert_equal 2, value.size
|
||||
end
|
||||
end
|
||||
|
||||
should 'have unique-element values' do
|
||||
@changes.values.each do |value|
|
||||
assert_equal value.uniq, value
|
||||
end
|
||||
end
|
||||
|
||||
should "equal the model's changes" do
|
||||
@user.first_name = 'Stephen'
|
||||
model_changes = @user.changed_data
|
||||
@user.save
|
||||
changes = @user.journals.last.details
|
||||
assert_equal model_changes, changes
|
||||
end
|
||||
end
|
||||
|
||||
context 'A hash of changes' do
|
||||
setup do
|
||||
@changes = { 'first_name' => ['Steve', 'Stephen'] }
|
||||
@other = { 'first_name' => ['Catie', 'Catherine'] }
|
||||
end
|
||||
|
||||
should 'properly append other changes' do
|
||||
expected = { 'first_name' => ['Steve', 'Catherine'] }
|
||||
changes = @changes.append_changes(@other)
|
||||
assert_equal expected, changes
|
||||
@changes.append_changes!(@other)
|
||||
assert_equal expected, @changes
|
||||
end
|
||||
|
||||
should 'properly prepend other changes' do
|
||||
expected = { 'first_name' => ['Catie', 'Stephen'] }
|
||||
changes = @changes.prepend_changes(@other)
|
||||
assert_equal expected, changes
|
||||
@changes.prepend_changes!(@other)
|
||||
assert_equal expected, @changes
|
||||
end
|
||||
|
||||
should 'be reversible' do
|
||||
expected = { 'first_name' => ['Stephen', 'Steve'] }
|
||||
changes = @changes.reverse_changes
|
||||
assert_equal expected, changes
|
||||
@changes.reverse_changes!
|
||||
assert_equal expected, @changes
|
||||
end
|
||||
end
|
||||
|
||||
context 'The changes between two journals' do
|
||||
setup do
|
||||
name = 'Steve Richert'
|
||||
@user = User.create(name: name) # 1
|
||||
@user.update_attribute(:last_name, 'Jobs') # 2
|
||||
@user.update_attribute(:first_name, 'Stephen') # 3
|
||||
@user.update_attribute(:last_name, 'Richert') # 4
|
||||
@user.update_attribute(:name, name) # 5
|
||||
@version = @user.version
|
||||
end
|
||||
|
||||
should 'be a hash' do
|
||||
1.upto(@version) do |i|
|
||||
1.upto(@version) do |j|
|
||||
changes = @user.changes_between(i, j)
|
||||
assert_kind_of Hash, changes
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
should 'have string keys' do
|
||||
1.upto(@version) do |i|
|
||||
1.upto(@version) do |j|
|
||||
changes = @user.changes_between(i, j)
|
||||
changes.keys.each do |key|
|
||||
assert_kind_of String, key
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
should 'have array values' do
|
||||
1.upto(@version) do |i|
|
||||
1.upto(@version) do |j|
|
||||
changes = @user.changes_between(i, j)
|
||||
changes.values.each do |value|
|
||||
assert_kind_of Array, value
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
should 'have two-element values' do
|
||||
1.upto(@version) do |i|
|
||||
1.upto(@version) do |j|
|
||||
changes = @user.changes_between(i, j)
|
||||
changes.values.each do |value|
|
||||
assert_equal 2, value.size
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
should 'have unique-element values' do
|
||||
1.upto(@version) do |i|
|
||||
1.upto(@version) do |j|
|
||||
changes = @user.changes_between(i, j)
|
||||
changes.values.each do |value|
|
||||
assert_equal value.uniq, value
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
should 'be empty between identical versions' do
|
||||
assert @user.changes_between(1, @version).empty?
|
||||
assert @user.changes_between(@version, 1).empty?
|
||||
end
|
||||
|
||||
should 'be should reverse with direction' do
|
||||
1.upto(@version) do |i|
|
||||
i.upto(@version) do |j|
|
||||
up = @user.changes_between(i, j)
|
||||
down = @user.changes_between(j, i)
|
||||
assert_equal up, down.reverse_changes
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
should 'be empty with invalid arguments' do
|
||||
1.upto(@version) do |i|
|
||||
assert @user.changes_between(i, nil)
|
||||
assert @user.changes_between(nil, i)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,167 +0,0 @@
|
||||
#-- 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.
|
||||
#++
|
||||
|
||||
#-- encoding: UTF-8
|
||||
require File.join(File.dirname(__FILE__), 'test_helper')
|
||||
|
||||
class ConditionsTest < Test::Unit::TestCase
|
||||
context 'Converted :if conditions' do
|
||||
setup do
|
||||
User.class_eval do
|
||||
def true; true; end
|
||||
end
|
||||
end
|
||||
|
||||
should 'be an array' do
|
||||
assert_kind_of Array, User.vestal_journals_options[:if]
|
||||
User.prepare_journaled_options(if: :true)
|
||||
assert_kind_of Array, User.vestal_journals_options[:if]
|
||||
end
|
||||
|
||||
should 'have proc values' do
|
||||
User.prepare_journaled_options(if: :true)
|
||||
assert User.vestal_journals_options[:if].all? { |i| i.is_a?(Proc) }
|
||||
end
|
||||
|
||||
teardown do
|
||||
User.prepare_journaled_options(if: [])
|
||||
end
|
||||
end
|
||||
|
||||
context 'Converted :unless conditions' do
|
||||
setup do
|
||||
User.class_eval do
|
||||
def true; true; end
|
||||
end
|
||||
end
|
||||
|
||||
should 'be an array' do
|
||||
assert_kind_of Array, User.vestal_journals_options[:unless]
|
||||
User.prepare_journaled_options(unless: :true)
|
||||
assert_kind_of Array, User.vestal_journals_options[:unless]
|
||||
end
|
||||
|
||||
should 'have proc values' do
|
||||
User.prepare_journaled_options(unless: :true)
|
||||
assert User.vestal_journals_options[:unless].all? { |i| i.is_a?(Proc) }
|
||||
end
|
||||
|
||||
teardown do
|
||||
User.prepare_journaled_options(unless: [])
|
||||
end
|
||||
end
|
||||
|
||||
context 'A new journal' do
|
||||
setup do
|
||||
User.class_eval do
|
||||
def true; true; end
|
||||
|
||||
def false; false; end
|
||||
end
|
||||
|
||||
@user = User.create(name: 'Steve Richert')
|
||||
@count = @user.journals.count
|
||||
end
|
||||
|
||||
context 'with :if conditions' do
|
||||
context 'that pass' do
|
||||
setup do
|
||||
User.prepare_journaled_options(if: [:true])
|
||||
@user.update_attribute(:last_name, 'Jobs')
|
||||
end
|
||||
|
||||
should 'be created' do
|
||||
assert_equal @count + 1, @user.journals.count
|
||||
end
|
||||
end
|
||||
|
||||
context 'that fail' do
|
||||
setup do
|
||||
User.prepare_journaled_options(if: [:false])
|
||||
@user.update_attribute(:last_name, 'Jobs')
|
||||
end
|
||||
|
||||
should 'not be created' do
|
||||
assert_equal @count, @user.journals.count
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'with :unless conditions' do
|
||||
context 'that pass' do
|
||||
setup do
|
||||
User.prepare_journaled_options(unless: [:true])
|
||||
@user.update_attribute(:last_name, 'Jobs')
|
||||
end
|
||||
|
||||
should 'not be created' do
|
||||
assert_equal @count, @user.journals.count
|
||||
end
|
||||
end
|
||||
|
||||
context 'that fail' do
|
||||
setup do
|
||||
User.prepare_journaled_options(unless: [:false])
|
||||
@user.update_attribute(:last_name, 'Jobs')
|
||||
end
|
||||
|
||||
should 'not be created' do
|
||||
assert_equal @count + 1, @user.journals.count
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'with :if and :unless conditions' do
|
||||
context 'that pass' do
|
||||
setup do
|
||||
User.prepare_journaled_options(if: [:true], unless: [:true])
|
||||
@user.update_attribute(:last_name, 'Jobs')
|
||||
end
|
||||
|
||||
should 'not be created' do
|
||||
assert_equal @count, @user.journals.count
|
||||
end
|
||||
end
|
||||
|
||||
context 'that fail' do
|
||||
setup do
|
||||
User.prepare_journaled_options(if: [:false], unless: [:false])
|
||||
@user.update_attribute(:last_name, 'Jobs')
|
||||
end
|
||||
|
||||
should 'not be created' do
|
||||
assert_equal @count, @user.journals.count
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
teardown do
|
||||
User.prepare_journaled_options(if: [], unless: [])
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,68 +0,0 @@
|
||||
#-- 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.
|
||||
#++
|
||||
|
||||
#-- encoding: UTF-8
|
||||
require File.join(File.dirname(__FILE__), 'test_helper')
|
||||
|
||||
class ConfigurationTest < Test::Unit::TestCase
|
||||
context 'Global configuration options' do
|
||||
setup do
|
||||
module Extension; end
|
||||
|
||||
@options = {
|
||||
'class_name' => 'CustomVersion',
|
||||
extend: Extension,
|
||||
as: :parent
|
||||
}
|
||||
|
||||
VestalVersions.configure do |config|
|
||||
@options.each do |key, value|
|
||||
config.send("#{key}=", value)
|
||||
end
|
||||
end
|
||||
|
||||
@configuration = VestalVersions::Configuration.options
|
||||
end
|
||||
|
||||
should 'should be a hash' do
|
||||
assert_kind_of Hash, @configuration
|
||||
end
|
||||
|
||||
should 'have symbol keys' do
|
||||
assert @configuration.keys.all? { |k| k.is_a?(Symbol) }
|
||||
end
|
||||
|
||||
should 'store values identical to those given' do
|
||||
assert_equal @options.symbolize_keys, @configuration
|
||||
end
|
||||
|
||||
teardown do
|
||||
VestalVersions::Configuration.options.clear
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,181 +0,0 @@
|
||||
#-- 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.
|
||||
#++
|
||||
|
||||
#-- encoding: UTF-8
|
||||
require File.join(File.dirname(__FILE__), 'test_helper')
|
||||
|
||||
class ControlTest < Test::Unit::TestCase
|
||||
context 'Within a skip_journal block,' do
|
||||
setup do
|
||||
@user = User.create(name: 'Steve Richert')
|
||||
@count = @user.journals.count
|
||||
end
|
||||
|
||||
context 'a model update' do
|
||||
setup do
|
||||
@user.skip_journal do
|
||||
@user.update_attribute(:last_name, 'Jobs')
|
||||
end
|
||||
end
|
||||
|
||||
should 'not create a journal' do
|
||||
assert_equal @count, @user.journals.count
|
||||
end
|
||||
end
|
||||
|
||||
context 'multiple model updates' do
|
||||
setup do
|
||||
@user.skip_journal do
|
||||
@user.update_attribute(:first_name, 'Stephen')
|
||||
@user.update_attribute(:last_name, 'Jobs')
|
||||
@user.update_attribute(:first_name, 'Steve')
|
||||
end
|
||||
end
|
||||
|
||||
should 'not create a journal' do
|
||||
assert_equal @count, @user.journals.count
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'Within a merge_journal block,' do
|
||||
setup do
|
||||
@user = User.create(name: 'Steve Richert')
|
||||
@count = @user.journals.count
|
||||
end
|
||||
|
||||
context 'a model update' do
|
||||
setup do
|
||||
@user.merge_journal do
|
||||
@user.update_attribute(:last_name, 'Jobs')
|
||||
end
|
||||
end
|
||||
|
||||
should 'create a journal' do
|
||||
assert_equal @count + 1, @user.journals.count
|
||||
end
|
||||
end
|
||||
|
||||
context 'multiple model updates' do
|
||||
setup do
|
||||
@user.merge_journal do
|
||||
@user.update_attribute(:first_name, 'Stephen')
|
||||
@user.update_attribute(:last_name, 'Jobs')
|
||||
@user.update_attribute(:first_name, 'Steve')
|
||||
end
|
||||
end
|
||||
|
||||
should 'create a journal' do
|
||||
assert_equal @count + 1, @user.journals.count
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'Within a append_journal block' do
|
||||
context '(when no journals exist),' do
|
||||
setup do
|
||||
@user = User.create(name: 'Steve Richert')
|
||||
@count = @user.journals.count
|
||||
end
|
||||
|
||||
context 'a model update' do
|
||||
setup do
|
||||
@user.append_journal do
|
||||
@user.update_attribute(:last_name, 'Jobs')
|
||||
end
|
||||
end
|
||||
|
||||
should 'create a journal' do
|
||||
assert_equal @count + 1, @user.journals.count
|
||||
end
|
||||
end
|
||||
|
||||
context 'multiple model updates' do
|
||||
setup do
|
||||
@user.append_journal do
|
||||
@user.update_attribute(:first_name, 'Stephen')
|
||||
@user.update_attribute(:last_name, 'Jobs')
|
||||
@user.update_attribute(:first_name, 'Steve')
|
||||
end
|
||||
end
|
||||
|
||||
should 'create a journal' do
|
||||
assert_equal @count + 1, @user.journals.count
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context '(when journals exist),' do
|
||||
setup do
|
||||
@user = User.create(name: 'Steve Richert')
|
||||
@user.update_attribute(:last_name, 'Jobs')
|
||||
@user.update_attribute(:last_name, 'Richert')
|
||||
@last_journal = @user.journals.last
|
||||
@count = @user.journals.count
|
||||
end
|
||||
|
||||
context 'a model update' do
|
||||
setup do
|
||||
@user.append_journal do
|
||||
@user.update_attribute(:last_name, 'Jobs')
|
||||
end
|
||||
end
|
||||
|
||||
should 'not create a journal' do
|
||||
assert_equal @count, @user.journals.count
|
||||
end
|
||||
|
||||
should 'update the last journal' do
|
||||
last_journal = @user.journals(true).last
|
||||
assert_equal @last_journal.id, last_journal.id
|
||||
assert_not_equal @last_journal.attributes, last_journal.attributes
|
||||
end
|
||||
end
|
||||
|
||||
context 'multiple model updates' do
|
||||
setup do
|
||||
@user.append_journal do
|
||||
@user.update_attribute(:first_name, 'Stephen')
|
||||
@user.update_attribute(:last_name, 'Jobs')
|
||||
@user.update_attribute(:first_name, 'Steve')
|
||||
end
|
||||
end
|
||||
|
||||
should 'not create a journal' do
|
||||
assert_equal @count, @user.journals.count
|
||||
end
|
||||
|
||||
should 'update the last journal' do
|
||||
last_journal = @user.journals(true).last
|
||||
assert_equal @last_journal.id, last_journal.id
|
||||
assert_not_equal @last_journal.attributes, last_journal.attributes
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,139 +0,0 @@
|
||||
#-- 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.
|
||||
#++
|
||||
|
||||
#-- encoding: UTF-8
|
||||
require File.join(File.dirname(__FILE__), 'test_helper')
|
||||
|
||||
class CreationTest < Test::Unit::TestCase
|
||||
context 'The number of journals' do
|
||||
setup do
|
||||
@name = 'Steve Richert'
|
||||
@user = User.create(name: @name)
|
||||
@count = @user.journals.count
|
||||
end
|
||||
|
||||
should 'initially equal zero' do
|
||||
assert_equal 0, @count
|
||||
end
|
||||
|
||||
should 'not increase when no changes are made in an update' do
|
||||
@user.update_attribute(:name, @name)
|
||||
assert_equal @count, @user.journals.count
|
||||
end
|
||||
|
||||
should 'not increase when no changes are made before a save' do
|
||||
@user.save
|
||||
assert_equal @count, @user.journals.count
|
||||
end
|
||||
|
||||
context 'after an update' do
|
||||
setup do
|
||||
@user.update_attribute(:last_name, 'Jobs')
|
||||
end
|
||||
|
||||
should 'increase by one' do
|
||||
assert_equal @count + 1, @user.journals.count
|
||||
end
|
||||
end
|
||||
|
||||
context 'after multiple updates' do
|
||||
setup do
|
||||
@user.update_attribute(:last_name, 'Jobs')
|
||||
@user.update_attribute(:last_name, 'Richert')
|
||||
end
|
||||
|
||||
should 'increase multiple times' do
|
||||
assert_operator @count + 1, :<, @user.journals.count
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "A created journal's changes" do
|
||||
setup do
|
||||
@user = User.create(name: 'Steve Richert')
|
||||
@user.update_attribute(:last_name, 'Jobs')
|
||||
end
|
||||
|
||||
should 'not contain Rails timestamps' do
|
||||
%w(created_at created_on updated_at updated_on).each do |timestamp|
|
||||
assert_does_not_contain @user.journals.last.details.keys, timestamp
|
||||
end
|
||||
end
|
||||
|
||||
context '(with :only options)' do
|
||||
setup do
|
||||
@only = %w(first_name)
|
||||
User.prepare_journaled_options(only: @only)
|
||||
@user.update_attribute(:name, 'Steven Tyler')
|
||||
end
|
||||
|
||||
should 'only contain the specified columns' do
|
||||
assert_equal @only, @user.journals.last.details.keys
|
||||
end
|
||||
|
||||
teardown do
|
||||
User.prepare_journaled_options(only: nil)
|
||||
end
|
||||
end
|
||||
|
||||
context '(with :except options)' do
|
||||
setup do
|
||||
@except = %w(first_name)
|
||||
User.prepare_journaled_options(except: @except)
|
||||
@user.update_attribute(:name, 'Steven Tyler')
|
||||
end
|
||||
|
||||
should 'not contain the specified columns' do
|
||||
@except.each do |column|
|
||||
assert_does_not_contain @user.journals.last.details.keys, column
|
||||
end
|
||||
end
|
||||
|
||||
teardown do
|
||||
User.prepare_journaled_options(except: nil)
|
||||
end
|
||||
end
|
||||
|
||||
context '(with both :only and :except options)' do
|
||||
setup do
|
||||
@only = %w(first_name)
|
||||
@except = @only
|
||||
User.prepare_journaled_options(only: @only, except: @except)
|
||||
@user.update_attribute(:name, 'Steven Tyler')
|
||||
end
|
||||
|
||||
should 'respect only the :only options' do
|
||||
assert_equal @only, @user.journals.last.details.keys
|
||||
end
|
||||
|
||||
teardown do
|
||||
User.prepare_journaled_options(only: nil, except: nil)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,81 +0,0 @@
|
||||
#-- 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.
|
||||
#++
|
||||
|
||||
#-- encoding: UTF-8
|
||||
require File.join(File.dirname(__FILE__), 'test_helper')
|
||||
|
||||
class OptionsTest < Test::Unit::TestCase
|
||||
context 'Configuration options' do
|
||||
setup do
|
||||
@options = { dependent: :destroy }
|
||||
@configuration = { class_name: 'MyCustomVersion' }
|
||||
|
||||
VestalVersions::Configuration.options.clear
|
||||
@configuration.each { |k, v| VestalVersions::Configuration.send("#{k}=", v) }
|
||||
|
||||
@prepared_options = User.prepare_journaled_options(@options.dup)
|
||||
end
|
||||
|
||||
should 'have symbolized keys' do
|
||||
assert User.vestal_journals_options.keys.all? { |k| k.is_a?(Symbol) }
|
||||
end
|
||||
|
||||
should 'combine class-level and global configuration options' do
|
||||
combined_keys = (@options.keys + @configuration.keys).map(&:to_sym).uniq
|
||||
combined_options = @configuration.symbolize_keys.merge(@options.symbolize_keys)
|
||||
assert_equal @prepared_options.slice(*combined_keys), combined_options
|
||||
end
|
||||
|
||||
teardown do
|
||||
VestalVersions::Configuration.options.clear
|
||||
User.prepare_journaled_options({})
|
||||
end
|
||||
end
|
||||
|
||||
context 'Given no options, configuration options' do
|
||||
setup do
|
||||
@prepared_options = User.prepare_journaled_options({})
|
||||
end
|
||||
|
||||
should 'default to "VestalVersions::Version" for :class_name' do
|
||||
assert_equal 'VestalVersions::Version', @prepared_options[:class_name]
|
||||
end
|
||||
|
||||
should 'default to :delete_all for :dependent' do
|
||||
assert_equal :delete_all, @prepared_options[:dependent]
|
||||
end
|
||||
|
||||
should 'force the :as option value to :journaled' do
|
||||
assert_equal :journaled, @prepared_options[:as]
|
||||
end
|
||||
|
||||
should 'default to [VestalVersions::Versions] for :extend' do
|
||||
assert_equal [VestalVersions::Versions], @prepared_options[:extend]
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,48 +0,0 @@
|
||||
#-- 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.
|
||||
#++
|
||||
|
||||
#-- encoding: UTF-8
|
||||
require File.join(File.dirname(__FILE__), 'test_helper')
|
||||
|
||||
class ReloadTest < Test::Unit::TestCase
|
||||
context 'Reloading a reverted model' do
|
||||
setup do
|
||||
@user = User.create(name: 'Steve Richert')
|
||||
first_version = @user.version
|
||||
@user.update_attribute(:last_name, 'Jobs')
|
||||
@last_version = @user.version
|
||||
@user.revert_to(first_version)
|
||||
end
|
||||
|
||||
should 'reset the journal number to the most recent journal' do
|
||||
assert_not_equal @last_journal, @user.journal
|
||||
@user.reload
|
||||
assert_equal @last_journal, @user.journal
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,142 +0,0 @@
|
||||
#-- 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.
|
||||
#++
|
||||
|
||||
#-- encoding: UTF-8
|
||||
require File.join(File.dirname(__FILE__), 'test_helper')
|
||||
|
||||
class ResetTest < Test::Unit::TestCase
|
||||
context 'Resetting a model' do
|
||||
setup do
|
||||
@original_dependent = User.reflect_on_association(:journals).options[:dependent]
|
||||
@user = User.new
|
||||
@journals = []
|
||||
@names = ['Steve Richert', 'Stephen Richert', 'Stephen Jobs', 'Steve Jobs']
|
||||
@names.each do |name|
|
||||
@user.update_attribute(:name, name)
|
||||
@journals << @user.journal
|
||||
end
|
||||
end
|
||||
|
||||
should "properly revert the model's attributes" do
|
||||
@journals.reverse.each_with_index do |journal, i|
|
||||
@user.reset_to!(journal)
|
||||
assert_equal @names.reverse[i], @user.name
|
||||
end
|
||||
end
|
||||
|
||||
should 'dissociate all journals after the target' do
|
||||
@journals.reverse_each do |journal|
|
||||
@user.reset_to!(journal)
|
||||
assert_equal 0, @user.journals(true).after(journal).count
|
||||
end
|
||||
end
|
||||
|
||||
context 'with the :dependent option as :delete_all' do
|
||||
setup do
|
||||
User.reflect_on_association(:journals).options[:dependent] = :delete_all
|
||||
end
|
||||
|
||||
should 'delete all journals after the target journal' do
|
||||
@journals.reverse_each do |journal|
|
||||
later_journals = @user.journals.after(journal)
|
||||
@user.reset_to!(journal)
|
||||
later_journals.each do |later_journal|
|
||||
assert_raise ActiveRecord::RecordNotFound do
|
||||
later_journal.reload
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
should 'not destroy all journals after the target journal' do
|
||||
VestalVersions::Version.any_instance.stub(:destroy).and_raise(RuntimeError)
|
||||
@journals.reverse_each do |journal|
|
||||
assert_nothing_raised do
|
||||
@user.reset_to!(journal)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'with the :dependent option as :destroy' do
|
||||
setup do
|
||||
User.reflect_on_association(:journals).options[:dependent] = :destroy
|
||||
end
|
||||
|
||||
should 'delete all journals after the target journal' do
|
||||
@journals.reverse_each do |journal|
|
||||
later_journals = @user.journals.after(journal)
|
||||
@user.reset_to!(journal)
|
||||
later_journals.each do |later_journal|
|
||||
assert_raise ActiveRecord::RecordNotFound do
|
||||
later_journal.reload
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
should 'destroy all journals after the target journal' do
|
||||
VestalVersions::Version.any_instance.stub(:destroy).and_raise(RuntimeError)
|
||||
@journals.reverse_each do |journal|
|
||||
later_journals = @user.journals.after(journal)
|
||||
if later_journals.empty?
|
||||
assert_nothing_raised do
|
||||
@user.reset_to!(journal)
|
||||
end
|
||||
else
|
||||
assert_raise RuntimeError do
|
||||
@user.reset_to!(journal)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'with the :dependent option as :nullify' do
|
||||
setup do
|
||||
User.reflect_on_association(:journals).options[:dependent] = :nullify
|
||||
end
|
||||
|
||||
should 'leave all journals after the target journal' do
|
||||
@journals.reverse_each do |journal|
|
||||
later_journals = @user.journals.after(journal)
|
||||
@user.reset_to!(journal)
|
||||
later_journals.each do |later_journal|
|
||||
assert_nothing_raised do
|
||||
later_journal.reload
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
teardown do
|
||||
User.reflect_on_association(:journals).options[:dependent] = @original_dependent
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,100 +0,0 @@
|
||||
#-- 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.
|
||||
#++
|
||||
|
||||
#-- encoding: UTF-8
|
||||
require File.join(File.dirname(__FILE__), 'test_helper')
|
||||
|
||||
class RejournalTest < Test::Unit::TestCase
|
||||
context 'A model rejournal' do
|
||||
setup do
|
||||
@user = User.new
|
||||
@attributes = {}
|
||||
@times = {}
|
||||
names = ['Steve Richert', 'Stephen Richert', 'Stephen Jobs', 'Steve Jobs']
|
||||
time = names.size.hours.ago
|
||||
names.each do |name|
|
||||
@user.update_attribute(:name, name)
|
||||
@attributes[@user.journal] = @user.attributes
|
||||
time += 1.hour
|
||||
if last_journal = @user.journals.last
|
||||
last_journal.update_attribute(:created_at, time)
|
||||
end
|
||||
@times[@user.journal] = time
|
||||
end
|
||||
@user.reload.journals.reload
|
||||
@first_journal = @attributes.keys.min
|
||||
@last_journal = @attributes.keys.max
|
||||
end
|
||||
|
||||
should 'return the new journal number' do
|
||||
new_journal = @user.revert_to(@first_journal)
|
||||
assert_equal @first_journal, new_journal
|
||||
end
|
||||
|
||||
should 'change the journal number when saved' do
|
||||
current_journal = @user.journal
|
||||
@user.revert_to!(@first_journal)
|
||||
assert_not_equal current_journal, @user.journal
|
||||
end
|
||||
|
||||
should 'do nothing for a invalid argument' do
|
||||
current_journal = @user.journal
|
||||
[nil, :bogus, 'bogus', (1..2)].each do |invalid|
|
||||
@user.revert_to(invalid)
|
||||
assert_equal current_journal, @user.journal
|
||||
end
|
||||
end
|
||||
|
||||
should 'be able to target a journal number' do
|
||||
@user.revert_to(1)
|
||||
assert 1, @user.journal
|
||||
end
|
||||
|
||||
should 'be able to target a date and time' do
|
||||
@times.each do |journal, time|
|
||||
@user.revert_to(time + 1.second)
|
||||
assert_equal journal, @user.journal
|
||||
end
|
||||
end
|
||||
|
||||
should 'be able to target a journal object' do
|
||||
@user.journals.each do |journal|
|
||||
@user.revert_to(journal)
|
||||
assert_equal journal.number, @user.journal
|
||||
end
|
||||
end
|
||||
|
||||
should "correctly roll back the model's attributes" do
|
||||
timestamps = %w(created_at created_on updated_at updated_on)
|
||||
@attributes.each do |journal, attributes|
|
||||
@user.revert_to!(journal)
|
||||
assert_equal attributes.except(*timestamps), @user.attributes.except(*timestamps)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,72 +0,0 @@
|
||||
#-- 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.
|
||||
#++
|
||||
|
||||
#-- encoding: UTF-8
|
||||
ActiveRecord::Base.establish_connection(
|
||||
adapter: defined?(RUBY_ENGINE) && RUBY_ENGINE == 'jruby' ? 'jdbcsqlite3' : 'sqlite3',
|
||||
database: File.join(File.dirname(__FILE__), 'test.db')
|
||||
)
|
||||
|
||||
class CreateSchema < ActiveRecord::Migration
|
||||
def self.up
|
||||
create_table :users, force: true do |t|
|
||||
t.string :first_name
|
||||
t.string :last_name
|
||||
t.timestamps
|
||||
end
|
||||
|
||||
create_table :journals, force: true do |t|
|
||||
t.belongs_to :journaled, polymorphic: true
|
||||
t.belongs_to :user, polymorphic: true
|
||||
t.string :user_name
|
||||
t.text :changed_data
|
||||
t.integer :number
|
||||
t.string :tag
|
||||
t.timestamps
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
CreateSchema.suppress_messages do
|
||||
CreateSchema.migrate(:up)
|
||||
end
|
||||
|
||||
class User < ActiveRecord::Base
|
||||
journaled
|
||||
|
||||
def name
|
||||
[first_name, last_name].compact.join(' ')
|
||||
end
|
||||
|
||||
def name=(names)
|
||||
self[:first_name], self[:last_name] = names.split(' ', 2)
|
||||
end
|
||||
end
|
||||
|
||||
class MyCustomVersion < VestalVersions::Version
|
||||
end
|
||||
@@ -1,68 +0,0 @@
|
||||
#-- 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.
|
||||
#++
|
||||
|
||||
#-- encoding: UTF-8
|
||||
require File.join(File.dirname(__FILE__), 'test_helper')
|
||||
|
||||
class TaggingTest < Test::Unit::TestCase
|
||||
context 'Tagging a journal' do
|
||||
setup do
|
||||
@user = User.create(name: 'Steve Richert')
|
||||
@user.update_attribute(:last_name, 'Jobs')
|
||||
end
|
||||
|
||||
should "update the journal record's tag column" do
|
||||
tag_name = 'TAG'
|
||||
last_journal = @user.journals.last
|
||||
assert_not_equal tag_name, last_journal.tag
|
||||
@user.tag_journal(tag_name)
|
||||
assert_equal tag_name, last_journal.reload.tag
|
||||
end
|
||||
|
||||
should 'create a journal record for an initial journal' do
|
||||
@user.revert_to(1)
|
||||
assert_nil @user.journals.at(1)
|
||||
@user.tag_journal('TAG')
|
||||
assert_not_nil @user.journals.at(1)
|
||||
end
|
||||
end
|
||||
|
||||
context 'A tagged journal' do
|
||||
setup do
|
||||
user = User.create(name: 'Steve Richert')
|
||||
user.update_attribute(:last_name, 'Jobs')
|
||||
user.tag_journal('TAG')
|
||||
@journal = user.journals.last
|
||||
end
|
||||
|
||||
should 'return true for the "tagged?" method' do
|
||||
assert @journal.respond_to?(:tagged?)
|
||||
assert_equal true, @journal.tagged?
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,39 +0,0 @@
|
||||
#-- 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.
|
||||
#++
|
||||
|
||||
#-- encoding: UTF-8
|
||||
$: << File.join(File.dirname(__FILE__), '..', 'lib')
|
||||
$: << File.dirname(__FILE__)
|
||||
|
||||
require 'rubygems'
|
||||
require 'test/unit'
|
||||
require 'active_record'
|
||||
require 'shoulda'
|
||||
require 'vestal_versions'
|
||||
require 'schema'
|
||||
begin; require 'redgreen'; rescue LoadError; end
|
||||
@@ -1,54 +0,0 @@
|
||||
#-- 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.
|
||||
#++
|
||||
|
||||
#-- encoding: UTF-8
|
||||
require 'test_helper'
|
||||
|
||||
class UsersTest < Test::Unit::TestCase
|
||||
context 'The user responsible for an update' do
|
||||
setup do
|
||||
@updated_by = User.create(name: 'Steve Jobs')
|
||||
@user = User.create(name: 'Steve Richert')
|
||||
end
|
||||
|
||||
should 'default to nil' do
|
||||
@user.update_attributes(first_name: 'Stephen')
|
||||
assert_nil @user.journals.last.user
|
||||
end
|
||||
|
||||
should 'accept and return an ActiveRecord user' do
|
||||
@user.update_attributes(first_name: 'Stephen', updated_by: @updated_by)
|
||||
assert_equal @updated_by, @user.journals.last.user
|
||||
end
|
||||
|
||||
should 'accept and return a string user name' do
|
||||
@user.update_attributes(first_name: 'Stephen', updated_by: @updated_by.name)
|
||||
assert_equal @updated_by.name, @user.journals.last.user
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,74 +0,0 @@
|
||||
#-- 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.
|
||||
#++
|
||||
|
||||
#-- encoding: UTF-8
|
||||
require File.join(File.dirname(__FILE__), 'test_helper')
|
||||
|
||||
class VersionTest < Test::Unit::TestCase
|
||||
context 'Versions' do
|
||||
setup do
|
||||
@user = User.create(name: 'Stephen Richert')
|
||||
@user.update_attribute(:name, 'Steve Jobs')
|
||||
@user.update_attribute(:last_name, 'Richert')
|
||||
@first_journal = @user.journals.first
|
||||
@last_journal = @user.journals.last
|
||||
end
|
||||
|
||||
should 'be comparable to another journal based on journal number' do
|
||||
assert @first_journal == @first_journal
|
||||
assert @last_journal == @last_journal
|
||||
assert @first_journal != @last_journal
|
||||
assert @last_journal != @first_journal
|
||||
assert @first_journal < @last_journal
|
||||
assert @last_journal > @first_journal
|
||||
assert @first_journal <= @last_journal
|
||||
assert @last_journal >= @first_journal
|
||||
end
|
||||
|
||||
should "not equal a separate model's journal with the same number" do
|
||||
user = User.create(name: 'Stephen Richert')
|
||||
user.update_attribute(:name, 'Steve Jobs')
|
||||
user.update_attribute(:last_name, 'Richert')
|
||||
first_journal = user.journals.first
|
||||
last_journal = user.journals.last
|
||||
assert_not_equal @first_journal, first_journal
|
||||
assert_not_equal @last_journal, last_journal
|
||||
end
|
||||
|
||||
should 'default to ordering by number when finding through association' do
|
||||
order = @user.journals.send(:scope, :find)[:order]
|
||||
assert_equal 'journals.number ASC', order
|
||||
end
|
||||
|
||||
should 'return true for the "initial?" method when the journal number is 1' do
|
||||
journal = @user.journals.build(number: 1)
|
||||
assert_equal 1, journal.number
|
||||
assert_equal true, journal.initial?
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,47 +0,0 @@
|
||||
#-- 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.
|
||||
#++
|
||||
|
||||
#-- encoding: UTF-8
|
||||
require File.join(File.dirname(__FILE__), 'test_helper')
|
||||
|
||||
class VersionedTest < Test::Unit::TestCase
|
||||
context 'ActiveRecord models' do
|
||||
should 'respond to the "journaled?" method' do
|
||||
assert ActiveRecord::Base.respond_to?(:journaled?)
|
||||
assert User.respond_to?(:journaled?)
|
||||
end
|
||||
|
||||
should 'return true for the "journaled?" method if the model is journaled' do
|
||||
assert_equal true, User.journaled?
|
||||
end
|
||||
|
||||
should 'return false for the "journaled?" method if the model is not journaled' do
|
||||
assert_equal false, ActiveRecord::Base.journaled?
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,202 +0,0 @@
|
||||
#-- 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.
|
||||
#++
|
||||
|
||||
#-- encoding: UTF-8
|
||||
require File.join(File.dirname(__FILE__), 'test_helper')
|
||||
|
||||
class VersionsTest < Test::Unit::TestCase
|
||||
context 'A collection of associated journals' do
|
||||
setup do
|
||||
@user = User.new
|
||||
@times = {}
|
||||
names = ['Steve Richert', 'Stephen Richert', 'Stephen Jobs', 'Steve Jobs']
|
||||
time = names.size.hours.ago
|
||||
names.each do |name|
|
||||
@user.update_attribute(:name, name)
|
||||
@user.tag_journal(@user.journal.to_s)
|
||||
time += 1.hour
|
||||
@user.journals.last.update_attribute(:created_at, time)
|
||||
@times[@user.journal] = time
|
||||
end
|
||||
end
|
||||
|
||||
should 'be searchable between two valid journal values' do
|
||||
@times.keys.each do |number|
|
||||
@times.values.each do |time|
|
||||
assert_kind_of Array, @user.journals.between(number, number)
|
||||
assert_kind_of Array, @user.journals.between(number, time)
|
||||
assert_kind_of Array, @user.journals.between(time, number)
|
||||
assert_kind_of Array, @user.journals.between(time, time)
|
||||
assert !@user.journals.between(number, number).empty?
|
||||
assert !@user.journals.between(number, time).empty?
|
||||
assert !@user.journals.between(time, number).empty?
|
||||
assert !@user.journals.between(time, time).empty?
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
should 'return an empty array when searching between a valid and an invalid journal value' do
|
||||
@times.each do |number, time|
|
||||
assert_equal [], @user.journals.between(number, nil)
|
||||
assert_equal [], @user.journals.between(time, nil)
|
||||
assert_equal [], @user.journals.between(nil, number)
|
||||
assert_equal [], @user.journals.between(nil, time)
|
||||
end
|
||||
end
|
||||
|
||||
should 'return an empty array when searching between two invalid journal values' do
|
||||
assert_equal [], @user.journals.between(nil, nil)
|
||||
end
|
||||
|
||||
should 'be searchable before a valid journal value' do
|
||||
@times.sort.each_with_index do |(number, time), i|
|
||||
assert_equal i, @user.journals.before(number).size
|
||||
assert_equal i, @user.journals.before(time).size
|
||||
end
|
||||
end
|
||||
|
||||
should 'return an empty array when searching before an invalid journal value' do
|
||||
assert_equal [], @user.journals.before(nil)
|
||||
end
|
||||
|
||||
should 'be searchable after a valid journal value' do
|
||||
@times.sort.reverse.each_with_index do |(number, time), i|
|
||||
assert_equal i, @user.journals.after(number).size
|
||||
assert_equal i, @user.journals.after(time).size
|
||||
end
|
||||
end
|
||||
|
||||
should 'return an empty array when searching after an invalid journal value' do
|
||||
assert_equal [], @user.journals.after(nil)
|
||||
end
|
||||
|
||||
should 'be fetchable by journal number' do
|
||||
@times.keys.each do |number|
|
||||
assert_kind_of VestalVersions::Version, @user.journals.at(number)
|
||||
assert_equal number, @user.journals.at(number).number
|
||||
end
|
||||
end
|
||||
|
||||
should 'be fetchable by tag' do
|
||||
@times.keys.map { |n| [n, n.to_s] }.each do |number, tag|
|
||||
assert_kind_of VestalVersions::Version, @user.journals.at(tag)
|
||||
assert_equal number, @user.journals.at(tag).number
|
||||
end
|
||||
end
|
||||
|
||||
should "be fetchable by the exact time of a journal's creation" do
|
||||
@times.each do |number, time|
|
||||
assert_kind_of VestalVersions::Version, @user.journals.at(time)
|
||||
assert_equal number, @user.journals.at(time).number
|
||||
end
|
||||
end
|
||||
|
||||
should "be fetchable by any time after the model's creation" do
|
||||
@times.each do |number, time|
|
||||
assert_kind_of VestalVersions::Version, @user.journals.at(time + 30.minutes)
|
||||
assert_equal number, @user.journals.at(time + 30.minutes).number
|
||||
end
|
||||
end
|
||||
|
||||
should "return nil when fetching a time before the model's creation" do
|
||||
creation = @times.values.min
|
||||
assert_nil @user.journals.at(creation - 1.second)
|
||||
end
|
||||
|
||||
should 'be fetchable by an association extension method' do
|
||||
assert_kind_of VestalVersions::Version, @user.journals.at(:first)
|
||||
assert_kind_of VestalVersions::Version, @user.journals.at(:last)
|
||||
assert_equal @times.keys.min, @user.journals.at(:first).number
|
||||
assert_equal @times.keys.max, @user.journals.at(:last).number
|
||||
end
|
||||
|
||||
should 'be fetchable by a journal object' do
|
||||
@times.keys.each do |number|
|
||||
journal = @user.journals.at(number)
|
||||
assert_kind_of VestalVersions::Version, journal
|
||||
assert_kind_of VestalVersions::Version, @user.journals.at(journal)
|
||||
assert_equal number, @user.journals.at(journal).number
|
||||
end
|
||||
end
|
||||
|
||||
should 'return nil when fetching an invalid journal value' do
|
||||
assert_nil @user.journals.at(nil)
|
||||
end
|
||||
|
||||
should 'provide a journal number for any given numeric journal value' do
|
||||
@times.keys.each do |number|
|
||||
assert_kind_of Fixnum, @user.journals.number_at(number)
|
||||
assert_kind_of Fixnum, @user.journals.number_at(number + 0.5)
|
||||
assert_equal @user.journals.number_at(number), @user.journals.number_at(number + 0.5)
|
||||
end
|
||||
end
|
||||
|
||||
should 'provide a journal number for a valid tag' do
|
||||
@times.keys.map { |n| [n, n.to_s] }.each do |number, tag|
|
||||
assert_kind_of Fixnum, @user.journals.number_at(tag)
|
||||
assert_equal number, @user.journals.number_at(tag)
|
||||
end
|
||||
end
|
||||
|
||||
should 'return nil when providing a journal number for an invalid tag' do
|
||||
assert_nil @user.journals.number_at('INVALID')
|
||||
end
|
||||
|
||||
should 'provide a journal number of a journal corresponding to an association extension method' do
|
||||
assert_kind_of VestalVersions::Version, @user.journals.at(:first)
|
||||
assert_kind_of VestalVersions::Version, @user.journals.at(:last)
|
||||
assert_equal @times.keys.min, @user.journals.number_at(:first)
|
||||
assert_equal @times.keys.max, @user.journals.number_at(:last)
|
||||
end
|
||||
|
||||
should 'return nil when providing a journal number for an invalid association extension method' do
|
||||
assert_nil @user.journals.number_at(:INVALID)
|
||||
end
|
||||
|
||||
should "provide a journal number for any time after the model's creation" do
|
||||
@times.each do |number, time|
|
||||
assert_kind_of Fixnum, @user.journals.number_at(time + 30.minutes)
|
||||
assert_equal number, @user.journals.number_at(time + 30.minutes)
|
||||
end
|
||||
end
|
||||
|
||||
should "provide a journal number of 1 for a time before the model's creation" do
|
||||
creation = @times.values.min
|
||||
assert_equal 1, @user.journals.number_at(creation - 1.second)
|
||||
end
|
||||
|
||||
should 'provide a journal number for a given journal object' do
|
||||
@times.keys.each do |number|
|
||||
journal = @user.journals.at(number)
|
||||
assert_kind_of VestalVersions::Version, journal
|
||||
assert_kind_of Fixnum, @user.journals.number_at(journal)
|
||||
assert_equal number, @user.journals.number_at(journal)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,19 +0,0 @@
|
||||
require 'rubygems'
|
||||
require 'test/unit'
|
||||
require 'active_support'
|
||||
require 'action_controller'
|
||||
|
||||
require File.dirname(__FILE__) + '/../lib/action_controller/verification'
|
||||
|
||||
SharedTestRoutes = ActionDispatch::Routing::RouteSet.new
|
||||
SharedTestRoutes.draw do
|
||||
match ':controller(/:action(/:id))'
|
||||
end
|
||||
|
||||
ActionController::Base.send :include, SharedTestRoutes.url_helpers
|
||||
|
||||
module ActionController
|
||||
class TestCase
|
||||
setup { @routes = SharedTestRoutes }
|
||||
end
|
||||
end
|
||||
@@ -121,13 +121,7 @@ module Redmine #:nodoc:
|
||||
rescue PluginNotFound => e
|
||||
# find circular dependencies
|
||||
raise PluginCircularDependency.new(id) if dependencies_for(e.plugin_id).include?(id)
|
||||
if RedminePluginLocator.instance.has_plugin? e.plugin_id
|
||||
# The required plugin is going to be loaded later, defer loading this plugin
|
||||
(deferred_plugins[e.plugin_id] ||= []) << [id, block]
|
||||
return p
|
||||
else
|
||||
raise
|
||||
end
|
||||
raise e
|
||||
end
|
||||
|
||||
# returns an array of all dependencies we know of for plugin id
|
||||
|
||||
@@ -1,51 +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.
|
||||
#++
|
||||
|
||||
class RedminePluginLocator < Rails::Plugin::FileSystemLocator
|
||||
def initialize(initializer)
|
||||
super
|
||||
@@instance = self
|
||||
end
|
||||
|
||||
def self.instance
|
||||
@@instance
|
||||
end
|
||||
|
||||
# This locator is not meant for loading plugins
|
||||
# The plugin loading is done by the default rails locator, this one is
|
||||
# only for querying available plugins easily
|
||||
def plugins(for_loading = true)
|
||||
return [] if for_loading
|
||||
super()
|
||||
end
|
||||
|
||||
def has_plugin?(name)
|
||||
plugins(false).map(&:name).include? name.to_s
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user