From 459889827df83cbbbf5acf161aa37f460972042c Mon Sep 17 00:00:00 2001 From: Justin Balthrop Date: Tue, 13 Aug 2013 17:46:14 -0700 Subject: [PATCH 01/22] add gemspec --- Gemfile | 3 +++ registry.gemspec | 24 ++++++++++++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 Gemfile create mode 100644 registry.gemspec diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..e8e3471 --- /dev/null +++ b/Gemfile @@ -0,0 +1,3 @@ +source "http://www.rubygems.org" + +gemspec diff --git a/registry.gemspec b/registry.gemspec new file mode 100644 index 0000000..133b469 --- /dev/null +++ b/registry.gemspec @@ -0,0 +1,24 @@ +lib = File.expand_path('../lib', __FILE__) +$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) + +Gem::Specification.new do |gem| + gem.name = "registry" + gem.version = IO.read('VERSION') + gem.authors = ["Michael Berkovich", "Scott Steadman"] + gem.email = ["michael@geni.com"] + gem.description = %q{Framework for controlling application behavior through configurable properties} + gem.summary = gem.description + gem.homepage = "https://github.com/berk/registry" + gem.license = 'MIT' + + gem.add_development_dependency 'shoulda', '3.0.1' + gem.add_development_dependency 'mocha' + gem.add_development_dependency 'rake' + + gem.add_dependency 'rails', '~> 2.3.0' + + gem.files = `git ls-files`.split($/) + gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) } + gem.test_files = gem.files.grep(%r{^(test|spec|features)/}) + gem.require_paths = ["lib"] +end From 3c716b3c19a4d65dc4e0ab7210e0cb58cd6ef2d8 Mon Sep 17 00:00:00 2001 From: Justin Balthrop Date: Tue, 13 Aug 2013 17:54:33 -0700 Subject: [PATCH 02/22] version 2.3.0 --- VERSION | 1 + 1 file changed, 1 insertion(+) create mode 100644 VERSION diff --git a/VERSION b/VERSION new file mode 100644 index 0000000..cc6612c --- /dev/null +++ b/VERSION @@ -0,0 +1 @@ +2.3.0 \ No newline at end of file From c0ebf72c49fa05880fd0728271ad3a589290bbfd Mon Sep 17 00:00:00 2001 From: Scott Steadman Date: Tue, 12 Nov 2013 11:17:01 -0800 Subject: [PATCH 03/22] Tests work again. --- .gitignore | 2 ++ Rakefile | 1 - config/environment.rb | 2 +- config/environments/test.rb | 2 ++ registry.gemspec | 1 + .../registry/registry_controller_test.rb | 22 +++++++++---------- 6 files changed, 17 insertions(+), 13 deletions(-) diff --git a/.gitignore b/.gitignore index 3dd573d..7ea6b03 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,5 @@ db/schema.rb* *.log *.sqlite3 *.swp +Gemfile.lock +.bundle diff --git a/Rakefile b/Rakefile index fbebfca..d531538 100644 --- a/Rakefile +++ b/Rakefile @@ -2,6 +2,5 @@ require(File.join(File.dirname(__FILE__), 'config', 'boot')) require 'rake' require 'rake/testtask' -require 'rake/rdoctask' require 'tasks/rails' diff --git a/config/environment.rb b/config/environment.rb index 46fc971..9c0c715 100644 --- a/config/environment.rb +++ b/config/environment.rb @@ -1,7 +1,7 @@ # Bootstrap the Rails environment, frameworks, and default configuration require File.join(File.dirname(__FILE__), 'boot') -RAILS_GEM_VERSION = '2.3.10' unless defined? RAILS_GEM_VERSION +RAILS_GEM_VERSION = '2.3.18' unless defined? RAILS_GEM_VERSION Rails::Initializer.run do |config| # Settings in config/environments/* take precedence over those specified here. diff --git a/config/environments/test.rb b/config/environments/test.rb index 06996bf..fe64305 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -2,6 +2,8 @@ require 'pp' +require 'mocha/setup' + # The test environment is used exclusively to run your application's # test suite. You never need to work with it otherwise. Remember that # your test database is "scratch space" for the test suite and is wiped diff --git a/registry.gemspec b/registry.gemspec index 133b469..5457783 100644 --- a/registry.gemspec +++ b/registry.gemspec @@ -14,6 +14,7 @@ Gem::Specification.new do |gem| gem.add_development_dependency 'shoulda', '3.0.1' gem.add_development_dependency 'mocha' gem.add_development_dependency 'rake' + gem.add_development_dependency 'sqlite3' gem.add_dependency 'rails', '~> 2.3.0' diff --git a/test/functional/registry/registry_controller_test.rb b/test/functional/registry/registry_controller_test.rb index d1df6eb..34e88d7 100644 --- a/test/functional/registry/registry_controller_test.rb +++ b/test/functional/registry/registry_controller_test.rb @@ -41,7 +41,7 @@ def setup get :folders, :node => folder.parent.id assert_response :success expected = [{'id' => folder.id.to_s, 'key' => 'folder', 'label' => 'Label', 'text' => 'Label', 'cls' => 'folder'}] - assert_equal expected, JSON.parse(@response.body) + assert_equal expected, ActiveSupport::JSON.decode(@response.body) end test 'folder' do @@ -52,7 +52,7 @@ def setup 'success' => true, 'folders' => [{'id' => @root.id.to_s, 'key' => @root.key, 'label' => @root.label, 'text' => @root.label, 'cls' => 'folder'}] } - assert_equal expected, JSON.parse(@response.body) + assert_equal expected, ActiveSupport::JSON.decode(@response.body) end test 'folder creation' do @@ -66,7 +66,7 @@ def setup 'success' => true, 'folders' => [{'id' => @root.folders.first.id.to_s, 'key' => 'key', 'label' => 'Label', 'text' => 'Label', 'cls' => 'folder'}] } - assert_equal expected, JSON.parse(@response.body) + assert_equal expected, ActiveSupport::JSON.decode(@response.body) assert_equal id, Registry::Folder.last.user_id end end @@ -86,7 +86,7 @@ def setup 'success' => true, 'folders' => [{'id' => child.id.to_s, 'key' => 'Key', 'label' => 'Label', 'text' => 'Label', 'cls' => 'folder'}] } - assert_equal expected, JSON.parse(@response.body) + assert_equal expected, ActiveSupport::JSON.decode(@response.body) assert_equal id, child.user_id end end @@ -101,7 +101,7 @@ def setup 'success' => true, 'properties' => [{'label' => '', 'value' => '', 'description' => '', 'key' => ''}] } - assert_equal expected, JSON.parse(@response.body) + assert_equal expected, ActiveSupport::JSON.decode(@response.body) end test 'property creation' do @@ -115,7 +115,7 @@ def setup 'success' => true, 'properties' => [{'label' => 'Label', 'value' => 'value', 'description' => 'Description', 'key' => 'key'}] } - assert_equal expected, JSON.parse(@response.body) + assert_equal expected, ActiveSupport::JSON.decode(@response.body) assert_equal id, Registry::Entry.last.user_id end end @@ -135,7 +135,7 @@ def setup 'success' => true, 'properties' => [{'key' => 'Key', 'value' => 'Value', 'label' => 'Label', 'description' => 'Description'}] } - assert_equal expected, JSON.parse(@response.body) + assert_equal expected, ActiveSupport::JSON.decode(@response.body) assert_equal id, Registry::Entry.last.user_id end end @@ -153,7 +153,7 @@ def setup {'id' => two.id.to_s, 'key' => 'two', 'value' => '2', 'label' => 'two', 'description' => '', 'access_code' => 'Registry.two', 'notes' => ''}, ] } - assert_equal expected, JSON.parse(@response.body) + assert_equal expected, ActiveSupport::JSON.decode(@response.body) end test 'properties put' do @@ -168,7 +168,7 @@ def setup {'id' => one.id.to_s, 'key' => 'one', 'value' => '2', 'label' => 'one', 'description' => '', 'access_code' => 'Registry.one', 'notes' => ''}, ] } - assert_equal expected, JSON.parse(@response.body) + assert_equal expected, ActiveSupport::JSON.decode(@response.body) assert_equal id, Registry::Entry.last.user_id end end @@ -185,7 +185,7 @@ def setup 'success' => true, 'properties' => [] } - assert_equal expected, JSON.parse(@response.body) + assert_equal expected, ActiveSupport::JSON.decode(@response.body) assert_equal id, Registry::Entry::Version.last.user_id end end @@ -207,7 +207,7 @@ def setup {'id' => first.id.to_s, 'value' => '1', 'label' => 'one', 'updated' => first.updated_at.to_s, 'notes' => '', 'user' => ''}, ] } - assert_equal expected, JSON.parse(@response.body) + assert_equal expected, ActiveSupport::JSON.decode(@response.body) end From 5a9dfc6489b1ae4c259296aba5e52126b58b77fa Mon Sep 17 00:00:00 2001 From: Scott Steadman Date: Tue, 12 Nov 2013 12:01:24 -0800 Subject: [PATCH 04/22] Added Registry._last_updated_at This will indicate what time the registry was last updated. --- app/models/registry/entry.rb | 8 ++++++-- config/preinitializer.rb | 20 ++++++++++++++++++++ test/unit/registry/entry_test.rb | 19 +++++++++++-------- test/unit/registry_test.rb | 18 +++++++++++++++++- 4 files changed, 54 insertions(+), 11 deletions(-) create mode 100644 config/preinitializer.rb diff --git a/app/models/registry/entry.rb b/app/models/registry/entry.rb index 06fae46..bff5da3 100644 --- a/app/models/registry/entry.rb +++ b/app/models/registry/entry.rb @@ -236,9 +236,13 @@ def to_form_property_hash # * +hash+ - Optional, hash to update. # # call-seq: - # Registry::Entry.root.export #=> {'api' => {'enabled' => true}} + # Registry::Entry.root.export #=> {'api' => {'enabled' => true}, '_last_updated_at' => ...} def export(hash={}, entries=nil) - entries ||= Entry.all(:conditions => ['env = ? and id != ?', env, id]) + + if entries.nil? + entries = Entry.all(:conditions => ['env = ? and id != ?', env, id]) + hash['_last_updated_at'] = entries.inject(Time.at(0)) {|old_max, entry| [old_max, entry.updated_at].max} + end properties, entries = entries.partition {|entry| entry.parent_id == id && !entry.folder?} properties.each do |p| diff --git a/config/preinitializer.rb b/config/preinitializer.rb new file mode 100644 index 0000000..5d27894 --- /dev/null +++ b/config/preinitializer.rb @@ -0,0 +1,20 @@ +begin + require 'rubygems' + require 'bundler' +rescue LoadError + raise "Could not load the bundler gem. Install it with `gem install bundler`." +end + +if Gem::Version.new(Bundler::VERSION) <= Gem::Version.new("0.9.24") + raise RuntimeError, "Your bundler version is too old for Rails 2.3.\n" + + "Run `gem install bundler` to upgrade." +end + +begin + # Set up load paths for all bundled gems + ENV["BUNDLE_GEMFILE"] = File.expand_path("../../Gemfile", __FILE__) + Bundler.setup +rescue Bundler::GemNotFound + raise RuntimeError, "Bundler couldn't find some gems.\n" + + "Did you run `bundle install`?" +end diff --git a/test/unit/registry/entry_test.rb b/test/unit/registry/entry_test.rb index 41190b3..37a6004 100644 --- a/test/unit/registry/entry_test.rb +++ b/test/unit/registry/entry_test.rb @@ -17,14 +17,14 @@ def setup test 'export!' do expected = create_entries - assert_equal expected, Entry.export!(CONFIG) + assert_hash expected, Entry.export!(CONFIG) assert_equal true, File.exists?(CONFIG), 'Export file should be created' end test 'export! no file' do File.delete(Entry::DEFAULT_YML_LOCATION) rescue nil expected = create_entries - assert_equal expected, Entry.export!(nil) + assert_hash expected, Entry.export!(nil) assert_equal false, File.exists?(Entry::DEFAULT_YML_LOCATION), 'Export file should NOT be created' end @@ -54,12 +54,13 @@ def setup expected = { 'dev' => { - 'one' => 'preserve', - 'two' => {'one' => 'preserve', 'two' => 'new'}, - 'tre' => 'new', + '_last_updated_at' => '__any__', + 'one' => 'preserve', + 'two' => {'one' => 'preserve', 'two' => 'new'}, + 'tre' => 'new', } } - assert_equal expected, Entry.export!(nil) + assert_hash expected, Entry.export!(nil) end test 'versioning' do @@ -124,8 +125,8 @@ def setup Entry.root.merge({'keep' => {:keep => 'ignored'}, :keep => 'ignored'}, :delete => true) - expected = {'keep' => {:keep => true}, :keep => 'keep'} - assert_equal expected, Entry.root.export + expected = {'keep' => {:keep => true}, :keep => 'keep', '_last_updated_at' => '__any__'} + assert_hash expected, Entry.root.export end test 'child' do @@ -169,6 +170,8 @@ def create_entries(envs=nil, folders=nil, values=nil) entries[env][folder.key].store(key, value) end end + + entries[env]['_last_updated_at'] = '__any__' end entries diff --git a/test/unit/registry_test.rb b/test/unit/registry_test.rb index 6583a7b..7118e41 100755 --- a/test/unit/registry_test.rb +++ b/test/unit/registry_test.rb @@ -85,6 +85,7 @@ def setup end expected = { + '_last_updated_at' => '__any__', 'unchanged' => { 'string' => 'default', }, @@ -96,7 +97,7 @@ def setup 'string' => 'new', }, } - assert_equal expected, Registry.to_hash + assert_hash expected, Registry.to_hash end test 'import with purge' do @@ -221,6 +222,21 @@ def setup assert_equal 1, wrapper.one end + test '_last_updated_at' do + assert_equal Time.at(0), Registry._last_updated_at + + reg = { + 'api' => { + :enabled => true, + 'limit' => 1, + }, + } + Registry::Entry.root.merge(reg) + Registry.reset + + assert_not_equal Time.at(0), Registry._last_updated_at + end + private def registry_hash_with_defaults From 2ae1eea49f9b693abf7a2929b1a562d95a28b137 Mon Sep 17 00:00:00 2001 From: Scott Steadman Date: Mon, 3 Feb 2020 09:59:31 -0800 Subject: [PATCH 05/22] update README The README had references to plugin installation from berk's repository. --- README | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/README b/README index 0ff69fe..9efbcc0 100644 --- a/README +++ b/README @@ -6,8 +6,8 @@ === Installation - script/plugin install git://github.com/berk/registry.git - + # Gemfile + gem 'registry', :git => 'https://github.com/ss/registry.git' === Test @@ -37,7 +37,7 @@ === Example usage in app/controllers/api_controller.rb - + class ApiController < ActionController::Base before_filter :ensure_api_enabled, :check_rate_limit @@ -80,15 +80,15 @@ development: api_request_window: 100 - + test: api_request_window: 100 - + production: api_enabled: false api_request_limit: 10 api_request_window: 10000 - + in lib/tasks/my_tasks.rake From 5b310eb532dec68d715c98cb6b5bfce52c8f198c Mon Sep 17 00:00:00 2001 From: Scott Steadman Date: Mon, 3 Feb 2020 10:17:06 -0800 Subject: [PATCH 06/22] fix rake db:migrate rake db:migrate wasn't working --- README | 7 ++++++- registry.gemspec | 3 ++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/README b/README index 9efbcc0..57d0ff9 100644 --- a/README +++ b/README @@ -9,7 +9,12 @@ # Gemfile gem 'registry', :git => 'https://github.com/ss/registry.git' -=== Test +== Testing/Coverage + + bundle install --clean --path=vendor/bundle + bundle exec rake db:create db:migrate + +=== UI Access script/server point your browser at http://localhost:3000/registry diff --git a/registry.gemspec b/registry.gemspec index 5457783..932ab72 100644 --- a/registry.gemspec +++ b/registry.gemspec @@ -11,9 +11,10 @@ Gem::Specification.new do |gem| gem.homepage = "https://github.com/berk/registry" gem.license = 'MIT' - gem.add_development_dependency 'shoulda', '3.0.1' + gem.add_development_dependency 'iconv' gem.add_development_dependency 'mocha' gem.add_development_dependency 'rake' + gem.add_development_dependency 'shoulda', '3.0.1' gem.add_development_dependency 'sqlite3' gem.add_dependency 'rails', '~> 2.3.0' From 403ede626d25ced50fca8f42d3bb24224e3fa678 Mon Sep 17 00:00:00 2001 From: Scott Steadman Date: Mon, 3 Feb 2020 10:17:31 -0800 Subject: [PATCH 07/22] update registry.gemspec I changed the references to me since Berk is, probably, no longer maintaining this gem. --- registry.gemspec | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/registry.gemspec b/registry.gemspec index 932ab72..a190ce6 100644 --- a/registry.gemspec +++ b/registry.gemspec @@ -5,10 +5,10 @@ Gem::Specification.new do |gem| gem.name = "registry" gem.version = IO.read('VERSION') gem.authors = ["Michael Berkovich", "Scott Steadman"] - gem.email = ["michael@geni.com"] + gem.email = ["registry-gem@stdmn.com"] gem.description = %q{Framework for controlling application behavior through configurable properties} gem.summary = gem.description - gem.homepage = "https://github.com/berk/registry" + gem.homepage = "https://github.com/ss/registry" gem.license = 'MIT' gem.add_development_dependency 'iconv' From 2d43c000e36bdddfe6c60683921f5552a0d30365 Mon Sep 17 00:00:00 2001 From: Scott Steadman Date: Mon, 3 Feb 2020 10:18:24 -0800 Subject: [PATCH 08/22] update .gitignore Add vendor/bundle to .gitignore so we don't see it when we run git status. --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 7ea6b03..51c8657 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ db/schema.rb* *.swp Gemfile.lock .bundle +vendor/bundle From 600803c8db5e104ce6d9bb243c2872a9df697432 Mon Sep 17 00:00:00 2001 From: Scott Steadman Date: Mon, 3 Feb 2020 10:32:00 -0800 Subject: [PATCH 09/22] remove vendor/gems I want to load acts_as_versioned as a gem. since that will externalize the dependency somewhat. --- app/models/registry/entry.rb | 2 +- registry.gemspec | 1 + .../CHANGELOG | 115 ----- .../MIT-LICENSE | 20 - .../README.rdoc | 24 - .../RUNNING_UNIT_TESTS | 21 - .../Rakefile | 24 - .../lib/acts_as_versioned.rb | 483 ------------------ .../test/fixtures/authors.yml | 6 - .../test/fixtures/landmark_versions.yml | 7 - .../test/fixtures/landmarks.yml | 7 - .../test/fixtures/locked_pages.yml | 10 - .../test/fixtures/locked_pages_revisions.yml | 27 - .../test/fixtures/page_versions.yml | 16 - .../test/fixtures/pages.yml | 8 - .../test/fixtures/widgets.yml | 2 - .../test/helper.rb | 27 - .../test/lib/boot.rb | 68 --- .../test/lib/database.yml | 26 - .../test/lib/schema.rb | 91 ---- .../test/migration_test.rb | 43 -- .../test/migrations/1_add_versioned_tables.rb | 19 - .../test/models/author.rb | 3 - .../test/models/landmark.rb | 3 - .../test/models/page.rb | 38 -- .../test/models/thing.rb | 7 - .../test/models/widget.rb | 6 - .../test/versioned_test.rb | 335 ------------ 28 files changed, 2 insertions(+), 1437 deletions(-) delete mode 100644 vendor/gems/metaskills-acts_as_versioned-0.6.3/CHANGELOG delete mode 100644 vendor/gems/metaskills-acts_as_versioned-0.6.3/MIT-LICENSE delete mode 100644 vendor/gems/metaskills-acts_as_versioned-0.6.3/README.rdoc delete mode 100644 vendor/gems/metaskills-acts_as_versioned-0.6.3/RUNNING_UNIT_TESTS delete mode 100644 vendor/gems/metaskills-acts_as_versioned-0.6.3/Rakefile delete mode 100644 vendor/gems/metaskills-acts_as_versioned-0.6.3/lib/acts_as_versioned.rb delete mode 100644 vendor/gems/metaskills-acts_as_versioned-0.6.3/test/fixtures/authors.yml delete mode 100644 vendor/gems/metaskills-acts_as_versioned-0.6.3/test/fixtures/landmark_versions.yml delete mode 100644 vendor/gems/metaskills-acts_as_versioned-0.6.3/test/fixtures/landmarks.yml delete mode 100644 vendor/gems/metaskills-acts_as_versioned-0.6.3/test/fixtures/locked_pages.yml delete mode 100644 vendor/gems/metaskills-acts_as_versioned-0.6.3/test/fixtures/locked_pages_revisions.yml delete mode 100644 vendor/gems/metaskills-acts_as_versioned-0.6.3/test/fixtures/page_versions.yml delete mode 100644 vendor/gems/metaskills-acts_as_versioned-0.6.3/test/fixtures/pages.yml delete mode 100644 vendor/gems/metaskills-acts_as_versioned-0.6.3/test/fixtures/widgets.yml delete mode 100644 vendor/gems/metaskills-acts_as_versioned-0.6.3/test/helper.rb delete mode 100644 vendor/gems/metaskills-acts_as_versioned-0.6.3/test/lib/boot.rb delete mode 100644 vendor/gems/metaskills-acts_as_versioned-0.6.3/test/lib/database.yml delete mode 100644 vendor/gems/metaskills-acts_as_versioned-0.6.3/test/lib/schema.rb delete mode 100644 vendor/gems/metaskills-acts_as_versioned-0.6.3/test/migration_test.rb delete mode 100644 vendor/gems/metaskills-acts_as_versioned-0.6.3/test/migrations/1_add_versioned_tables.rb delete mode 100644 vendor/gems/metaskills-acts_as_versioned-0.6.3/test/models/author.rb delete mode 100644 vendor/gems/metaskills-acts_as_versioned-0.6.3/test/models/landmark.rb delete mode 100644 vendor/gems/metaskills-acts_as_versioned-0.6.3/test/models/page.rb delete mode 100644 vendor/gems/metaskills-acts_as_versioned-0.6.3/test/models/thing.rb delete mode 100644 vendor/gems/metaskills-acts_as_versioned-0.6.3/test/models/widget.rb delete mode 100644 vendor/gems/metaskills-acts_as_versioned-0.6.3/test/versioned_test.rb diff --git a/app/models/registry/entry.rb b/app/models/registry/entry.rb index bff5da3..659b065 100644 --- a/app/models/registry/entry.rb +++ b/app/models/registry/entry.rb @@ -22,7 +22,7 @@ # require 'registry' -require File.expand_path(File.dirname(__FILE__) + '/../../../vendor/gems/metaskills-acts_as_versioned-0.6.3/lib/acts_as_versioned') +require 'acts_as_versioned' module Registry class Entry < ActiveRecord::Base diff --git a/registry.gemspec b/registry.gemspec index a190ce6..92199d0 100644 --- a/registry.gemspec +++ b/registry.gemspec @@ -17,6 +17,7 @@ Gem::Specification.new do |gem| gem.add_development_dependency 'shoulda', '3.0.1' gem.add_development_dependency 'sqlite3' + gem.add_dependency 'acts_as_versioned', '~> 0.2.0' gem.add_dependency 'rails', '~> 2.3.0' gem.files = `git ls-files`.split($/) diff --git a/vendor/gems/metaskills-acts_as_versioned-0.6.3/CHANGELOG b/vendor/gems/metaskills-acts_as_versioned-0.6.3/CHANGELOG deleted file mode 100644 index 533360c..0000000 --- a/vendor/gems/metaskills-acts_as_versioned-0.6.3/CHANGELOG +++ /dev/null @@ -1,115 +0,0 @@ - -[master] - - * - -[0.6.3] - - * (04 Apr 2009) Remove :dependent => :delete_all options as it is hard to override with - association_options. [Ken Collins] - -[0.6.2] - - * (08 Feb 2009) Avoid error with model preload by removing create_versioned_table call in AAV call. [Ngoc Dao] - * (08 Feb 2009) Do not force updated_at [Ngoc Dao] - * (08 Feb 2009) Change the create_versioned_table class method to ask the connection if table_exists?. Fixes - a bug that allows adapters that allow user owned prefixes for table names. [Ken Collins] - - -[0.6.1] - - * (29 Dec 2008) Remove #versions_count really. [Ken Collins] - * (30 Dec 2008) Add assert_sql support in boot.rb. Also changed core lib to order by the has many versions - association with the version_column, support with tests. [Ken Collins] - -[0.6] - - * (23 Dec 2008) Clean up old old code and start move towards new gem [Ken Collins] - * Starting a .gitignore file. - * Moving to a test/lib based directory structure with a boot and AAV test case based from ActiveRecord's case. - * Create rake test and test_dbs tasks. - * Create a gemspec for publishing as a gem. - -[0.5.2] - - * (16 Jun 2008) Backwards Compatibility is overrated (big updates for rails 2.1) - * Use ActiveRecord 2.1's dirty attribute checking instead [Asa Calow] - * Remove last traces of #non_versioned_fields - * Remove AR::Base.find_version and AR::Base.find_versions, rely on AR association proxies and named_scope - * Remove #versions_count, rely on AR association counter caching. - * Remove #versioned_attributes, basically the same as AR::Base.versioned_columns - - * (5 Oct 2006) Allow customization of #versions association options [Dan Peterson] - -[0.5.1] - - * (8 Aug 2006) Versioned models now belong to the unversioned model. @article_version.article.class => Article [Aslak Hellesoy] - -[0.5] - - * (21 Apr 2006) Added without_locking and without_revision methods. - Foo.without_revision do - @foo.update_attributes ... - end - -[0.4] - - * (28 March 2006) Rename non_versioned_fields to non_versioned_columns (old one is kept for compatibility). - * (28 March 2006) Made explicit documentation note that string column names are required for non_versioned_columns. - -[0.3.1] - - * (7 Jan 2006) explicitly set :foreign_key option for the versioned model's belongs_to assocation for STI [Caged] - * (7 Jan 2006) added tests to prove has_many :through joins work - -[0.3] - - * (2 Jan 2006) added ability to share a mixin with versioned class - * (2 Jan 2006) changed the dynamic version model to MyModel::Version - -[0.2.4] - - * (27 Nov 2005) added note about possible destructive behavior of if_changed? [Michael Schuerig] - -[0.2.3] - - * (12 Nov 2005) fixed bug with old behavior of #blank? [Michael Schuerig] - * (12 Nov 2005) updated tests to use ActiveRecord Schema - -[0.2.2] - - * (3 Nov 2005) added documentation note to #acts_as_versioned [Martin Jul] - -[0.2.1] - - * (6 Oct 2005) renamed dirty? to changed? to keep it uniform. it was aliased to keep it backwards compatible. - -[0.2] - - * (6 Oct 2005) added find_versions and find_version class methods. - - * (6 Oct 2005) removed transaction from create_versioned_table(). - this way you can specify your own transaction around a group of operations. - - * (30 Sep 2005) fixed bug where find_versions() would order by 'version' twice. (found by Joe Clark) - - * (26 Sep 2005) added :sequence_name option to acts_as_versioned to set the sequence name on the versioned model - -[0.1.3] - - * (18 Sep 2005) First RubyForge release - -[0.1.2] - - * check if module is already included when acts_as_versioned is called - -[0.1.1] - - * Adding tests and rdocs - -[0.1] - - * Initial transfer from Rails ticket: http://dev.rubyonrails.com/ticket/1974 - - - diff --git a/vendor/gems/metaskills-acts_as_versioned-0.6.3/MIT-LICENSE b/vendor/gems/metaskills-acts_as_versioned-0.6.3/MIT-LICENSE deleted file mode 100644 index 5851fda..0000000 --- a/vendor/gems/metaskills-acts_as_versioned-0.6.3/MIT-LICENSE +++ /dev/null @@ -1,20 +0,0 @@ -Copyright (c) 2005 Rick Olson - -Permission is hereby granted, free of charge, to any person obtaining -a copy of this software and associated documentation files (the -"Software"), to deal in the Software without restriction, including -without limitation the rights to use, copy, modify, merge, publish, -distribute, sublicense, and/or sell copies of the Software, and to -permit persons to whom the Software is furnished to do so, subject to -the following conditions: - -The above copyright notice and this permission notice shall be -included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file diff --git a/vendor/gems/metaskills-acts_as_versioned-0.6.3/README.rdoc b/vendor/gems/metaskills-acts_as_versioned-0.6.3/README.rdoc deleted file mode 100644 index 147f2d3..0000000 --- a/vendor/gems/metaskills-acts_as_versioned-0.6.3/README.rdoc +++ /dev/null @@ -1,24 +0,0 @@ - -= MetaSkills ActsAsVersioned - -A fork of Rick Olson's ActsAsVersioned plugin that has been gem'ized along with a few features I need. This library -adds simple versioning to an ActiveRecord class which of course requires ActiveRecord for use. - -Has tests for many DBs in ActiveRecord version 2.2.2 - - -== Resources - -Install the gem manually. - - $ sudo gem install metaskills-acts_as_versioned - -Or with a rails config.gem dependency. - - config.gem 'metaskills-acts_as_versioned', :lib => 'acts_as_versioned', :source => 'http://gems.github.com/' - - -The git repository is located here: - -* http://github.com/metaskills/acts_as_versioned/tree/master - diff --git a/vendor/gems/metaskills-acts_as_versioned-0.6.3/RUNNING_UNIT_TESTS b/vendor/gems/metaskills-acts_as_versioned-0.6.3/RUNNING_UNIT_TESTS deleted file mode 100644 index 7241fbd..0000000 --- a/vendor/gems/metaskills-acts_as_versioned-0.6.3/RUNNING_UNIT_TESTS +++ /dev/null @@ -1,21 +0,0 @@ - -== Creating the test database - -The default name for the test databases is can be found in the test/lib/database.yml files. By -default the tests will run on sqlite3 but can be changed using and ENV['DB'] variable like postresql, -mysql or even sqlserver. - -== Running with Rake - -The easiest way to run the unit tests is through Rake. The default task runs all the test cases. -There is even a rake task called test_dbs that will run all test cases for each DB. - -== Running by hand - -Unit tests are located in test directory. If you only want to run a single test suite, -or don't want to bother with Rake, you can do so with something like: - - cd test ; ruby -I "test" versioned_test.rb - -Likewise you can just hit Command-R if you are using TextMate. - diff --git a/vendor/gems/metaskills-acts_as_versioned-0.6.3/Rakefile b/vendor/gems/metaskills-acts_as_versioned-0.6.3/Rakefile deleted file mode 100644 index 4896c96..0000000 --- a/vendor/gems/metaskills-acts_as_versioned-0.6.3/Rakefile +++ /dev/null @@ -1,24 +0,0 @@ -require 'rubygems' -require 'rake/testtask' - -desc 'Default: Test ActsAsVersioned with default ActiveRecord version.' -task :default => :test - -desc 'Test ActsAsVersioned with default ActiveRecord version.' -Rake::TestTask.new(:test) do |t| - t.libs << 'lib' << 'test' - t.pattern = 'test/**/*_test.rb' - t.verbose = true -end - -desc 'Test ActsAsVersioned with all databases.' -task :test_dbs do - test = Rake::Task['test'] - dbs = ['sqlite3','postgresql','mysql','sqlserver'] - dbs.each do |db| - ENV['DB'] = db - test.invoke - test.reenable - end -end - diff --git a/vendor/gems/metaskills-acts_as_versioned-0.6.3/lib/acts_as_versioned.rb b/vendor/gems/metaskills-acts_as_versioned-0.6.3/lib/acts_as_versioned.rb deleted file mode 100644 index ae57a71..0000000 --- a/vendor/gems/metaskills-acts_as_versioned-0.6.3/lib/acts_as_versioned.rb +++ /dev/null @@ -1,483 +0,0 @@ -# Copyright (c) 2005 Rick Olson -# -# Permission is hereby granted, free of charge, to any person obtaining -# a copy of this software and associated documentation files (the -# "Software"), to deal in the Software without restriction, including -# without limitation the rights to use, copy, modify, merge, publish, -# distribute, sublicense, and/or sell copies of the Software, and to -# permit persons to whom the Software is furnished to do so, subject to -# the following conditions: -# -# The above copyright notice and this permission notice shall be -# included in all copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - -module ActiveRecord #:nodoc: - module Acts #:nodoc: - # Specify this act if you want to save a copy of the row in a versioned table. This assumes there is a - # versioned table ready and that your model has a version field. This works with optimistic locking if the - # lock_version column is present as well. - # - # The class for the versioned model is derived the first time it is seen. Therefore, if you change your - # database schema you have to restart your container for the changes to be reflected. In development mode - # this usually means restarting WEBrick. - # - # class Page < ActiveRecord::Base - # # assumes pages_versions table - # acts_as_versioned - # end - # - # Example: - # - # page = Page.create(:title => 'hello world!') - # page.version # => 1 - # - # page.title = 'hello world' - # page.save - # page.version # => 2 - # page.versions.size # => 2 - # - # page.revert_to(1) # using version number - # page.title # => 'hello world!' - # - # page.revert_to(page.versions.last) # using versioned instance - # page.title # => 'hello world' - # - # page.versions.earliest # efficient query to find the first version - # page.versions.latest # efficient query to find the most recently created version - # - # - # Simple Queries to page between versions - # - # page.versions.before(version) - # page.versions.after(version) - # - # Access the previous/next versions from the versioned model itself - # - # version = page.versions.latest - # version.previous # go back one version - # version.next # go forward one version - # - # See ActiveRecord::Acts::Versioned::ClassMethods#acts_as_versioned for configuration options - module Versioned - CALLBACKS = [:set_new_version, :save_version, :save_version?] - def self.included(base) # :nodoc: - base.extend ClassMethods - end - - module ClassMethods - # == Configuration options - # - # * class_name - versioned model class name (default: PageVersion in the above example) - # * table_name - versioned model table name (default: page_versions in the above example) - # * foreign_key - foreign key used to relate the versioned model to the original model (default: page_id in the above example) - # * inheritance_column - name of the column to save the model's inheritance_column value for STI. (default: versioned_type) - # * version_column - name of the column in the model that keeps the version number (default: version) - # * sequence_name - name of the custom sequence to be used by the versioned model. - # * limit - number of revisions to keep, defaults to unlimited - # * if - symbol of method to check before saving a new version. If this method returns false, a new version is not saved. - # For finer control, pass either a Proc or modify Model#version_condition_met? - # - # acts_as_versioned :if => Proc.new { |auction| !auction.expired? } - # - # or... - # - # class Auction - # def version_condition_met? # totally bypasses the :if option - # !expired? - # end - # end - # - # * if_changed - Simple way of specifying attributes that are required to be changed before saving a model. This takes - # either a symbol or array of symbols. - # - # * extend - Lets you specify a module to be mixed in both the original and versioned models. You can also just pass a block - # to create an anonymous mixin: - # - # class Auction - # acts_as_versioned do - # def started? - # !started_at.nil? - # end - # end - # end - # - # or... - # - # module AuctionExtension - # def started? - # !started_at.nil? - # end - # end - # class Auction - # acts_as_versioned :extend => AuctionExtension - # end - # - # Example code: - # - # @auction = Auction.find(1) - # @auction.started? - # @auction.versions.first.started? - # - # == Database Schema - # - # The model that you're versioning needs to have a 'version' attribute. The model is versioned into a - # table called #{model}_versions where the model name is singlular. The _versions table should contain - # all the fields you want versioned, the same version column, and a #{model}_id foreign key field. - # - # A lock_version field is also accepted if your model uses Optimistic Locking. If your table uses Single - # Table inheritance, then that field is reflected in the versioned model as 'versioned_type' by default. - # - # Acts_as_versioned comes prepared with the ActiveRecord::Acts::Versioned::ActMethods::ClassMethods#create_versioned_table - # method, perfect for a migration. It will also create the version column if the main model does not - # already have it. - # - # class AddVersions < ActiveRecord::Migration - # def self.up - # # create_versioned_table takes the same options hash - # # that create_table does - # Post.create_versioned_table - # end - # - # def self.down - # Post.drop_versioned_table - # end - # end - # - # == Changing What Fields Are Versioned - # - # By default, acts_as_versioned will version all but these fields: - # - # [self.primary_key, inheritance_column, 'version', 'lock_version', versioned_inheritance_column] - # - # You can add or change those by modifying #non_versioned_columns. Note that this takes strings and not symbols. - # - # class Post < ActiveRecord::Base - # acts_as_versioned - # self.non_versioned_columns << 'comments_count' - # end - # - def acts_as_versioned(options = {}, &extension) - # don't allow multiple calls - return if self.included_modules.include?(ActiveRecord::Acts::Versioned::ActMethods) - - send :include, ActiveRecord::Acts::Versioned::ActMethods - - cattr_accessor :versioned_class_name, :versioned_foreign_key, :versioned_table_name, :versioned_inheritance_column, - :version_column, :max_version_limit, :track_altered_attributes, :version_condition, :version_sequence_name, :non_versioned_columns, - :version_association_options, :version_if_changed - - self.versioned_class_name = options[:class_name] || "Version" - self.versioned_foreign_key = options[:foreign_key] || self.to_s.foreign_key - self.versioned_table_name = options[:table_name] || "#{table_name_prefix}#{base_class.name.demodulize.underscore}_versions#{table_name_suffix}" - self.versioned_inheritance_column = options[:inheritance_column] || "versioned_#{inheritance_column}" - self.version_column = options[:version_column] || 'version' - self.version_sequence_name = options[:sequence_name] - self.max_version_limit = options[:limit].to_i - self.version_condition = options[:if] || true - self.non_versioned_columns = [self.primary_key, inheritance_column, self.version_column, 'lock_version', versioned_inheritance_column, 'created_at', 'created_on'] + options[:non_versioned_columns].to_a.map(&:to_s) - self.version_association_options = { - :class_name => "#{self.to_s}::#{versioned_class_name}", - :foreign_key => versioned_foreign_key, - :order => "#{version_column} ASC" - }.merge(options[:association_options] || {}) - - if block_given? - extension_module_name = "#{versioned_class_name}Extension" - silence_warnings do - self.const_set(extension_module_name, Module.new(&extension)) - end - - options[:extend] = self.const_get(extension_module_name) - end - - class_eval <<-CLASS_METHODS - has_many :versions, version_association_options do - # finds earliest version of this record - def earliest - @earliest ||= find(:first, :order => '#{version_column}') - end - - # find latest version of this record - def latest - @latest ||= find(:first, :order => '#{version_column} desc') - end - end - before_save :set_new_version - after_save :save_version - after_save :clear_old_versions - - unless options[:if_changed].nil? - self.track_altered_attributes = true - options[:if_changed] = [options[:if_changed]] unless options[:if_changed].is_a?(Array) - self.version_if_changed = options[:if_changed].map(&:to_s) - end - - include options[:extend] if options[:extend].is_a?(Module) - CLASS_METHODS - - # create the dynamic versioned model - const_set(versioned_class_name, Class.new(ActiveRecord::Base)).class_eval do - def self.reloadable? ; false ; end - # find first version before the given version - def self.before(version) - find :first, :order => 'version desc', - :conditions => ["#{original_class.versioned_foreign_key} = ? and version < ?", version.send(original_class.versioned_foreign_key), version.version] - end - - # find first version after the given version. - def self.after(version) - find :first, :order => 'version', - :conditions => ["#{original_class.versioned_foreign_key} = ? and version > ?", version.send(original_class.versioned_foreign_key), version.version] - end - - def previous - self.class.before(self) - end - - def next - self.class.after(self) - end - - end - - versioned_class.cattr_accessor :original_class - versioned_class.original_class = self - versioned_class.set_table_name versioned_table_name - versioned_class.belongs_to self.to_s.demodulize.underscore.to_sym, - :class_name => "::#{self.to_s}", - :foreign_key => versioned_foreign_key - versioned_class.send :include, options[:extend] if options[:extend].is_a?(Module) - versioned_class.set_sequence_name version_sequence_name if version_sequence_name - end - end - - module ActMethods - def self.included(base) # :nodoc: - base.extend ClassMethods - end - - # Saves a version of the model in the versioned table. This is called in the after_save callback by default - def save_version - if @saving_version - @saving_version = nil - rev = self.class.versioned_class.new - clone_versioned_model(self, rev) - rev.send("#{self.class.version_column}=", send(self.class.version_column)) - rev.send("#{self.class.versioned_foreign_key}=", id) - rev.save - end - end - - # Clears old revisions if a limit is set with the :limit option in acts_as_versioned. - # Override this method to set your own criteria for clearing old versions. - def clear_old_versions - return if self.class.max_version_limit == 0 - excess_baggage = send(self.class.version_column).to_i - self.class.max_version_limit - if excess_baggage > 0 - self.class.versioned_class.delete_all ["#{self.class.version_column} <= ? and #{self.class.versioned_foreign_key} = ?", excess_baggage, id] - end - end - - # Reverts a model to a given version. Takes either a version number or an instance of the versioned model - def revert_to(version) - if version.is_a?(self.class.versioned_class) - return false unless version.send(self.class.versioned_foreign_key) == id and !version.new_record? - else - return false unless version = versions.send("find_by_#{self.class.version_column}", version) - end - self.clone_versioned_model(version, self) - send("#{self.class.version_column}=", version.send(self.class.version_column)) - true - end - - # Reverts a model to a given version and saves the model. - # Takes either a version number or an instance of the versioned model - def revert_to!(version) - revert_to(version) ? save_without_revision : false - end - - # Temporarily turns off Optimistic Locking while saving. Used when reverting so that a new version is not created. - def save_without_revision - save_without_revision! - true - rescue - false - end - - def save_without_revision! - without_locking do - without_revision do - save! - end - end - end - - def altered? - track_altered_attributes ? (version_if_changed - changed).length < version_if_changed.length : changed? - end - - # Clones a model. Used when saving a new version or reverting a model's version. - def clone_versioned_model(orig_model, new_model) - self.class.versioned_columns.each do |col| - new_model.send("#{col.name}=", orig_model.send(col.name)) if orig_model.has_attribute?(col.name) - end - - if orig_model.is_a?(self.class.versioned_class) - new_model[new_model.class.inheritance_column] = orig_model[self.class.versioned_inheritance_column] - elsif new_model.is_a?(self.class.versioned_class) - new_model[self.class.versioned_inheritance_column] = orig_model[orig_model.class.inheritance_column] - end - end - - # Checks whether a new version shall be saved or not. Calls version_condition_met? and changed?. - def save_version? - version_condition_met? && altered? - end - - # Checks condition set in the :if option to check whether a revision should be created or not. Override this for - # custom version condition checking. - def version_condition_met? - case - when version_condition.is_a?(Symbol) - send(version_condition) - when version_condition.respond_to?(:call) && (version_condition.arity == 1 || version_condition.arity == -1) - version_condition.call(self) - else - version_condition - end - end - - # Executes the block with the versioning callbacks disabled. - # - # @foo.without_revision do - # @foo.save - # end - # - def without_revision(&block) - self.class.without_revision(&block) - end - - # Turns off optimistic locking for the duration of the block - # - # @foo.without_locking do - # @foo.save - # end - # - def without_locking(&block) - self.class.without_locking(&block) - end - - def empty_callback() end #:nodoc: - - protected - # sets the new version before saving, unless you're using optimistic locking. In that case, let it take care of the version. - def set_new_version - @saving_version = new_record? || save_version? - self.send("#{self.class.version_column}=", next_version) if new_record? || (!locking_enabled? && save_version?) - end - - # Gets the next available version for the current record, or 1 for a new record - def next_version - (new_record? ? 0 : versions.calculate(:max, version_column).to_i) + 1 - end - - module ClassMethods - # Returns an array of columns that are versioned. See non_versioned_columns - def versioned_columns - @versioned_columns ||= columns.select { |c| !non_versioned_columns.include?(c.name) } - end - - # Returns an instance of the dynamic versioned model - def versioned_class - const_get versioned_class_name - end - - # Rake migration task to create the versioned table using options passed to acts_as_versioned - def create_versioned_table(create_table_options = {}) - # create version column in main table if it does not exist - if !self.content_columns.find { |c| [version_column.to_s, 'lock_version'].include? c.name } - self.connection.add_column table_name, version_column, :integer - self.reset_column_information - end - - return if connection.table_exists?(versioned_table_name) - - self.connection.create_table(versioned_table_name, create_table_options) do |t| - t.column versioned_foreign_key, :integer - t.column version_column, :integer - end - - self.versioned_columns.each do |col| - self.connection.add_column versioned_table_name, col.name, col.type, - :limit => col.limit, - :default => col.default, - :scale => col.scale, - :precision => col.precision - end - - if type_col = self.columns_hash[inheritance_column] - self.connection.add_column versioned_table_name, versioned_inheritance_column, type_col.type, - :limit => type_col.limit, - :default => type_col.default, - :scale => type_col.scale, - :precision => type_col.precision - end - - self.connection.add_index versioned_table_name, versioned_foreign_key - end - - # Rake migration task to drop the versioned table - def drop_versioned_table - self.connection.drop_table versioned_table_name - end - - # Executes the block with the versioning callbacks disabled. - # - # Foo.without_revision do - # @foo.save - # end - # - def without_revision(&block) - class_eval do - CALLBACKS.each do |attr_name| - alias_method "orig_#{attr_name}".to_sym, attr_name - alias_method attr_name, :empty_callback - end - end - block.call - ensure - class_eval do - CALLBACKS.each do |attr_name| - alias_method attr_name, "orig_#{attr_name}".to_sym - end - end - end - - # Turns off optimistic locking for the duration of the block - # - # Foo.without_locking do - # @foo.save - # end - # - def without_locking(&block) - current = ActiveRecord::Base.lock_optimistically - ActiveRecord::Base.lock_optimistically = false if current - result = block.call - ActiveRecord::Base.lock_optimistically = true if current - result - end - end - end - end - end -end - -ActiveRecord::Base.send :include, ActiveRecord::Acts::Versioned \ No newline at end of file diff --git a/vendor/gems/metaskills-acts_as_versioned-0.6.3/test/fixtures/authors.yml b/vendor/gems/metaskills-acts_as_versioned-0.6.3/test/fixtures/authors.yml deleted file mode 100644 index bd7a5ae..0000000 --- a/vendor/gems/metaskills-acts_as_versioned-0.6.3/test/fixtures/authors.yml +++ /dev/null @@ -1,6 +0,0 @@ -caged: - id: 1 - name: caged -mly: - id: 2 - name: mly \ No newline at end of file diff --git a/vendor/gems/metaskills-acts_as_versioned-0.6.3/test/fixtures/landmark_versions.yml b/vendor/gems/metaskills-acts_as_versioned-0.6.3/test/fixtures/landmark_versions.yml deleted file mode 100644 index 2dbd54e..0000000 --- a/vendor/gems/metaskills-acts_as_versioned-0.6.3/test/fixtures/landmark_versions.yml +++ /dev/null @@ -1,7 +0,0 @@ -washington: - id: 1 - landmark_id: 1 - version: 1 - name: Washington, D.C. - latitude: 38.895 - longitude: -77.036667 diff --git a/vendor/gems/metaskills-acts_as_versioned-0.6.3/test/fixtures/landmarks.yml b/vendor/gems/metaskills-acts_as_versioned-0.6.3/test/fixtures/landmarks.yml deleted file mode 100644 index cf06390..0000000 --- a/vendor/gems/metaskills-acts_as_versioned-0.6.3/test/fixtures/landmarks.yml +++ /dev/null @@ -1,7 +0,0 @@ -washington: - id: 1 - name: Washington, D.C. - latitude: 38.895 - longitude: -77.036667 - doesnt_trigger_version: This is not important - version: 1 diff --git a/vendor/gems/metaskills-acts_as_versioned-0.6.3/test/fixtures/locked_pages.yml b/vendor/gems/metaskills-acts_as_versioned-0.6.3/test/fixtures/locked_pages.yml deleted file mode 100644 index 318e776..0000000 --- a/vendor/gems/metaskills-acts_as_versioned-0.6.3/test/fixtures/locked_pages.yml +++ /dev/null @@ -1,10 +0,0 @@ -welcome: - id: 1 - title: Welcome to the weblog - lock_version: 24 - type: LockedPage -thinking: - id: 2 - title: So I was thinking - lock_version: 24 - type: SpecialLockedPage diff --git a/vendor/gems/metaskills-acts_as_versioned-0.6.3/test/fixtures/locked_pages_revisions.yml b/vendor/gems/metaskills-acts_as_versioned-0.6.3/test/fixtures/locked_pages_revisions.yml deleted file mode 100644 index 3a1be5a..0000000 --- a/vendor/gems/metaskills-acts_as_versioned-0.6.3/test/fixtures/locked_pages_revisions.yml +++ /dev/null @@ -1,27 +0,0 @@ -welcome_1: - id: 1 - page_id: 1 - title: Welcome to the weblg - lock_version: 23 - version_type: LockedPage - -welcome_2: - id: 2 - page_id: 1 - title: Welcome to the weblog - lock_version: 24 - version_type: LockedPage - -thinking_1: - id: 3 - page_id: 2 - title: So I was thinking!!! - lock_version: 23 - version_type: SpecialLockedPage - -thinking_2: - id: 4 - page_id: 2 - title: So I was thinking - lock_version: 24 - version_type: SpecialLockedPage diff --git a/vendor/gems/metaskills-acts_as_versioned-0.6.3/test/fixtures/page_versions.yml b/vendor/gems/metaskills-acts_as_versioned-0.6.3/test/fixtures/page_versions.yml deleted file mode 100644 index ef565fa..0000000 --- a/vendor/gems/metaskills-acts_as_versioned-0.6.3/test/fixtures/page_versions.yml +++ /dev/null @@ -1,16 +0,0 @@ -welcome_2: - id: 1 - page_id: 1 - title: Welcome to the weblog - body: Such a lovely day - version: 24 - author_id: 1 - revisor_id: 1 -welcome_1: - id: 2 - page_id: 1 - title: Welcome to the weblg - body: Such a lovely day - version: 23 - author_id: 2 - revisor_id: 2 diff --git a/vendor/gems/metaskills-acts_as_versioned-0.6.3/test/fixtures/pages.yml b/vendor/gems/metaskills-acts_as_versioned-0.6.3/test/fixtures/pages.yml deleted file mode 100644 index 9f4ab54..0000000 --- a/vendor/gems/metaskills-acts_as_versioned-0.6.3/test/fixtures/pages.yml +++ /dev/null @@ -1,8 +0,0 @@ -welcome: - id: 1 - title: Welcome to the weblog - body: Such a lovely day - version: 24 - author_id: 1 - revisor_id: 1 - created_on: "2008-01-01 00:00:00" \ No newline at end of file diff --git a/vendor/gems/metaskills-acts_as_versioned-0.6.3/test/fixtures/widgets.yml b/vendor/gems/metaskills-acts_as_versioned-0.6.3/test/fixtures/widgets.yml deleted file mode 100644 index 139597f..0000000 --- a/vendor/gems/metaskills-acts_as_versioned-0.6.3/test/fixtures/widgets.yml +++ /dev/null @@ -1,2 +0,0 @@ - - diff --git a/vendor/gems/metaskills-acts_as_versioned-0.6.3/test/helper.rb b/vendor/gems/metaskills-acts_as_versioned-0.6.3/test/helper.rb deleted file mode 100644 index 10bd2f4..0000000 --- a/vendor/gems/metaskills-acts_as_versioned-0.6.3/test/helper.rb +++ /dev/null @@ -1,27 +0,0 @@ -require 'test/unit' -require File.join(File.dirname(__FILE__),'lib/boot') unless defined?(ActiveRecord) -require 'acts_as_versioned' - -class AAVTestCase < ActiveRecord::TestCase - - self.use_transactional_fixtures = true - self.use_instantiated_fixtures = false - - fixtures :all - set_fixture_class :page_versions => Page::Version - - protected - - def assert_sql(*patterns_to_match) - $queries_executed = [] - yield - ensure - failed_patterns = [] - patterns_to_match.each do |pattern| - failed_patterns << pattern unless $queries_executed.any?{ |sql| pattern === sql } - end - assert failed_patterns.empty?, "Query pattern(s) #{failed_patterns.map(&:inspect).join(', ')} not found in:\n#{$queries_executed.inspect}" - end - -end - diff --git a/vendor/gems/metaskills-acts_as_versioned-0.6.3/test/lib/boot.rb b/vendor/gems/metaskills-acts_as_versioned-0.6.3/test/lib/boot.rb deleted file mode 100644 index 075ed77..0000000 --- a/vendor/gems/metaskills-acts_as_versioned-0.6.3/test/lib/boot.rb +++ /dev/null @@ -1,68 +0,0 @@ - -# Requiring ActiveRecord via RubyGems. - -require 'rubygems' - -PROJECT_ROOT = File.expand_path(File.join(File.dirname(__FILE__),'..','..')) -AR_VERSION = ENV['AR_VERSION'] || '2.2.2' - -['.','lib','test','test/models'].each do |test_lib| - load_path = File.expand_path(File.join(PROJECT_ROOT,test_lib)) - $LOAD_PATH.unshift(load_path) unless $LOAD_PATH.include?(load_path) -end - -puts "Using ActiveRecord #{AR_VERSION} from gems" -gem 'activerecord', AR_VERSION -require 'active_record' - - -# Setting up ActiveRecord TestCase and fixtures. We make sure our setup runs before setup_fixtures. - -FIXTURES_ROOT = PROJECT_ROOT + "/test/fixtures" -MIGRATIONS_ROOT = PROJECT_ROOT + "/test/migrations" - -require 'active_record/fixtures' -require 'active_record/test_case' - - -# Establishing the ActiveRecord connection and DB specific tasks. - -ardb = ENV['DB'] || 'sqlite3' -arconfig = YAML::load(IO.read("#{PROJECT_ROOT}/test/lib/database.yml")) - -case ardb -when 'sqlserver' - gem 'rails-sqlserver-2000-2005-adapter' - require 'active_record/connection_adapters/sqlserver_adapter' -end - -ActiveRecord::Base.logger = Logger.new("#{PROJECT_ROOT}/test/debug.log") -ActiveRecord::Base.configurations = {'test' => arconfig[ardb]} -ActiveRecord::Base.establish_connection(ActiveRecord::Base.configurations['test']) -puts "With database: #{ardb}" - -ActiveRecord::Base.connection.class.class_eval do - IGNORED_SQL = [/^PRAGMA/, /^SELECT currval/, /^SELECT CAST/, /^SELECT @@IDENTITY/, /^SELECT @@ROWCOUNT/] - def execute_with_query_record(sql, name = nil, &block) - $queries_executed ||= [] - $queries_executed << sql unless IGNORED_SQL.any? { |r| sql =~ r } - execute_without_query_record(sql, name, &block) - end - alias_method_chain :execute, :query_record -end - - -# Creating the DB schema and DB specific tasks. - -ActiveRecord::Migration.verbose = false - -load(File.dirname(__FILE__)+"/schema.rb") - -case ardb -when 'postgresql' - ActiveRecord::Base.connection.execute "DROP SEQUENCE widgets_seq;" rescue nil - ActiveRecord::Base.connection.remove_column :widget_versions, :id - ActiveRecord::Base.connection.execute "CREATE SEQUENCE widgets_seq START 101;" - ActiveRecord::Base.connection.execute "ALTER TABLE widget_versions ADD COLUMN id INTEGER PRIMARY KEY DEFAULT nextval('widgets_seq');" -end - diff --git a/vendor/gems/metaskills-acts_as_versioned-0.6.3/test/lib/database.yml b/vendor/gems/metaskills-acts_as_versioned-0.6.3/test/lib/database.yml deleted file mode 100644 index ab3c51c..0000000 --- a/vendor/gems/metaskills-acts_as_versioned-0.6.3/test/lib/database.yml +++ /dev/null @@ -1,26 +0,0 @@ - -sqlite3: - adapter: sqlite3 - database: ":memory:" - -postgresql: - adapter: postgresql - username: postgres - password: postgres - database: acts_as_versioned_plugin_test - min_messages: ERROR - -mysql: - adapter: mysql - host: localhost - username: rails - password: - database: acts_as_versioned_plugin_test - -sqlserver: - adapter: sqlserver - mode: ODBC - username: rails - password: - dsn: acts_as_versioned_plugin_test - diff --git a/vendor/gems/metaskills-acts_as_versioned-0.6.3/test/lib/schema.rb b/vendor/gems/metaskills-acts_as_versioned-0.6.3/test/lib/schema.rb deleted file mode 100644 index 38def5f..0000000 --- a/vendor/gems/metaskills-acts_as_versioned-0.6.3/test/lib/schema.rb +++ /dev/null @@ -1,91 +0,0 @@ -ActiveRecord::Base.class_eval do - - connection.create_table :pages, :force => true do |t| - t.column :version, :integer - t.column :title, :string, :limit => 255 - t.column :body, :text - t.column :created_on, :datetime - t.column :updated_on, :datetime - t.column :author_id, :integer - t.column :revisor_id, :integer - end - - connection.create_table :page_versions, :force => true do |t| - t.column :page_id, :integer - t.column :version, :integer - t.column :title, :string, :limit => 255 - t.column :body, :text - t.column :created_on, :datetime - t.column :updated_on, :datetime - t.column :author_id, :integer - t.column :revisor_id, :integer - end - - connection.add_index :page_versions, [:page_id, :version], :unique => true - - connection.create_table :authors, :force => true do |t| - t.column :page_id, :integer - t.column :name, :string - end - - connection.create_table :locked_pages, :force => true do |t| - t.column :lock_version, :integer - t.column :title, :string, :limit => 255 - t.column :body, :text - t.column :type, :string, :limit => 255 - end - - connection.create_table :locked_pages_revisions, :force => true do |t| - t.column :page_id, :integer - t.column :lock_version, :integer - t.column :title, :string, :limit => 255 - t.column :body, :text - t.column :version_type, :string, :limit => 255 - t.column :updated_at, :datetime - end - - connection.add_index :locked_pages_revisions, [:page_id, :lock_version], :unique => true - - connection.create_table :widgets, :force => true do |t| - t.column :name, :string, :limit => 50 - t.column :foo, :string - t.column :version, :integer - t.column :updated_at, :datetime - end - - connection.create_table :widget_versions, :force => true do |t| - t.column :widget_id, :integer - t.column :name, :string, :limit => 50 - t.column :version, :integer - t.column :updated_at, :datetime - end - - connection.add_index :widget_versions, [:widget_id, :version], :unique => true - - connection.create_table :landmarks, :force => true do |t| - t.column :name, :string - t.column :latitude, :float - t.column :longitude, :float - t.column :doesnt_trigger_version, :string - t.column :version, :integer - end - - connection.create_table :landmark_versions, :force => true do |t| - t.column :landmark_id, :integer - t.column :name, :string - t.column :latitude, :float - t.column :longitude, :float - t.column :doesnt_trigger_version, :string - t.column :version, :integer - end - - connection.add_index :landmark_versions, [:landmark_id, :version], :unique => true - - connection.create_table :things, :force => true do |t| - t.column :title, :text - t.column :price, :decimal, :precision => 7, :scale => 2 - t.column :type, :string - end - -end - diff --git a/vendor/gems/metaskills-acts_as_versioned-0.6.3/test/migration_test.rb b/vendor/gems/metaskills-acts_as_versioned-0.6.3/test/migration_test.rb deleted file mode 100644 index 0e81567..0000000 --- a/vendor/gems/metaskills-acts_as_versioned-0.6.3/test/migration_test.rb +++ /dev/null @@ -1,43 +0,0 @@ -require 'helper' -require 'models/thing' - -class MigrationTest < AAVTestCase - - self.use_transactional_fixtures = false - - setup :migrate_up, :create_thing - teardown :migrate_down - - - test "that the price column has remembered its value correctly" do - assert_equal @thing.price, @thing.versions.first.price - assert_equal @thing.title, @thing.versions.first.title - assert_equal @thing[:type], @thing.versions.first[:type] - end - - test "to make sure that the precision of the price column has been preserved" do - assert_equal 7, Thing::Version.columns.find{|c| c.name == "price"}.precision - assert_equal 2, Thing::Version.columns.find{|c| c.name == "price"}.scale - end - - - protected - - def migrate_up - ActiveRecord::Migrator.up(MIGRATIONS_ROOT) - Thing.reset_column_information - end - - def create_thing - @thing = Thing.create :title => 'blah blah', :price => 123.45, :type => 'Thing' - end - - def migrate_down - ActiveRecord::Migrator.down(MIGRATIONS_ROOT) - ActiveRecord::Base.connection.initialize_schema_migrations_table - ActiveRecord::Base.connection.assume_migrated_upto_version(0) - end - - -end - diff --git a/vendor/gems/metaskills-acts_as_versioned-0.6.3/test/migrations/1_add_versioned_tables.rb b/vendor/gems/metaskills-acts_as_versioned-0.6.3/test/migrations/1_add_versioned_tables.rb deleted file mode 100644 index 8a68ebf..0000000 --- a/vendor/gems/metaskills-acts_as_versioned-0.6.3/test/migrations/1_add_versioned_tables.rb +++ /dev/null @@ -1,19 +0,0 @@ -class AddVersionedTables < ActiveRecord::Migration - - def self.up - drop_table :things rescue nil - drop_table :thing_versions rescue nil - create_table :things do |t| - t.column :title, :text - t.column :price, :decimal, :precision => 7, :scale => 2 - t.column :type, :string - end - Thing.create_versioned_table - end - - def self.down - drop_table :things rescue nil - drop_table :thing_versions rescue nil - end - -end diff --git a/vendor/gems/metaskills-acts_as_versioned-0.6.3/test/models/author.rb b/vendor/gems/metaskills-acts_as_versioned-0.6.3/test/models/author.rb deleted file mode 100644 index 4ac53f7..0000000 --- a/vendor/gems/metaskills-acts_as_versioned-0.6.3/test/models/author.rb +++ /dev/null @@ -1,3 +0,0 @@ -class Author < ActiveRecord::Base - has_many :pages -end diff --git a/vendor/gems/metaskills-acts_as_versioned-0.6.3/test/models/landmark.rb b/vendor/gems/metaskills-acts_as_versioned-0.6.3/test/models/landmark.rb deleted file mode 100644 index cb9b930..0000000 --- a/vendor/gems/metaskills-acts_as_versioned-0.6.3/test/models/landmark.rb +++ /dev/null @@ -1,3 +0,0 @@ -class Landmark < ActiveRecord::Base - acts_as_versioned :if_changed => [ :name, :longitude, :latitude ] -end diff --git a/vendor/gems/metaskills-acts_as_versioned-0.6.3/test/models/page.rb b/vendor/gems/metaskills-acts_as_versioned-0.6.3/test/models/page.rb deleted file mode 100644 index daf7c1b..0000000 --- a/vendor/gems/metaskills-acts_as_versioned-0.6.3/test/models/page.rb +++ /dev/null @@ -1,38 +0,0 @@ -class Page < ActiveRecord::Base - belongs_to :author - has_many :authors, :through => :versions, :order => 'name' - belongs_to :revisor, :class_name => 'Author' - has_many :revisors, :class_name => 'Author', :through => :versions, :order => 'name' - acts_as_versioned :if => :feeling_good? do - def self.included(base) - base.cattr_accessor :feeling_good - base.feeling_good = true - base.belongs_to :author - base.belongs_to :revisor, :class_name => 'Author' - end - def feeling_good? - @@feeling_good == true - end - end -end - -module LockedPageExtension - def hello_world - 'hello_world' - end -end - -class LockedPage < ActiveRecord::Base - acts_as_versioned \ - :inheritance_column => :version_type, - :foreign_key => :page_id, - :table_name => :locked_pages_revisions, - :class_name => 'LockedPageRevision', - :version_column => :lock_version, - :limit => 2, - :if_changed => :title, - :extend => LockedPageExtension -end - -class SpecialLockedPage < LockedPage -end diff --git a/vendor/gems/metaskills-acts_as_versioned-0.6.3/test/models/thing.rb b/vendor/gems/metaskills-acts_as_versioned-0.6.3/test/models/thing.rb deleted file mode 100644 index 891f378..0000000 --- a/vendor/gems/metaskills-acts_as_versioned-0.6.3/test/models/thing.rb +++ /dev/null @@ -1,7 +0,0 @@ -class Thing < ActiveRecord::Base - - attr_accessor :version - acts_as_versioned - - -end diff --git a/vendor/gems/metaskills-acts_as_versioned-0.6.3/test/models/widget.rb b/vendor/gems/metaskills-acts_as_versioned-0.6.3/test/models/widget.rb deleted file mode 100644 index 14bd3c2..0000000 --- a/vendor/gems/metaskills-acts_as_versioned-0.6.3/test/models/widget.rb +++ /dev/null @@ -1,6 +0,0 @@ -class Widget < ActiveRecord::Base - acts_as_versioned :sequence_name => 'widgets_seq', :association_options => { - :dependent => :nullify, :order => 'version desc' - } - non_versioned_columns << 'foo' -end diff --git a/vendor/gems/metaskills-acts_as_versioned-0.6.3/test/versioned_test.rb b/vendor/gems/metaskills-acts_as_versioned-0.6.3/test/versioned_test.rb deleted file mode 100644 index 6db5520..0000000 --- a/vendor/gems/metaskills-acts_as_versioned-0.6.3/test/versioned_test.rb +++ /dev/null @@ -1,335 +0,0 @@ -require 'helper' - -class VersionedTest < AAVTestCase - - - test "saves versioned copy" do - p = Page.create! :title => 'first title', :body => 'first body' - assert !p.new_record? - assert_equal 1, p.versions.size - assert_equal 1, p.version - assert_instance_of Page.versioned_class, p.versions.first - end - - test "version has unique created on" do - p = pages(:welcome) - p.title = 'update me' - p.save! - assert_not_equal p.created_on, p.versions.latest.created_on - end - - test "saves without revision" do - p = pages(:welcome) - old_versions = p.versions.count - p.save_without_revision - p.without_revision do - p.update_attributes :title => 'changed' - end - assert_equal old_versions, p.versions.count - end - - test "rollback with version number" do - p = pages(:welcome) - assert_equal 24, p.version - assert_equal 'Welcome to the weblog', p.title - assert p.revert_to!(23), "Couldn't revert to 23" - assert_equal 23, p.version - assert_equal 'Welcome to the weblg', p.title - end - - test "versioned class name" do - assert_equal 'Version', Page.versioned_class_name - assert_equal 'LockedPageRevision', LockedPage.versioned_class_name - end - - test "versioned class" do - assert_equal Page::Version, Page.versioned_class - assert_equal LockedPage::LockedPageRevision, LockedPage.versioned_class - end - - test "special methods" do - assert_nothing_raised { pages(:welcome).feeling_good? } - assert_nothing_raised { pages(:welcome).versions.first.feeling_good? } - assert_nothing_raised { locked_pages(:welcome).hello_world } - assert_nothing_raised { locked_pages(:welcome).versions.first.hello_world } - end - - test "version objects are ordered by the version columns" do - p = pages(:welcome) - assert_sql(/ORDER BY version ASC/) { p.versions(true) } - assert_equal [23,24], p.versions.map(&:version) - end - - test "rollback with version class" do - p = pages(:welcome) - assert_equal 24, p.version - assert_equal 'Welcome to the weblog', p.title - assert p.revert_to!(p.versions.find_by_version(23)), "Couldn't revert to 23" - assert_equal 23, p.version - assert_equal 'Welcome to the weblg', p.title - end - - test "rollback fails with invalid revision" do - p = locked_pages(:welcome) - assert !p.revert_to!(locked_pages(:thinking)) - end - - test "saves versioned copy with options" do - p = LockedPage.create! :title => 'first title' - assert !p.new_record? - assert_equal 1, p.versions.size - assert_instance_of LockedPage.versioned_class, p.versions.first - end - - test "rollback with version number with options" do - p = locked_pages(:welcome) - assert_equal 'Welcome to the weblog', p.title - assert_equal 'LockedPage', p.versions.first.version_type - assert p.revert_to!(p.versions.first.lock_version), "Couldn't revert to 23" - assert_equal 'Welcome to the weblg', p.title - assert_equal 'LockedPage', p.versions.first.version_type - end - - test "rollback with version class with options" do - p = locked_pages(:welcome) - assert_equal 'Welcome to the weblog', p.title - assert_equal 'LockedPage', p.versions.first.version_type - assert p.revert_to!(p.versions.first), "Couldn't revert to 1" - assert_equal 'Welcome to the weblg', p.title - assert_equal 'LockedPage', p.versions.first.version_type - end - - test "saves versioned copy with sti" do - p = SpecialLockedPage.create! :title => 'first title' - assert !p.new_record? - assert_equal 1, p.versions.size - assert_instance_of LockedPage.versioned_class, p.versions.first - assert_equal 'SpecialLockedPage', p.versions.first.version_type - end - - test "rollback with version number with sti" do - p = locked_pages(:thinking) - assert_equal 'So I was thinking', p.title - - assert p.revert_to!(p.versions.first.lock_version), "Couldn't revert to 1" - assert_equal 'So I was thinking!!!', p.title - assert_equal 'SpecialLockedPage', p.versions.first.version_type - end - - test "lock version works with versioning" do - p = locked_pages(:thinking) - p2 = LockedPage.find(p.id) - p.title = 'fresh title' - p.save - assert_equal 2, p.versions.size # limit! - assert_raises(ActiveRecord::StaleObjectError) do - p2.title = 'stale title' - p2.save - end - end - - test "version if condition" do - p = Page.create! :title => "title" - assert_equal 1, p.version - Page.feeling_good = false - p.save - assert_equal 1, p.version - Page.feeling_good = true - end - - test "version if condition2" do - # set new if condition - Page.class_eval do - def new_feeling_good() title[0..0] == 'a'; end - alias_method :old_feeling_good, :feeling_good? - alias_method :feeling_good?, :new_feeling_good - end - p = Page.create! :title => "title" - assert_equal 1, p.version # version does not increment - assert_equal 1, p.versions.count - p.update_attributes(:title => 'new title') - assert_equal 1, p.version # version does not increment - assert_equal 1, p.versions.count - p.update_attributes(:title => 'a title') - assert_equal 2, p.version - assert_equal 2, p.versions.count - # reset original if condition - Page.class_eval { alias_method :feeling_good?, :old_feeling_good } - end - - test "version if condition with block" do - # set new if condition - old_condition = Page.version_condition - Page.version_condition = Proc.new { |page| page.title[0..0] == 'b' } - p = Page.create! :title => "title" - assert_equal 1, p.version # version does not increment - assert_equal 1, p.versions.count - p.update_attributes(:title => 'a title') - assert_equal 1, p.version # version does not increment - assert_equal 1, p.versions.count - p.update_attributes(:title => 'b title') - assert_equal 2, p.version - assert_equal 2, p.versions.count - # reset original if condition - Page.version_condition = old_condition - end - - test "version no limit" do - p = Page.create! :title => "title", :body => 'first body' - p.save - p.save - 5.times do |i| - p.title = "title#{i}" - p.save - assert_equal "title#{i}", p.title - assert_equal (i+2), p.version - end - end - - test "version max limit" do - p = LockedPage.create! :title => "title" - p.update_attributes(:title => "title1") - p.update_attributes(:title => "title2") - 5.times do |i| - p.title = "title#{i}" - p.save - assert_equal "title#{i}", p.title - assert_equal (i+4), p.lock_version - assert p.versions(true).size <= 2, "locked version can only store 2 versions" - end - end - - test "track altered attributes default value" do - assert !Page.track_altered_attributes - assert LockedPage.track_altered_attributes - assert SpecialLockedPage.track_altered_attributes - end - - test "track altered attributes" do - p = LockedPage.create! :title => "title" - assert_equal 1, p.lock_version - assert_equal 1, p.versions(true).size - p.body = 'whoa' - assert !p.save_version? - p.save - assert_equal 2, p.lock_version # still increments version because of optimistic locking - assert_equal 1, p.versions(true).size - p.title = 'updated title' - assert p.save_version? - p.save - assert_equal 3, p.lock_version - assert_equal 1, p.versions(true).size # version 1 deleted - p.title = 'updated title!' - assert p.save_version? - p.save - assert_equal 4, p.lock_version - assert_equal 2, p.versions(true).size # version 1 deleted - end - - test "find versions" do - assert_equal 1, locked_pages(:welcome).versions.find(:all, :conditions => ['title LIKE ?', '%weblog%']).size - end - - test "find version" do - assert_equal page_versions(:welcome_1), pages(:welcome).versions.find_by_version(23) - end - - test "with sequence" do - assert_equal 'widgets_seq', Widget.versioned_class.sequence_name - 3.times { Widget.create! :name => 'new widget' } - assert_equal 3, Widget.count - assert_equal 3, Widget.versioned_class.count - end - - test "has many through" do - assert_equal [authors(:caged), authors(:mly)], pages(:welcome).authors - end - - test "has many through with custom association" do - assert_equal [authors(:caged), authors(:mly)], pages(:welcome).revisors - end - - test "referential integrity" do - pages(:welcome).destroy - assert_equal 0, Page.count - assert_equal 2, Page::Version.count - end - - test "association options" do - association = Page.reflect_on_association(:versions) - options = association.options - association = Widget.reflect_on_association(:versions) - options = association.options - assert_equal :nullify, options[:dependent] - assert_equal 'version desc', options[:order] - assert_equal 'widget_id', options[:foreign_key] - widget = Widget.create! :name => 'new widget' - assert_equal 1, Widget.count - assert_equal 1, Widget.versioned_class.count - widget.destroy - assert_equal 0, Widget.count - assert_equal 1, Widget::Version.count - end - - test "versioned records should belong to parent" do - page = pages(:welcome) - page_version = page.versions.last - assert_equal page, page_version.page - end - - test "unaltered attributes" do - landmarks(:washington).attributes = landmarks(:washington).attributes.except("id") - assert !landmarks(:washington).changed? - end - - test "unchanged string attributes" do - landmarks(:washington).attributes = landmarks(:washington).attributes.except("id").inject({}) { |params, (key, value)| params.update(key => value.to_s) } - assert !landmarks(:washington).changed? - end - - test "should find earliest version" do - assert_equal page_versions(:welcome_1), pages(:welcome).versions.earliest - end - - test "should find latest version" do - assert_equal page_versions(:welcome_2), pages(:welcome).versions.latest - end - - test "should find previous version" do - assert_equal page_versions(:welcome_1), page_versions(:welcome_2).previous - assert_equal page_versions(:welcome_1), pages(:welcome).versions.before(page_versions(:welcome_2)) - end - - test "should find next version" do - assert_equal page_versions(:welcome_2), page_versions(:welcome_1).next - assert_equal page_versions(:welcome_2), pages(:welcome).versions.after(page_versions(:welcome_1)) - end - - test "should find version count" do - assert_equal 2, pages(:welcome).versions.size - end - - test "if changed creates version if a listed column is changed" do - landmarks(:washington).name = "Washington" - assert landmarks(:washington).changed? - assert landmarks(:washington).altered? - end - - test "if changed creates version if all listed columns are changed" do - landmarks(:washington).name = "Washington" - landmarks(:washington).latitude = 1.0 - landmarks(:washington).longitude = 1.0 - assert landmarks(:washington).changed? - assert landmarks(:washington).altered? - end - - test "if changed does not create new version if unlisted column is changed" do - landmarks(:washington).doesnt_trigger_version = "This should not trigger version" - assert landmarks(:washington).changed? - assert !landmarks(:washington).altered? - end - - -end - - From 457f39c5249ee3c382e7853d514d2ec349c09f6e Mon Sep 17 00:00:00 2001 From: Scott Steadman Date: Mon, 3 Feb 2020 10:36:36 -0800 Subject: [PATCH 10/22] remove scripts These are Geni specific and don't belong here. --- script/skynet | 26 -------------------------- script/sweatshop | 17 ----------------- 2 files changed, 43 deletions(-) delete mode 100755 script/skynet delete mode 100755 script/sweatshop diff --git a/script/skynet b/script/skynet deleted file mode 100755 index 5a0a8ae..0000000 --- a/script/skynet +++ /dev/null @@ -1,26 +0,0 @@ -#!/usr/bin/env ruby - -# Load your rails app -require File.expand_path(File.dirname(__FILE__)) + '/../config/environment' -require 'rubygems' -require 'skynet' -require 'erb' -require 'pp' - -Skynet::CONFIG[:LAUNCHER_PATH] ||= File.expand_path(__FILE__) -Skynet::CONFIG[:SKYNET_LOG_LEVEL] ||= Logger::ERROR -Skynet::CONFIG[:MYSQL_QUEUE_DATABASE] ||= 'skynet_queue' - -SKYNET_GUID = GuidGenerator.new(:namespace => :skynet, :batch_size => 10_000) -Skynet::CONFIG[:GUID_GENERATOR] = lambda { SKYNET_GUID.next } - -## See config/initializers/skynet.rb for more settings - -class ExceptionReport - include SkynetDebugger - def self.save(worker, exception) - mock_controller = OpenStruct.new(:name => worker.class.name) - LoggedException.create_from_exception(mock_controller, exception) - end -end -Skynet.start diff --git a/script/sweatshop b/script/sweatshop deleted file mode 100755 index 7f12613..0000000 --- a/script/sweatshop +++ /dev/null @@ -1,17 +0,0 @@ -#!/usr/bin/env ruby - -if ARGV.include?('-d') - ARGV.delete('-d') - ARGV.unshift('start') unless ARGV.detect{|a| ['start', 'restart'].include?(a)} - - root = File.expand_path(File.dirname(__FILE__) + '/..') - ARGV << "--rails=#{root}" - - system("ruby #{root}/vendor/gems/sweatshop/lib/sweatshop/sweatd.rb #{ARGV.join(' ')}") - exit $?.exitstatus -else - puts "Loading Rails..." - require File.dirname(__FILE__) + '/../config/environment' - puts "Listening for new tasks..." - Sweatshop.do_all_tasks -end From e1da5ba931bf8fc2ec328bad3f97ad9746626d89 Mon Sep 17 00:00:00 2001 From: Scott Steadman Date: Mon, 3 Feb 2020 14:19:57 -0800 Subject: [PATCH 11/22] add .ruby-version We need to make sure we're running the correct ruby version. --- .ruby-version | 1 + 1 file changed, 1 insertion(+) create mode 100644 .ruby-version diff --git a/.ruby-version b/.ruby-version new file mode 100644 index 0000000..68b3a4c --- /dev/null +++ b/.ruby-version @@ -0,0 +1 @@ +1.9.3-p551 From 679c8e3a776a89b7850f25ec4be284dc72e52684 Mon Sep 17 00:00:00 2001 From: Scott Steadman Date: Mon, 3 Feb 2020 15:02:42 -0800 Subject: [PATCH 12/22] update scripts These weren't working because they used an old require line --- script/breakpointer | 4 ++-- script/console | 2 +- script/dbconsole | 2 +- script/destroy | 4 ++-- script/generate | 4 ++-- script/plugin | 4 ++-- script/runner | 4 ++-- script/server | 4 ++-- 8 files changed, 14 insertions(+), 14 deletions(-) diff --git a/script/breakpointer b/script/breakpointer index 64af76e..d7db15a 100755 --- a/script/breakpointer +++ b/script/breakpointer @@ -1,3 +1,3 @@ #!/usr/bin/env ruby -require File.dirname(__FILE__) + '/../config/boot' -require 'commands/breakpointer' \ No newline at end of file +require File.expand_path('../../config/boot', __FILE__) +require 'commands/breakpointer' diff --git a/script/console b/script/console index ca2f865..e76d91b 100755 --- a/script/console +++ b/script/console @@ -1,4 +1,4 @@ #!/usr/bin/env ruby $lazy_load_rails = true -require File.dirname(__FILE__) + '/../config/boot' +require File.expand_path('../../config/boot', __FILE__) require 'commands/console' diff --git a/script/dbconsole b/script/dbconsole index caa60ce..83c8436 100755 --- a/script/dbconsole +++ b/script/dbconsole @@ -1,3 +1,3 @@ #!/usr/bin/env ruby -require File.dirname(__FILE__) + '/../config/boot' +require File.expand_path('../../config/boot', __FILE__) require 'commands/dbconsole' diff --git a/script/destroy b/script/destroy index fa0e6fc..88d295f 100755 --- a/script/destroy +++ b/script/destroy @@ -1,3 +1,3 @@ #!/usr/bin/env ruby -require File.dirname(__FILE__) + '/../config/boot' -require 'commands/destroy' \ No newline at end of file +require File.expand_path('../../config/boot', __FILE__) +require 'commands/destroy' diff --git a/script/generate b/script/generate index ef976e0..62a8a4c 100755 --- a/script/generate +++ b/script/generate @@ -1,3 +1,3 @@ #!/usr/bin/env ruby -require File.dirname(__FILE__) + '/../config/boot' -require 'commands/generate' \ No newline at end of file +require File.expand_path('../../config/boot', __FILE__) +require 'commands/generate' diff --git a/script/plugin b/script/plugin index 26ca64c..b82201f 100755 --- a/script/plugin +++ b/script/plugin @@ -1,3 +1,3 @@ #!/usr/bin/env ruby -require File.dirname(__FILE__) + '/../config/boot' -require 'commands/plugin' \ No newline at end of file +require File.expand_path('../../config/boot', __FILE__) +require 'commands/plugin' diff --git a/script/runner b/script/runner index ccc30f9..be4c5d4 100755 --- a/script/runner +++ b/script/runner @@ -1,3 +1,3 @@ #!/usr/bin/env ruby -require File.dirname(__FILE__) + '/../config/boot' -require 'commands/runner' \ No newline at end of file +require File.expand_path('../../config/boot', __FILE__) +require 'commands/runner' diff --git a/script/server b/script/server index dfabcb8..b9fcb71 100755 --- a/script/server +++ b/script/server @@ -1,3 +1,3 @@ #!/usr/bin/env ruby -require File.dirname(__FILE__) + '/../config/boot' -require 'commands/server' \ No newline at end of file +require File.expand_path('../../config/boot', __FILE__) +require 'commands/server' From 7e1f71d48d75ccaa2eddb932ec7459443a235e2c Mon Sep 17 00:00:00 2001 From: Scott Steadman Date: Mon, 3 Feb 2020 15:20:35 -0800 Subject: [PATCH 13/22] update confid/database.yml There were useless references. --- config/database.yml | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/config/database.yml b/config/database.yml index 1f6bdf8..668978a 100644 --- a/config/database.yml +++ b/config/database.yml @@ -11,17 +11,3 @@ test: database: db/test.sqlite3 pool: 5 timeout: 5000 - -pg_development: - adapter: postgresql - host: localhost - encoding: utf8 - username: postgres - database: sme_dev - -pg_test: - adapter: postgresql - host: localhost - encoding: utf8 - username: postgres - database: sme_test From 29e34db2b64233101aa8f9e2ff98d8be954b1e95 Mon Sep 17 00:00:00 2001 From: Scott Steadman Date: Mon, 3 Feb 2020 15:23:59 -0800 Subject: [PATCH 14/22] fix registry.gemspec I need to set the gem versions since I've locked the ruby version to 1.9. --- registry.gemspec | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/registry.gemspec b/registry.gemspec index 92199d0..7f4c65f 100644 --- a/registry.gemspec +++ b/registry.gemspec @@ -13,12 +13,13 @@ Gem::Specification.new do |gem| gem.add_development_dependency 'iconv' gem.add_development_dependency 'mocha' - gem.add_development_dependency 'rake' - gem.add_development_dependency 'shoulda', '3.0.1' - gem.add_development_dependency 'sqlite3' + gem.add_development_dependency 'rails', '~> 2.3.0' + gem.add_development_dependency 'rake', '0.9.2.2' + gem.add_development_dependency 'shoulda', '3.0.1' + gem.add_development_dependency 'simplecov', '~>0.6.0' + gem.add_development_dependency 'sqlite3', '~>1.3.0' gem.add_dependency 'acts_as_versioned', '~> 0.2.0' - gem.add_dependency 'rails', '~> 2.3.0' gem.files = `git ls-files`.split($/) gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) } From 9b07c3793ebcb925e843c962182b855627eb98c8 Mon Sep 17 00:00:00 2001 From: Scott Steadman Date: Mon, 3 Feb 2020 15:25:30 -0800 Subject: [PATCH 15/22] fix bundle exec rake test Testing works. There are a lot of failures though. --- README | 8 +++++++- config/environments/test.rb | 1 + test/functional/registry/registry_controller_test.rb | 2 +- test/test_helper.rb | 1 - test/unit/registry/entry_test.rb | 2 +- test/unit/registry/transcoder/base_test.rb | 2 +- test/unit/registry/transcoder/dsl_test.rb | 2 +- test/unit/registry_test.rb | 2 +- 8 files changed, 13 insertions(+), 7 deletions(-) diff --git a/README b/README index 57d0ff9..5e098ed 100644 --- a/README +++ b/README @@ -11,8 +11,14 @@ == Testing/Coverage + # setup test environment + rbenv install 1.9.3-p551 + gem install bundler -v '~>1.0.0' bundle install --clean --path=vendor/bundle - bundle exec rake db:create db:migrate + bundle exec rake db:migrate + + # run tests + bundle exec rake test === UI Access diff --git a/config/environments/test.rb b/config/environments/test.rb index fe64305..3ae79b5 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -2,6 +2,7 @@ require 'pp' +require 'test/unit' require 'mocha/setup' # The test environment is used exclusively to run your application's diff --git a/test/functional/registry/registry_controller_test.rb b/test/functional/registry/registry_controller_test.rb index 34e88d7..2d3f597 100644 --- a/test/functional/registry/registry_controller_test.rb +++ b/test/functional/registry/registry_controller_test.rb @@ -1,4 +1,4 @@ -require 'test/test_helper.rb' +require 'test_helper.rb' class Registry::RegistryControllerTest < ActionController::TestCase diff --git a/test/test_helper.rb b/test/test_helper.rb index fefff2e..a536921 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -2,7 +2,6 @@ require File.expand_path(File.dirname(__FILE__) + '/../config/environment') require 'test_help' require 'ostruct' -require 'init' class ActiveSupport::TestCase diff --git a/test/unit/registry/entry_test.rb b/test/unit/registry/entry_test.rb index 37a6004..feb4024 100644 --- a/test/unit/registry/entry_test.rb +++ b/test/unit/registry/entry_test.rb @@ -1,4 +1,4 @@ -require 'test/test_helper' +require 'test_helper' module Registry class EntryTest < ActiveRecord::TestCase diff --git a/test/unit/registry/transcoder/base_test.rb b/test/unit/registry/transcoder/base_test.rb index 6891ba9..f351cd4 100644 --- a/test/unit/registry/transcoder/base_test.rb +++ b/test/unit/registry/transcoder/base_test.rb @@ -1,4 +1,4 @@ -require 'test/test_helper' +require 'test_helper' module Registry module Transcoder diff --git a/test/unit/registry/transcoder/dsl_test.rb b/test/unit/registry/transcoder/dsl_test.rb index fd72c31..403bae1 100644 --- a/test/unit/registry/transcoder/dsl_test.rb +++ b/test/unit/registry/transcoder/dsl_test.rb @@ -1,4 +1,4 @@ -require 'test/test_helper' +require 'test_helper' module Registry module Transcoder diff --git a/test/unit/registry_test.rb b/test/unit/registry_test.rb index 7118e41..daf2ef2 100755 --- a/test/unit/registry_test.rb +++ b/test/unit/registry_test.rb @@ -1,4 +1,4 @@ -require 'test/test_helper' +require 'test_helper' class RegistryTest < ActiveSupport::TestCase From c255a7de1c67f24f1bd36571c190e1e90a726721 Mon Sep 17 00:00:00 2001 From: Scott Steadman Date: Tue, 4 Feb 2020 11:29:09 -0800 Subject: [PATCH 16/22] fix rake test The tests pass. I had to get the acts_as_versioned gem directly from github. This was the version I removed in an earlier commit. --- .gitignore | 1 + Gemfile | 2 ++ registry.gemspec | 2 -- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 51c8657..3ac8628 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,4 @@ db/schema.rb* Gemfile.lock .bundle vendor/bundle +config/registry.yml diff --git a/Gemfile b/Gemfile index e8e3471..3ac4c60 100644 --- a/Gemfile +++ b/Gemfile @@ -1,3 +1,5 @@ source "http://www.rubygems.org" gemspec + +gem 'acts_as_versioned', :git => 'https://github.com/metaskills/acts_as_versioned.git', :ref => '25fc25b' diff --git a/registry.gemspec b/registry.gemspec index 7f4c65f..9938896 100644 --- a/registry.gemspec +++ b/registry.gemspec @@ -19,8 +19,6 @@ Gem::Specification.new do |gem| gem.add_development_dependency 'simplecov', '~>0.6.0' gem.add_development_dependency 'sqlite3', '~>1.3.0' - gem.add_dependency 'acts_as_versioned', '~> 0.2.0' - gem.files = `git ls-files`.split($/) gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) } gem.test_files = gem.files.grep(%r{^(test|spec|features)/}) From df8534bbda6493cc6888cc5a1d0e7a5c41aea796 Mon Sep 17 00:00:00 2001 From: Scott Steadman Date: Tue, 4 Feb 2020 12:44:07 -0800 Subject: [PATCH 17/22] fix rake registry:coverage I had to convert from rcov to simplecov. --- .gitignore | 1 + README | 8 +++----- config/environments/test.rb | 9 +++++++++ lib/tasks/registry.rake | 9 +++------ 4 files changed, 16 insertions(+), 11 deletions(-) diff --git a/.gitignore b/.gitignore index 3ac8628..1ed0492 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,4 @@ Gemfile.lock .bundle vendor/bundle config/registry.yml +public/coverage diff --git a/README b/README index 5e098ed..71fd4b1 100644 --- a/README +++ b/README @@ -20,11 +20,9 @@ # run tests bundle exec rake test -=== UI Access - - script/server - point your browser at http://localhost:3000/registry - + # generate coverage report + bundle exec rake registry:coverage + # point your browser at http://localhost:3000/coverage/ === Usage diff --git a/config/environments/test.rb b/config/environments/test.rb index 3ae79b5..454406f 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -28,3 +28,12 @@ config.action_mailer.delivery_method = :test config.action_controller.session = { :key => "_test_session", :secret => "218d878f47b437169e7de9975d2e1286" } + +if ENV['COVERAGE'] + require 'simplecov' + FileUtils.rm_rf(Rails.root + 'public/coverage') + SimpleCov.start 'rails' do + add_filter '/vendor/bundle/' + coverage_dir 'public/coverage' + end +end diff --git a/lib/tasks/registry.rake b/lib/tasks/registry.rake index 2a74e4a..1d1b8fa 100644 --- a/lib/tasks/registry.rake +++ b/lib/tasks/registry.rake @@ -6,12 +6,9 @@ namespace :registry do end desc 'Generate coverage report' - task :coverage => [:environment] do - excludes = %w[boot.rb config vendor].join(',') - output_dir = "#{Rails.root}/public/coverage" - files = Dir['test/{unit,functional}/**/*_test.rb'].join(' ') - rm_rf(output_dir) - sh "rcov --rails -t --sort coverage -o public/coverage -x 'gems' #{files}" + task :coverage do + ENV['COVERAGE'] = '1' + system('rake test') end desc "Set a registry value (eg 'api.enabled'=true)" From 197deb0bb1032c659b561ba962841f1d47c76a6c Mon Sep 17 00:00:00 2001 From: Scott Steadman Date: Tue, 4 Feb 2020 13:12:14 -0800 Subject: [PATCH 18/22] fix date parsing Entering an invalid date caused the registry to raise an error which prevented our application from coming up. I now try to parse the date in three different formats, and if that fails I just return the string. --- lib/registry/transcoder.rb | 8 +++++++- test/unit/registry/transcoder/base_test.rb | 11 +++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/lib/registry/transcoder.rb b/lib/registry/transcoder.rb index bfa1ff8..6b0356a 100644 --- a/lib/registry/transcoder.rb +++ b/lib/registry/transcoder.rb @@ -34,7 +34,13 @@ # Date transcoder config.add_transcoder do to_db {|value| value.strftime("%Y-%m-%d")} - from_db {|string| Date.parse(string)} + from_db do |string| + result = Date.strptime(string, '%d-%m-%Y') rescue nil + result ||= Date.strptime(string, '%Y-%m-%d') rescue nil + result ||= Date.strptime(string, '%m-%d-%Y') rescue nil + + result || string + end matches do |value| value.is_a?(Date) or # to_db diff --git a/test/unit/registry/transcoder/base_test.rb b/test/unit/registry/transcoder/base_test.rb index f351cd4..4f448d9 100644 --- a/test/unit/registry/transcoder/base_test.rb +++ b/test/unit/registry/transcoder/base_test.rb @@ -24,6 +24,17 @@ class BaseTest < ActiveSupport::TestCase assert_same self, Transcoder.from_db(self) end + test 'date_parsing different formats' do + date_string = '2007-01-16' + assert_equal Date.strptime(date_string, '%Y-%m-%d'), Transcoder.from_db(date_string) + date_string = '01-16-2007' + assert_equal Date.strptime(date_string, '%m-%d-%Y'), Transcoder.from_db(date_string) + date_string = '16-01-2007' + assert_equal Date.strptime(date_string, '%d-%m-%Y'), Transcoder.from_db(date_string) + date_string = '99-99-99' + assert_equal date_string, Transcoder.from_db(date_string) + end + test 'from_db handles leading zeros in ranges' do assert_equal 0 .. 9, Transcoder.from_db('00 .. 09'), 'leading zero range transcoding failed' end From 2d5a71559938ae7bfc3ef39ea771fb38716009fa Mon Sep 17 00:00:00 2001 From: Scott Steadman Date: Tue, 4 Feb 2020 13:21:02 -0800 Subject: [PATCH 19/22] bump version --- VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VERSION b/VERSION index cc6612c..2bf1c1c 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -2.3.0 \ No newline at end of file +2.3.1 From 194df9ddec807351717786eb4b9b5bdaf455ab0b Mon Sep 17 00:00:00 2001 From: Scott Steadman Date: Tue, 4 Feb 2020 13:58:43 -0800 Subject: [PATCH 20/22] move acts_as_versioned from gem It looks like gems specified in Gemfile aren't included when you include the Gem in another project. So I copied the acts_as_versioned file from the gem into our lib directory. --- Gemfile | 2 - lib/acts_as_versioned.rb | 483 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 483 insertions(+), 2 deletions(-) create mode 100644 lib/acts_as_versioned.rb diff --git a/Gemfile b/Gemfile index 3ac4c60..e8e3471 100644 --- a/Gemfile +++ b/Gemfile @@ -1,5 +1,3 @@ source "http://www.rubygems.org" gemspec - -gem 'acts_as_versioned', :git => 'https://github.com/metaskills/acts_as_versioned.git', :ref => '25fc25b' diff --git a/lib/acts_as_versioned.rb b/lib/acts_as_versioned.rb new file mode 100644 index 0000000..ae57a71 --- /dev/null +++ b/lib/acts_as_versioned.rb @@ -0,0 +1,483 @@ +# Copyright (c) 2005 Rick Olson +# +# Permission is hereby granted, free of charge, to any person obtaining +# a copy of this software and associated documentation files (the +# "Software"), to deal in the Software without restriction, including +# without limitation the rights to use, copy, modify, merge, publish, +# distribute, sublicense, and/or sell copies of the Software, and to +# permit persons to whom the Software is furnished to do so, subject to +# the following conditions: +# +# The above copyright notice and this permission notice shall be +# included in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +module ActiveRecord #:nodoc: + module Acts #:nodoc: + # Specify this act if you want to save a copy of the row in a versioned table. This assumes there is a + # versioned table ready and that your model has a version field. This works with optimistic locking if the + # lock_version column is present as well. + # + # The class for the versioned model is derived the first time it is seen. Therefore, if you change your + # database schema you have to restart your container for the changes to be reflected. In development mode + # this usually means restarting WEBrick. + # + # class Page < ActiveRecord::Base + # # assumes pages_versions table + # acts_as_versioned + # end + # + # Example: + # + # page = Page.create(:title => 'hello world!') + # page.version # => 1 + # + # page.title = 'hello world' + # page.save + # page.version # => 2 + # page.versions.size # => 2 + # + # page.revert_to(1) # using version number + # page.title # => 'hello world!' + # + # page.revert_to(page.versions.last) # using versioned instance + # page.title # => 'hello world' + # + # page.versions.earliest # efficient query to find the first version + # page.versions.latest # efficient query to find the most recently created version + # + # + # Simple Queries to page between versions + # + # page.versions.before(version) + # page.versions.after(version) + # + # Access the previous/next versions from the versioned model itself + # + # version = page.versions.latest + # version.previous # go back one version + # version.next # go forward one version + # + # See ActiveRecord::Acts::Versioned::ClassMethods#acts_as_versioned for configuration options + module Versioned + CALLBACKS = [:set_new_version, :save_version, :save_version?] + def self.included(base) # :nodoc: + base.extend ClassMethods + end + + module ClassMethods + # == Configuration options + # + # * class_name - versioned model class name (default: PageVersion in the above example) + # * table_name - versioned model table name (default: page_versions in the above example) + # * foreign_key - foreign key used to relate the versioned model to the original model (default: page_id in the above example) + # * inheritance_column - name of the column to save the model's inheritance_column value for STI. (default: versioned_type) + # * version_column - name of the column in the model that keeps the version number (default: version) + # * sequence_name - name of the custom sequence to be used by the versioned model. + # * limit - number of revisions to keep, defaults to unlimited + # * if - symbol of method to check before saving a new version. If this method returns false, a new version is not saved. + # For finer control, pass either a Proc or modify Model#version_condition_met? + # + # acts_as_versioned :if => Proc.new { |auction| !auction.expired? } + # + # or... + # + # class Auction + # def version_condition_met? # totally bypasses the :if option + # !expired? + # end + # end + # + # * if_changed - Simple way of specifying attributes that are required to be changed before saving a model. This takes + # either a symbol or array of symbols. + # + # * extend - Lets you specify a module to be mixed in both the original and versioned models. You can also just pass a block + # to create an anonymous mixin: + # + # class Auction + # acts_as_versioned do + # def started? + # !started_at.nil? + # end + # end + # end + # + # or... + # + # module AuctionExtension + # def started? + # !started_at.nil? + # end + # end + # class Auction + # acts_as_versioned :extend => AuctionExtension + # end + # + # Example code: + # + # @auction = Auction.find(1) + # @auction.started? + # @auction.versions.first.started? + # + # == Database Schema + # + # The model that you're versioning needs to have a 'version' attribute. The model is versioned into a + # table called #{model}_versions where the model name is singlular. The _versions table should contain + # all the fields you want versioned, the same version column, and a #{model}_id foreign key field. + # + # A lock_version field is also accepted if your model uses Optimistic Locking. If your table uses Single + # Table inheritance, then that field is reflected in the versioned model as 'versioned_type' by default. + # + # Acts_as_versioned comes prepared with the ActiveRecord::Acts::Versioned::ActMethods::ClassMethods#create_versioned_table + # method, perfect for a migration. It will also create the version column if the main model does not + # already have it. + # + # class AddVersions < ActiveRecord::Migration + # def self.up + # # create_versioned_table takes the same options hash + # # that create_table does + # Post.create_versioned_table + # end + # + # def self.down + # Post.drop_versioned_table + # end + # end + # + # == Changing What Fields Are Versioned + # + # By default, acts_as_versioned will version all but these fields: + # + # [self.primary_key, inheritance_column, 'version', 'lock_version', versioned_inheritance_column] + # + # You can add or change those by modifying #non_versioned_columns. Note that this takes strings and not symbols. + # + # class Post < ActiveRecord::Base + # acts_as_versioned + # self.non_versioned_columns << 'comments_count' + # end + # + def acts_as_versioned(options = {}, &extension) + # don't allow multiple calls + return if self.included_modules.include?(ActiveRecord::Acts::Versioned::ActMethods) + + send :include, ActiveRecord::Acts::Versioned::ActMethods + + cattr_accessor :versioned_class_name, :versioned_foreign_key, :versioned_table_name, :versioned_inheritance_column, + :version_column, :max_version_limit, :track_altered_attributes, :version_condition, :version_sequence_name, :non_versioned_columns, + :version_association_options, :version_if_changed + + self.versioned_class_name = options[:class_name] || "Version" + self.versioned_foreign_key = options[:foreign_key] || self.to_s.foreign_key + self.versioned_table_name = options[:table_name] || "#{table_name_prefix}#{base_class.name.demodulize.underscore}_versions#{table_name_suffix}" + self.versioned_inheritance_column = options[:inheritance_column] || "versioned_#{inheritance_column}" + self.version_column = options[:version_column] || 'version' + self.version_sequence_name = options[:sequence_name] + self.max_version_limit = options[:limit].to_i + self.version_condition = options[:if] || true + self.non_versioned_columns = [self.primary_key, inheritance_column, self.version_column, 'lock_version', versioned_inheritance_column, 'created_at', 'created_on'] + options[:non_versioned_columns].to_a.map(&:to_s) + self.version_association_options = { + :class_name => "#{self.to_s}::#{versioned_class_name}", + :foreign_key => versioned_foreign_key, + :order => "#{version_column} ASC" + }.merge(options[:association_options] || {}) + + if block_given? + extension_module_name = "#{versioned_class_name}Extension" + silence_warnings do + self.const_set(extension_module_name, Module.new(&extension)) + end + + options[:extend] = self.const_get(extension_module_name) + end + + class_eval <<-CLASS_METHODS + has_many :versions, version_association_options do + # finds earliest version of this record + def earliest + @earliest ||= find(:first, :order => '#{version_column}') + end + + # find latest version of this record + def latest + @latest ||= find(:first, :order => '#{version_column} desc') + end + end + before_save :set_new_version + after_save :save_version + after_save :clear_old_versions + + unless options[:if_changed].nil? + self.track_altered_attributes = true + options[:if_changed] = [options[:if_changed]] unless options[:if_changed].is_a?(Array) + self.version_if_changed = options[:if_changed].map(&:to_s) + end + + include options[:extend] if options[:extend].is_a?(Module) + CLASS_METHODS + + # create the dynamic versioned model + const_set(versioned_class_name, Class.new(ActiveRecord::Base)).class_eval do + def self.reloadable? ; false ; end + # find first version before the given version + def self.before(version) + find :first, :order => 'version desc', + :conditions => ["#{original_class.versioned_foreign_key} = ? and version < ?", version.send(original_class.versioned_foreign_key), version.version] + end + + # find first version after the given version. + def self.after(version) + find :first, :order => 'version', + :conditions => ["#{original_class.versioned_foreign_key} = ? and version > ?", version.send(original_class.versioned_foreign_key), version.version] + end + + def previous + self.class.before(self) + end + + def next + self.class.after(self) + end + + end + + versioned_class.cattr_accessor :original_class + versioned_class.original_class = self + versioned_class.set_table_name versioned_table_name + versioned_class.belongs_to self.to_s.demodulize.underscore.to_sym, + :class_name => "::#{self.to_s}", + :foreign_key => versioned_foreign_key + versioned_class.send :include, options[:extend] if options[:extend].is_a?(Module) + versioned_class.set_sequence_name version_sequence_name if version_sequence_name + end + end + + module ActMethods + def self.included(base) # :nodoc: + base.extend ClassMethods + end + + # Saves a version of the model in the versioned table. This is called in the after_save callback by default + def save_version + if @saving_version + @saving_version = nil + rev = self.class.versioned_class.new + clone_versioned_model(self, rev) + rev.send("#{self.class.version_column}=", send(self.class.version_column)) + rev.send("#{self.class.versioned_foreign_key}=", id) + rev.save + end + end + + # Clears old revisions if a limit is set with the :limit option in acts_as_versioned. + # Override this method to set your own criteria for clearing old versions. + def clear_old_versions + return if self.class.max_version_limit == 0 + excess_baggage = send(self.class.version_column).to_i - self.class.max_version_limit + if excess_baggage > 0 + self.class.versioned_class.delete_all ["#{self.class.version_column} <= ? and #{self.class.versioned_foreign_key} = ?", excess_baggage, id] + end + end + + # Reverts a model to a given version. Takes either a version number or an instance of the versioned model + def revert_to(version) + if version.is_a?(self.class.versioned_class) + return false unless version.send(self.class.versioned_foreign_key) == id and !version.new_record? + else + return false unless version = versions.send("find_by_#{self.class.version_column}", version) + end + self.clone_versioned_model(version, self) + send("#{self.class.version_column}=", version.send(self.class.version_column)) + true + end + + # Reverts a model to a given version and saves the model. + # Takes either a version number or an instance of the versioned model + def revert_to!(version) + revert_to(version) ? save_without_revision : false + end + + # Temporarily turns off Optimistic Locking while saving. Used when reverting so that a new version is not created. + def save_without_revision + save_without_revision! + true + rescue + false + end + + def save_without_revision! + without_locking do + without_revision do + save! + end + end + end + + def altered? + track_altered_attributes ? (version_if_changed - changed).length < version_if_changed.length : changed? + end + + # Clones a model. Used when saving a new version or reverting a model's version. + def clone_versioned_model(orig_model, new_model) + self.class.versioned_columns.each do |col| + new_model.send("#{col.name}=", orig_model.send(col.name)) if orig_model.has_attribute?(col.name) + end + + if orig_model.is_a?(self.class.versioned_class) + new_model[new_model.class.inheritance_column] = orig_model[self.class.versioned_inheritance_column] + elsif new_model.is_a?(self.class.versioned_class) + new_model[self.class.versioned_inheritance_column] = orig_model[orig_model.class.inheritance_column] + end + end + + # Checks whether a new version shall be saved or not. Calls version_condition_met? and changed?. + def save_version? + version_condition_met? && altered? + end + + # Checks condition set in the :if option to check whether a revision should be created or not. Override this for + # custom version condition checking. + def version_condition_met? + case + when version_condition.is_a?(Symbol) + send(version_condition) + when version_condition.respond_to?(:call) && (version_condition.arity == 1 || version_condition.arity == -1) + version_condition.call(self) + else + version_condition + end + end + + # Executes the block with the versioning callbacks disabled. + # + # @foo.without_revision do + # @foo.save + # end + # + def without_revision(&block) + self.class.without_revision(&block) + end + + # Turns off optimistic locking for the duration of the block + # + # @foo.without_locking do + # @foo.save + # end + # + def without_locking(&block) + self.class.without_locking(&block) + end + + def empty_callback() end #:nodoc: + + protected + # sets the new version before saving, unless you're using optimistic locking. In that case, let it take care of the version. + def set_new_version + @saving_version = new_record? || save_version? + self.send("#{self.class.version_column}=", next_version) if new_record? || (!locking_enabled? && save_version?) + end + + # Gets the next available version for the current record, or 1 for a new record + def next_version + (new_record? ? 0 : versions.calculate(:max, version_column).to_i) + 1 + end + + module ClassMethods + # Returns an array of columns that are versioned. See non_versioned_columns + def versioned_columns + @versioned_columns ||= columns.select { |c| !non_versioned_columns.include?(c.name) } + end + + # Returns an instance of the dynamic versioned model + def versioned_class + const_get versioned_class_name + end + + # Rake migration task to create the versioned table using options passed to acts_as_versioned + def create_versioned_table(create_table_options = {}) + # create version column in main table if it does not exist + if !self.content_columns.find { |c| [version_column.to_s, 'lock_version'].include? c.name } + self.connection.add_column table_name, version_column, :integer + self.reset_column_information + end + + return if connection.table_exists?(versioned_table_name) + + self.connection.create_table(versioned_table_name, create_table_options) do |t| + t.column versioned_foreign_key, :integer + t.column version_column, :integer + end + + self.versioned_columns.each do |col| + self.connection.add_column versioned_table_name, col.name, col.type, + :limit => col.limit, + :default => col.default, + :scale => col.scale, + :precision => col.precision + end + + if type_col = self.columns_hash[inheritance_column] + self.connection.add_column versioned_table_name, versioned_inheritance_column, type_col.type, + :limit => type_col.limit, + :default => type_col.default, + :scale => type_col.scale, + :precision => type_col.precision + end + + self.connection.add_index versioned_table_name, versioned_foreign_key + end + + # Rake migration task to drop the versioned table + def drop_versioned_table + self.connection.drop_table versioned_table_name + end + + # Executes the block with the versioning callbacks disabled. + # + # Foo.without_revision do + # @foo.save + # end + # + def without_revision(&block) + class_eval do + CALLBACKS.each do |attr_name| + alias_method "orig_#{attr_name}".to_sym, attr_name + alias_method attr_name, :empty_callback + end + end + block.call + ensure + class_eval do + CALLBACKS.each do |attr_name| + alias_method attr_name, "orig_#{attr_name}".to_sym + end + end + end + + # Turns off optimistic locking for the duration of the block + # + # Foo.without_locking do + # @foo.save + # end + # + def without_locking(&block) + current = ActiveRecord::Base.lock_optimistically + ActiveRecord::Base.lock_optimistically = false if current + result = block.call + ActiveRecord::Base.lock_optimistically = true if current + result + end + end + end + end + end +end + +ActiveRecord::Base.send :include, ActiveRecord::Acts::Versioned \ No newline at end of file From 0a8046eecdfcd4865c9cd53122d79ba9a1fd9c81 Mon Sep 17 00:00:00 2001 From: Scott Steadman Date: Tue, 5 Apr 2022 14:15:33 -0700 Subject: [PATCH 21/22] add :verbose option to Registry::Entry.import! There's something wonky with our config/registry.yml and I need some more details. I decided that adding a :verbose flag would be easier than rescuing the error, updating the messge and re-raising. --- README | 2 +- app/models/registry/entry.rb | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/README b/README index 71fd4b1..bac62bf 100644 --- a/README +++ b/README @@ -103,7 +103,7 @@ desc 'Import configuration' task :import_configuration => [:environment] do - Registry.import("#{Rails.root}/config/registry.yml") + Registry.import("#{Rails.root}/config/registry.yml", :verbose => true) end --- diff --git a/app/models/registry/entry.rb b/app/models/registry/entry.rb index 659b065..426f46e 100644 --- a/app/models/registry/entry.rb +++ b/app/models/registry/entry.rb @@ -85,7 +85,12 @@ def self.export!(file_path = DEFAULT_YML_LOCATION) # ==== Parameters # # * +file_path+ - Path to yml file. - # * +opts+ - Optional, merge options (see documentation for merge method) + # * +opts+ - Optional parameters + # + # ==== Options + # + # * verbose - If true, print information to stderr. + # * merge options (see documentation for merge method) # # ==== File Format # @@ -113,6 +118,7 @@ def self.import!(file_path = DEFAULT_YML_LOCATION, opts={}) hash = YAML.load_file(file_path) default_entries = hash.delete(Registry::DEFAULTS_KEY) || {} hash.each do |env, entries| + STDERR.puts "Importing: #{env}" if opts[:verbose] root(env).merge(default_entries.deep_merge(entries), opts) end end From 184efbbb395a31640384135fa3244b0fb5d54589 Mon Sep 17 00:00:00 2001 From: Mike Stangel Date: Fri, 28 Jun 2024 05:33:45 -0700 Subject: [PATCH 22/22] replace script tags with javascript_tag method so our app can insert the CSP nonce --- app/views/registry/registry/viewport.html.erb | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/app/views/registry/registry/viewport.html.erb b/app/views/registry/registry/viewport.html.erb index 4e228c5..88a7038 100644 --- a/app/views/registry/registry/viewport.html.erb +++ b/app/views/registry/registry/viewport.html.erb @@ -10,16 +10,16 @@ - + } %>