versioned_record 0.3.1 → 0.3.2
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.
- checksums.yaml +4 -4
- data/lib/versioned_record/class_methods.rb +1 -1
- data/lib/versioned_record/version.rb +1 -1
- data/lib/versioned_record.rb +1 -1
- data/spec/composite_belongs_to_spec.rb +24 -0
- data/spec/{composite_belongs_to.rb → composite_has_many_spec.rb} +1 -1
- data/spec/support/catalog.rb +7 -0
- data/spec/support/database.rb +6 -0
- data/spec/support/versioned_product.rb +5 -0
- data/spec/version_class_methods_spec.rb +9 -6
- metadata +8 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 60698c47669db53300faa0ac76472e2f2c6bf165
|
4
|
+
data.tar.gz: 2999d4a36edb3075cb52c7a87fc69362cbe8fbb6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7d0636a118bfaef0caf890cbedadde46555b6e3da3fe1bc3c07f6cb2337db387c2ec46632e3cb904da4fd2bf7bb8c13283140eb8c9e8317f0f51e425c424b0bb
|
7
|
+
data.tar.gz: 2875b2175b8419f973562920f2b85f06a425b1eb73f4731e3a9c7b113c9a6b8ec45b104387e92bdcaf362f3fa307abf46c46e5552e50f69490063f93297a7334
|
data/lib/versioned_record.rb
CHANGED
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Catalog do
|
4
|
+
describe 'chained versioning' do
|
5
|
+
let(:catalog) { Catalog.create(name: 'Products 2013') }
|
6
|
+
let(:product) { VersionedProduct.create(name: 'Headphones', price: '200', catalog: catalog) }
|
7
|
+
|
8
|
+
let(:new_product) { product.build_version }
|
9
|
+
let(:new_catalog) { new_product.catalog.build_version }
|
10
|
+
|
11
|
+
before do
|
12
|
+
new_catalog.name = 'Products 2014'
|
13
|
+
new_product.association(:catalog).writer(new_catalog)
|
14
|
+
new_product.save!
|
15
|
+
end
|
16
|
+
|
17
|
+
specify do
|
18
|
+
expect(new_product).to be_persisted
|
19
|
+
expect(new_product).to have(2).versions
|
20
|
+
expect(new_product.catalog).to eq(new_catalog)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
data/spec/support/database.rb
CHANGED
@@ -10,6 +10,8 @@ ActiveRecord::Schema.define :version => 0 do
|
|
10
10
|
|
11
11
|
create_table :versioned_products, versioned: true, force: true do |t|
|
12
12
|
t.references :company
|
13
|
+
t.references :catalog
|
14
|
+
t.integer :catalog_version
|
13
15
|
t.string :name
|
14
16
|
t.decimal :price
|
15
17
|
end
|
@@ -56,4 +58,8 @@ ActiveRecord::Schema.define :version => 0 do
|
|
56
58
|
t.integer :versioned_product_version
|
57
59
|
t.string :name
|
58
60
|
end
|
61
|
+
|
62
|
+
create_table :catalogs, force: true, versioned: true do |t|
|
63
|
+
t.string :name
|
64
|
+
end
|
59
65
|
end
|
@@ -8,6 +8,11 @@ class VersionedProduct < ActiveRecord::Base
|
|
8
8
|
# Simple Belongs To
|
9
9
|
has_many :comments
|
10
10
|
|
11
|
+
# Composite Belongs To where the related record is also versioned
|
12
|
+
belongs_to :catalog, {
|
13
|
+
foreign_key: [:catalog_id, :catalog_version]
|
14
|
+
}
|
15
|
+
|
11
16
|
# Composite has many
|
12
17
|
has_many :sales, {
|
13
18
|
foreign_key: [:versioned_product_id, :versioned_product_version]
|
@@ -34,12 +34,15 @@ describe VersionedProduct do
|
|
34
34
|
end
|
35
35
|
|
36
36
|
describe 'scopes' do
|
37
|
-
let!(:
|
38
|
-
let!(:
|
37
|
+
let!(:a_v0) { VersionedProduct.create(name: 'Macbook Pro') }
|
38
|
+
let!(:a_v1) { a_v0.create_version!(name: 'Macbook Retina') }
|
39
|
+
let!(:a_v2) { a_v1.create_version!(name: 'Macbook Retina Sick') }
|
40
|
+
let!(:b_v0) { VersionedProduct.create(name: 'Macbook Air') }
|
41
|
+
let!(:b_v1) { b_v0.create_version!(name: 'Macbook Air 2') }
|
39
42
|
|
40
43
|
describe '::find_current' do
|
41
44
|
it 'finds the latest version' do
|
42
|
-
expect(VersionedProduct.find_current(
|
45
|
+
expect(VersionedProduct.find_current(a_v0.id)).to eq(a_v2)
|
43
46
|
end
|
44
47
|
|
45
48
|
context 'where no matching record exists' do
|
@@ -51,19 +54,19 @@ describe VersionedProduct do
|
|
51
54
|
|
52
55
|
describe '::current_versions' do
|
53
56
|
it 'returns only the current version' do
|
54
|
-
expect(VersionedProduct.current_versions).to eq([
|
57
|
+
expect(VersionedProduct.current_versions).to eq([a_v2, b_v1])
|
55
58
|
end
|
56
59
|
end
|
57
60
|
|
58
61
|
describe '::exclude_current' do
|
59
62
|
it 'returns only the current version' do
|
60
|
-
expect(VersionedProduct.exclude_current).to eq([
|
63
|
+
expect(VersionedProduct.exclude_current.order(:id, :version)).to eq([a_v0, a_v1, b_v0])
|
61
64
|
end
|
62
65
|
end
|
63
66
|
|
64
67
|
describe '::exclude' do
|
65
68
|
it 'returns everything but the excluded record' do
|
66
|
-
expect(
|
69
|
+
expect(b_v1.versions.exclude(b_v1)).to eq([b_v0])
|
67
70
|
end
|
68
71
|
end
|
69
72
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: versioned_record
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dan Draper
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-05
|
11
|
+
date: 2014-06-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -175,13 +175,15 @@ files:
|
|
175
175
|
- lib/versioned_record/connection_adapters/postgresql.rb
|
176
176
|
- lib/versioned_record/version.rb
|
177
177
|
- spec/association_preservation_spec.rb
|
178
|
-
- spec/
|
178
|
+
- spec/composite_belongs_to_spec.rb
|
179
|
+
- spec/composite_has_many_spec.rb
|
179
180
|
- spec/composite_onesided_habtm_spec.rb
|
180
181
|
- spec/has_one_spec.rb
|
181
182
|
- spec/has_one_through_spec.rb
|
182
183
|
- spec/simple_belongs_to_spec.rb
|
183
184
|
- spec/simple_onesided_habtm_spec.rb
|
184
185
|
- spec/spec_helper.rb
|
186
|
+
- spec/support/catalog.rb
|
185
187
|
- spec/support/comment.rb
|
186
188
|
- spec/support/company.rb
|
187
189
|
- spec/support/container.rb
|
@@ -222,13 +224,15 @@ specification_version: 4
|
|
222
224
|
summary: Version ActiveRecord models using composite primary keys
|
223
225
|
test_files:
|
224
226
|
- spec/association_preservation_spec.rb
|
225
|
-
- spec/
|
227
|
+
- spec/composite_belongs_to_spec.rb
|
228
|
+
- spec/composite_has_many_spec.rb
|
226
229
|
- spec/composite_onesided_habtm_spec.rb
|
227
230
|
- spec/has_one_spec.rb
|
228
231
|
- spec/has_one_through_spec.rb
|
229
232
|
- spec/simple_belongs_to_spec.rb
|
230
233
|
- spec/simple_onesided_habtm_spec.rb
|
231
234
|
- spec/spec_helper.rb
|
235
|
+
- spec/support/catalog.rb
|
232
236
|
- spec/support/comment.rb
|
233
237
|
- spec/support/company.rb
|
234
238
|
- spec/support/container.rb
|