houston-vestal_versions 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +22 -0
  3. data/.travis.yml +22 -0
  4. data/CHANGELOG.md +7 -0
  5. data/Gemfile +10 -0
  6. data/LICENSE +20 -0
  7. data/README.rdoc +206 -0
  8. data/Rakefile +6 -0
  9. data/gemfiles/activerecord_3_0.gemfile +10 -0
  10. data/gemfiles/activerecord_3_1.gemfile +10 -0
  11. data/gemfiles/activerecord_3_2.gemfile +10 -0
  12. data/gemfiles/activerecord_4_0.gemfile +10 -0
  13. data/lib/generators/vestal_versions/migration/migration_generator.rb +17 -0
  14. data/lib/generators/vestal_versions/migration/templates/initializer.rb +9 -0
  15. data/lib/generators/vestal_versions/migration/templates/migration.rb +28 -0
  16. data/lib/generators/vestal_versions.rb +11 -0
  17. data/lib/vestal_versions/changes.rb +121 -0
  18. data/lib/vestal_versions/conditions.rb +57 -0
  19. data/lib/vestal_versions/control.rb +199 -0
  20. data/lib/vestal_versions/creation.rb +93 -0
  21. data/lib/vestal_versions/deletion.rb +37 -0
  22. data/lib/vestal_versions/options.rb +41 -0
  23. data/lib/vestal_versions/reload.rb +16 -0
  24. data/lib/vestal_versions/reset.rb +24 -0
  25. data/lib/vestal_versions/reversion.rb +81 -0
  26. data/lib/vestal_versions/users.rb +54 -0
  27. data/lib/vestal_versions/version.rb +84 -0
  28. data/lib/vestal_versions/version_tagging.rb +51 -0
  29. data/lib/vestal_versions/versioned.rb +27 -0
  30. data/lib/vestal_versions/versions.rb +89 -0
  31. data/lib/vestal_versions.rb +126 -0
  32. data/spec/spec_helper.rb +28 -0
  33. data/spec/support/models.rb +19 -0
  34. data/spec/support/schema.rb +25 -0
  35. data/spec/vestal_versions/changes_spec.rb +134 -0
  36. data/spec/vestal_versions/conditions_spec.rb +103 -0
  37. data/spec/vestal_versions/control_spec.rb +120 -0
  38. data/spec/vestal_versions/creation_spec.rb +90 -0
  39. data/spec/vestal_versions/deletion_spec.rb +86 -0
  40. data/spec/vestal_versions/options_spec.rb +45 -0
  41. data/spec/vestal_versions/reload_spec.rb +18 -0
  42. data/spec/vestal_versions/reset_spec.rb +111 -0
  43. data/spec/vestal_versions/reversion_spec.rb +103 -0
  44. data/spec/vestal_versions/users_spec.rb +21 -0
  45. data/spec/vestal_versions/version_spec.rb +61 -0
  46. data/spec/vestal_versions/version_tagging_spec.rb +39 -0
  47. data/spec/vestal_versions/versioned_spec.rb +16 -0
  48. data/spec/vestal_versions/versions_spec.rb +176 -0
  49. data/vestal_versions.gemspec +23 -0
  50. metadata +181 -0
