geothird_vestal_versions 1.2.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +20 -0
  3. data/README.rdoc +196 -0
  4. data/lib/generators/vestal_versions.rb +11 -0
  5. data/lib/generators/vestal_versions/migration/migration_generator.rb +17 -0
  6. data/lib/generators/vestal_versions/migration/templates/initializer.rb +9 -0
  7. data/lib/generators/vestal_versions/migration/templates/migration.rb +28 -0
  8. data/lib/vestal_versions.rb +126 -0
  9. data/lib/vestal_versions/changes.rb +120 -0
  10. data/lib/vestal_versions/conditions.rb +55 -0
  11. data/lib/vestal_versions/control.rb +197 -0
  12. data/lib/vestal_versions/creation.rb +91 -0
  13. data/lib/vestal_versions/deletion.rb +37 -0
  14. data/lib/vestal_versions/options.rb +41 -0
  15. data/lib/vestal_versions/reload.rb +15 -0
  16. data/lib/vestal_versions/reset.rb +22 -0
  17. data/lib/vestal_versions/reversion.rb +80 -0
  18. data/lib/vestal_versions/users.rb +53 -0
  19. data/lib/vestal_versions/version.rb +81 -0
  20. data/lib/vestal_versions/version_num.rb +3 -0
  21. data/lib/vestal_versions/version_tagging.rb +48 -0
  22. data/lib/vestal_versions/versioned.rb +27 -0
  23. data/lib/vestal_versions/versions.rb +74 -0
  24. data/spec/spec_helper.rb +20 -0
  25. data/spec/support/models.rb +19 -0
  26. data/spec/support/schema.rb +25 -0
  27. data/spec/vestal_versions/changes_spec.rb +134 -0
  28. data/spec/vestal_versions/conditions_spec.rb +103 -0
  29. data/spec/vestal_versions/control_spec.rb +120 -0
  30. data/spec/vestal_versions/creation_spec.rb +90 -0
  31. data/spec/vestal_versions/deletion_spec.rb +86 -0
  32. data/spec/vestal_versions/options_spec.rb +45 -0
  33. data/spec/vestal_versions/reload_spec.rb +18 -0
  34. data/spec/vestal_versions/reset_spec.rb +111 -0
  35. data/spec/vestal_versions/reversion_spec.rb +103 -0
  36. data/spec/vestal_versions/users_spec.rb +21 -0
  37. data/spec/vestal_versions/version_spec.rb +61 -0
  38. data/spec/vestal_versions/version_tagging_spec.rb +39 -0
  39. data/spec/vestal_versions/versioned_spec.rb +16 -0
  40. data/spec/vestal_versions/versions_spec.rb +176 -0
  41. metadata +169 -0
