modified_acts_as_versioned 0.5.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/CHANGELOG +82 -0
- data/MIT-LICENSE +20 -0
- data/README +28 -0
- data/RUNNING_UNIT_TESTS +41 -0
- data/Rakefile +50 -0
- data/VERSION.yml +4 -0
- data/acts_as_versioned.gemspec +29 -0
- data/init.rb +1 -0
- data/lib/acts_as_versioned.rb +488 -0
- data/rdoc/classes/ActiveRecord/Acts/Versioned/ActMethods/ClassMethods.html +336 -0
- data/rdoc/classes/ActiveRecord/Acts/Versioned/ActMethods.html +581 -0
- data/rdoc/classes/ActiveRecord/Acts/Versioned/ClassMethods.html +506 -0
- data/rdoc/classes/ActiveRecord/Acts/Versioned.html +187 -0
- data/rdoc/created.rid +1 -0
- data/rdoc/files/CHANGELOG.html +288 -0
- data/rdoc/files/README.html +158 -0
- data/rdoc/files/RUNNING_UNIT_TESTS.html +158 -0
- data/rdoc/files/lib/acts_as_versioned_rb.html +129 -0
- data/rdoc/fr_class_index.html +30 -0
- data/rdoc/fr_file_index.html +30 -0
- data/rdoc/fr_method_index.html +54 -0
- data/rdoc/index.html +24 -0
- data/rdoc/rdoc-style.css +208 -0
- data/test/abstract_unit.rb +60 -0
- data/test/database.yml +18 -0
- data/test/fixtures/authors.yml +6 -0
- data/test/fixtures/landmark.rb +3 -0
- data/test/fixtures/landmark_versions.yml +7 -0
- data/test/fixtures/landmarks.yml +7 -0
- data/test/fixtures/locked_pages.yml +10 -0
- data/test/fixtures/locked_pages_revisions.yml +27 -0
- data/test/fixtures/migrations/1_add_versioned_tables.rb +15 -0
- data/test/fixtures/page.rb +48 -0
- data/test/fixtures/page_versions.yml +16 -0
- data/test/fixtures/pages.yml +8 -0
- data/test/fixtures/widget.rb +6 -0
- data/test/migration_test.rb +47 -0
- data/test/schema.rb +82 -0
- data/test/versioned_test.rb +379 -0
- metadata +114 -0
@@ -0,0 +1,60 @@
|
|
1
|
+
$:.unshift(File.dirname(__FILE__) + '/../../../rails/activesupport/lib')
|
2
|
+
$:.unshift(File.dirname(__FILE__) + '/../../../rails/activerecord/lib')
|
3
|
+
$:.unshift(File.dirname(__FILE__) + '/../lib')
|
4
|
+
require 'test/unit'
|
5
|
+
begin
|
6
|
+
require 'active_support'
|
7
|
+
require 'active_record'
|
8
|
+
require 'active_record/fixtures'
|
9
|
+
rescue LoadError
|
10
|
+
require 'rubygems'
|
11
|
+
retry
|
12
|
+
end
|
13
|
+
|
14
|
+
begin
|
15
|
+
require 'ruby-debug'
|
16
|
+
Debugger.start
|
17
|
+
rescue LoadError
|
18
|
+
end
|
19
|
+
|
20
|
+
require 'acts_as_versioned'
|
21
|
+
|
22
|
+
config = YAML::load(IO.read(File.dirname(__FILE__) + '/database.yml'))
|
23
|
+
ActiveRecord::Base.logger = Logger.new(File.dirname(__FILE__) + "/debug.log")
|
24
|
+
ActiveRecord::Base.configurations = {'test' => config[ENV['DB'] || 'sqlite3']}
|
25
|
+
ActiveRecord::Base.establish_connection(ActiveRecord::Base.configurations['test'])
|
26
|
+
|
27
|
+
load(File.dirname(__FILE__) + "/schema.rb")
|
28
|
+
|
29
|
+
# set up custom sequence on widget_versions for DBs that support sequences
|
30
|
+
if ENV['DB'] == 'postgresql'
|
31
|
+
ActiveRecord::Base.connection.execute "DROP SEQUENCE widgets_seq;" rescue nil
|
32
|
+
ActiveRecord::Base.connection.remove_column :widget_versions, :id
|
33
|
+
ActiveRecord::Base.connection.execute "CREATE SEQUENCE widgets_seq START 101;"
|
34
|
+
ActiveRecord::Base.connection.execute "ALTER TABLE widget_versions ADD COLUMN id INTEGER PRIMARY KEY DEFAULT nextval('widgets_seq');"
|
35
|
+
end
|
36
|
+
|
37
|
+
|
38
|
+
fixture_path_klazz = Test::Unit::TestCase
|
39
|
+
if defined?(ActiveRecord::TestFixtures)
|
40
|
+
fixture_path_klazz = ActiveSupport::TestCase
|
41
|
+
class ActiveSupport::TestCase
|
42
|
+
include ActiveRecord::TestFixtures
|
43
|
+
end
|
44
|
+
end
|
45
|
+
fixture_path_klazz.fixture_path = File.dirname(__FILE__) + "/fixtures"
|
46
|
+
$LOAD_PATH.unshift(fixture_path_klazz.fixture_path)
|
47
|
+
|
48
|
+
#Test::Unit::TestCase.fixture_path = File.dirname(__FILE__) + "/fixtures/"
|
49
|
+
#$:.unshift(Test::Unit::TestCase.fixture_path)
|
50
|
+
|
51
|
+
#class Test::Unit::TestCase #:nodoc:
|
52
|
+
class ActiveSupport::TestCase #:nodoc:
|
53
|
+
# Turn off transactional fixtures if you're working with MyISAM tables in MySQL
|
54
|
+
self.use_transactional_fixtures = true
|
55
|
+
|
56
|
+
# Instantiated fixtures are slow, but give you @david where you otherwise would need people(:david)
|
57
|
+
self.use_instantiated_fixtures = false
|
58
|
+
|
59
|
+
# Add more helper methods to be used by all tests here...
|
60
|
+
end
|
data/test/database.yml
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
sqlite:
|
2
|
+
:adapter: sqlite
|
3
|
+
:dbfile: acts_as_versioned_plugin.sqlite.db
|
4
|
+
sqlite3:
|
5
|
+
:adapter: sqlite3
|
6
|
+
:dbfile: acts_as_versioned_plugin.sqlite3.db
|
7
|
+
postgresql:
|
8
|
+
:adapter: postgresql
|
9
|
+
:username: postgres
|
10
|
+
:password: postgres
|
11
|
+
:database: acts_as_versioned_plugin_test
|
12
|
+
:min_messages: ERROR
|
13
|
+
mysql:
|
14
|
+
:adapter: mysql
|
15
|
+
:host: localhost
|
16
|
+
:username: rails
|
17
|
+
:password:
|
18
|
+
:database: acts_as_versioned_plugin_test
|
@@ -0,0 +1,27 @@
|
|
1
|
+
welcome_1:
|
2
|
+
id: 1
|
3
|
+
page_id: 1
|
4
|
+
title: Welcome to the weblg
|
5
|
+
lock_version: 23
|
6
|
+
version_type: LockedPage
|
7
|
+
|
8
|
+
welcome_2:
|
9
|
+
id: 2
|
10
|
+
page_id: 1
|
11
|
+
title: Welcome to the weblog
|
12
|
+
lock_version: 24
|
13
|
+
version_type: LockedPage
|
14
|
+
|
15
|
+
thinking_1:
|
16
|
+
id: 3
|
17
|
+
page_id: 2
|
18
|
+
title: So I was thinking!!!
|
19
|
+
lock_version: 23
|
20
|
+
version_type: SpecialLockedPage
|
21
|
+
|
22
|
+
thinking_2:
|
23
|
+
id: 4
|
24
|
+
page_id: 2
|
25
|
+
title: So I was thinking
|
26
|
+
lock_version: 24
|
27
|
+
version_type: SpecialLockedPage
|
@@ -0,0 +1,15 @@
|
|
1
|
+
class AddVersionedTables < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
create_table("things") do |t|
|
4
|
+
t.column :title, :text
|
5
|
+
t.column :price, :decimal, :precision => 7, :scale => 2
|
6
|
+
t.column :type, :string
|
7
|
+
end
|
8
|
+
Thing.create_versioned_table
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.down
|
12
|
+
Thing.drop_versioned_table
|
13
|
+
drop_table "things" rescue nil
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
class Page < ActiveRecord::Base
|
2
|
+
belongs_to :author
|
3
|
+
has_many :authors, :through => :versions, :order => 'name'
|
4
|
+
belongs_to :revisor, :class_name => 'Author'
|
5
|
+
has_many :revisors, :class_name => 'Author', :through => :versions, :order => 'name'
|
6
|
+
acts_as_versioned :if => :feeling_good? do
|
7
|
+
def self.included(base)
|
8
|
+
base.cattr_accessor :feeling_good
|
9
|
+
base.feeling_good = true
|
10
|
+
base.belongs_to :author
|
11
|
+
base.belongs_to :revisor, :class_name => 'Author'
|
12
|
+
end
|
13
|
+
|
14
|
+
def feeling_good?
|
15
|
+
@@feeling_good == true
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
class AlternativeVersionsNamePage < ActiveRecord::Base
|
21
|
+
set_table_name "pages"
|
22
|
+
acts_as_versioned :versions_name => :happy_versions, :table_name => 'page_versions', :foreign_key => 'page_id'
|
23
|
+
end
|
24
|
+
|
25
|
+
module LockedPageExtension
|
26
|
+
def hello_world
|
27
|
+
'hello_world'
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
class LockedPage < ActiveRecord::Base
|
32
|
+
acts_as_versioned \
|
33
|
+
:inheritance_column => :version_type,
|
34
|
+
:foreign_key => :page_id,
|
35
|
+
:table_name => :locked_pages_revisions,
|
36
|
+
:class_name => 'LockedPageRevision',
|
37
|
+
:version_column => :lock_version,
|
38
|
+
:limit => 2,
|
39
|
+
:if_changed => :title,
|
40
|
+
:extend => LockedPageExtension
|
41
|
+
end
|
42
|
+
|
43
|
+
class SpecialLockedPage < LockedPage
|
44
|
+
end
|
45
|
+
|
46
|
+
class Author < ActiveRecord::Base
|
47
|
+
has_many :pages
|
48
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
welcome_2:
|
2
|
+
id: 1
|
3
|
+
page_id: 1
|
4
|
+
title: Welcome to the weblog
|
5
|
+
body: Such a lovely day
|
6
|
+
version: 24
|
7
|
+
author_id: 1
|
8
|
+
revisor_id: 1
|
9
|
+
welcome_1:
|
10
|
+
id: 2
|
11
|
+
page_id: 1
|
12
|
+
title: Welcome to the weblg
|
13
|
+
body: Such a lovely day
|
14
|
+
version: 23
|
15
|
+
author_id: 2
|
16
|
+
revisor_id: 2
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'abstract_unit')
|
2
|
+
|
3
|
+
if ActiveRecord::Base.connection.supports_migrations?
|
4
|
+
class Thing < ActiveRecord::Base
|
5
|
+
attr_accessor :version
|
6
|
+
acts_as_versioned
|
7
|
+
end
|
8
|
+
|
9
|
+
# class MigrationTest < Test::Unit::TestCase
|
10
|
+
class MigrationTest < ActiveSupport::TestCase
|
11
|
+
self.use_transactional_fixtures = false
|
12
|
+
def teardown
|
13
|
+
if ActiveRecord::Base.connection.respond_to?(:initialize_schema_information)
|
14
|
+
ActiveRecord::Base.connection.initialize_schema_information
|
15
|
+
ActiveRecord::Base.connection.update "UPDATE schema_info SET version = 0"
|
16
|
+
else
|
17
|
+
ActiveRecord::Base.connection.initialize_schema_migrations_table
|
18
|
+
ActiveRecord::Base.connection.assume_migrated_upto_version(0)
|
19
|
+
end
|
20
|
+
|
21
|
+
Thing.connection.drop_table "things" rescue nil
|
22
|
+
Thing.connection.drop_table "thing_versions" rescue nil
|
23
|
+
Thing.reset_column_information
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_versioned_migration
|
27
|
+
assert_raises(ActiveRecord::StatementInvalid) { Thing.create :title => 'blah blah' }
|
28
|
+
# take 'er up
|
29
|
+
ActiveRecord::Migrator.up(File.dirname(__FILE__) + '/fixtures/migrations/')
|
30
|
+
t = Thing.create :title => 'blah blah', :price => 123.45, :type => 'Thing'
|
31
|
+
assert_equal 1, t.versions.size
|
32
|
+
|
33
|
+
# check that the price column has remembered its value correctly
|
34
|
+
assert_equal t.price, t.versions.first.price
|
35
|
+
assert_equal t.title, t.versions.first.title
|
36
|
+
assert_equal t[:type], t.versions.first[:type]
|
37
|
+
|
38
|
+
# make sure that the precision of the price column has been preserved
|
39
|
+
assert_equal 7, Thing::Version.columns.find{|c| c.name == "price"}.precision
|
40
|
+
assert_equal 2, Thing::Version.columns.find{|c| c.name == "price"}.scale
|
41
|
+
|
42
|
+
# now lets take 'er back down
|
43
|
+
ActiveRecord::Migrator.down(File.dirname(__FILE__) + '/fixtures/migrations/')
|
44
|
+
assert_raises(ActiveRecord::StatementInvalid) { Thing.create :title => 'blah blah' }
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
data/test/schema.rb
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
ActiveRecord::Schema.define(:version => 0) do
|
2
|
+
create_table :pages, :force => true do |t|
|
3
|
+
t.column :version, :integer
|
4
|
+
t.column :title, :string, :limit => 255
|
5
|
+
t.column :body, :text
|
6
|
+
t.column :created_on, :datetime
|
7
|
+
t.column :updated_on, :datetime
|
8
|
+
t.column :author_id, :integer
|
9
|
+
t.column :revisor_id, :integer
|
10
|
+
end
|
11
|
+
|
12
|
+
create_table :page_versions, :force => true do |t|
|
13
|
+
t.column :page_id, :integer
|
14
|
+
t.column :version, :integer
|
15
|
+
t.column :title, :string, :limit => 255
|
16
|
+
t.column :body, :text
|
17
|
+
t.column :created_on, :datetime
|
18
|
+
t.column :updated_on, :datetime
|
19
|
+
t.column :author_id, :integer
|
20
|
+
t.column :revisor_id, :integer
|
21
|
+
end
|
22
|
+
|
23
|
+
add_index :page_versions, [:page_id, :version], :unique => true
|
24
|
+
|
25
|
+
create_table :authors, :force => true do |t|
|
26
|
+
t.column :page_id, :integer
|
27
|
+
t.column :name, :string
|
28
|
+
end
|
29
|
+
|
30
|
+
create_table :locked_pages, :force => true do |t|
|
31
|
+
t.column :lock_version, :integer
|
32
|
+
t.column :title, :string, :limit => 255
|
33
|
+
t.column :body, :text
|
34
|
+
t.column :type, :string, :limit => 255
|
35
|
+
end
|
36
|
+
|
37
|
+
create_table :locked_pages_revisions, :force => true do |t|
|
38
|
+
t.column :page_id, :integer
|
39
|
+
t.column :lock_version, :integer
|
40
|
+
t.column :title, :string, :limit => 255
|
41
|
+
t.column :body, :text
|
42
|
+
t.column :version_type, :string, :limit => 255
|
43
|
+
t.column :updated_at, :datetime
|
44
|
+
end
|
45
|
+
|
46
|
+
add_index :locked_pages_revisions, [:page_id, :lock_version], :unique => true
|
47
|
+
|
48
|
+
create_table :widgets, :force => true do |t|
|
49
|
+
t.column :name, :string, :limit => 50
|
50
|
+
t.column :foo, :string
|
51
|
+
t.column :version, :integer
|
52
|
+
t.column :updated_at, :datetime
|
53
|
+
end
|
54
|
+
|
55
|
+
create_table :widget_versions, :force => true do |t|
|
56
|
+
t.column :widget_id, :integer
|
57
|
+
t.column :name, :string, :limit => 50
|
58
|
+
t.column :version, :integer
|
59
|
+
t.column :updated_at, :datetime
|
60
|
+
end
|
61
|
+
|
62
|
+
add_index :widget_versions, [:widget_id, :version], :unique => true
|
63
|
+
|
64
|
+
create_table :landmarks, :force => true do |t|
|
65
|
+
t.column :name, :string
|
66
|
+
t.column :latitude, :float
|
67
|
+
t.column :longitude, :float
|
68
|
+
t.column :doesnt_trigger_version,:string
|
69
|
+
t.column :version, :integer
|
70
|
+
end
|
71
|
+
|
72
|
+
create_table :landmark_versions, :force => true do |t|
|
73
|
+
t.column :landmark_id, :integer
|
74
|
+
t.column :name, :string
|
75
|
+
t.column :latitude, :float
|
76
|
+
t.column :longitude, :float
|
77
|
+
t.column :doesnt_trigger_version,:string
|
78
|
+
t.column :version, :integer
|
79
|
+
end
|
80
|
+
|
81
|
+
add_index :landmark_versions, [:landmark_id, :version], :unique => true
|
82
|
+
end
|