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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 562b1ce360d24ed679ebdfb9f20b2c3759882a27
4
- data.tar.gz: f1f2c1ce89911fcc4563aa66cf0061485b0d2783
3
+ metadata.gz: c493059288eb10618dae68cad6cfe6ee6e1d6689
4
+ data.tar.gz: 8f848574c1c10769c52e5030e9dbc72b16e61cb9
5
5
  SHA512:
6
- metadata.gz: 233b14b9f0ce7f0d7a0800f555d8b41e00cfdfec1a702f5e0480aab639a87a23248d06fbb45e98b2ce32d98e72788261a94f225792e2ade35ad96985f2295d5c
7
- data.tar.gz: 8dd8dc76db0e376cfb2345811c2eb0345d384fe2878aeb3070d0268910831d7ce68a875bfc9315dac3a7db40f655fe7a3bf539fdf7ad8458b1c98b4b6113bd2d
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 = @record.attributes.symbolize_keys.merge(@new_attrs.merge({
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
@@ -1,3 +1,3 @@
1
1
  module VersionedRecord
2
- VERSION = "0.4.0"
2
+ VERSION = "0.4.1"
3
3
  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
+
@@ -1,9 +1,9 @@
1
1
  require 'coveralls'
2
2
  Coveralls.wear!
3
3
 
4
- #require 'active_record'
5
4
  require 'versioned_record'
6
5
  require 'database_cleaner'
6
+ require 'timecop'
7
7
 
8
8
  require 'byebug'
9
9
 
@@ -14,6 +14,7 @@ ActiveRecord::Schema.define :version => 0 do
14
14
  t.integer :catalog_version
15
15
  t.string :name
16
16
  t.decimal :price
17
+ t.timestamps
17
18
  end
18
19
 
19
20
  create_table :comments, force: true do |t|
@@ -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
+
@@ -31,4 +31,5 @@ Gem::Specification.new do |spec|
31
31
  spec.add_development_dependency "yard"
32
32
  spec.add_development_dependency "coveralls"
33
33
  spec.add_development_dependency "byebug"
34
+ spec.add_development_dependency "timecop"
34
35
  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.0
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-06 00:00:00.000000000 Z
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: