vestal_versions 1.0.2 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +19 -20
- data/.travis.yml +22 -0
- data/CHANGELOG.md +7 -0
- data/Gemfile +10 -0
- data/README.rdoc +63 -36
- data/Rakefile +4 -43
- data/gemfiles/activerecord_3_0.gemfile +10 -0
- data/gemfiles/activerecord_3_1.gemfile +10 -0
- data/gemfiles/activerecord_3_2.gemfile +10 -0
- data/gemfiles/activerecord_4_0.gemfile +10 -0
- data/lib/generators/vestal_versions.rb +11 -0
- data/lib/generators/vestal_versions/migration/migration_generator.rb +17 -0
- data/{generators/vestal_versions → lib/generators/vestal_versions/migration}/templates/initializer.rb +0 -0
- data/{generators/vestal_versions → lib/generators/vestal_versions/migration}/templates/migration.rb +4 -3
- data/lib/vestal_versions.rb +39 -12
- data/lib/vestal_versions/changes.rb +43 -47
- data/lib/vestal_versions/conditions.rb +31 -43
- data/lib/vestal_versions/control.rb +162 -138
- data/lib/vestal_versions/creation.rb +67 -59
- data/lib/vestal_versions/deletion.rb +37 -0
- data/lib/vestal_versions/options.rb +6 -10
- data/lib/vestal_versions/reload.rb +7 -14
- data/lib/vestal_versions/reset.rb +15 -19
- data/lib/vestal_versions/reversion.rb +64 -52
- data/lib/vestal_versions/users.rb +36 -39
- data/lib/vestal_versions/version.rb +57 -2
- data/lib/vestal_versions/version_tagging.rb +51 -0
- data/lib/vestal_versions/versioned.rb +14 -17
- data/lib/vestal_versions/versions.rb +22 -7
- data/spec/spec_helper.rb +28 -0
- data/spec/support/models.rb +19 -0
- data/spec/support/schema.rb +25 -0
- data/spec/vestal_versions/changes_spec.rb +134 -0
- data/spec/vestal_versions/conditions_spec.rb +103 -0
- data/spec/vestal_versions/control_spec.rb +120 -0
- data/spec/vestal_versions/creation_spec.rb +90 -0
- data/spec/vestal_versions/deletion_spec.rb +86 -0
- data/spec/vestal_versions/options_spec.rb +45 -0
- data/spec/vestal_versions/reload_spec.rb +18 -0
- data/spec/vestal_versions/reset_spec.rb +111 -0
- data/spec/vestal_versions/reversion_spec.rb +103 -0
- data/spec/vestal_versions/users_spec.rb +21 -0
- data/spec/vestal_versions/version_spec.rb +61 -0
- data/spec/vestal_versions/version_tagging_spec.rb +39 -0
- data/spec/vestal_versions/versioned_spec.rb +16 -0
- data/spec/vestal_versions/versions_spec.rb +176 -0
- data/vestal_versions.gemspec +18 -100
- metadata +153 -102
- data/VERSION +0 -1
- data/generators/vestal_versions/vestal_versions_generator.rb +0 -10
- data/init.rb +0 -1
- data/lib/vestal_versions/configuration.rb +0 -40
- data/lib/vestal_versions/tagging.rb +0 -50
- data/test/changes_test.rb +0 -169
- data/test/conditions_test.rb +0 -137
- data/test/configuration_test.rb +0 -39
- data/test/control_test.rb +0 -152
- data/test/creation_test.rb +0 -110
- data/test/options_test.rb +0 -52
- data/test/reload_test.rb +0 -19
- data/test/reset_test.rb +0 -112
- data/test/reversion_test.rb +0 -68
- data/test/schema.rb +0 -43
- data/test/tagging_test.rb +0 -39
- data/test/test_helper.rb +0 -11
- data/test/users_test.rb +0 -25
- data/test/version_test.rb +0 -43
- data/test/versioned_test.rb +0 -18
- data/test/versions_test.rb +0 -172
metadata
CHANGED
@@ -1,140 +1,191 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: vestal_versions
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 2.0.0
|
5
|
+
prerelease:
|
5
6
|
platform: ruby
|
6
|
-
authors:
|
7
|
-
-
|
7
|
+
authors:
|
8
|
+
- Steve Richert
|
9
|
+
- James O'Kelly
|
10
|
+
- C. Jason Harrelson
|
8
11
|
autorequire:
|
9
12
|
bindir: bin
|
10
13
|
cert_chain: []
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
dependencies:
|
15
|
-
- !ruby/object:Gem::Dependency
|
14
|
+
date: 2014-01-21 00:00:00.000000000 Z
|
15
|
+
dependencies:
|
16
|
+
- !ruby/object:Gem::Dependency
|
16
17
|
name: activerecord
|
18
|
+
requirement: !ruby/object:Gem::Requirement
|
19
|
+
none: false
|
20
|
+
requirements:
|
21
|
+
- - ! '>='
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: '3'
|
24
|
+
- - <
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '5'
|
17
27
|
type: :runtime
|
18
|
-
|
19
|
-
version_requirements: !ruby/object:Gem::Requirement
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
-
|
26
|
-
|
28
|
+
prerelease: false
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
|
+
none: false
|
31
|
+
requirements:
|
32
|
+
- - ! '>='
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '3'
|
35
|
+
- - <
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '5'
|
38
|
+
- !ruby/object:Gem::Dependency
|
39
|
+
name: activesupport
|
40
|
+
requirement: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '3'
|
46
|
+
- - <
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '5'
|
49
|
+
type: :runtime
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
none: false
|
53
|
+
requirements:
|
54
|
+
- - ! '>='
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: '3'
|
57
|
+
- - <
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: '5'
|
60
|
+
- !ruby/object:Gem::Dependency
|
61
|
+
name: bundler
|
62
|
+
requirement: !ruby/object:Gem::Requirement
|
63
|
+
none: false
|
64
|
+
requirements:
|
65
|
+
- - ~>
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '1.0'
|
27
68
|
type: :development
|
28
|
-
|
29
|
-
version_requirements: !ruby/object:Gem::Requirement
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
- !ruby/object:Gem::Dependency
|
36
|
-
name:
|
69
|
+
prerelease: false
|
70
|
+
version_requirements: !ruby/object:Gem::Requirement
|
71
|
+
none: false
|
72
|
+
requirements:
|
73
|
+
- - ~>
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '1.0'
|
76
|
+
- !ruby/object:Gem::Dependency
|
77
|
+
name: rake
|
78
|
+
requirement: !ruby/object:Gem::Requirement
|
79
|
+
none: false
|
80
|
+
requirements:
|
81
|
+
- - ~>
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '10.0'
|
37
84
|
type: :development
|
38
|
-
|
39
|
-
version_requirements: !ruby/object:Gem::Requirement
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
85
|
+
prerelease: false
|
86
|
+
version_requirements: !ruby/object:Gem::Requirement
|
87
|
+
none: false
|
88
|
+
requirements:
|
89
|
+
- - ~>
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: '10.0'
|
45
92
|
description: Keep a DRY history of your ActiveRecord models' changes
|
46
|
-
email:
|
93
|
+
email:
|
94
|
+
- steve.richert@gmail.com
|
95
|
+
- dreamr.okelly@gmail.com
|
96
|
+
- jason@lookforwardenterprises.com
|
47
97
|
executables: []
|
48
|
-
|
49
98
|
extensions: []
|
50
|
-
|
51
|
-
|
52
|
-
- LICENSE
|
53
|
-
- README.rdoc
|
54
|
-
files:
|
99
|
+
extra_rdoc_files: []
|
100
|
+
files:
|
55
101
|
- .gitignore
|
102
|
+
- .travis.yml
|
103
|
+
- CHANGELOG.md
|
104
|
+
- Gemfile
|
56
105
|
- LICENSE
|
57
106
|
- README.rdoc
|
58
107
|
- Rakefile
|
59
|
-
-
|
60
|
-
-
|
61
|
-
-
|
62
|
-
-
|
63
|
-
-
|
108
|
+
- gemfiles/activerecord_3_0.gemfile
|
109
|
+
- gemfiles/activerecord_3_1.gemfile
|
110
|
+
- gemfiles/activerecord_3_2.gemfile
|
111
|
+
- gemfiles/activerecord_4_0.gemfile
|
112
|
+
- lib/generators/vestal_versions.rb
|
113
|
+
- lib/generators/vestal_versions/migration/migration_generator.rb
|
114
|
+
- lib/generators/vestal_versions/migration/templates/initializer.rb
|
115
|
+
- lib/generators/vestal_versions/migration/templates/migration.rb
|
64
116
|
- lib/vestal_versions.rb
|
65
117
|
- lib/vestal_versions/changes.rb
|
66
118
|
- lib/vestal_versions/conditions.rb
|
67
|
-
- lib/vestal_versions/configuration.rb
|
68
119
|
- lib/vestal_versions/control.rb
|
69
120
|
- lib/vestal_versions/creation.rb
|
121
|
+
- lib/vestal_versions/deletion.rb
|
70
122
|
- lib/vestal_versions/options.rb
|
71
123
|
- lib/vestal_versions/reload.rb
|
72
124
|
- lib/vestal_versions/reset.rb
|
73
125
|
- lib/vestal_versions/reversion.rb
|
74
|
-
- lib/vestal_versions/tagging.rb
|
75
126
|
- lib/vestal_versions/users.rb
|
76
127
|
- lib/vestal_versions/version.rb
|
128
|
+
- lib/vestal_versions/version_tagging.rb
|
77
129
|
- lib/vestal_versions/versioned.rb
|
78
130
|
- lib/vestal_versions/versions.rb
|
79
|
-
-
|
80
|
-
-
|
81
|
-
-
|
82
|
-
-
|
83
|
-
-
|
84
|
-
-
|
85
|
-
-
|
86
|
-
-
|
87
|
-
-
|
88
|
-
-
|
89
|
-
-
|
90
|
-
-
|
91
|
-
-
|
92
|
-
-
|
93
|
-
-
|
94
|
-
-
|
131
|
+
- spec/spec_helper.rb
|
132
|
+
- spec/support/models.rb
|
133
|
+
- spec/support/schema.rb
|
134
|
+
- spec/vestal_versions/changes_spec.rb
|
135
|
+
- spec/vestal_versions/conditions_spec.rb
|
136
|
+
- spec/vestal_versions/control_spec.rb
|
137
|
+
- spec/vestal_versions/creation_spec.rb
|
138
|
+
- spec/vestal_versions/deletion_spec.rb
|
139
|
+
- spec/vestal_versions/options_spec.rb
|
140
|
+
- spec/vestal_versions/reload_spec.rb
|
141
|
+
- spec/vestal_versions/reset_spec.rb
|
142
|
+
- spec/vestal_versions/reversion_spec.rb
|
143
|
+
- spec/vestal_versions/users_spec.rb
|
144
|
+
- spec/vestal_versions/version_spec.rb
|
145
|
+
- spec/vestal_versions/version_tagging_spec.rb
|
146
|
+
- spec/vestal_versions/versioned_spec.rb
|
147
|
+
- spec/vestal_versions/versions_spec.rb
|
95
148
|
- vestal_versions.gemspec
|
96
|
-
has_rdoc: true
|
97
149
|
homepage: http://github.com/laserlemon/vestal_versions
|
98
|
-
licenses:
|
99
|
-
|
150
|
+
licenses:
|
151
|
+
- MIT
|
100
152
|
post_install_message:
|
101
|
-
rdoc_options:
|
102
|
-
|
103
|
-
require_paths:
|
153
|
+
rdoc_options: []
|
154
|
+
require_paths:
|
104
155
|
- lib
|
105
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
156
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
157
|
+
none: false
|
158
|
+
requirements:
|
159
|
+
- - ! '>='
|
160
|
+
- !ruby/object:Gem::Version
|
161
|
+
version: '0'
|
162
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
163
|
+
none: false
|
164
|
+
requirements:
|
165
|
+
- - ! '>='
|
166
|
+
- !ruby/object:Gem::Version
|
167
|
+
version: '0'
|
117
168
|
requirements: []
|
118
|
-
|
119
169
|
rubyforge_project:
|
120
|
-
rubygems_version: 1.
|
170
|
+
rubygems_version: 1.8.25
|
121
171
|
signing_key:
|
122
172
|
specification_version: 3
|
123
173
|
summary: Keep a DRY history of your ActiveRecord models' changes
|
124
|
-
test_files:
|
125
|
-
-
|
126
|
-
-
|
127
|
-
-
|
128
|
-
-
|
129
|
-
-
|
130
|
-
-
|
131
|
-
-
|
132
|
-
-
|
133
|
-
-
|
134
|
-
-
|
135
|
-
-
|
136
|
-
-
|
137
|
-
-
|
138
|
-
-
|
139
|
-
-
|
140
|
-
-
|
174
|
+
test_files:
|
175
|
+
- spec/spec_helper.rb
|
176
|
+
- spec/support/models.rb
|
177
|
+
- spec/support/schema.rb
|
178
|
+
- spec/vestal_versions/changes_spec.rb
|
179
|
+
- spec/vestal_versions/conditions_spec.rb
|
180
|
+
- spec/vestal_versions/control_spec.rb
|
181
|
+
- spec/vestal_versions/creation_spec.rb
|
182
|
+
- spec/vestal_versions/deletion_spec.rb
|
183
|
+
- spec/vestal_versions/options_spec.rb
|
184
|
+
- spec/vestal_versions/reload_spec.rb
|
185
|
+
- spec/vestal_versions/reset_spec.rb
|
186
|
+
- spec/vestal_versions/reversion_spec.rb
|
187
|
+
- spec/vestal_versions/users_spec.rb
|
188
|
+
- spec/vestal_versions/version_spec.rb
|
189
|
+
- spec/vestal_versions/version_tagging_spec.rb
|
190
|
+
- spec/vestal_versions/versioned_spec.rb
|
191
|
+
- spec/vestal_versions/versions_spec.rb
|
data/VERSION
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
1.0.2
|
@@ -1,10 +0,0 @@
|
|
1
|
-
class VestalVersionsGenerator < Rails::Generator::Base
|
2
|
-
def manifest
|
3
|
-
record do |m|
|
4
|
-
m.migration_template 'migration.rb', File.join('db', 'migrate'), :migration_file_name => 'create_vestal_versions'
|
5
|
-
|
6
|
-
m.directory File.join('config', 'initializers')
|
7
|
-
m.template 'initializer.rb', File.join('config', 'initializers', 'vestal_versions.rb')
|
8
|
-
end
|
9
|
-
end
|
10
|
-
end
|
data/init.rb
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), 'lib', 'vestal_versions')
|
@@ -1,40 +0,0 @@
|
|
1
|
-
module VestalVersions
|
2
|
-
# Allows for easy application-wide configuration of options passed into the +versioned+ method.
|
3
|
-
module Configuration
|
4
|
-
# The VestalVersions module is extended by VestalVersions::Configuration, allowing the
|
5
|
-
# +configure method+ to be used as follows in a Rails initializer:
|
6
|
-
#
|
7
|
-
# VestalVersions.configure do |config|
|
8
|
-
# config.class_name = "MyCustomVersion"
|
9
|
-
# config.dependent = :destroy
|
10
|
-
# end
|
11
|
-
#
|
12
|
-
# Each variable assignment in the +configure+ block corresponds directly with the options
|
13
|
-
# available to the +versioned+ method. Assigning common options in an initializer can keep your
|
14
|
-
# models tidy.
|
15
|
-
#
|
16
|
-
# If an option is given in both an initializer and in the options passed to +versioned+, the
|
17
|
-
# value given in the model itself will take precedence.
|
18
|
-
def configure
|
19
|
-
yield Configuration
|
20
|
-
end
|
21
|
-
|
22
|
-
class << self
|
23
|
-
# Simply stores a hash of options given to the +configure+ block.
|
24
|
-
def options
|
25
|
-
@options ||= {}
|
26
|
-
end
|
27
|
-
|
28
|
-
# If given a setter method name, will assign the first argument to the +options+ hash with
|
29
|
-
# the method name (sans "=") as the key. If given a getter method name, will attempt to
|
30
|
-
# a value from the +options+ hash for that key. If the key doesn't exist, defers to +super+.
|
31
|
-
def method_missing(symbol, *args)
|
32
|
-
if (method = symbol.to_s).sub!(/\=$/, '')
|
33
|
-
options[method.to_sym] = args.first
|
34
|
-
else
|
35
|
-
options.fetch(method.to_sym, super)
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
@@ -1,50 +0,0 @@
|
|
1
|
-
module VestalVersions
|
2
|
-
# Allows specific versions to be tagged with a custom string. Useful for assigning a more
|
3
|
-
# meaningful value to a version for the purpose of reversion.
|
4
|
-
module Tagging
|
5
|
-
def self.included(base) # :nodoc:
|
6
|
-
Version.send(:include, VersionMethods)
|
7
|
-
|
8
|
-
base.class_eval do
|
9
|
-
include InstanceMethods
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
# Adds an instance method which allows version tagging through the parent object.
|
14
|
-
module InstanceMethods
|
15
|
-
# Accepts a single string argument which is attached to the version record associated with
|
16
|
-
# the current version number of the parent object.
|
17
|
-
#
|
18
|
-
# Returns the given tag if successful, nil if not. Tags must be unique within the scope of
|
19
|
-
# the parent object. Tag creation will fail if non-unique.
|
20
|
-
#
|
21
|
-
# Version records corresponding to version number 1 are not typically created, but one will
|
22
|
-
# be built to house the given tag if the parent object's current version number is 1.
|
23
|
-
def tag_version(tag)
|
24
|
-
v = versions.at(version) || versions.build(:number => 1)
|
25
|
-
v.tag!(tag)
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
# Instance methods included into VestalVersions::Version to enable version tagging.
|
30
|
-
module VersionMethods
|
31
|
-
def self.included(base) # :nodoc:
|
32
|
-
base.class_eval do
|
33
|
-
validates_uniqueness_of :tag, :scope => [:versioned_id, :versioned_type], :if => :tagged?
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
# Attaches the given string to the version tag column. If the uniqueness validation fails,
|
38
|
-
# nil is returned. Otherwise, the given string is returned.
|
39
|
-
def tag!(tag)
|
40
|
-
write_attribute(:tag, tag)
|
41
|
-
save ? tag : nil
|
42
|
-
end
|
43
|
-
|
44
|
-
# Simply returns a boolean signifying whether the version instance has a tag value attached.
|
45
|
-
def tagged?
|
46
|
-
!tag.nil?
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
data/test/changes_test.rb
DELETED
@@ -1,169 +0,0 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), 'test_helper')
|
2
|
-
|
3
|
-
class ChangesTest < Test::Unit::TestCase
|
4
|
-
context "A version's changes" do
|
5
|
-
setup do
|
6
|
-
@user = User.create(:name => 'Steve Richert')
|
7
|
-
@user.update_attribute(:last_name, 'Jobs')
|
8
|
-
@changes = @user.versions.last.changes
|
9
|
-
end
|
10
|
-
|
11
|
-
should 'be a hash' do
|
12
|
-
assert_kind_of Hash, @changes
|
13
|
-
end
|
14
|
-
|
15
|
-
should 'not be empty' do
|
16
|
-
assert !@changes.empty?
|
17
|
-
end
|
18
|
-
|
19
|
-
should 'have string keys' do
|
20
|
-
@changes.keys.each do |key|
|
21
|
-
assert_kind_of String, key
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
should 'have array values' do
|
26
|
-
@changes.values.each do |value|
|
27
|
-
assert_kind_of Array, value
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
should 'have two-element values' do
|
32
|
-
@changes.values.each do |value|
|
33
|
-
assert_equal 2, value.size
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
should 'have unique-element values' do
|
38
|
-
@changes.values.each do |value|
|
39
|
-
assert_equal value.uniq, value
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
should "equal the model's changes" do
|
44
|
-
@user.first_name = 'Stephen'
|
45
|
-
model_changes = @user.changes
|
46
|
-
@user.save
|
47
|
-
changes = @user.versions.last.changes
|
48
|
-
assert_equal model_changes, changes
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
context 'A hash of changes' do
|
53
|
-
setup do
|
54
|
-
@changes = {'first_name' => ['Steve', 'Stephen']}
|
55
|
-
@other = {'first_name' => ['Catie', 'Catherine']}
|
56
|
-
end
|
57
|
-
|
58
|
-
should 'properly append other changes' do
|
59
|
-
expected = {'first_name' => ['Steve', 'Catherine']}
|
60
|
-
changes = @changes.append_changes(@other)
|
61
|
-
assert_equal expected, changes
|
62
|
-
@changes.append_changes!(@other)
|
63
|
-
assert_equal expected, @changes
|
64
|
-
end
|
65
|
-
|
66
|
-
should 'properly prepend other changes' do
|
67
|
-
expected = {'first_name' => ['Catie', 'Stephen']}
|
68
|
-
changes = @changes.prepend_changes(@other)
|
69
|
-
assert_equal expected, changes
|
70
|
-
@changes.prepend_changes!(@other)
|
71
|
-
assert_equal expected, @changes
|
72
|
-
end
|
73
|
-
|
74
|
-
should 'be reversible' do
|
75
|
-
expected = {'first_name' => ['Stephen', 'Steve']}
|
76
|
-
changes = @changes.reverse_changes
|
77
|
-
assert_equal expected, changes
|
78
|
-
@changes.reverse_changes!
|
79
|
-
assert_equal expected, @changes
|
80
|
-
end
|
81
|
-
end
|
82
|
-
|
83
|
-
context 'The changes between two versions' do
|
84
|
-
setup do
|
85
|
-
name = 'Steve Richert'
|
86
|
-
@user = User.create(:name => name) # 1
|
87
|
-
@user.update_attribute(:last_name, 'Jobs') # 2
|
88
|
-
@user.update_attribute(:first_name, 'Stephen') # 3
|
89
|
-
@user.update_attribute(:last_name, 'Richert') # 4
|
90
|
-
@user.update_attribute(:name, name) # 5
|
91
|
-
@version = @user.version
|
92
|
-
end
|
93
|
-
|
94
|
-
should 'be a hash' do
|
95
|
-
1.upto(@version) do |i|
|
96
|
-
1.upto(@version) do |j|
|
97
|
-
changes = @user.changes_between(i, j)
|
98
|
-
assert_kind_of Hash, changes
|
99
|
-
end
|
100
|
-
end
|
101
|
-
end
|
102
|
-
|
103
|
-
should 'have string keys' do
|
104
|
-
1.upto(@version) do |i|
|
105
|
-
1.upto(@version) do |j|
|
106
|
-
changes = @user.changes_between(i, j)
|
107
|
-
changes.keys.each do |key|
|
108
|
-
assert_kind_of String, key
|
109
|
-
end
|
110
|
-
end
|
111
|
-
end
|
112
|
-
end
|
113
|
-
|
114
|
-
should 'have array values' do
|
115
|
-
1.upto(@version) do |i|
|
116
|
-
1.upto(@version) do |j|
|
117
|
-
changes = @user.changes_between(i, j)
|
118
|
-
changes.values.each do |value|
|
119
|
-
assert_kind_of Array, value
|
120
|
-
end
|
121
|
-
end
|
122
|
-
end
|
123
|
-
end
|
124
|
-
|
125
|
-
should 'have two-element values' do
|
126
|
-
1.upto(@version) do |i|
|
127
|
-
1.upto(@version) do |j|
|
128
|
-
changes = @user.changes_between(i, j)
|
129
|
-
changes.values.each do |value|
|
130
|
-
assert_equal 2, value.size
|
131
|
-
end
|
132
|
-
end
|
133
|
-
end
|
134
|
-
end
|
135
|
-
|
136
|
-
should 'have unique-element values' do
|
137
|
-
1.upto(@version) do |i|
|
138
|
-
1.upto(@version) do |j|
|
139
|
-
changes = @user.changes_between(i, j)
|
140
|
-
changes.values.each do |value|
|
141
|
-
assert_equal value.uniq, value
|
142
|
-
end
|
143
|
-
end
|
144
|
-
end
|
145
|
-
end
|
146
|
-
|
147
|
-
should 'be empty between identical versions' do
|
148
|
-
assert @user.changes_between(1, @version).empty?
|
149
|
-
assert @user.changes_between(@version, 1).empty?
|
150
|
-
end
|
151
|
-
|
152
|
-
should 'be should reverse with direction' do
|
153
|
-
1.upto(@version) do |i|
|
154
|
-
i.upto(@version) do |j|
|
155
|
-
up = @user.changes_between(i, j)
|
156
|
-
down = @user.changes_between(j, i)
|
157
|
-
assert_equal up, down.reverse_changes
|
158
|
-
end
|
159
|
-
end
|
160
|
-
end
|
161
|
-
|
162
|
-
should 'be empty with invalid arguments' do
|
163
|
-
1.upto(@version) do |i|
|
164
|
-
assert @user.changes_between(i, nil)
|
165
|
-
assert @user.changes_between(nil, i)
|
166
|
-
end
|
167
|
-
end
|
168
|
-
end
|
169
|
-
end
|