@@ -0,0 +1,39 @@
1
+ require 'spec_helper'
2
+
3
+ describe VestalVersions::VersionTagging do
4
+ let(:user){ User.create(:name => 'Steve Richert') }
5
+
6
+ before do
7
+ user.update_attribute(:last_name, 'Jobs')
8
+ end
9
+
10
+ context 'an untagged version' do
11
+ it "updates the version record's tag column" do
12
+ tag_name = 'TAG'
13
+ last_version = user.versions.last
14
+
15
+ last_version.tag.should_not == tag_name
16
+ user.tag_version(tag_name)
17
+ last_version.reload.tag.should == tag_name
18
+ end
19
+
20
+ it 'creates a version record for an initial version' do
21
+ user.revert_to(1)
22
+ user.versions.at(1).should be_nil
23
+
24
+ user.tag_version('TAG')
25
+ user.versions.at(1).should_not be_nil
26
+ end
27
+ end
28
+
29
+ context 'A tagged version' do
30
+ subject{ user.versions.last }
31
+
32
+ before do
33
+ user.tag_version('TAG')
34
+ end
35
+
36
+ it { should be_tagged }
37
+ end
38
+
39
+ end
@@ -0,0 +1,16 @@
1
+ require 'spec_helper'
2
+
3
+ describe VestalVersions::Versioned do
4
+ it 'respond to the "versioned?" method' do
5
+ ActiveRecord::Base.should respond_to(:versioned?)
6
+ User.should respond_to(:versioned?)
7
+ end
8
+
9
+ it 'return true for the "versioned?" method if the model is versioned' do
10
+ User.should be_versioned
11
+ end
12
+
13
+ it 'return false for the "versioned?" method if the model is not versioned' do
14
+ ActiveRecord::Base.should_not be_versioned
15
+ end
16
+ end
@@ -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
metadata ADDED
@@ -0,0 +1,169 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: geothird_vestal_versions
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.2.3
5
+ platform: ruby
6
+ authors:
7
+ - Adam Cooper
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-04-04 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activerecord
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: 3.1.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: 3.1.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: activesupport
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: 3.1.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: 3.1.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: sqlite3-ruby
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: Keep a DRY history of your ActiveRecord models' changes
84
+ email:
85
+ - adam.cooper@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - lib/generators/vestal_versions.rb
91
+ - lib/generators/vestal_versions/migration/migration_generator.rb
92
+ - lib/generators/vestal_versions/migration/templates/initializer.rb
93
+ - lib/generators/vestal_versions/migration/templates/migration.rb
94
+ - lib/vestal_versions.rb
95
+ - lib/vestal_versions/changes.rb
96
+ - lib/vestal_versions/conditions.rb
97
+ - lib/vestal_versions/control.rb
98
+ - lib/vestal_versions/creation.rb
99
+ - lib/vestal_versions/deletion.rb
100
+ - lib/vestal_versions/options.rb
101
+ - lib/vestal_versions/reload.rb
102
+ - lib/vestal_versions/reset.rb
103
+ - lib/vestal_versions/reversion.rb
104
+ - lib/vestal_versions/users.rb
105
+ - lib/vestal_versions/version.rb
106
+ - lib/vestal_versions/version_num.rb
107
+ - lib/vestal_versions/version_tagging.rb
108
+ - lib/vestal_versions/versioned.rb
109
+ - lib/vestal_versions/versions.rb
110
+ - README.rdoc
111
+ - LICENSE
112
+ - spec/spec_helper.rb
113
+ - spec/support/models.rb
114
+ - spec/support/schema.rb
115
+ - spec/vestal_versions/changes_spec.rb
116
+ - spec/vestal_versions/conditions_spec.rb
117
+ - spec/vestal_versions/control_spec.rb
118
+ - spec/vestal_versions/creation_spec.rb
119
+ - spec/vestal_versions/deletion_spec.rb
120
+ - spec/vestal_versions/options_spec.rb
121
+ - spec/vestal_versions/reload_spec.rb
122
+ - spec/vestal_versions/reset_spec.rb
123
+ - spec/vestal_versions/reversion_spec.rb
124
+ - spec/vestal_versions/users_spec.rb
125
+ - spec/vestal_versions/version_spec.rb
126
+ - spec/vestal_versions/version_tagging_spec.rb
127
+ - spec/vestal_versions/versioned_spec.rb
128
+ - spec/vestal_versions/versions_spec.rb
129
+ homepage: http://github.com/adamcooper/vestal_versions
130
+ licenses: []
131
+ metadata: {}
132
+ post_install_message:
133
+ rdoc_options: []
134
+ require_paths:
135
+ - lib
136
+ required_ruby_version: !ruby/object:Gem::Requirement
137
+ requirements:
138
+ - - '>='
139
+ - !ruby/object:Gem::Version
140
+ version: '0'
141
+ required_rubygems_version: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - '>='
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ requirements: []
147
+ rubyforge_project:
148
+ rubygems_version: 2.0.0
149
+ signing_key:
150
+ specification_version: 4
151
+ summary: Keep a DRY history of your ActiveRecord models' changes
152
+ test_files:
153
+ - spec/spec_helper.rb
154
+ - spec/support/models.rb
155
+ - spec/support/schema.rb
156
+ - spec/vestal_versions/changes_spec.rb
157
+ - spec/vestal_versions/conditions_spec.rb
158
+ - spec/vestal_versions/control_spec.rb
159
+ - spec/vestal_versions/creation_spec.rb
160
+ - spec/vestal_versions/deletion_spec.rb
161
+ - spec/vestal_versions/options_spec.rb
162
+ - spec/vestal_versions/reload_spec.rb
163
+ - spec/vestal_versions/reset_spec.rb
164
+ - spec/vestal_versions/reversion_spec.rb
165
+ - spec/vestal_versions/users_spec.rb
166
+ - spec/vestal_versions/version_spec.rb
167
+ - spec/vestal_versions/version_tagging_spec.rb
168
+ - spec/vestal_versions/versioned_spec.rb
169
+ - spec/vestal_versions/versions_spec.rb