working_hours 1.1.3 → 1.1.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 84b53643f4f18edb7c63446575a16d2f670d658e
4
- data.tar.gz: dff1cc9158cf632f559734fdf52b31b41b16d004
3
+ metadata.gz: f00a9f2b6cd9d293631464feb64a41d6c738b03f
4
+ data.tar.gz: c18fa540c8033e1d8c1f42cad501420f16c6c7d7
5
5
  SHA512:
6
- metadata.gz: ffaa30b066b7fa1aca5627d26698b6fa54c4f594d7d5dc4a876be57ab065557d6bcd078ad2a3682d855804981e992979ed7c6b986ba9b8e1135850d2e4716ea2
7
- data.tar.gz: 124cd2067fbb66250df7bf78451a0561d37b2b3a27ff91cfd8b85155af0e806193b20fb272065fd615ac85500b6539c1080ac93c2daed37e48e00d9ae2b8d346
6
+ metadata.gz: fb32d4257bb17d0c0dc5d7595e19f808ec76970d38bb46ab3b4bf0893ed3d05e9f1734db7f49ec09a89eb495bc21e45a98bd08ce40979edd89efbbfd039f8539
7
+ data.tar.gz: f9874b5d95e6b47846d194347de5e78c14fe56d95a36071a1215e016dfe9312c3a57f0343aabdb4a4280fc89900e100e5c5598975954683d32a08cb18cfd92bd
data/CHANGELOG.md CHANGED
@@ -1,6 +1,9 @@
1
1
  # Unreleased
2
2
 
3
- [Compare master with v1.1.3](https://github.com/intrepidd/working_hours/compare/v1.1.3...master)
3
+ [Compare master with v1.1.4](https://github.com/intrepidd/working_hours/compare/v1.1.4...master)
4
+
5
+ # v1.1.4
6
+ * Fix thread safety - [#36](https://github.com/Intrepidd/working_hours/pull/36)
4
7
 
5
8
  # v1.1.3
6
9
  * Fixed warnings with Ruby 2.4.0+ - [#32](https://github.com/Intrepidd/working_hours/pull/32)
@@ -89,7 +89,7 @@ module WorkingHours
89
89
  private
90
90
 
91
91
  def config
92
- Thread.current[:working_hours] ||= global_config
92
+ Thread.current[:working_hours] ||= global_config.dup
93
93
  end
94
94
 
95
95
  def global_config
@@ -1,3 +1,3 @@
1
1
  module WorkingHours
2
- VERSION = "1.1.3"
2
+ VERSION = "1.1.4"
3
3
  end
@@ -5,25 +5,58 @@ describe WorkingHours::Config do
5
5
  describe '.working_hours' do
6
6
 
7
7
  let(:config) { WorkingHours::Config.working_hours }
8
+ let(:config2) { { :mon => { '08:00' => '14:00' } } }
9
+ let(:config3) { { :tue => { '10:00' => '16:00' } } }
8
10
 
9
11
  it 'has a default config' do
10
12
  expect(config).to be_kind_of(Hash)
11
13
  end
12
14
 
13
15
  it 'is thread safe' do
16
+ expect(WorkingHours::Config.working_hours).to eq(config)
17
+
18
+ thread = Thread.new do
19
+ WorkingHours::Config.working_hours = config2
20
+ expect(WorkingHours::Config.working_hours).to eq(config2)
21
+ Thread.stop
22
+ expect(WorkingHours::Config.working_hours).to eq(config2)
23
+ end
24
+
25
+ expect {
26
+ sleep 0.1 # let the thread begin its execution
27
+ }.not_to change { WorkingHours::Config.working_hours }.from(config)
28
+
29
+ expect {
30
+ WorkingHours::Config.working_hours = config3
31
+ }.to change { WorkingHours::Config.working_hours }.from(config).to(config3)
32
+
14
33
  expect {
15
- Thread.new {
16
- WorkingHours::Config.working_hours = {:mon => {'08:00' => '14:00'}}
17
- }.join
18
- }.not_to change { WorkingHours::Config.working_hours }
34
+ thread.run
35
+ thread.join
36
+ }.not_to change { WorkingHours::Config.working_hours }.from(config3)
19
37
  end
20
38
 
21
39
  it 'is fiber safe' do
40
+ expect(WorkingHours::Config.working_hours).to eq(config)
41
+
42
+ fiber = Fiber.new do
43
+ WorkingHours::Config.working_hours = config2
44
+ expect(WorkingHours::Config.working_hours).to eq(config2)
45
+ Fiber.yield
46
+ expect(WorkingHours::Config.working_hours).to eq(config2)
47
+ end
48
+
49
+ expect {
50
+ fiber.resume
51
+ }.not_to change { WorkingHours::Config.working_hours }.from(config)
52
+
53
+ expect {
54
+ WorkingHours::Config.working_hours = config3
55
+ }.to change { WorkingHours::Config.working_hours }.from(config).to(config3)
56
+
22
57
  expect {
23
- Fiber.new {
24
- WorkingHours::Config.working_hours = {:mon => {'08:00' => '14:00'}}
25
- }.resume
26
- }.not_to change { WorkingHours::Config.working_hours }
58
+ fiber.resume
59
+ }.not_to change { WorkingHours::Config.working_hours }.from(config3)
27
60
  end
28
61
 
29
62
  it 'is initialized from last known global config' do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: working_hours
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.3
4
+ version: 1.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adrien Jarthon
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2017-04-03 00:00:00.000000000 Z
12
+ date: 2018-11-30 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
@@ -154,7 +154,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
154
154
  version: '0'
155
155
  requirements: []
156
156
  rubyforge_project:
157
- rubygems_version: 2.6.6
157
+ rubygems_version: 2.5.1
158
158
  signing_key:
159
159
  specification_version: 4
160
160
  summary: time calculation with working hours
@@ -167,3 +167,4 @@ test_files:
167
167
  - spec/working_hours/duration_proxy_spec.rb
168
168
  - spec/working_hours/duration_spec.rb
169
169
  - spec/working_hours_spec.rb
170
+ has_rdoc: