brianjlandau-vestal_versions 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. data/.gitignore +27 -0
  2. data/Gemfile +3 -0
  3. data/LICENSE +20 -0
  4. data/README.rdoc +196 -0
  5. data/Rakefile +50 -0
  6. data/VERSION +1 -0
  7. data/generators/vestal_versions/templates/initializer.rb +9 -0
  8. data/generators/vestal_versions/templates/migration.rb +28 -0
  9. data/generators/vestal_versions/vestal_versions_generator.rb +10 -0
  10. data/init.rb +1 -0
  11. data/lib/vestal_versions.rb +104 -0
  12. data/lib/vestal_versions/associations.rb +67 -0
  13. data/lib/vestal_versions/changes.rb +125 -0
  14. data/lib/vestal_versions/conditions.rb +69 -0
  15. data/lib/vestal_versions/configuration.rb +40 -0
  16. data/lib/vestal_versions/control.rb +175 -0
  17. data/lib/vestal_versions/creation.rb +85 -0
  18. data/lib/vestal_versions/deletion.rb +46 -0
  19. data/lib/vestal_versions/options.rb +45 -0
  20. data/lib/vestal_versions/reload.rb +22 -0
  21. data/lib/vestal_versions/reset.rb +28 -0
  22. data/lib/vestal_versions/reversion.rb +92 -0
  23. data/lib/vestal_versions/tagging.rb +54 -0
  24. data/lib/vestal_versions/users.rb +56 -0
  25. data/lib/vestal_versions/version.rb +76 -0
  26. data/lib/vestal_versions/versioned.rb +30 -0
  27. data/lib/vestal_versions/versions.rb +74 -0
  28. data/test/associations_test.rb +49 -0
  29. data/test/changes_test.rb +169 -0
  30. data/test/conditions_test.rb +137 -0
  31. data/test/configuration_test.rb +39 -0
  32. data/test/control_test.rb +152 -0
  33. data/test/creation_test.rb +110 -0
  34. data/test/deletion_test.rb +121 -0
  35. data/test/options_test.rb +52 -0
  36. data/test/reload_test.rb +19 -0
  37. data/test/reset_test.rb +112 -0
  38. data/test/reversion_test.rb +99 -0
  39. data/test/schema.rb +62 -0
  40. data/test/tagging_test.rb +39 -0
  41. data/test/test_helper.rb +12 -0
  42. data/test/users_test.rb +25 -0
  43. data/test/version_test.rb +61 -0
  44. data/test/versioned_test.rb +18 -0
  45. data/test/versions_test.rb +172 -0
  46. data/vestal_versions.gemspec +124 -0
  47. metadata +245 -0
