acts_as_versioned 0.1.3 → 0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG +11 -0
- data/README +16 -8
- data/lib/acts_as_versioned.rb +50 -32
- data/test/debug.log +99 -0
- data/test/fixtures/activerecord_versioned.sqlite +0 -0
- data/test/fixtures/db_definitions/postgresql.sql +19 -1
- data/test/fixtures/widget.rb +3 -0
- data/test/migration_test.rb +5 -3
- data/test/versioned_test.rb +10 -0
- metadata +5 -2
data/CHANGELOG
CHANGED
@@ -1,3 +1,14 @@
|
|
1
|
+
*0.2*
|
2
|
+
|
3
|
+
* (6 Oct 2005) added find_versions and find_version class methods.
|
4
|
+
|
5
|
+
* (6 Oct 2005) removed transaction from create_versioned_table().
|
6
|
+
this way you can specify your own transaction around a group of operations.
|
7
|
+
|
8
|
+
* (30 Sep 2005) fixed bug where find_versions() would order by 'version' twice. (found by Joe Clark)
|
9
|
+
|
10
|
+
* (26 Sep 2005) added :sequence_name option to acts_as_versioned to set the sequence name on the versioned model
|
11
|
+
|
1
12
|
*0.1.3* (18 Sep 2005)
|
2
13
|
|
3
14
|
* First RubyForge release
|
data/README
CHANGED
@@ -2,19 +2,27 @@
|
|
2
2
|
|
3
3
|
This library adds simple versioning to an ActiveRecord module. ActiveRecord is required.
|
4
4
|
|
5
|
-
==
|
5
|
+
== Resources
|
6
6
|
|
7
|
-
|
7
|
+
Install
|
8
8
|
|
9
|
-
|
10
|
-
|
11
|
-
Download:
|
9
|
+
* gem install acts_as_versioned
|
12
10
|
|
13
|
-
|
11
|
+
Rubyforge project
|
14
12
|
|
15
|
-
|
13
|
+
* http://rubyforge.org/projects/ar-versioned
|
16
14
|
|
17
|
-
RDocs
|
15
|
+
RDocs
|
16
|
+
|
17
|
+
* http://ar-versioned.rubyforge.org
|
18
|
+
|
19
|
+
Subversion
|
20
|
+
|
21
|
+
* http://techno-weenie.net/svn/projects/acts_as_versioned
|
22
|
+
|
23
|
+
Collaboa
|
24
|
+
|
25
|
+
* http://collaboa.techno-weenie.net/repository/browse/acts_as_versioned
|
18
26
|
|
19
27
|
Special thanks to Dreamer on ##rubyonrails for help in early testing. His ServerSideWiki (http://serversidewiki.com)
|
20
28
|
was the first project to use acts_as_versioned <em>in the wild</em>.
|
data/lib/acts_as_versioned.rb
CHANGED
@@ -60,6 +60,7 @@ module ActiveRecord #:nodoc:
|
|
60
60
|
# * <tt>foreign_key</tt> - foreign key used to relate the versioned model to the original model (default: page_id in the above example)
|
61
61
|
# * <tt>inheritance_column</tt> - name of the column to save the model's inheritance_column value for STI. (default: versioned_type)
|
62
62
|
# * <tt>version_column</tt> - name of the column in the model that keeps the version number (default: version)
|
63
|
+
# * <tt>sequence_name</tt> - name of the custom sequence to be used by the versioned model.
|
63
64
|
# * <tt>limit</tt> - number of revisions to keep, defaults to unlimited
|
64
65
|
# * <tt>if</tt> - symbol of method to check before saving a new version. If this method returns false, a new version is not saved.
|
65
66
|
# For finer control, pass either a Proc or modify Model#version_condition_met?
|
@@ -107,7 +108,7 @@ module ActiveRecord #:nodoc:
|
|
107
108
|
class_eval do
|
108
109
|
include ActiveRecord::Acts::Versioned::ActMethods
|
109
110
|
cattr_accessor :versioned_class_name, :versioned_foreign_key, :versioned_table_name, :versioned_inheritance_column,
|
110
|
-
:version_column, :max_version_limit, :track_changed_attributes, :version_condition
|
111
|
+
:version_column, :max_version_limit, :track_changed_attributes, :version_condition, :version_sequence_name
|
111
112
|
attr_accessor :changed_attributes
|
112
113
|
end
|
113
114
|
|
@@ -116,6 +117,7 @@ module ActiveRecord #:nodoc:
|
|
116
117
|
self.versioned_table_name = options[:table_name] || "#{table_name_prefix}#{Inflector.underscore(Inflector.demodulize(class_name_of_active_record_descendant(self)))}_versions#{table_name_suffix}"
|
117
118
|
self.versioned_inheritance_column = options[:inheritance_column] || "versioned_#{inheritance_column}"
|
118
119
|
self.version_column = options[:version_column] || 'version'
|
120
|
+
self.version_sequence_name = options[:sequence_name]
|
119
121
|
self.max_version_limit = options[:limit].to_i
|
120
122
|
self.version_condition = options[:if] || true
|
121
123
|
|
@@ -143,12 +145,16 @@ module ActiveRecord #:nodoc:
|
|
143
145
|
end
|
144
146
|
|
145
147
|
# create the dynamic versioned model
|
146
|
-
|
148
|
+
# maybe if i sit down long enough i can think up a better way to do this.
|
149
|
+
dynamic_model = <<-EOV
|
147
150
|
class ActiveRecord::Acts::Versioned::#{versioned_class_name} < ActiveRecord::Base
|
148
151
|
set_table_name "#{versioned_table_name}"
|
149
152
|
belongs_to :#{self.to_s.demodulize.underscore}, :class_name => "#{self.to_s}"
|
150
|
-
end
|
151
153
|
EOV
|
154
|
+
|
155
|
+
dynamic_model += %Q{set_sequence_name "#{version_sequence_name}"\n} if version_sequence_name
|
156
|
+
|
157
|
+
eval dynamic_model + 'end'
|
152
158
|
end
|
153
159
|
end
|
154
160
|
|
@@ -191,7 +197,7 @@ module ActiveRecord #:nodoc:
|
|
191
197
|
|
192
198
|
# Finds versions of this model. Takes an options hash like <tt>find</tt>
|
193
199
|
def find_versions(options = {})
|
194
|
-
versions.find(:all,
|
200
|
+
versions.find(:all, options)
|
195
201
|
end
|
196
202
|
|
197
203
|
# Reverts a model to a given version. Takes either a version number or an instance of the versioned model
|
@@ -312,6 +318,20 @@ module ActiveRecord #:nodoc:
|
|
312
318
|
end
|
313
319
|
|
314
320
|
module ClassMethods
|
321
|
+
# Finds a specific version of a specific row of this model
|
322
|
+
def find_version(id, version)
|
323
|
+
find_versions(id,
|
324
|
+
:conditions => ["#{versioned_foreign_key} = ? AND version = ?", id, version],
|
325
|
+
:limit => 1).first
|
326
|
+
end
|
327
|
+
|
328
|
+
# Finds versions of a specific model. Takes an options hash like <tt>find</tt>
|
329
|
+
def find_versions(id, options = {})
|
330
|
+
versioned_class.find :all, {
|
331
|
+
:conditions => ["#{versioned_foreign_key} = ?", id],
|
332
|
+
:order => 'version' }.merge(options)
|
333
|
+
end
|
334
|
+
|
315
335
|
# Returns an array of columns that are versioned. See non_versioned_fields
|
316
336
|
def versioned_columns
|
317
337
|
self.columns.select { |c| !non_versioned_fields.include?(c.name) }
|
@@ -329,34 +349,32 @@ module ActiveRecord #:nodoc:
|
|
329
349
|
|
330
350
|
# Rake migration task to create the versioned table using options passed to acts_as_versioned
|
331
351
|
def create_versioned_table(create_table_options = {})
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
self.connection.add_column versioned_table_name, :updated_at, :timestamp
|
359
|
-
end
|
352
|
+
# create version column in main table if it does not exist
|
353
|
+
if !self.content_columns.find { |c| %w(version lock_version).include? c.name }
|
354
|
+
self.connection.add_column table_name, :version, :integer
|
355
|
+
end
|
356
|
+
|
357
|
+
self.connection.create_table(versioned_table_name, create_table_options) do |t|
|
358
|
+
t.column versioned_foreign_key, :integer
|
359
|
+
t.column :version, :integer
|
360
|
+
end
|
361
|
+
|
362
|
+
updated_col = nil
|
363
|
+
self.versioned_columns.each do |col|
|
364
|
+
updated_col = col if !updated_col and %(updated_at updated_on).include?(col.name)
|
365
|
+
self.connection.add_column versioned_table_name, col.name, col.type,
|
366
|
+
:limit => col.limit,
|
367
|
+
:default => col.default
|
368
|
+
end
|
369
|
+
|
370
|
+
if type_col = self.columns_hash[inheritance_column]
|
371
|
+
self.connection.add_column versioned_table_name, versioned_inheritance_column, type_col.type,
|
372
|
+
:limit => type_col.limit,
|
373
|
+
:default => type_col.default
|
374
|
+
end
|
375
|
+
|
376
|
+
if updated_col.nil?
|
377
|
+
self.connection.add_column versioned_table_name, :updated_at, :timestamp
|
360
378
|
end
|
361
379
|
end
|
362
380
|
|
data/test/debug.log
ADDED
@@ -0,0 +1,99 @@
|
|
1
|
+
# Logfile created on Thu Sep 29 08:57:24 CDT 2005 by logger.rb/1.5.2.4
|
2
|
+
[4;33mSQL (0.001227)[m [1;37mPRAGMA table_info(locked_pages)[m
|
3
|
+
[4;35mSQL (0.000842)[m [0;37mINSERT INTO locked_pages ('title', 'lock_version', 'type') VALUES('title', 1, NULL)[m
|
4
|
+
[4;33mSQL (0.001495)[m [1;37mPRAGMA table_info(locked_pages_revisions)[m
|
5
|
+
[4;35mSQL (0.001511)[m [0;37mINSERT INTO locked_pages_revisions ('updated_at', 'version_type', 'title', 'page_id', 'version') VALUES('2005-09-29 08:57:25', NULL, 'title', 3, 1)[m
|
6
|
+
[4;33mActiveRecord::Acts::Versioned::LockedPageRevision Load (0.001209)[m [1;37mSELECT * FROM locked_pages_revisions WHERE locked_pages_revisions.page_id = 3 ORDER BY version [m
|
7
|
+
[4;35mLockedPage Update with optimistic locking (0.002959)[m [0;37m UPDATE locked_pages
|
8
|
+
SET 'title' = 'title', 'type' = NULL, 'lock_version' = 2
|
9
|
+
WHERE id = 3 AND lock_version = 1
|
10
|
+
[m
|
11
|
+
[4;33mActiveRecord::Acts::Versioned::LockedPageRevision Load (0.001171)[m [1;37mSELECT * FROM locked_pages_revisions WHERE locked_pages_revisions.page_id = 3 ORDER BY version [m
|
12
|
+
[4;35mLockedPage Update with optimistic locking (0.001465)[m [0;37m UPDATE locked_pages
|
13
|
+
SET 'title' = 'updated title', 'type' = NULL, 'lock_version' = 3
|
14
|
+
WHERE id = 3 AND lock_version = 2
|
15
|
+
[m
|
16
|
+
[4;33mSQL (0.001484)[m [1;37mINSERT INTO locked_pages_revisions ('updated_at', 'version_type', 'title', 'page_id', 'version') VALUES('2005-09-29 08:57:25', NULL, 'updated title', 3, 3)[m
|
17
|
+
[4;35mSQL (0.000553)[m [0;37mDELETE FROM locked_pages_revisions WHERE version <= 1 AND page_id = 3[m
|
18
|
+
[4;33mActiveRecord::Acts::Versioned::LockedPageRevision Load (0.001214)[m [1;37mSELECT * FROM locked_pages_revisions WHERE locked_pages_revisions.page_id = 3 ORDER BY version [m
|
19
|
+
[4;35mLockedPage Update with optimistic locking (0.001613)[m [0;37m UPDATE locked_pages
|
20
|
+
SET 'title' = 'updated title!', 'type' = NULL, 'lock_version' = 4
|
21
|
+
WHERE id = 3 AND lock_version = 3
|
22
|
+
[m
|
23
|
+
[4;33mSQL (0.001447)[m [1;37mINSERT INTO locked_pages_revisions ('updated_at', 'version_type', 'title', 'page_id', 'version') VALUES('2005-09-29 08:57:25', NULL, 'updated title!', 3, 4)[m
|
24
|
+
[4;35mSQL (0.000522)[m [0;37mDELETE FROM locked_pages_revisions WHERE version <= 2 AND page_id = 3[m
|
25
|
+
[4;33mActiveRecord::Acts::Versioned::LockedPageRevision Load (0.001439)[m [1;37mSELECT * FROM locked_pages_revisions WHERE locked_pages_revisions.page_id = 3 ORDER BY version [m
|
26
|
+
[4;33mSQL (0.001207)[m [1;37mPRAGMA table_info(locked_pages)[m
|
27
|
+
[4;35mSQL (0.000549)[m [0;37mINSERT INTO locked_pages ('title', 'lock_version', 'type') VALUES('title', 1, NULL)[m
|
28
|
+
[4;33mSQL (0.001507)[m [1;37mPRAGMA table_info(locked_pages_revisions)[m
|
29
|
+
[4;35mSQL (0.001516)[m [0;37mINSERT INTO locked_pages_revisions ('updated_at', 'version_type', 'title', 'page_id', 'version') VALUES('2005-09-29 09:02:00', NULL, 'title', 3, 1)[m
|
30
|
+
[4;33mActiveRecord::Acts::Versioned::LockedPageRevision Load (0.001315)[m [1;37mSELECT * FROM locked_pages_revisions WHERE locked_pages_revisions.page_id = 3 ORDER BY version [m
|
31
|
+
[4;35mLockedPage Update with optimistic locking (0.001660)[m [0;37m UPDATE locked_pages
|
32
|
+
SET 'title' = 'title', 'type' = NULL, 'lock_version' = 2
|
33
|
+
WHERE id = 3 AND lock_version = 1
|
34
|
+
[m
|
35
|
+
[4;33mActiveRecord::Acts::Versioned::LockedPageRevision Load (0.001203)[m [1;37mSELECT * FROM locked_pages_revisions WHERE locked_pages_revisions.page_id = 3 ORDER BY version [m
|
36
|
+
[4;35mLockedPage Update with optimistic locking (0.003941)[m [0;37m UPDATE locked_pages
|
37
|
+
SET 'title' = 'updated title', 'type' = NULL, 'lock_version' = 3
|
38
|
+
WHERE id = 3 AND lock_version = 2
|
39
|
+
[m
|
40
|
+
[4;33mSQL (0.001514)[m [1;37mINSERT INTO locked_pages_revisions ('updated_at', 'version_type', 'title', 'page_id', 'version') VALUES('2005-09-29 09:02:12', NULL, 'updated title', 3, 3)[m
|
41
|
+
[4;35mSQL (0.000591)[m [0;37mDELETE FROM locked_pages_revisions WHERE version <= 1 AND page_id = 3[m
|
42
|
+
[4;33mLockedPage Update with optimistic locking (0.001470)[m [1;37m UPDATE locked_pages
|
43
|
+
SET 'title' = 'updated title', 'type' = NULL, 'lock_version' = 4
|
44
|
+
WHERE id = 3 AND lock_version = 3
|
45
|
+
[m
|
46
|
+
[4;35mSQL (0.000550)[m [0;37mDELETE FROM locked_pages_revisions WHERE version <= 2 AND page_id = 3[m
|
47
|
+
[4;33mLockedPage Load (0.001156)[m [1;37mSELECT * FROM locked_pages WHERE locked_pages.id = 1 LIMIT 1[m
|
48
|
+
[4;35mSQL (0.001285)[m [0;37mPRAGMA table_info(locked_pages)[m
|
49
|
+
[4;33mActiveRecord::Acts::Versioned::LockedPageRevision Count (0.001063)[m [1;37mSELECT COUNT(*) FROM locked_pages_revisions WHERE locked_pages_revisions.page_id = 1 [m
|
50
|
+
[4;35mActiveRecord::Acts::Versioned::LockedPageRevision Load (0.001321)[m [0;37mSELECT * FROM locked_pages_revisions WHERE locked_pages_revisions.page_id = 1 AND (title LIKE '%weblog%') ORDER BY version, version [m
|
51
|
+
[4;33mActiveRecord::Acts::Versioned::LockedPageRevision Load (0.001450)[m [1;37mSELECT * FROM locked_pages_revisions WHERE locked_pages_revisions.page_id = 1 AND (title LIKE '%web%') ORDER BY version, version [m
|
52
|
+
[4;35mLockedPage Load (0.001090)[m [0;37mSELECT * FROM locked_pages WHERE locked_pages.id = 2 LIMIT 1[m
|
53
|
+
[4;33mSQL (0.001236)[m [1;37mPRAGMA table_info(locked_pages)[m
|
54
|
+
[4;35mActiveRecord::Acts::Versioned::LockedPageRevision Load (0.000906)[m [0;37mSELECT * FROM locked_pages_revisions WHERE locked_pages_revisions.page_id = 2 AND (title LIKE '%web%') ORDER BY version, version [m
|
55
|
+
[4;33mActiveRecord::Acts::Versioned::LockedPageRevision Load (0.001316)[m [1;37mSELECT * FROM locked_pages_revisions WHERE locked_pages_revisions.page_id = 1 ORDER BY version, version [m
|
56
|
+
[4;35mLockedPage Load (0.001179)[m [0;37mSELECT * FROM locked_pages WHERE locked_pages.id = 2 LIMIT 1[m
|
57
|
+
[4;33mLockedPage Load (0.001558)[m [1;37mSELECT * FROM locked_pages WHERE locked_pages.id = 2 LIMIT 1[m
|
58
|
+
[4;35mSpecialLockedPage Update with optimistic locking (0.001752)[m [0;37m UPDATE locked_pages
|
59
|
+
SET 'title' = 'fresh title', 'type' = 'SpecialLockedPage', 'lock_version' = 25
|
60
|
+
WHERE id = 2 AND lock_version = 24
|
61
|
+
[m
|
62
|
+
[4;33mSQL (0.001611)[m [1;37mPRAGMA table_info(locked_pages_revisions)[m
|
63
|
+
[4;35mSQL (0.001602)[m [0;37mINSERT INTO locked_pages_revisions ('updated_at', 'version_type', 'title', 'page_id', 'version') VALUES('2005-09-30 12:06:35', 'SpecialLockedPage', 'fresh title', 2, 25)[m
|
64
|
+
[4;33mSQL (0.000741)[m [1;37mDELETE FROM locked_pages_revisions WHERE version <= 23 AND page_id = 2[m
|
65
|
+
[4;35mActiveRecord::Acts::Versioned::LockedPageRevision Count (0.001129)[m [0;37mSELECT COUNT(*) FROM locked_pages_revisions WHERE locked_pages_revisions.page_id = 2 [m
|
66
|
+
[4;33mSpecialLockedPage Update with optimistic locking (0.001867)[m [1;37m UPDATE locked_pages
|
67
|
+
SET 'title' = 'stale title', 'type' = 'SpecialLockedPage', 'lock_version' = 25
|
68
|
+
WHERE id = 2 AND lock_version = 24
|
69
|
+
[m
|
70
|
+
[4;35mLockedPage Load (0.001088)[m [0;37mSELECT * FROM locked_pages WHERE locked_pages.id = 1 LIMIT 1[m
|
71
|
+
[4;33mLockedPage Load (0.001127)[m [1;37mSELECT * FROM locked_pages WHERE locked_pages.id = 2 LIMIT 1[m
|
72
|
+
[4;33mLockedPage Load (0.003112)[m [1;37mSELECT * FROM locked_pages WHERE locked_pages.id = 1 LIMIT 1[m
|
73
|
+
[4;35mLockedPage Load (0.001110)[m [0;37mSELECT * FROM locked_pages WHERE locked_pages.id = 2 LIMIT 1[m
|
74
|
+
[4;33mSQL (0.001694)[m [1;37mPRAGMA table_info(locked_pages)[m
|
75
|
+
[4;33mLockedPage Load (0.001492)[m [1;37mSELECT * FROM locked_pages WHERE locked_pages.id = 1 LIMIT 1[m
|
76
|
+
[4;35mLockedPage Load (0.001084)[m [0;37mSELECT * FROM locked_pages WHERE locked_pages.id = 2 LIMIT 1[m
|
77
|
+
[4;33mSQL (0.001457)[m [1;37mPRAGMA table_info(locked_pages)[m
|
78
|
+
[4;35mActiveRecord::Acts::Versioned::LockedPageRevision Load (0.001049)[m [0;37mSELECT * FROM locked_pages_revisions WHERE locked_pages_revisions.page_id = 1 AND (version = NULL) ORDER BY version, version LIMIT 1[m
|
79
|
+
[4;33mActiveRecord::Acts::Versioned::LockedPageRevision Load (0.035705)[m [1;37mSELECT * FROM locked_pages_revisions WHERE locked_pages_revisions.page_id = 1 AND (version = NULL) ORDER BY version, version LIMIT 1[m
|
80
|
+
[4;35mActiveRecord::Acts::Versioned::LockedPageRevision Load (0.000930)[m [0;37mSELECT * FROM locked_pages_revisions WHERE locked_pages_revisions.page_id = 1 AND (version = NULL) ORDER BY version, version LIMIT 1[m
|
81
|
+
[4;33mLockedPage Load (0.001490)[m [1;37mSELECT * FROM locked_pages WHERE locked_pages.id = 1 LIMIT 1[m
|
82
|
+
[4;35mLockedPage Load (0.001195)[m [0;37mSELECT * FROM locked_pages WHERE locked_pages.id = 2 LIMIT 1[m
|
83
|
+
[4;33mSQL (0.001632)[m [1;37mPRAGMA table_info(locked_pages)[m
|
84
|
+
[4;35mActiveRecord::Acts::Versioned::LockedPageRevision Load (0.001005)[m [0;37mSELECT * FROM locked_pages_revisions WHERE locked_pages_revisions.page_id = 1 AND (version = NULL) ORDER BY version, version LIMIT 1[m
|
85
|
+
[4;33mLockedPage Load (0.001169)[m [1;37mSELECT * FROM locked_pages WHERE locked_pages.id = 1 LIMIT 1[m
|
86
|
+
[4;35mLockedPage Load (0.001370)[m [0;37mSELECT * FROM locked_pages WHERE locked_pages.id = 2 LIMIT 1[m
|
87
|
+
[4;33mSQL (0.005599)[m [1;37mPRAGMA table_info(locked_pages)[m
|
88
|
+
[4;35mActiveRecord::Acts::Versioned::LockedPageRevision Load (0.001175)[m [0;37mSELECT * FROM locked_pages_revisions WHERE locked_pages_revisions.page_id = 1 AND (version = NULL) ORDER BY version, version LIMIT 1[m
|
89
|
+
[4;33mPage Load (0.002110)[m [1;37mSELECT * FROM pages WHERE pages.id = 1 LIMIT 1[m
|
90
|
+
[4;35mSQL (0.001568)[m [0;37mPRAGMA table_info(pages)[m
|
91
|
+
[4;33mActiveRecord::Acts::Versioned::PageVersion Load (0.001352)[m [1;37mSELECT * FROM page_versions WHERE page_versions.page_id = 1 ORDER BY version [m
|
92
|
+
[4;35mSQL (0.003145)[m [0;37mPRAGMA table_info(page_versions)[m
|
93
|
+
[4;33mActiveRecord::Acts::Versioned::PageVersion Load (0.001432)[m [1;37mSELECT * FROM page_versions WHERE page_versions.page_id = 1 AND (version = 23) ORDER BY version, version LIMIT 1[m
|
94
|
+
[4;35mPage Update (0.002421)[m [0;37mUPDATE pages SET 'updated_on' = '2005-09-30 12:11:01', 'body' = 'Such a lovely day', 'version' = 23, 'title' = 'Welcome to the weblg' WHERE id = 1[m
|
95
|
+
[4;33mPage Load (0.001187)[m [1;37mSELECT * FROM pages WHERE pages.id = 1 LIMIT 1[m
|
96
|
+
[4;35mSQL (0.001723)[m [0;37mPRAGMA table_info(pages)[m
|
97
|
+
[4;33mActiveRecord::Acts::Versioned::PageVersion Load (0.001722)[m [1;37mSELECT * FROM page_versions WHERE page_versions.page_id = 1 ORDER BY version [m
|
98
|
+
[4;35mSQL (0.001417)[m [0;37mPRAGMA table_info(page_versions)[m
|
99
|
+
[4;33mActiveRecord::Acts::Versioned::PageVersion Load (0.001533)[m [1;37mSELECT * FROM page_versions WHERE page_versions.page_id = 1 AND (version = 23) ORDER BY version LIMIT 1[m
|
Binary file
|
@@ -31,4 +31,22 @@ CREATE TABLE locked_pages_revisions (
|
|
31
31
|
title VARCHAR(255),
|
32
32
|
version_type VARCHAR(255),
|
33
33
|
updated_at TIMESTAMP
|
34
|
-
);
|
34
|
+
);
|
35
|
+
|
36
|
+
CREATE TABLE widgets (
|
37
|
+
id SERIAL,
|
38
|
+
name VARCHAR(50),
|
39
|
+
version INTEGER,
|
40
|
+
updated_at TIMESTAMP
|
41
|
+
);
|
42
|
+
|
43
|
+
CREATE SEQUENCE widgets_seq START 101;
|
44
|
+
|
45
|
+
CREATE TABLE widget_versions (
|
46
|
+
id INTEGER DEFAULT nextval('widgets_seq'),
|
47
|
+
widget_id INTEGER,
|
48
|
+
name VARCHAR(50),
|
49
|
+
version INTEGER,
|
50
|
+
updated_at TIMESTAMP,
|
51
|
+
PRIMARY KEY (id)
|
52
|
+
);
|
data/test/migration_test.rb
CHANGED
@@ -7,9 +7,6 @@ if ActiveRecord::Base.connection.supports_migrations?
|
|
7
7
|
end
|
8
8
|
|
9
9
|
class MigrationTest < Test::Unit::TestCase
|
10
|
-
def setup
|
11
|
-
end
|
12
|
-
|
13
10
|
def teardown
|
14
11
|
ActiveRecord::Base.connection.initialize_schema_information
|
15
12
|
ActiveRecord::Base.connection.update "UPDATE schema_info SET version = 0"
|
@@ -21,9 +18,14 @@ if ActiveRecord::Base.connection.supports_migrations?
|
|
21
18
|
|
22
19
|
def test_versioned_migration
|
23
20
|
assert_raises(ActiveRecord::StatementInvalid) { Thing.create :title => 'blah blah' }
|
21
|
+
# take 'er up
|
24
22
|
ActiveRecord::Migrator.up(File.dirname(__FILE__) + '/fixtures/migrations/')
|
25
23
|
t = Thing.create :title => 'blah blah'
|
26
24
|
assert_equal 1, t.versions.size
|
25
|
+
|
26
|
+
# now lets take 'er back down
|
27
|
+
ActiveRecord::Migrator.down(File.dirname(__FILE__) + '/fixtures/migrations/')
|
28
|
+
assert_raises(ActiveRecord::StatementInvalid) { Thing.create :title => 'blah blah' }
|
27
29
|
end
|
28
30
|
end
|
29
31
|
end
|
data/test/versioned_test.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'abstract_unit'
|
2
2
|
require 'fixtures/page'
|
3
|
+
require 'fixtures/widget'
|
3
4
|
|
4
5
|
class VersionedTest < Test::Unit::TestCase
|
5
6
|
fixtures :pages, :page_versions, :locked_pages, :locked_pages_revisions
|
@@ -225,4 +226,13 @@ class VersionedTest < Test::Unit::TestCase
|
|
225
226
|
assert_equal 0, locked_pages(:thinking).find_versions(:conditions => ['title LIKE ?', '%web%']).length
|
226
227
|
assert_equal 2, locked_pages(:welcome).find_versions.length
|
227
228
|
end
|
229
|
+
|
230
|
+
def test_with_sequence
|
231
|
+
assert_equal 'widgets_seq', Widget.versioned_class.sequence_name
|
232
|
+
Widget.create :name => 'new widget'
|
233
|
+
Widget.create :name => 'new widget'
|
234
|
+
Widget.create :name => 'new widget'
|
235
|
+
assert_equal 3, Widget.count
|
236
|
+
assert_equal 3, Widget.versions.size
|
237
|
+
end
|
228
238
|
end
|
metadata
CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.8.10
|
|
3
3
|
specification_version: 1
|
4
4
|
name: acts_as_versioned
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.
|
7
|
-
date: 2005-
|
6
|
+
version: "0.2"
|
7
|
+
date: 2005-10-06
|
8
8
|
summary: Simple versioning with active record models
|
9
9
|
require_paths:
|
10
10
|
- lib
|
@@ -30,6 +30,7 @@ files:
|
|
30
30
|
- lib/acts_as_versioned.rb
|
31
31
|
- test/abstract_unit.rb
|
32
32
|
- test/connections
|
33
|
+
- test/debug.log
|
33
34
|
- test/fixtures
|
34
35
|
- test/migration_test.rb
|
35
36
|
- test/tests.rb
|
@@ -50,6 +51,7 @@ files:
|
|
50
51
|
- test/connections/native_sqlite3/connection.rb
|
51
52
|
- test/connections/native_sqlserver/connection.rb
|
52
53
|
- test/connections/native_sqlserver_odbc/connection.rb
|
54
|
+
- test/fixtures/activerecord_versioned.sqlite
|
53
55
|
- test/fixtures/activerecord_versioned.sqlite3
|
54
56
|
- test/fixtures/db_definitions
|
55
57
|
- test/fixtures/locked_pages.yml
|
@@ -58,6 +60,7 @@ files:
|
|
58
60
|
- test/fixtures/page.rb
|
59
61
|
- test/fixtures/page_versions.yml
|
60
62
|
- test/fixtures/pages.yml
|
63
|
+
- test/fixtures/widget.rb
|
61
64
|
- test/fixtures/db_definitions/mysql.drop.sql
|
62
65
|
- test/fixtures/db_definitions/mysql.sql
|
63
66
|
- test/fixtures/db_definitions/postgresql.drop.sql
|