kkorach-acts_as_revisable 0.9.7
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/LICENSE +20 -0
- data/README.rdoc +222 -0
- data/Rakefile +44 -0
- data/generators/revisable_migration/revisable_migration_generator.rb +9 -0
- data/generators/revisable_migration/templates/migration.rb +13 -0
- data/lib/acts_as_revisable/acts/common.rb +231 -0
- data/lib/acts_as_revisable/acts/deletable.rb +29 -0
- data/lib/acts_as_revisable/acts/revisable.rb +479 -0
- data/lib/acts_as_revisable/acts/revision.rb +151 -0
- data/lib/acts_as_revisable/acts/scoped_model.rb +75 -0
- data/lib/acts_as_revisable/base.rb +66 -0
- data/lib/acts_as_revisable/clone_associations.rb +36 -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 +35 -0
- data/lib/acts_as_revisable/version.rb +11 -0
- data/lib/acts_as_revisable.rb +14 -0
- data/rails/init.rb +1 -0
- data/spec/associations_spec.rb +22 -0
- data/spec/branch_spec.rb +42 -0
- data/spec/find_spec.rb +38 -0
- data/spec/general_spec.rb +73 -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 +79 -0
- metadata +86 -0
data/spec/branch_spec.rb
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper.rb'
|
2
|
+
|
3
|
+
class Project
|
4
|
+
validates_presence_of :name
|
5
|
+
end
|
6
|
+
|
7
|
+
describe FatJam::ActsAsRevisable, "with branching" do
|
8
|
+
after(:each) do
|
9
|
+
cleanup_db
|
10
|
+
end
|
11
|
+
|
12
|
+
before(:each) do
|
13
|
+
@project = Project.create(:name => "Rich", :notes => "a note")
|
14
|
+
@project.update_attribute(:name, "Sam")
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should allow for branch creation" do
|
18
|
+
@project.should == @project.branch.branch_source
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should branch without saving" do
|
22
|
+
@project.branch.should be_new_record
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should branch and save" do
|
26
|
+
@project.branch!.should_not be_new_record
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should not raise an error for a valid branch" do
|
30
|
+
lambda { @project.branch!(:name => "A New User") }.should_not raise_error
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should raise an error for invalid records" do
|
34
|
+
lambda { @project.branch!(:name => nil) }.should raise_error
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should not save an invalid record" do
|
38
|
+
@branch = @project.branch(:name => nil)
|
39
|
+
@branch.save.should be_false
|
40
|
+
@branch.should be_new_record
|
41
|
+
end
|
42
|
+
end
|
data/spec/find_spec.rb
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper.rb'
|
2
|
+
|
3
|
+
describe FatJam::ActsAsRevisable do
|
4
|
+
after(:each) do
|
5
|
+
cleanup_db
|
6
|
+
end
|
7
|
+
|
8
|
+
describe "with a single revision" do
|
9
|
+
before(:each) do
|
10
|
+
@project1 = Project.create(:name => "Rich", :notes => "a note")
|
11
|
+
@project1.update_attribute(:name, "Sam")
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should just find the current revision by default" do
|
15
|
+
Project.find(:first).name.should == "Sam"
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should accept the :with_revisions options" do
|
19
|
+
lambda { Project.find(:all, :with_revisions => true) }.should_not raise_error
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should provide find_with_revisions" do
|
23
|
+
lambda { Project.find_with_revisions(:all) }.should_not raise_error
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should find current and revisions with the :with_revisions option" do
|
27
|
+
Project.find(:all, :with_revisions => true).size.should == 2
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should find current and revisions with the find_with_revisions method" do
|
31
|
+
Project.find_with_revisions(:all).size.should == 2
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should find revisions with conditions" do
|
35
|
+
Project.find_with_revisions(:all, :conditions => {:name => "Rich"}).should == [@project1.find_revision(:previous)]
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper.rb'
|
2
|
+
|
3
|
+
describe FatJam::ActsAsRevisable do
|
4
|
+
after(:each) do
|
5
|
+
cleanup_db
|
6
|
+
end
|
7
|
+
|
8
|
+
before(:each) do
|
9
|
+
@project = Project.create(:name => "Rich", :notes => "this plugin's author")
|
10
|
+
end
|
11
|
+
|
12
|
+
describe "without revisions" do
|
13
|
+
it "should have a revision_number of zero" do
|
14
|
+
@project.revision_number.should be_zero
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should be the current revision" do
|
18
|
+
@project.revisable_is_current.should be_true
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should respond to current_revision? positively" do
|
22
|
+
@project.current_revision?.should be_true
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should not have any revisions in the generic association" do
|
26
|
+
@project.revisions.should be_empty
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should not have any revisions in the pretty named association" do
|
30
|
+
@project.sessions.should be_empty
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
describe "with revisions" do
|
35
|
+
before(:each) do
|
36
|
+
@project.update_attribute(:name, "Stephen")
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should have a revision_number of one" do
|
40
|
+
@project.revision_number.should == 1
|
41
|
+
end
|
42
|
+
|
43
|
+
it "should have a single revision in the generic association" do
|
44
|
+
@project.revisions.size.should == 1
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should have a single revision in the pretty named association" do
|
48
|
+
@project.sessions.size.should == 1
|
49
|
+
end
|
50
|
+
|
51
|
+
it "should return an instance of the revision class" do
|
52
|
+
@project.revisions.first.should be_an_instance_of(Session)
|
53
|
+
end
|
54
|
+
|
55
|
+
it "should have the original revision's data" do
|
56
|
+
@project.revisions.first.name.should == "Rich"
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
describe "with excluded columns modified" do
|
61
|
+
before(:each) do
|
62
|
+
@project.update_attribute(:unimportant, "a new value")
|
63
|
+
end
|
64
|
+
|
65
|
+
it "should maintain the revision_number at zero" do
|
66
|
+
@project.revision_number.should be_zero
|
67
|
+
end
|
68
|
+
|
69
|
+
it "should not have any revisions" do
|
70
|
+
@project.revisions.should be_empty
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
@@ -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 FatJam::ActsAsRevisable::Options do
|
42
|
+
describe "with hash options" do
|
43
|
+
before(:each) do
|
44
|
+
@options = FatJam::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 = FatJam::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 = FatJam::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 = FatJam::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 == Project.send(:quote_bound_value_with_quoted_column, "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 FatJam::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,79 @@
|
|
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", :dbfile => ":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
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
setup_db
|
43
|
+
|
44
|
+
def cleanup_db
|
45
|
+
ActiveRecord::Base.connection.tables.each do |table|
|
46
|
+
ActiveRecord::Base.connection.execute("delete from #{table}")
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
class Person < ActiveRecord::Base
|
51
|
+
belongs_to :project
|
52
|
+
|
53
|
+
acts_as_revisable do
|
54
|
+
revision_class_name "OldPerson"
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
class OldPerson < ActiveRecord::Base
|
59
|
+
acts_as_revision do
|
60
|
+
revisable_class_name "Person"
|
61
|
+
clone_associations :all
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
class Project < ActiveRecord::Base
|
66
|
+
has_many :people
|
67
|
+
|
68
|
+
acts_as_revisable do
|
69
|
+
revision_class_name "Session"
|
70
|
+
except :unimportant
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
class Session < ActiveRecord::Base
|
75
|
+
acts_as_revision do
|
76
|
+
revisable_class_name "Project"
|
77
|
+
clone_associations :all
|
78
|
+
end
|
79
|
+
end
|
metadata
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: kkorach-acts_as_revisable
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.9.7
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Rich Cavanaugh of JamLab, LLC.
|
8
|
+
- Stephen Caudill of JamLab, LLC.
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2008-08-13 00:00:00 -07:00
|
14
|
+
default_executable:
|
15
|
+
dependencies: []
|
16
|
+
|
17
|
+
description:
|
18
|
+
email: cavanaugh@fatjam.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/find_spec.rb
|
33
|
+
- spec/general_spec.rb
|
34
|
+
- spec/options_spec.rb
|
35
|
+
- spec/quoted_columns_spec.rb
|
36
|
+
- spec/revert_spec.rb
|
37
|
+
- spec/spec.opts
|
38
|
+
- spec/spec_helper.rb
|
39
|
+
- lib/acts_as_revisable
|
40
|
+
- lib/acts_as_revisable/acts
|
41
|
+
- lib/acts_as_revisable/acts/common.rb
|
42
|
+
- lib/acts_as_revisable/acts/deletable.rb
|
43
|
+
- lib/acts_as_revisable/acts/revisable.rb
|
44
|
+
- lib/acts_as_revisable/acts/revision.rb
|
45
|
+
- lib/acts_as_revisable/acts/scoped_model.rb
|
46
|
+
- lib/acts_as_revisable/base.rb
|
47
|
+
- lib/acts_as_revisable/clone_associations.rb
|
48
|
+
- lib/acts_as_revisable/gem_spec_options.rb
|
49
|
+
- lib/acts_as_revisable/options.rb
|
50
|
+
- lib/acts_as_revisable/quoted_columns.rb
|
51
|
+
- lib/acts_as_revisable/version.rb
|
52
|
+
- lib/acts_as_revisable.rb
|
53
|
+
- generators/revisable_migration
|
54
|
+
- generators/revisable_migration/revisable_migration_generator.rb
|
55
|
+
- generators/revisable_migration/templates
|
56
|
+
- generators/revisable_migration/templates/migration.rb
|
57
|
+
- rails/init.rb
|
58
|
+
has_rdoc: true
|
59
|
+
homepage: http://github.com/kkorach/acts_as_revisable/tree/master
|
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.2.0
|
82
|
+
signing_key:
|
83
|
+
specification_version: 2
|
84
|
+
summary: acts_as_revisable enables revision tracking, querying, reverting and branching of ActiveRecord models. Inspired by acts_as_versioned.
|
85
|
+
test_files: []
|
86
|
+
|