@@ -0,0 +1,176 @@
1
+ require 'spec_helper'
2
+
3
+ describe VestalVersions::Versions do
4
+ subject{ User.new }
5
+ let(:times){ {} }
6
+ let(:names){
7
+ ['Steve Richert', 'Stephen Richert', 'Stephen Jobs', 'Steve Jobs']
8
+ }
9
+
10
+ before do
11
+ time = names.size.hours.ago
12
+
13
+ names.each do |name|
14
+ subject.update_attribute(:name, name)
15
+ subject.tag_version(subject.version.to_s)
16
+ time += 1.hour
17
+
18
+ subject.versions.last.update_attribute(:created_at, time)
19
+ times[subject.version] = time
20
+ end
21
+ end
22
+
23
+ it 'is searchable between two valid version values' do
24
+ times.keys.each do |number|
25
+ times.values.each do |time|
26
+ subject.versions.between(number, number).should be_a(Array)
27
+ subject.versions.between(number, time).should be_a(Array)
28
+ subject.versions.between(time, number).should be_a(Array)
29
+ subject.versions.between(time, time).should be_a(Array)
30
+ subject.versions.between(number, number).should_not be_empty
31
+ subject.versions.between(number, time).should_not be_empty
32
+ subject.versions.between(time, number).should_not be_empty
33
+ subject.versions.between(time, time).should_not be_empty
34
+ end
35
+ end
36
+ end
37
+
38
+ it 'returns an empty array when searching between a valid and an invalid version value' do
39
+ times.each do |number, time|
40
+ subject.versions.between(number, nil).should == []
41
+ subject.versions.between(time, nil).should == []
42
+ subject.versions.between(nil, number).should == []
43
+ subject.versions.between(nil, time).should == []
44
+ end
45
+ end
46
+
47
+ it 'returns an empty array when searching between two invalid version values' do
48
+ subject.versions.between(nil, nil).should == []
49
+ end
50
+
51
+ it 'is searchable before a valid version value' do
52
+ times.sort.each_with_index do |(number, time), i|
53
+ subject.versions.before(number).size.should == i
54
+ subject.versions.before(time).size.should == i
55
+ end
56
+ end
57
+
58
+ it 'returns an empty array when searching before an invalid version value' do
59
+ subject.versions.before(nil).should == []
60
+ end
61
+
62
+ it 'is searchable after a valid version value' do
63
+ times.sort.reverse.each_with_index do |(number, time), i|
64
+ subject.versions.after(number).size.should == i
65
+ subject.versions.after(time).size.should == i
66
+ end
67
+ end
68
+
69
+ it 'returns an empty array when searching after an invalid version value' do
70
+ subject.versions.after(nil).should == []
71
+ end
72
+
73
+ it 'is fetchable by version number' do
74
+ times.keys.each do |number|
75
+ subject.versions.at(number).should be_a(VestalVersions::Version)
76
+ subject.versions.at(number).number.should == number
77
+ end
78
+ end
79
+
80
+ it 'is fetchable by tag' do
81
+ times.keys.map{|n| [n, n.to_s] }.each do |number, tag|
82
+ subject.versions.at(tag).should be_a(VestalVersions::Version)
83
+ subject.versions.at(tag).number.should == number
84
+ end
85
+ end
86
+
87
+ it "is fetchable by the exact time of a version's creation" do
88
+ times.each do |number, time|
89
+ subject.versions.at(time).should be_a(VestalVersions::Version)
90
+ subject.versions.at(time).number.should == number
91
+ end
92
+ end
93
+
94
+ it "is fetchable by any time after the model's creation" do
95
+ times.each do |number, time|
96
+ subject.versions.at(time + 30.minutes).should be_a(VestalVersions::Version)
97
+ subject.versions.at(time + 30.minutes).number.should == number
98
+ end
99
+ end
100
+
101
+ it "returns nil when fetching a time before the model's creation" do
102
+ creation = times.values.min
103
+ subject.versions.at(creation - 1.second).should be_nil
104
+ end
105
+
106
+ it 'is fetchable by an association extension method' do
107
+ subject.versions.at(:first).should be_a(VestalVersions::Version)
108
+ subject.versions.at(:last).should be_a(VestalVersions::Version)
109
+ subject.versions.at(:first).number.should == times.keys.min
110
+ subject.versions.at(:last).number.should == times.keys.max
111
+ end
112
+
113
+ it 'is fetchable by a version object' do
114
+ times.keys.each do |number|
115
+ version = subject.versions.at(number)
116
+
117
+ subject.versions.at(version).should be_a(VestalVersions::Version)
118
+ subject.versions.at(version).number.should == number
119
+ end
120
+ end
121
+
122
+ it 'returns nil when fetching an invalid version value' do
123
+ subject.versions.at(nil).should be_nil
124
+ end
125
+
126
+ it 'provides a version number for any given numeric version value' do
127
+ times.keys.each do |number|
128
+ subject.versions.number_at(number).should be_a(Fixnum)
129
+ subject.versions.number_at(number + 0.5).should be_a(Fixnum)
130
+ subject.versions.number_at(number).should == subject.versions.number_at(number + 0.5)
131
+ end
132
+ end
133
+
134
+ it 'provides a version number for a valid tag' do
135
+ times.keys.map{|n| [n, n.to_s] }.each do |number, tag|
136
+ subject.versions.number_at(tag).should be_a(Fixnum)
137
+ subject.versions.number_at(tag).should == number
138
+ end
139
+ end
140
+
141
+ it 'returns nil when providing a version number for an invalid tag' do
142
+ subject.versions.number_at('INVALID').should be_nil
143
+ end
144
+
145
+ it 'provides a version number of a version corresponding to an association extension method' do
146
+ subject.versions.at(:first).should be_a(VestalVersions::Version)
147
+ subject.versions.at(:last).should be_a(VestalVersions::Version)
148
+ subject.versions.number_at(:first).should == times.keys.min
149
+ subject.versions.number_at(:last).should == times.keys.max
150
+ end
151
+
152
+ it 'returns nil when providing a version number for an invalid association extension method' do
153
+ subject.versions.number_at(:INVALID).should be_nil
154
+ end
155
+
156
+ it "provides a version number for any time after the model's creation" do
157
+ times.each do |number, time|
158
+ subject.versions.number_at(time + 30.minutes).should be_a(Fixnum)
159
+ subject.versions.number_at(time + 30.minutes).should == number
160
+ end
161
+ end
162
+
163
+ it "provides a version number of 1 for a time before the model's creation" do
164
+ creation = times.values.min
165
+ subject.versions.number_at(creation - 1.second).should == 1
166
+ end
167
+
168
+ it 'provides a version number for a given version object' do
169
+ times.keys.each do |number|
170
+ version = subject.versions.at(number)
171
+
172
+ subject.versions.number_at(version).should == number
173
+ end
174
+ end
175
+
176
+ end
@@ -0,0 +1,23 @@
1
+ # encoding: utf-8
2
+
3
+ Gem::Specification.new do |gem|
4
+ gem.name = 'houston-vestal_versions'
5
+ gem.version = '2.0.0'
6
+
7
+ gem.authors = ['Steve Richert', "James O'Kelly", 'C. Jason Harrelson']
8
+ gem.email = ['steve.richert@gmail.com', 'dreamr.okelly@gmail.com', 'jason@lookforwardenterprises.com']
9
+ gem.description = "Keep a DRY history of your ActiveRecord models' changes"
10
+ gem.summary = gem.description
11
+ gem.homepage = 'http://github.com/laserlemon/vestal_versions'
12
+ gem.license = 'MIT'
13
+
14
+ gem.add_dependency 'activerecord', '>= 3', '< 5'
15
+ gem.add_dependency 'activesupport', '>= 3', '< 5'
16
+
17
+ gem.add_development_dependency 'bundler', '~> 1.0'
18
+ gem.add_development_dependency 'rake', '~> 10.0'
19
+
20
+ gem.files = `git ls-files`.split($\)
21
+ gem.test_files = gem.files.grep(/^spec/)
22
+ gem.require_paths = ['lib']
23
+ end
metadata ADDED
@@ -0,0 +1,181 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: houston-vestal_versions
3
+ version: !ruby/object:Gem::Version
4
+ version: 2.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Steve Richert
8
+ - James O'Kelly
9
+ - C. Jason Harrelson
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+ date: 2015-09-08 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: activerecord
17
+ requirement: !ruby/object:Gem::Requirement
18
+ requirements:
19
+ - - ">="
20
+ - !ruby/object:Gem::Version
21
+ version: '3'
22
+ - - "<"
23
+ - !ruby/object:Gem::Version
24
+ version: '5'
25
+ type: :runtime
26
+ prerelease: false
27
+ version_requirements: !ruby/object:Gem::Requirement
28
+ requirements:
29
+ - - ">="
30
+ - !ruby/object:Gem::Version
31
+ version: '3'
32
+ - - "<"
33
+ - !ruby/object:Gem::Version
34
+ version: '5'
35
+ - !ruby/object:Gem::Dependency
36
+ name: activesupport
37
+ requirement: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ version: '3'
42
+ - - "<"
43
+ - !ruby/object:Gem::Version
44
+ version: '5'
45
+ type: :runtime
46
+ prerelease: false
47
+ version_requirements: !ruby/object:Gem::Requirement
48
+ requirements:
49
+ - - ">="
50
+ - !ruby/object:Gem::Version
51
+ version: '3'
52
+ - - "<"
53
+ - !ruby/object:Gem::Version
54
+ version: '5'
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '10.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '10.0'
83
+ description: Keep a DRY history of your ActiveRecord models' changes
84
+ email:
85
+ - steve.richert@gmail.com
86
+ - dreamr.okelly@gmail.com
87
+ - jason@lookforwardenterprises.com
88
+ executables: []
89
+ extensions: []
90
+ extra_rdoc_files: []
91
+ files:
92
+ - ".gitignore"
93
+ - ".travis.yml"
94
+ - CHANGELOG.md
95
+ - Gemfile
96
+ - LICENSE
97
+ - README.rdoc
98
+ - Rakefile
99
+ - gemfiles/activerecord_3_0.gemfile
100
+ - gemfiles/activerecord_3_1.gemfile
101
+ - gemfiles/activerecord_3_2.gemfile
102
+ - gemfiles/activerecord_4_0.gemfile
103
+ - lib/generators/vestal_versions.rb
104
+ - lib/generators/vestal_versions/migration/migration_generator.rb
105
+ - lib/generators/vestal_versions/migration/templates/initializer.rb
106
+ - lib/generators/vestal_versions/migration/templates/migration.rb
107
+ - lib/vestal_versions.rb
108
+ - lib/vestal_versions/changes.rb
109
+ - lib/vestal_versions/conditions.rb
110
+ - lib/vestal_versions/control.rb
111
+ - lib/vestal_versions/creation.rb
112
+ - lib/vestal_versions/deletion.rb
113
+ - lib/vestal_versions/options.rb
114
+ - lib/vestal_versions/reload.rb
115
+ - lib/vestal_versions/reset.rb
116
+ - lib/vestal_versions/reversion.rb
117
+ - lib/vestal_versions/users.rb
118
+ - lib/vestal_versions/version.rb
119
+ - lib/vestal_versions/version_tagging.rb
120
+ - lib/vestal_versions/versioned.rb
121
+ - lib/vestal_versions/versions.rb
122
+ - spec/spec_helper.rb
123
+ - spec/support/models.rb
124
+ - spec/support/schema.rb
125
+ - spec/vestal_versions/changes_spec.rb
126
+ - spec/vestal_versions/conditions_spec.rb
127
+ - spec/vestal_versions/control_spec.rb
128
+ - spec/vestal_versions/creation_spec.rb
129
+ - spec/vestal_versions/deletion_spec.rb
130
+ - spec/vestal_versions/options_spec.rb
131
+ - spec/vestal_versions/reload_spec.rb
132
+ - spec/vestal_versions/reset_spec.rb
133
+ - spec/vestal_versions/reversion_spec.rb
134
+ - spec/vestal_versions/users_spec.rb
135
+ - spec/vestal_versions/version_spec.rb
136
+ - spec/vestal_versions/version_tagging_spec.rb
137
+ - spec/vestal_versions/versioned_spec.rb
138
+ - spec/vestal_versions/versions_spec.rb
139
+ - vestal_versions.gemspec
140
+ homepage: http://github.com/laserlemon/vestal_versions
141
+ licenses:
142
+ - MIT
143
+ metadata: {}
144
+ post_install_message:
145
+ rdoc_options: []
146
+ require_paths:
147
+ - lib
148
+ required_ruby_version: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ required_rubygems_version: !ruby/object:Gem::Requirement
154
+ requirements:
155
+ - - ">="
156
+ - !ruby/object:Gem::Version
157
+ version: '0'
158
+ requirements: []
159
+ rubyforge_project:
160
+ rubygems_version: 2.2.2
161
+ signing_key:
162
+ specification_version: 4
163
+ summary: Keep a DRY history of your ActiveRecord models' changes
164
+ test_files:
165
+ - spec/spec_helper.rb
166
+ - spec/support/models.rb
167
+ - spec/support/schema.rb
168
+ - spec/vestal_versions/changes_spec.rb
169
+ - spec/vestal_versions/conditions_spec.rb
170
+ - spec/vestal_versions/control_spec.rb
171
+ - spec/vestal_versions/creation_spec.rb
172
+ - spec/vestal_versions/deletion_spec.rb
173
+ - spec/vestal_versions/options_spec.rb
174
+ - spec/vestal_versions/reload_spec.rb
175
+ - spec/vestal_versions/reset_spec.rb
176
+ - spec/vestal_versions/reversion_spec.rb
177
+ - spec/vestal_versions/users_spec.rb
178
+ - spec/vestal_versions/version_spec.rb
179
+ - spec/vestal_versions/version_tagging_spec.rb
180
+ - spec/vestal_versions/versioned_spec.rb
181
+ - spec/vestal_versions/versions_spec.rb