sequel_bitemporal 0.4.10 → 0.4.11

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,30 +1,32 @@
1
1
  module Sequel
2
2
  module Plugins
3
3
  module Bitemporal
4
+ THREAD_POINT_IN_TIME_KEY = :sequel_plugins_bitemporal_point_in_time
4
5
  def self.as_we_knew_it(time)
6
+ previous = Thread.current[THREAD_POINT_IN_TIME_KEY]
5
7
  raise ArgumentError, "requires a block" unless block_given?
6
- key = :sequel_plugins_bitemporal_point_in_time
7
- previous, Thread.current[key] = Thread.current[key], time.to_time
8
- result = yield
9
- Thread.current[key] = previous
10
- result
8
+ Thread.current[THREAD_POINT_IN_TIME_KEY] = time.to_time
9
+ yield
10
+ ensure
11
+ Thread.current[THREAD_POINT_IN_TIME_KEY] = previous
11
12
  end
12
13
 
13
14
  def self.point_in_time
14
- Thread.current[:sequel_plugins_bitemporal_point_in_time] || Time.now
15
+ Thread.current[THREAD_POINT_IN_TIME_KEY] || Time.now
15
16
  end
16
17
 
17
- def self.at(time)
18
+ THREAD_NOW_KEY = :sequel_plugins_bitemporal_now
19
+ def self.at(time)
20
+ previous = Thread.current[THREAD_NOW_KEY]
18
21
  raise ArgumentError, "requires a block" unless block_given?
19
- key = :sequel_plugins_bitemporal_now
20
- previous, Thread.current[key] = Thread.current[key], time.to_time
21
- result = yield
22
- Thread.current[key] = previous
23
- result
22
+ Thread.current[THREAD_NOW_KEY] = time.to_time
23
+ yield
24
+ ensure
25
+ Thread.current[THREAD_NOW_KEY] = previous
24
26
  end
25
27
 
26
28
  def self.now
27
- Thread.current[:sequel_plugins_bitemporal_now] || Time.now
29
+ Thread.current[THREAD_NOW_KEY] || Time.now
28
30
  end
29
31
 
30
32
  def self.configure(master, opts = {})
@@ -3,7 +3,7 @@ $:.push File.expand_path("../lib", __FILE__)
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "sequel_bitemporal"
6
- s.version = "0.4.10"
6
+ s.version = "0.4.11"
7
7
  s.authors = ["Joseph HALTER", "Jonathan TRON"]
8
8
  s.email = ["joseph.halter@thetalentbox.com", "jonathan.tron@thetalentbox.com"]
9
9
  s.homepage = "https://github.com/TalentBox/sequel_bitemporal"
@@ -387,6 +387,21 @@ describe "Sequel::Plugins::Bitemporal" do
387
387
  end
388
388
  end
389
389
  end
390
+ it "correctly reset time if failure when going back in time" do
391
+ before = Sequel::Plugins::Bitemporal.now
392
+ lambda do
393
+ Sequel::Plugins::Bitemporal.at(Date.today+2) do
394
+ raise StandardError, "error during back in time"
395
+ end
396
+ end.should raise_error StandardError
397
+ Sequel::Plugins::Bitemporal.now.should == before
398
+ lambda do
399
+ Sequel::Plugins::Bitemporal.as_we_knew_it(Date.today+2) do
400
+ raise StandardError, "error during back in time"
401
+ end
402
+ end.should raise_error StandardError
403
+ Sequel::Plugins::Bitemporal.now.should == before
404
+ end
390
405
  it "allows eager loading with conditions on current or future versions" do
391
406
  master = @master_class.new
392
407
  master.update_attributes name: "Single Standard", price: 98
@@ -309,6 +309,21 @@ describe "Sequel::Plugins::Bitemporal" do
309
309
  master.current_version(true).price.should == 98
310
310
  end
311
311
  end
312
+ it "correctly reset time if failure when going back in time" do
313
+ before = Sequel::Plugins::Bitemporal.now
314
+ lambda do
315
+ Sequel::Plugins::Bitemporal.at(Time.now+1*hour) do
316
+ raise StandardError, "error during back in time"
317
+ end
318
+ end.should raise_error StandardError
319
+ Sequel::Plugins::Bitemporal.now.should == before
320
+ lambda do
321
+ Sequel::Plugins::Bitemporal.as_we_knew_it(Time.now-1*hour) do
322
+ raise StandardError, "error during back in time"
323
+ end
324
+ end.should raise_error StandardError
325
+ Sequel::Plugins::Bitemporal.now.should == before
326
+ end
312
327
  it "allows eager loading with conditions on current or future versions" do
313
328
  master = @master_class.new
314
329
  master.update_attributes name: "Single Standard", price: 98
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sequel_bitemporal
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.10
4
+ version: 0.4.11
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-05-22 00:00:00.000000000 Z
13
+ date: 2012-06-13 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: sequel
@@ -127,7 +127,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
127
127
  version: '0'
128
128
  segments:
129
129
  - 0
130
- hash: -2831244389033292323
130
+ hash: -3307599890657545799
131
131
  required_rubygems_version: !ruby/object:Gem::Requirement
132
132
  none: false
133
133
  requirements:
@@ -136,7 +136,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
136
136
  version: '0'
137
137
  segments:
138
138
  - 0
139
- hash: -2831244389033292323
139
+ hash: -3307599890657545799
140
140
  requirements: []
141
141
  rubyforge_project:
142
142
  rubygems_version: 1.8.24