trice 0.2.0 → 0.2.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: b9097c61e695a9f53208d64b12cade17d4d2fe89
4
- data.tar.gz: 167602e225951b8c6dceb09f0e9cb872818af6aa
3
+ metadata.gz: 2b5c704c1fe09caf5987257b287f21616445d583
4
+ data.tar.gz: 6ca50c285e540bddd31fd167cf3f8c4c5656ca78
5
5
  SHA512:
6
- metadata.gz: c5040644cbc271721d2c439e194fa88ccf1091e33bb4617e9566975077c758eaa53a9c7ca13446f705d610ed0f0c18cb4ad342ee412de1cc25ac6a456a0f8956
7
- data.tar.gz: 8c1cf24577b05add0576ec7c1c97e7e1168564381d3cf46756e87ad2a5abd86ac232f886053b1a0e6ac3828d55fbacc432627b783cad9eb85698119aa26842e9
6
+ metadata.gz: 653a39eb48ae6332edabf6a0468c52b1cd2a202b27adf281b06ed41aaa4b0e4987b5be729ab01b33eed6dff150e0010845a40422d2633e2b28932c7b18c98fa0
7
+ data.tar.gz: d28c70c39e1f413c6a792116b10de2e49fa1dbca920569c1aa084a72ff0efae6eab4ba763f09227ea88faaf67b4d31e017c8d8201e10ccd4e6aa0b1b609a270d
data/README.md CHANGED
@@ -39,7 +39,7 @@ Then your controller and view gets an accessor method to access consistent time
39
39
 
40
40
  ### Include helper module outside of controller
41
41
 
42
- Inlude `Trice::ReferenceTime` add `#reference_time` method to lookup current reference time.
42
+ Include `Trice::ReferenceTime` add `#reference_time` method to lookup current reference time.
43
43
 
44
44
  Use it in Rails model.
45
45
 
@@ -84,7 +84,7 @@ Trice allows you to stub reference time to run travelled time-testing and / or p
84
84
 
85
85
  Set `_requested_at=<timish>` query parameter like below
86
86
  ```
87
- $ curl https://example.com/campaigns/12345?_requested_at=20160215130
87
+ $ curl https://example.com/campaigns/12345?_requested_at=201602151300
88
88
  ```
89
89
 
90
90
  Or can set HTTP header, useful for tests.
@@ -92,17 +92,17 @@ Or can set HTTP header, useful for tests.
92
92
  X-REQUESTED-AT: 2016-02-15T13:00:00+09:00
93
93
  ```
94
94
 
95
- Value format, which specified both query parameter and header, should be `Time.parsse` parasable.
95
+ Value format, which specified both query parameter and header, should be `Time.parse` parasable.
96
96
 
97
97
  #### Enable/Disable stubbing
98
98
 
99
- Toggle requested at stubbing in `config/initializers`. The default is below, enabled unelss `Rails.env.production?`.
99
+ Toggle requested at stubbing in `config/initializers`. The default is below, enabled unless `Rails.env.production?`.
100
100
 
101
101
  ```ruby
102
102
  Trice.support_requested_at_stubbing = !Rails.env.production?
103
103
  ```
104
104
 
105
- Setting callable object let you choice enable/disable dinamically by seeing request.
105
+ Setting callable object let you choice enable/disable dynamically by seeing request.
106
106
 
107
107
  ```ruby
108
108
  our_office_network = IPAddr.new('203.0.113.0/24')
@@ -127,7 +127,7 @@ 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_reference_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` declaration method to set `Trice.reference_time` in an example.
131
131
 
132
132
  ```ruby
133
133
  describe MyModel do
@@ -145,7 +145,7 @@ describe MyModel do
145
145
  end
146
146
  ```
147
147
 
148
- Feature specs (or othre Capybara based E2E tests) also has helper method using stubbing mechanism. `stub_requested_at <timish>` set `X-Trice-Requested-At` automatically.
148
+ Feature specs (or other Capybara based E2E tests) also has helper method using stubbing mechanism. `stub_requested_at <timish>` set `X-Trice-Requested-At` automatically.
149
149
 
150
150
  ```ruby
151
151
  context 'on ひな祭り day' do
@@ -10,27 +10,23 @@ module Trice
10
10
  end
11
11
 
12
12
  def around(controller, &action)
13
- t = determine_requested_at(controller)
13
+ t = stubbed_requested_at(controller) || Time.now
14
14
 
15
15
  Trice.with_reference_time(t, &action)
16
16
  end
17
17
 
18
18
  private
19
19
 
20
- def determine_requested_at(controller)
21
- if @stub_configuration.stubbable?(controller)
22
- extract_requested_at(controller.request) || Time.now
23
- else
24
- Time.now
20
+ def stubbed_requested_at(controller)
21
+ requested_at = requested_at_string(controller.request)
22
+
23
+ if requested_at && @stub_configuration.stubbable?(controller)
24
+ Time.zone.parse(requested_at)
25
25
  end
26
26
  end
27
27
 
28
- def extract_requested_at(request)
29
- if request.params[QUERY_STUB_KEY]
30
- Time.zone.parse(request.params[QUERY_STUB_KEY])
31
- elsif request.headers[HEADER_STUB_KEY]
32
- Time.zone.parse(request.headers[HEADER_STUB_KEY])
33
- end
28
+ def requested_at_string(request)
29
+ request.params[QUERY_STUB_KEY] || request.headers[HEADER_STUB_KEY]
34
30
  end
35
31
  end
36
32
  end
@@ -1,3 +1,3 @@
1
1
  module Trice
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.1"
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.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - moro
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-05-06 00:00:00.000000000 Z
11
+ date: 2016-09-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport