trice 0.1.1 → 0.2.0

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: 25190dbc72f712963bc37e9ee966324a5e19b342
4
- data.tar.gz: 701949aedd85f646106c34e2f89193b8af07bed1
3
+ metadata.gz: b9097c61e695a9f53208d64b12cade17d4d2fe89
4
+ data.tar.gz: 167602e225951b8c6dceb09f0e9cb872818af6aa
5
5
  SHA512:
6
- metadata.gz: 06408004d555c84c628e40ec675b1a693bb8f54b0f2914b361fa5c31ab8415a1f03c873e5e4d8f829d831194814109c0114e01e74cbdcb0accf0a84a707265b6
7
- data.tar.gz: 45b39aaf7bd9f5a33a1b082a03b266feefcd24ded644c2689bc7eb6befe7aaf8d60d9ad2944e384775f52fac5385988b3bdd2ff274e4d139cd6124339cc52f88
6
+ metadata.gz: c5040644cbc271721d2c439e194fa88ccf1091e33bb4617e9566975077c758eaa53a9c7ca13446f705d610ed0f0c18cb4ad342ee412de1cc25ac6a456a0f8956
7
+ data.tar.gz: 8c1cf24577b05add0576ec7c1c97e7e1168564381d3cf46756e87ad2a5abd86ac232f886053b1a0e6ac3828d55fbacc432627b783cad9eb85698119aa26842e9
data/README.md CHANGED
@@ -22,7 +22,7 @@ $ bundle
22
22
 
23
23
  ### With Rails controller
24
24
 
25
- This gem aims to serve consistency of time handling using refrence time to Rails application.
25
+ This gem aims to serve consistency of time handling using reference time to Rails application.
26
26
  The layer which should set reference time is controller layer, because reference time is one of external input.
27
27
 
28
28
  Include `Trice::ControllerMethods` to your controller
@@ -55,23 +55,23 @@ end
55
55
 
56
56
  ### Setting consistent reference time
57
57
 
58
- Set reference time with `Trice.refrence_time = _time_` or `Trice.with_refrence_time(_time_, &block)`.
58
+ Set reference time with `Trice.reference_time = _time_` or `Trice.with_reference_time(_time_, &block)`.
59
59
  Accessible by `Trice.reference_time`..
60
60
 
61
61
  ```ruby
62
62
  p Time.now
63
63
  => 2016-02-01 11:25:37 +0900
64
64
 
65
- Trice.with_refrence_time = Time.iso8601('2016-02-01T09:00:00Z')
65
+ Trice.with_reference_time = Time.iso8601('2016-02-01T09:00:00Z')
66
66
  p Trice.reference_time
67
67
  # => 2016-02-01 09:00:00 UTC
68
68
 
69
- Trice.with_refrence_time(Time.iso8601('2016-02-01T10:00:00Z')) do
69
+ Trice.with_reference_time(Time.iso8601('2016-02-01T10:00:00Z')) do
70
70
  p Trice.reference_time
71
71
  # => 2016-02-01 10:00:00 UTC
72
72
  end
73
73
 
74
- Trice.with_refrence_time = nil
74
+ Trice.with_reference_time = nil
75
75
  p Trice.reference_time
76
76
  # => raise Trice::NoReferenceTime
77
77
  ```
@@ -127,13 +127,13 @@ end
127
127
  I recommend to pass reference time to a model by method and/or constructor argument because reference time is an external input, should be handled controller layer.
128
128
  But sometimes it is required from deep inside of model logics and tests for them.
129
129
 
130
- Model unit spec has `with_refrence_time` and `set_now_to_reference_time` declarition method to set `Trice.reference_time` in an example.
130
+ Model unit spec has `with_reference_time` and `set_now_to_reference_time` declarition method to set `Trice.reference_time` in an example.
131
131
 
132
132
  ```ruby
133
133
  describe MyModel do
134
134
  let(:reference_time) { Time.zone.parse('2016/02/03 12:00') }
135
135
  context do
136
- set_reference_time { refrence_time }
136
+ set_reference_time { reference_time }
137
137
 
138
138
  let(:model) { MyModel.find_by_something(key) }
139
139
 
@@ -174,4 +174,3 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/cookpa
174
174
  ## License
175
175
 
176
176
  The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
177
-
@@ -1,3 +1,4 @@
1
+ require 'trice/controller_methods/raw_reference_time'
1
2
  require 'trice/controller_methods/reference_time_assignment'
2
3
  require 'trice/controller_methods/stub_configuration'
3
4
 
@@ -8,6 +9,10 @@ module Trice
8
9
 
9
10
  included do |controller|
10
11
  if controller.ancestors.include?(ActionController::Base)
12
+ unless controller.middleware_stack.include?(RawReferenceTime)
13
+ controller.use RawReferenceTime
14
+ end
15
+
11
16
  config = StubConfiguration.new(Trice.support_requested_at_stubbing)
12
17
  prepend_around_action ReferenceTimeAssignment.new(config)
13
18
 
@@ -0,0 +1,17 @@
1
+ module Trice
2
+ module ControllerMethods
3
+ class RawReferenceTime
4
+ ENV_KEY = 'trice.raw_reference_time'.freeze
5
+
6
+ def initialize(app)
7
+ @app = app
8
+ end
9
+
10
+ def call(env)
11
+ env[ENV_KEY] = Time.now
12
+
13
+ Trice.with_reference_time(env[ENV_KEY]) { @app.call(env) }
14
+ end
15
+ end
16
+ end
17
+ end
@@ -12,8 +12,6 @@ module Trice
12
12
  def around(controller, &action)
13
13
  t = determine_requested_at(controller)
14
14
 
15
- controller.request.env['trice.reference_time'] = t
16
-
17
15
  Trice.with_reference_time(t, &action)
18
16
  end
19
17
 
@@ -1,6 +1,8 @@
1
1
  require 'trice/errors'
2
2
 
3
3
  module Trice
4
+ class TestStubbingNotSupported < Error; end
5
+
4
6
  module SpecHelper
5
7
  def self.extract_time(runtime, static_time, block)
6
8
  block ? runtime.instance_eval(&block) : static_time
@@ -1,3 +1,3 @@
1
1
  module Trice
2
- VERSION = "0.1.1"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: trice
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - moro
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-02-08 00:00:00.000000000 Z
11
+ date: 2016-05-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -126,6 +126,7 @@ files:
126
126
  - bin/setup
127
127
  - lib/trice.rb
128
128
  - lib/trice/controller_methods.rb
129
+ - lib/trice/controller_methods/raw_reference_time.rb
129
130
  - lib/trice/controller_methods/reference_time_assignment.rb
130
131
  - lib/trice/controller_methods/stub_configuration.rb
131
132
  - lib/trice/errors.rb