@@ -0,0 +1,172 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), 'test_helper'))
2
+
3
+ class VersionsTest < Test::Unit::TestCase
4
+ context 'A collection of associated versions' do
5
+ setup do
6
+ @user, @times = User.new, {}
7
+ names = ['Steve Richert', 'Stephen Richert', 'Stephen Jobs', 'Steve Jobs']
8
+ time = names.size.hours.ago
9
+ names.each do |name|
10
+ @user.update_attributes(:name => name)
11
+ @user.tag_version(@user.version.to_s)
12
+ time += 1.hour
13
+ @user.versions.last.update_attributes(:created_at => time)
14
+ @times[@user.version] = time
15
+ end
16
+ end
17
+
18
+ should 'be searchable between two valid version values' do
19
+ @times.keys.each do |number|
20
+ @times.values.each do |time|
21
+ assert_kind_of Array, @user.versions.between(number, number)
22
+ assert_kind_of Array, @user.versions.between(number, time)
23
+ assert_kind_of Array, @user.versions.between(time, number)
24
+ assert_kind_of Array, @user.versions.between(time, time)
25
+ assert !@user.versions.between(number, number).empty?
26
+ assert !@user.versions.between(number, time).empty?
27
+ assert !@user.versions.between(time, number).empty?
28
+ assert !@user.versions.between(time, time).empty?
29
+ end
30
+ end
31
+ end
32
+
33
+ should 'return an empty array when searching between a valid and an invalid version value' do
34
+ @times.each do |number, time|
35
+ assert_equal [], @user.versions.between(number, nil)
36
+ assert_equal [], @user.versions.between(time, nil)
37
+ assert_equal [], @user.versions.between(nil, number)
38
+ assert_equal [], @user.versions.between(nil, time)
39
+ end
40
+ end
41
+
42
+ should 'return an empty array when searching between two invalid version values' do
43
+ assert_equal [], @user.versions.between(nil, nil)
44
+ end
45
+
46
+ should 'be searchable before a valid version value' do
47
+ @times.sort.each_with_index do |(number, time), i|
48
+ assert_equal i, @user.versions.before(number).size
49
+ assert_equal i, @user.versions.before(time).size
50
+ end
51
+ end
52
+
53
+ should 'return an empty array when searching before an invalid version value' do
54
+ assert_equal [], @user.versions.before(nil)
55
+ end
56
+
57
+ should 'be searchable after a valid version value' do
58
+ @times.sort.reverse.each_with_index do |(number, time), i|
59
+ assert_equal i, @user.versions.after(number).size
60
+ assert_equal i, @user.versions.after(time).size
61
+ end
62
+ end
63
+
64
+ should 'return an empty array when searching after an invalid version value' do
65
+ assert_equal [], @user.versions.after(nil)
66
+ end
67
+
68
+ should 'be fetchable by version number' do
69
+ @times.keys.each do |number|
70
+ assert_kind_of VestalVersions::Version, @user.versions.at(number)
71
+ assert_equal number, @user.versions.at(number).number
72
+ end
73
+ end
74
+
75
+ should 'be fetchable by tag' do
76
+ @times.keys.map{|n| [n, n.to_s] }.each do |number, tag|
77
+ assert_kind_of VestalVersions::Version, @user.versions.at(tag)
78
+ assert_equal number, @user.versions.at(tag).number
79
+ end
80
+ end
81
+
82
+ should "be fetchable by the exact time of a version's creation" do
83
+ @times.each do |number, time|
84
+ assert_kind_of VestalVersions::Version, @user.versions.at(time)
85
+ assert_equal number, @user.versions.at(time).number
86
+ end
87
+ end
88
+
89
+ should "be fetchable by any time after the model's creation" do
90
+ @times.each do |number, time|
91
+ assert_kind_of VestalVersions::Version, @user.versions.at(time + 30.minutes)
92
+ assert_equal number, @user.versions.at(time + 30.minutes).number
93
+ end
94
+ end
95
+
96
+ should "return nil when fetching a time before the model's creation" do
97
+ creation = @times.values.min
98
+ assert_nil @user.versions.at(creation - 1.second)
99
+ end
100
+
101
+ should 'be fetchable by an association extension method' do
102
+ assert_kind_of VestalVersions::Version, @user.versions.at(:first)
103
+ assert_kind_of VestalVersions::Version, @user.versions.at(:last)
104
+ assert_equal @times.keys.min, @user.versions.at(:first).number
105
+ assert_equal @times.keys.max, @user.versions.at(:last).number
106
+ end
107
+
108
+ should 'be fetchable by a version object' do
109
+ @times.keys.each do |number|
110
+ version = @user.versions.at(number)
111
+ assert_kind_of VestalVersions::Version, version
112
+ assert_kind_of VestalVersions::Version, @user.versions.at(version)
113
+ assert_equal number, @user.versions.at(version).number
114
+ end
115
+ end
116
+
117
+ should 'return nil when fetching an invalid version value' do
118
+ assert_nil @user.versions.at(nil)
119
+ end
120
+
121
+ should 'provide a version number for any given numeric version value' do
122
+ @times.keys.each do |number|
123
+ assert_kind_of Fixnum, @user.versions.number_at(number)
124
+ assert_kind_of Fixnum, @user.versions.number_at(number + 0.5)
125
+ assert_equal @user.versions.number_at(number), @user.versions.number_at(number + 0.5)
126
+ end
127
+ end
128
+
129
+ should 'provide a version number for a valid tag' do
130
+ @times.keys.map{|n| [n, n.to_s] }.each do |number, tag|
131
+ assert_kind_of Fixnum, @user.versions.number_at(tag)
132
+ assert_equal number, @user.versions.number_at(tag)
133
+ end
134
+ end
135
+
136
+ should 'return nil when providing a version number for an invalid tag' do
137
+ assert_nil @user.versions.number_at('INVALID')
138
+ end
139
+
140
+ should 'provide a version number of a version corresponding to an association extension method' do
141
+ assert_kind_of VestalVersions::Version, @user.versions.at(:first)
142
+ assert_kind_of VestalVersions::Version, @user.versions.at(:last)
143
+ assert_equal @times.keys.min, @user.versions.number_at(:first)
144
+ assert_equal @times.keys.max, @user.versions.number_at(:last)
145
+ end
146
+
147
+ should 'return nil when providing a version number for an invalid association extension method' do
148
+ assert_nil @user.versions.number_at(:INVALID)
149
+ end
150
+
151
+ should "provide a version number for any time after the model's creation" do
152
+ @times.each do |number, time|
153
+ assert_kind_of Fixnum, @user.versions.number_at(time + 30.minutes)
154
+ assert_equal number, @user.versions.number_at(time + 30.minutes)
155
+ end
156
+ end
157
+
158
+ should "provide a version number of 1 for a time before the model's creation" do
159
+ creation = @times.values.min
160
+ assert_equal 1, @user.versions.number_at(creation - 1.second)
161
+ end
162
+
163
+ should 'provide a version number for a given version object' do
164
+ @times.keys.each do |number|
165
+ version = @user.versions.at(number)
166
+ assert_kind_of VestalVersions::Version, version
167
+ assert_kind_of Fixnum, @user.versions.number_at(version)
168
+ assert_equal number, @user.versions.number_at(version)
169
+ end
170
+ end
171
+ end
172
+ end
@@ -0,0 +1,124 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{vestal_versions}
8
+ s.version = "1.2.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["laserlemon"]
12
+ s.date = %q{2010-10-11}
13
+ s.description = %q{Keep a DRY history of your ActiveRecord models' changes}
14
+ s.email = %q{steve@laserlemon.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".gitignore",
21
+ "Gemfile",
22
+ "LICENSE",
23
+ "README.rdoc",
24
+ "Rakefile",
25
+ "VERSION",
26
+ "generators/vestal_versions/templates/initializer.rb",
27
+ "generators/vestal_versions/templates/migration.rb",
28
+ "generators/vestal_versions/vestal_versions_generator.rb",
29
+ "init.rb",
30
+ "lib/vestal_versions.rb",
31
+ "lib/vestal_versions/changes.rb",
32
+ "lib/vestal_versions/conditions.rb",
33
+ "lib/vestal_versions/configuration.rb",
34
+ "lib/vestal_versions/control.rb",
35
+ "lib/vestal_versions/creation.rb",
36
+ "lib/vestal_versions/deletion.rb",
37
+ "lib/vestal_versions/options.rb",
38
+ "lib/vestal_versions/reload.rb",
39
+ "lib/vestal_versions/reset.rb",
40
+ "lib/vestal_versions/reversion.rb",
41
+ "lib/vestal_versions/tagging.rb",
42
+ "lib/vestal_versions/users.rb",
43
+ "lib/vestal_versions/version.rb",
44
+ "lib/vestal_versions/versioned.rb",
45
+ "lib/vestal_versions/versions.rb",
46
+ "test/changes_test.rb",
47
+ "test/conditions_test.rb",
48
+ "test/configuration_test.rb",
49
+ "test/control_test.rb",
50
+ "test/creation_test.rb",
51
+ "test/deletion_test.rb",
52
+ "test/options_test.rb",
53
+ "test/reload_test.rb",
54
+ "test/reset_test.rb",
55
+ "test/reversion_test.rb",
56
+ "test/schema.rb",
57
+ "test/tagging_test.rb",
58
+ "test/test_helper.rb",
59
+ "test/users_test.rb",
60
+ "test/version_test.rb",
61
+ "test/versioned_test.rb",
62
+ "test/versions_test.rb",
63
+ "vestal_versions.gemspec"
64
+ ]
65
+ s.homepage = %q{http://github.com/laserlemon/vestal_versions}
66
+ s.rdoc_options = ["--charset=UTF-8"]
67
+ s.require_paths = ["lib"]
68
+ s.rubygems_version = %q{1.3.7}
69
+ s.summary = %q{Keep a DRY history of your ActiveRecord models' changes}
70
+ s.test_files = [
71
+ "test/schema.rb",
72
+ "test/configuration_test.rb",
73
+ "test/control_test.rb",
74
+ "test/version_test.rb",
75
+ "test/conditions_test.rb",
76
+ "test/test_helper.rb",
77
+ "test/versioned_test.rb",
78
+ "test/tagging_test.rb",
79
+ "test/reload_test.rb",
80
+ "test/users_test.rb",
81
+ "test/reset_test.rb",
82
+ "test/reversion_test.rb",
83
+ "test/versions_test.rb",
84
+ "test/deletion_test.rb",
85
+ "test/changes_test.rb",
86
+ "test/creation_test.rb",
87
+ "test/options_test.rb"
88
+ ]
89
+
90
+ if s.respond_to? :specification_version then
91
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
92
+ s.specification_version = 3
93
+
94
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
95
+ s.add_runtime_dependency(%q<activerecord>, [">= 3.0.0"])
96
+ s.add_runtime_dependency(%q<railties>, [">= 3.0.0"])
97
+ s.add_development_dependency(%q<shoulda>, [">= 0"])
98
+ s.add_development_dependency(%q<mocha>, [">= 0"])
99
+ s.add_development_dependency(%q<rcov>, [">= 0"])
100
+ s.add_development_dependency(%q<rake>, [">= 0"])
101
+ s.add_development_dependency(%q<jeweler>, [">= 0"])
102
+ s.add_development_dependency(%q<sqlite3-ruby>, [">= 0"])
103
+ else
104
+ s.add_dependency(%q<activerecord>, [">= 3.0.0"])
105
+ s.add_dependency(%q<railties>, [">= 3.0.0"])
106
+ s.add_dependency(%q<shoulda>, [">= 0"])
107
+ s.add_dependency(%q<mocha>, [">= 0"])
108
+ s.add_dependency(%q<rcov>, [">= 0"])
109
+ s.add_dependency(%q<rake>, [">= 0"])
110
+ s.add_dependency(%q<jeweler>, [">= 0"])
111
+ s.add_dependency(%q<sqlite3-ruby>, [">= 0"])
112
+ end
113
+ else
114
+ s.add_dependency(%q<activerecord>, [">= 3.0.0"])
115
+ s.add_dependency(%q<railties>, [">= 3.0.0"])
116
+ s.add_dependency(%q<shoulda>, [">= 0"])
117
+ s.add_dependency(%q<mocha>, [">= 0"])
118
+ s.add_dependency(%q<rcov>, [">= 0"])
119
+ s.add_dependency(%q<rake>, [">= 0"])
120
+ s.add_dependency(%q<jeweler>, [">= 0"])
121
+ s.add_dependency(%q<sqlite3-ruby>, [">= 0"])
122
+ end
123
+ end
124
+
metadata ADDED
@@ -0,0 +1,245 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: brianjlandau-vestal_versions
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease: false
6
+ segments:
7
+ - 1
8
+ - 3
9
+ - 0
10
+ version: 1.3.0
11
+ platform: ruby
12
+ authors:
13
+ - laserlemon
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-10-28 00:00:00 -04:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: activerecord
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 19
30
+ segments:
31
+ - 2
32
+ - 3
33
+ - 8
34
+ version: 2.3.8
35
+ type: :runtime
36
+ version_requirements: *id001
37
+ - !ruby/object:Gem::Dependency
38
+ name: rails
39
+ prerelease: false
40
+ requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ hash: 19
46
+ segments:
47
+ - 2
48
+ - 3
49
+ - 8
50
+ version: 2.3.8
51
+ type: :runtime
52
+ version_requirements: *id002
53
+ - !ruby/object:Gem::Dependency
54
+ name: shoulda
55
+ prerelease: false
56
+ requirement: &id003 !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ hash: 3
62
+ segments:
63
+ - 0
64
+ version: "0"
65
+ type: :development
66
+ version_requirements: *id003
67
+ - !ruby/object:Gem::Dependency
68
+ name: mocha
69
+ prerelease: false
70
+ requirement: &id004 !ruby/object:Gem::Requirement
71
+ none: false
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ hash: 3
76
+ segments:
77
+ - 0
78
+ version: "0"
79
+ type: :development
80
+ version_requirements: *id004
81
+ - !ruby/object:Gem::Dependency
82
+ name: rcov
83
+ prerelease: false
84
+ requirement: &id005 !ruby/object:Gem::Requirement
85
+ none: false
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ hash: 3
90
+ segments:
91
+ - 0
92
+ version: "0"
93
+ type: :development
94
+ version_requirements: *id005
95
+ - !ruby/object:Gem::Dependency
96
+ name: rake
97
+ prerelease: false
98
+ requirement: &id006 !ruby/object:Gem::Requirement
99
+ none: false
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ hash: 3
104
+ segments:
105
+ - 0
106
+ version: "0"
107
+ type: :development
108
+ version_requirements: *id006
109
+ - !ruby/object:Gem::Dependency
110
+ name: jeweler
111
+ prerelease: false
112
+ requirement: &id007 !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ hash: 3
118
+ segments:
119
+ - 0
120
+ version: "0"
121
+ type: :development
122
+ version_requirements: *id007
123
+ - !ruby/object:Gem::Dependency
124
+ name: sqlite3-ruby
125
+ prerelease: false
126
+ requirement: &id008 !ruby/object:Gem::Requirement
127
+ none: false
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ hash: 3
132
+ segments:
133
+ - 0
134
+ version: "0"
135
+ type: :development
136
+ version_requirements: *id008
137
+ description: Keep a DRY history of your ActiveRecord models' changes
138
+ email: steve@laserlemon.com
139
+ executables: []
140
+
141
+ extensions: []
142
+
143
+ extra_rdoc_files:
144
+ - LICENSE
145
+ - README.rdoc
146
+ files:
147
+ - .gitignore
148
+ - Gemfile
149
+ - LICENSE
150
+ - README.rdoc
151
+ - Rakefile
152
+ - VERSION
153
+ - generators/vestal_versions/templates/initializer.rb
154
+ - generators/vestal_versions/templates/migration.rb
155
+ - generators/vestal_versions/vestal_versions_generator.rb
156
+ - init.rb
157
+ - lib/vestal_versions.rb
158
+ - lib/vestal_versions/associations.rb
159
+ - lib/vestal_versions/changes.rb
160
+ - lib/vestal_versions/conditions.rb
161
+ - lib/vestal_versions/configuration.rb
162
+ - lib/vestal_versions/control.rb
163
+ - lib/vestal_versions/creation.rb
164
+ - lib/vestal_versions/deletion.rb
165
+ - lib/vestal_versions/options.rb
166
+ - lib/vestal_versions/reload.rb
167
+ - lib/vestal_versions/reset.rb
168
+ - lib/vestal_versions/reversion.rb
169
+ - lib/vestal_versions/tagging.rb
170
+ - lib/vestal_versions/users.rb
171
+ - lib/vestal_versions/version.rb
172
+ - lib/vestal_versions/versioned.rb
173
+ - lib/vestal_versions/versions.rb
174
+ - test/associations_test.rb
175
+ - test/changes_test.rb
176
+ - test/conditions_test.rb
177
+ - test/configuration_test.rb
178
+ - test/control_test.rb
179
+ - test/creation_test.rb
180
+ - test/deletion_test.rb
181
+ - test/options_test.rb
182
+ - test/reload_test.rb
183
+ - test/reset_test.rb
184
+ - test/reversion_test.rb
185
+ - test/schema.rb
186
+ - test/tagging_test.rb
187
+ - test/test_helper.rb
188
+ - test/users_test.rb
189
+ - test/version_test.rb
190
+ - test/versioned_test.rb
191
+ - test/versions_test.rb
192
+ - vestal_versions.gemspec
193
+ has_rdoc: true
194
+ homepage: http://github.com/laserlemon/vestal_versions
195
+ licenses: []
196
+
197
+ post_install_message:
198
+ rdoc_options:
199
+ - --charset=UTF-8
200
+ require_paths:
201
+ - lib
202
+ required_ruby_version: !ruby/object:Gem::Requirement
203
+ none: false
204
+ requirements:
205
+ - - ">="
206
+ - !ruby/object:Gem::Version
207
+ hash: 3
208
+ segments:
209
+ - 0
210
+ version: "0"
211
+ required_rubygems_version: !ruby/object:Gem::Requirement
212
+ none: false
213
+ requirements:
214
+ - - ">="
215
+ - !ruby/object:Gem::Version
216
+ hash: 3
217
+ segments:
218
+ - 0
219
+ version: "0"
220
+ requirements: []
221
+
222
+ rubyforge_project:
223
+ rubygems_version: 1.3.7
224
+ signing_key:
225
+ specification_version: 3
226
+ summary: Keep a DRY history of your ActiveRecord models' changes
227
+ test_files:
228
+ - test/associations_test.rb
229
+ - test/changes_test.rb
230
+ - test/conditions_test.rb
231
+ - test/configuration_test.rb
232
+ - test/control_test.rb
233
+ - test/creation_test.rb
234
+ - test/deletion_test.rb
235
+ - test/options_test.rb
236
+ - test/reload_test.rb
237
+ - test/reset_test.rb
238
+ - test/reversion_test.rb
239
+ - test/schema.rb
240
+ - test/tagging_test.rb
241
+ - test/test_helper.rb
242
+ - test/users_test.rb
243
+ - test/version_test.rb
244
+ - test/versioned_test.rb
245
+ - test/versions_test.rb