versioned_record 0.4.0 → 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/versioned_record/attribute_builder.rb +12 -1
- data/lib/versioned_record/version.rb +1 -1
- data/spec/attribute_builder_spec.rb +30 -0
- data/spec/spec_helper.rb +1 -1
- data/spec/support/database.rb +1 -0
- data/spec/timestamps_spec.rb +23 -0
- data/versioned_record.gemspec +1 -0
- metadata +20 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c493059288eb10618dae68cad6cfe6ee6e1d6689
|
4
|
+
data.tar.gz: 8f848574c1c10769c52e5030e9dbc72b16e61cb9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: eda3a71d69ac706b47fa48da5a67c33a53284ccd257aa3331c0dfde6833a2fe88cc31ca9edaa97710f4f13a1f1661fa08bf649f03cdc1cacdd5e69d527c95f4e
|
7
|
+
data.tar.gz: fb61bd1da7907c6578544a8b4044a840fffa76950fad1ab8e4c0ddd333fdfa0f804af94211c4b33ff2c552b78a1376798e85bd8b9806d3145bd112083753369c
|
@@ -15,11 +15,22 @@ module VersionedRecord
|
|
15
15
|
# @param [Hash] new_attrs are the attributes we are changing in this version
|
16
16
|
def attributes(new_attrs)
|
17
17
|
@new_attrs = new_attrs.symbolize_keys
|
18
|
-
attrs =
|
18
|
+
attrs = original_attributes.merge(@new_attrs.merge({
|
19
19
|
is_current_version: true,
|
20
20
|
id: @record.id,
|
21
21
|
version: @record.version + 1
|
22
22
|
}))
|
23
23
|
end
|
24
|
+
|
25
|
+
# The relevant attributes of the previous version
|
26
|
+
# i.e: the record we initialized this builder with
|
27
|
+
#
|
28
|
+
# @return Hash excluding created_at and updated_at keys
|
29
|
+
#
|
30
|
+
def original_attributes
|
31
|
+
@record.attributes.symbolize_keys.select do |(attr, _)|
|
32
|
+
!%i(created_at updated_at).include?(attr)
|
33
|
+
end
|
34
|
+
end
|
24
35
|
end
|
25
36
|
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe VersionedRecord::AttributeBuilder do
|
4
|
+
describe '#original_attributes' do
|
5
|
+
let(:creation_attrs) do
|
6
|
+
{
|
7
|
+
name: 'Foo',
|
8
|
+
price: 100,
|
9
|
+
company_id: 1,
|
10
|
+
catalog_id: 2,
|
11
|
+
catalog_version: 0
|
12
|
+
}
|
13
|
+
end
|
14
|
+
|
15
|
+
let(:record) { VersionedProduct.create!(creation_attrs) }
|
16
|
+
subject { described_class.new(record) }
|
17
|
+
|
18
|
+
specify 'that original attributes does not include timestamps' do
|
19
|
+
expect(subject.original_attributes[:created_at]).to be_nil
|
20
|
+
expect(subject.original_attributes[:updated_at]).to be_nil
|
21
|
+
end
|
22
|
+
|
23
|
+
specify 'that the original attributes contain all relevant attributes' do
|
24
|
+
expect(subject.original_attributes).to eq(
|
25
|
+
creation_attrs.merge(id: record._id, version: 0, is_current_version: true)
|
26
|
+
)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
data/spec/spec_helper.rb
CHANGED
data/spec/support/database.rb
CHANGED
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe VersionedProduct, :timestamps do
|
4
|
+
before { Timecop.freeze(time1) }
|
5
|
+
after { Timecop.return }
|
6
|
+
let(:time1) { '2014-06-06 10:00'.to_time }
|
7
|
+
let(:company) { Company.create(name: 'Acme Corp') }
|
8
|
+
let!(:first_version) { VersionedProduct.create(name: 'iPad', price: 100, company: company) }
|
9
|
+
|
10
|
+
specify { expect(first_version.created_at).to eq(time1.utc) }
|
11
|
+
|
12
|
+
describe 'creating a new version at a later time' do
|
13
|
+
before { Timecop.freeze(time2) }
|
14
|
+
let(:time2) { '2014-06-08 10:00'.to_time }
|
15
|
+
let!(:second_version) { first_version.create_version! }
|
16
|
+
|
17
|
+
specify { expect(first_version.created_at).to eq(time1.utc) }
|
18
|
+
specify { expect(second_version.created_at).to eq(time2.utc) }
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
|
23
|
+
|
data/versioned_record.gemspec
CHANGED
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.
|
4
|
+
version: 0.4.1
|
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-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -150,6 +150,20 @@ dependencies:
|
|
150
150
|
- - ">="
|
151
151
|
- !ruby/object:Gem::Version
|
152
152
|
version: '0'
|
153
|
+
- !ruby/object:Gem::Dependency
|
154
|
+
name: timecop
|
155
|
+
requirement: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - ">="
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: '0'
|
160
|
+
type: :development
|
161
|
+
prerelease: false
|
162
|
+
version_requirements: !ruby/object:Gem::Requirement
|
163
|
+
requirements:
|
164
|
+
- - ">="
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: '0'
|
153
167
|
description: Version ActiveRecord models using composite primary keys
|
154
168
|
email:
|
155
169
|
- daniel@codehire.com
|
@@ -175,6 +189,7 @@ files:
|
|
175
189
|
- lib/versioned_record/connection_adapters/postgresql.rb
|
176
190
|
- lib/versioned_record/version.rb
|
177
191
|
- spec/association_preservation_spec.rb
|
192
|
+
- spec/attribute_builder_spec.rb
|
178
193
|
- spec/composite_belongs_to_spec.rb
|
179
194
|
- spec/composite_has_many_spec.rb
|
180
195
|
- spec/composite_onesided_habtm_spec.rb
|
@@ -197,6 +212,7 @@ files:
|
|
197
212
|
- spec/support/tag.rb
|
198
213
|
- spec/support/user.rb
|
199
214
|
- spec/support/versioned_product.rb
|
215
|
+
- spec/timestamps_spec.rb
|
200
216
|
- spec/version_class_methods_spec.rb
|
201
217
|
- spec/versions_spec.rb
|
202
218
|
- versioned_record.gemspec
|
@@ -226,6 +242,7 @@ specification_version: 4
|
|
226
242
|
summary: Version ActiveRecord models using composite primary keys
|
227
243
|
test_files:
|
228
244
|
- spec/association_preservation_spec.rb
|
245
|
+
- spec/attribute_builder_spec.rb
|
229
246
|
- spec/composite_belongs_to_spec.rb
|
230
247
|
- spec/composite_has_many_spec.rb
|
231
248
|
- spec/composite_onesided_habtm_spec.rb
|
@@ -248,6 +265,7 @@ test_files:
|
|
248
265
|
- spec/support/tag.rb
|
249
266
|
- spec/support/user.rb
|
250
267
|
- spec/support/versioned_product.rb
|
268
|
+
- spec/timestamps_spec.rb
|
251
269
|
- spec/version_class_methods_spec.rb
|
252
270
|
- spec/versions_spec.rb
|
253
271
|
has_rdoc:
|