versioned_record 0.3.2 → 0.4.0
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/README.md +0 -1
- data/lib/versioned_record/composite_predicates.rb +30 -16
- data/lib/versioned_record/version.rb +1 -1
- data/spec/simple_belongs_to_polymorphic_spec.rb +18 -0
- data/spec/support/company.rb +2 -1
- data/spec/support/database.rb +6 -1
- data/spec/support/user.rb +3 -0
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 562b1ce360d24ed679ebdfb9f20b2c3759882a27
|
4
|
+
data.tar.gz: f1f2c1ce89911fcc4563aa66cf0061485b0d2783
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 233b14b9f0ce7f0d7a0800f555d8b41e00cfdfec1a702f5e0480aab639a87a23248d06fbb45e98b2ce32d98e72788261a94f225792e2ade35ad96985f2295d5c
|
7
|
+
data.tar.gz: 8dd8dc76db0e376cfb2345811c2eb0345d384fe2878aeb3070d0268910831d7ce68a875bfc9315dac3a7db40f655fe7a3bf539fdf7ad8458b1c98b4b6113bd2d
|
data/README.md
CHANGED
@@ -113,7 +113,6 @@ Right now, only PostgreSQL has been tested. MySQL may or may not work but if you
|
|
113
113
|
## Limitations
|
114
114
|
|
115
115
|
* Does not currently work with ActiveRecord 4.1+
|
116
|
-
* Polymorphic belongs to does not work on versioned records
|
117
116
|
* HABTM where models on _both_ sides are versioned have not been tested
|
118
117
|
|
119
118
|
|
@@ -33,29 +33,43 @@ module VersionedRecord
|
|
33
33
|
eq_predicates = [ association_fields[0].eq(fields[0]) ]
|
34
34
|
case association.reflection.macro
|
35
35
|
when :belongs_to
|
36
|
-
|
37
|
-
if !association.options[:polymorphic]
|
38
|
-
if association.reflection.klass.versioned?
|
39
|
-
eq_predicates << association_table[:is_current_version].eq(true)
|
40
|
-
end
|
41
|
-
end
|
36
|
+
add_belongs_to_predicates!(eq_predicates, association_table)
|
42
37
|
when :has_and_belongs_to_many
|
43
|
-
|
44
|
-
if association.reflection.klass.table_name == association_table.name
|
45
|
-
eq_predicates << association_table[:is_current_version].eq(true)
|
46
|
-
end
|
47
|
-
end
|
38
|
+
add_habtm_predicates!(eq_predicates, association, association_table)
|
48
39
|
when :has_many, :has_one
|
49
|
-
|
50
|
-
if association.reflection.klass.table_name == association_table.name
|
51
|
-
eq_predicates << association_table[:is_current_version].eq(true)
|
52
|
-
end
|
53
|
-
end
|
40
|
+
add_has_x_predicates!(eq_predicates, association, association_table)
|
54
41
|
end
|
55
42
|
cpk_and_predicate(eq_predicates)
|
56
43
|
else
|
57
44
|
super
|
58
45
|
end
|
59
46
|
end
|
47
|
+
|
48
|
+
private
|
49
|
+
def add_belongs_to_predicates!(predicates, association_table)
|
50
|
+
if self.klass.versioned?
|
51
|
+
add_current_version_constraint!(predicates, association_table)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def add_habtm_predicates!(predicates, association, association_table)
|
56
|
+
if self.klass.versioned?
|
57
|
+
if association.reflection.klass.table_name == association_table.name
|
58
|
+
add_current_version_constraint!(predicates, association_table)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def add_has_x_predicates!(predicates, association, association_table)
|
64
|
+
if association.reflection.klass.versioned?
|
65
|
+
if association.reflection.klass.table_name == association_table.name
|
66
|
+
add_current_version_constraint!(predicates, association_table)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
def add_current_version_constraint!(predicates, association_table)
|
72
|
+
predicates << association_table[:is_current_version].eq(true)
|
73
|
+
end
|
60
74
|
end
|
61
75
|
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe User do
|
4
|
+
let(:company) { Company.create!(name: 'Google') }
|
5
|
+
let(:user) { User.create!(name: 'Lauren', entity: company) }
|
6
|
+
|
7
|
+
specify 'that the company is set as the entity' do
|
8
|
+
expect(user.entity).to eq(company)
|
9
|
+
end
|
10
|
+
|
11
|
+
describe 'a new version of the company is created' do
|
12
|
+
let!(:new_company) { company.create_version!(name: 'Google World Domination') }
|
13
|
+
|
14
|
+
specify 'that the company is still set as the entity' do
|
15
|
+
expect(user.reload.entity).to eq(new_company)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
data/spec/support/company.rb
CHANGED
data/spec/support/database.rb
CHANGED
@@ -4,7 +4,7 @@ ActiveRecord::Base.establish_connection(dbconfig[env]['postgresql'])
|
|
4
4
|
|
5
5
|
ActiveRecord::Schema.define :version => 0 do
|
6
6
|
|
7
|
-
create_table :companies, force: true do |t|
|
7
|
+
create_table :companies, force: true, versioned: true do |t|
|
8
8
|
t.string :name
|
9
9
|
end
|
10
10
|
|
@@ -62,4 +62,9 @@ ActiveRecord::Schema.define :version => 0 do
|
|
62
62
|
create_table :catalogs, force: true, versioned: true do |t|
|
63
63
|
t.string :name
|
64
64
|
end
|
65
|
+
|
66
|
+
create_table :users, force: true do |t|
|
67
|
+
t.references :company, polymorphic: true
|
68
|
+
t.string :name
|
69
|
+
end
|
65
70
|
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.
|
4
|
+
version: 0.4.0
|
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-06-
|
11
|
+
date: 2014-06-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -180,6 +180,7 @@ files:
|
|
180
180
|
- spec/composite_onesided_habtm_spec.rb
|
181
181
|
- spec/has_one_spec.rb
|
182
182
|
- spec/has_one_through_spec.rb
|
183
|
+
- spec/simple_belongs_to_polymorphic_spec.rb
|
183
184
|
- spec/simple_belongs_to_spec.rb
|
184
185
|
- spec/simple_onesided_habtm_spec.rb
|
185
186
|
- spec/spec_helper.rb
|
@@ -194,6 +195,7 @@ files:
|
|
194
195
|
- spec/support/package.rb
|
195
196
|
- spec/support/sale.rb
|
196
197
|
- spec/support/tag.rb
|
198
|
+
- spec/support/user.rb
|
197
199
|
- spec/support/versioned_product.rb
|
198
200
|
- spec/version_class_methods_spec.rb
|
199
201
|
- spec/versions_spec.rb
|
@@ -229,6 +231,7 @@ test_files:
|
|
229
231
|
- spec/composite_onesided_habtm_spec.rb
|
230
232
|
- spec/has_one_spec.rb
|
231
233
|
- spec/has_one_through_spec.rb
|
234
|
+
- spec/simple_belongs_to_polymorphic_spec.rb
|
232
235
|
- spec/simple_belongs_to_spec.rb
|
233
236
|
- spec/simple_onesided_habtm_spec.rb
|
234
237
|
- spec/spec_helper.rb
|
@@ -243,6 +246,7 @@ test_files:
|
|
243
246
|
- spec/support/package.rb
|
244
247
|
- spec/support/sale.rb
|
245
248
|
- spec/support/tag.rb
|
249
|
+
- spec/support/user.rb
|
246
250
|
- spec/support/versioned_product.rb
|
247
251
|
- spec/version_class_methods_spec.rb
|
248
252
|
- spec/versions_spec.rb
|