acts_as_revisable 1.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +20 -0
- data/README.rdoc +221 -0
- data/Rakefile +44 -0
- data/generators/revisable_migration/revisable_migration_generator.rb +21 -0
- data/generators/revisable_migration/templates/migration.rb +14 -0
- data/lib/acts_as_revisable.rb +10 -0
- data/lib/acts_as_revisable/acts/common.rb +209 -0
- data/lib/acts_as_revisable/acts/deletable.rb +33 -0
- data/lib/acts_as_revisable/acts/revisable.rb +485 -0
- data/lib/acts_as_revisable/acts/revision.rb +148 -0
- data/lib/acts_as_revisable/base.rb +54 -0
- data/lib/acts_as_revisable/gem_spec_options.rb +18 -0
- data/lib/acts_as_revisable/options.rb +22 -0
- data/lib/acts_as_revisable/quoted_columns.rb +31 -0
- data/lib/acts_as_revisable/validations.rb +11 -0
- data/lib/acts_as_revisable/version.rb +11 -0
- data/rails/init.rb +1 -0
- data/spec/associations_spec.rb +22 -0
- data/spec/branch_spec.rb +42 -0
- data/spec/deletable_spec.rb +16 -0
- data/spec/find_spec.rb +34 -0
- data/spec/general_spec.rb +115 -0
- data/spec/options_spec.rb +83 -0
- data/spec/quoted_columns_spec.rb +19 -0
- data/spec/revert_spec.rb +42 -0
- data/spec/spec.opts +1 -0
- data/spec/spec_helper.rb +121 -0
- data/spec/sti_spec.rb +42 -0
- data/spec/validations_spec.rb +25 -0
- metadata +86 -0
@@ -0,0 +1,83 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper.rb'
|
2
|
+
|
3
|
+
shared_examples_for "common Options usage" do
|
4
|
+
it "should return a set value" do
|
5
|
+
@options.one.should == 1
|
6
|
+
end
|
7
|
+
|
8
|
+
it "should return nil for an unset value" do
|
9
|
+
@options.two.should be_nil
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should return false for unset query option" do
|
13
|
+
@options.should_not be_unset_value
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should return true for a query option set to true" do
|
17
|
+
@options.should be_yes
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should return false for a query option set to false" do
|
21
|
+
@options.should_not be_no
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should return false for a query on a non-boolean value" do
|
25
|
+
@options.should_not be_one
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should return an array when passed one" do
|
29
|
+
@options.arr.should be_a_kind_of(Array)
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should not return an array when not passed one" do
|
33
|
+
@options.one.should_not be_a_kind_of(Array)
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should have the right number of elements in an array" do
|
37
|
+
@options.arr.size.should == 3
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
describe WithoutScope::ActsAsRevisable::Options do
|
42
|
+
describe "with hash options" do
|
43
|
+
before(:each) do
|
44
|
+
@options = WithoutScope::ActsAsRevisable::Options.new :one => 1, :yes => true, :no => false, :arr => [1,2,3]
|
45
|
+
end
|
46
|
+
|
47
|
+
it_should_behave_like "common Options usage"
|
48
|
+
end
|
49
|
+
|
50
|
+
describe "with block options" do
|
51
|
+
before(:each) do
|
52
|
+
@options = WithoutScope::ActsAsRevisable::Options.new do
|
53
|
+
one 1
|
54
|
+
yes true
|
55
|
+
arr [1,2,3]
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
it_should_behave_like "common Options usage"
|
60
|
+
end
|
61
|
+
|
62
|
+
describe "with both block and hash options" do
|
63
|
+
before(:each) do
|
64
|
+
@options = WithoutScope::ActsAsRevisable::Options.new(:yes => true, :arr => [1,2,3]) do
|
65
|
+
one 1
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
it_should_behave_like "common Options usage"
|
70
|
+
|
71
|
+
describe "the block should override the hash" do
|
72
|
+
before(:each) do
|
73
|
+
@options = WithoutScope::ActsAsRevisable::Options.new(:yes => false, :one => 10, :arr => [1,2,3,4,5]) do
|
74
|
+
one 1
|
75
|
+
yes true
|
76
|
+
arr [1,2,3]
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
it_should_behave_like "common Options usage"
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper.rb'
|
2
|
+
|
3
|
+
describe "the quoted_columns extension" do
|
4
|
+
after(:each) do
|
5
|
+
cleanup_db
|
6
|
+
end
|
7
|
+
|
8
|
+
it "should quote symbols matching column names as columns" do
|
9
|
+
Project.send(:quote_bound_value, :name).should == %q{"projects"."name"}
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should not quote symbols that don't match column names" do
|
13
|
+
Project.send(:quote_bound_value, :whatever).should == "'#{:whatever.to_yaml}'"
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should not quote strings any differently" do
|
17
|
+
Project.send(:quote_bound_value, "what").should == ActiveRecord::Base.send(:quote_bound_value, "what")
|
18
|
+
end
|
19
|
+
end
|
data/spec/revert_spec.rb
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper.rb'
|
2
|
+
|
3
|
+
describe WithoutScope::ActsAsRevisable, "with reverting" do
|
4
|
+
after(:each) do
|
5
|
+
cleanup_db
|
6
|
+
end
|
7
|
+
|
8
|
+
before(:each) do
|
9
|
+
@project = Project.create(:name => "Rich", :notes => "a note")
|
10
|
+
@project.update_attribute(:name, "Sam")
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should let you revert to previous versions" do
|
14
|
+
@project.revert_to!(:first)
|
15
|
+
@project.name.should == "Rich"
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should accept the :without_revision hash option" do
|
19
|
+
lambda { @project.revert_to!(:first, :without_revision => true) }.should_not raise_error
|
20
|
+
@project.name.should == "Rich"
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should support the revert_to_without_revision method" do
|
24
|
+
lambda { @project.revert_to_without_revision(:first).save }.should_not raise_error
|
25
|
+
@project.name.should == "Rich"
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should support the revert_to_without_revision! method" do
|
29
|
+
lambda { @project.revert_to_without_revision!(:first) }.should_not raise_error
|
30
|
+
@project.name.should == "Rich"
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should let you revert to previous versions without a new revision" do
|
34
|
+
@project.revert_to!(:first, :without_revision => true)
|
35
|
+
@project.revisions.size.should == 1
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should support the revert_to method" do
|
39
|
+
lambda{ @project.revert_to(:first) }.should_not raise_error
|
40
|
+
@project.should be_changed
|
41
|
+
end
|
42
|
+
end
|
data/spec/spec.opts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--colour
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,121 @@
|
|
1
|
+
begin
|
2
|
+
require 'spec'
|
3
|
+
rescue LoadError
|
4
|
+
require 'rubygems'
|
5
|
+
gem 'rspec'
|
6
|
+
require 'spec'
|
7
|
+
end
|
8
|
+
|
9
|
+
if ENV['EDGE_RAILS_PATH']
|
10
|
+
edge_path = File.expand_path(ENV['EDGE_RAILS_PATH'])
|
11
|
+
require File.join(edge_path, 'activesupport', 'lib', 'active_support')
|
12
|
+
require File.join(edge_path, 'activerecord', 'lib', 'active_record')
|
13
|
+
end
|
14
|
+
|
15
|
+
$:.unshift(File.dirname(__FILE__) + '/../lib')
|
16
|
+
require 'acts_as_revisable'
|
17
|
+
|
18
|
+
ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :database => ":memory:")
|
19
|
+
|
20
|
+
def setup_db
|
21
|
+
ActiveRecord::Schema.define(:version => 1) do
|
22
|
+
create_table :people do |t|
|
23
|
+
t.string :name, :revisable_name, :revisable_type
|
24
|
+
t.text :notes
|
25
|
+
t.boolean :revisable_is_current
|
26
|
+
t.integer :revisable_original_id, :revisable_branched_from_id, :revisable_number, :project_id
|
27
|
+
t.datetime :revisable_current_at, :revisable_revised_at, :revisable_deleted_at
|
28
|
+
t.timestamps
|
29
|
+
end
|
30
|
+
|
31
|
+
create_table :projects do |t|
|
32
|
+
t.string :name, :unimportant, :revisable_name, :revisable_type
|
33
|
+
t.text :notes
|
34
|
+
t.boolean :revisable_is_current
|
35
|
+
t.integer :revisable_original_id, :revisable_branched_from_id, :revisable_number
|
36
|
+
t.datetime :revisable_current_at, :revisable_revised_at, :revisable_deleted_at
|
37
|
+
t.timestamps
|
38
|
+
end
|
39
|
+
|
40
|
+
create_table :foos do |t|
|
41
|
+
t.string :name, :revisable_name, :revisable_type
|
42
|
+
t.text :notes
|
43
|
+
t.boolean :revisable_is_current
|
44
|
+
t.integer :revisable_original_id, :revisable_branched_from_id, :revisable_number, :project_id
|
45
|
+
t.datetime :revisable_current_at, :revisable_revised_at, :revisable_deleted_at
|
46
|
+
t.timestamps
|
47
|
+
end
|
48
|
+
|
49
|
+
create_table :posts do |t|
|
50
|
+
t.string :name, :revisable_name, :revisable_type, :type
|
51
|
+
t.boolean :revisable_is_current
|
52
|
+
t.integer :revisable_original_id, :revisable_branched_from_id, :revisable_number
|
53
|
+
t.datetime :revisable_current_at, :revisable_revised_at, :revisable_deleted_at
|
54
|
+
t.timestamps
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
setup_db
|
60
|
+
|
61
|
+
def cleanup_db
|
62
|
+
ActiveRecord::Base.connection.tables.each do |table|
|
63
|
+
ActiveRecord::Base.connection.execute("delete from #{table}")
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
class Person < ActiveRecord::Base
|
68
|
+
belongs_to :project
|
69
|
+
|
70
|
+
acts_as_revisable do
|
71
|
+
revision_class_name "OldPerson"
|
72
|
+
on_delete :revise
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
class OldPerson < ActiveRecord::Base
|
77
|
+
acts_as_revision do
|
78
|
+
revisable_class_name "Person"
|
79
|
+
clone_associations :all
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
class Project < ActiveRecord::Base
|
84
|
+
has_many :people
|
85
|
+
|
86
|
+
acts_as_revisable do
|
87
|
+
revision_class_name "Session"
|
88
|
+
except :unimportant
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
class Session < ActiveRecord::Base
|
93
|
+
acts_as_revision do
|
94
|
+
revisable_class_name "Project"
|
95
|
+
clone_associations :all
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
class Foo < ActiveRecord::Base
|
100
|
+
acts_as_revisable :generate_revision_class => true, :no_validation_scoping => true
|
101
|
+
|
102
|
+
validates_uniqueness_of :name
|
103
|
+
end
|
104
|
+
|
105
|
+
class Post < ActiveRecord::Base
|
106
|
+
acts_as_revisable
|
107
|
+
|
108
|
+
validates_uniqueness_of :name
|
109
|
+
end
|
110
|
+
|
111
|
+
class PostRevision < ActiveRecord::Base
|
112
|
+
acts_as_revision
|
113
|
+
end
|
114
|
+
|
115
|
+
class Article < Post
|
116
|
+
acts_as_revisable
|
117
|
+
end
|
118
|
+
|
119
|
+
class ArticleRevision < PostRevision
|
120
|
+
acts_as_revision
|
121
|
+
end
|
data/spec/sti_spec.rb
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper.rb'
|
2
|
+
|
3
|
+
describe WithoutScope::ActsAsRevisable, "with single table inheritance" do
|
4
|
+
after(:each) do
|
5
|
+
cleanup_db
|
6
|
+
end
|
7
|
+
|
8
|
+
before(:each) do
|
9
|
+
@article = Article.create(:name => 'an article')
|
10
|
+
@post = Post.create(:name => 'a post')
|
11
|
+
end
|
12
|
+
|
13
|
+
describe "after a revision" do
|
14
|
+
it "an article has revisions of the right type" do
|
15
|
+
@article.revise!
|
16
|
+
@article.revisions(true).first.class.should == ArticleRevision
|
17
|
+
end
|
18
|
+
|
19
|
+
it "a post has revisions of the right type" do
|
20
|
+
@post.revise!
|
21
|
+
@post.revisions(true).first.class.should == PostRevision
|
22
|
+
end
|
23
|
+
|
24
|
+
it "revisable_type column is nil for the root type" do
|
25
|
+
@post.revise!
|
26
|
+
@post.revisions(true).first.revisable_type.should == 'Post'
|
27
|
+
end
|
28
|
+
|
29
|
+
it "revisable_type column is set properly" do
|
30
|
+
@article.revise!
|
31
|
+
@article.revisions(true).first.revisable_type.should == 'Article'
|
32
|
+
end
|
33
|
+
|
34
|
+
it "can find an article by name" do
|
35
|
+
Article.find_by_name('an article').should_not be_nil
|
36
|
+
end
|
37
|
+
|
38
|
+
it "can find a post by name" do
|
39
|
+
Post.find_by_name('a post').should_not be_nil
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper.rb'
|
2
|
+
|
3
|
+
describe WithoutScope::ActsAsRevisable, "with validations" do
|
4
|
+
after(:each) do
|
5
|
+
cleanup_db
|
6
|
+
end
|
7
|
+
|
8
|
+
before(:each) do
|
9
|
+
@post = Post.create(:name => 'a post')
|
10
|
+
@foo = Foo.create(:name => 'a foo')
|
11
|
+
|
12
|
+
end
|
13
|
+
|
14
|
+
describe "unique fields" do
|
15
|
+
it "should allow revisions" do
|
16
|
+
lambda {@post.revise!; @post.revise!}.should_not raise_error
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe "unique fields with validation scoping off" do
|
21
|
+
it "should not allow revisions" do
|
22
|
+
lambda {@foo.revise!; @foo.revise!}.should raise_error
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: acts_as_revisable
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Rich Cavanaugh
|
8
|
+
- Stephen Caudill
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2009-10-02 00:00:00 -04:00
|
14
|
+
default_executable:
|
15
|
+
dependencies: []
|
16
|
+
|
17
|
+
description:
|
18
|
+
email: rich@withoutscope.com
|
19
|
+
executables: []
|
20
|
+
|
21
|
+
extensions: []
|
22
|
+
|
23
|
+
extra_rdoc_files:
|
24
|
+
- README.rdoc
|
25
|
+
- LICENSE
|
26
|
+
files:
|
27
|
+
- LICENSE
|
28
|
+
- README.rdoc
|
29
|
+
- Rakefile
|
30
|
+
- spec/associations_spec.rb
|
31
|
+
- spec/branch_spec.rb
|
32
|
+
- spec/deletable_spec.rb
|
33
|
+
- spec/find_spec.rb
|
34
|
+
- spec/general_spec.rb
|
35
|
+
- spec/options_spec.rb
|
36
|
+
- spec/quoted_columns_spec.rb
|
37
|
+
- spec/revert_spec.rb
|
38
|
+
- spec/spec.opts
|
39
|
+
- spec/spec_helper.rb
|
40
|
+
- spec/sti_spec.rb
|
41
|
+
- spec/validations_spec.rb
|
42
|
+
- lib/acts_as_revisable/acts/common.rb
|
43
|
+
- lib/acts_as_revisable/acts/deletable.rb
|
44
|
+
- lib/acts_as_revisable/acts/revisable.rb
|
45
|
+
- lib/acts_as_revisable/acts/revision.rb
|
46
|
+
- lib/acts_as_revisable/base.rb
|
47
|
+
- lib/acts_as_revisable/gem_spec_options.rb
|
48
|
+
- lib/acts_as_revisable/options.rb
|
49
|
+
- lib/acts_as_revisable/quoted_columns.rb
|
50
|
+
- lib/acts_as_revisable/validations.rb
|
51
|
+
- lib/acts_as_revisable/version.rb
|
52
|
+
- lib/acts_as_revisable.rb
|
53
|
+
- generators/revisable_migration/revisable_migration_generator.rb
|
54
|
+
- generators/revisable_migration/templates/migration.rb
|
55
|
+
- rails/init.rb
|
56
|
+
has_rdoc: true
|
57
|
+
homepage: http://github.com/rich/acts_as_revisable
|
58
|
+
licenses: []
|
59
|
+
|
60
|
+
post_install_message:
|
61
|
+
rdoc_options:
|
62
|
+
- --main
|
63
|
+
- README.rdoc
|
64
|
+
require_paths:
|
65
|
+
- lib
|
66
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
67
|
+
requirements:
|
68
|
+
- - ">="
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: "0"
|
71
|
+
version:
|
72
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - ">="
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: "0"
|
77
|
+
version:
|
78
|
+
requirements: []
|
79
|
+
|
80
|
+
rubyforge_project:
|
81
|
+
rubygems_version: 1.3.5
|
82
|
+
signing_key:
|
83
|
+
specification_version: 3
|
84
|
+
summary: acts_as_revisable enables revision tracking, querying, reverting and branching of ActiveRecord models. Inspired by acts_as_versioned.
|
85
|
+
test_files: []
|
86
|
+
|