trice 0.2.0 → 0.2.1
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 +4 -4
- data/README.md +7 -7
- data/lib/trice/controller_methods/reference_time_assignment.rb +8 -12
- data/lib/trice/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2b5c704c1fe09caf5987257b287f21616445d583
|
4
|
+
data.tar.gz: 6ca50c285e540bddd31fd167cf3f8c4c5656ca78
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
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=
|
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.
|
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
|
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
|
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`
|
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
|
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 =
|
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
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
Time.
|
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
|
29
|
-
|
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
|
data/lib/trice/version.rb
CHANGED
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.
|
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-
|
11
|
+
date: 2016-09-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|