search_flip 4.0.0.beta3 → 4.0.0.beta8

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
  SHA256:
3
- metadata.gz: c93ffb5c3868ef14b27903734bfb2d77384acc4a52eb529070f8a17a82f323a3
4
- data.tar.gz: 458f01664f5faf01006eddba2f59cdbcca7e10be22769aafca1084663c242a9b
3
+ metadata.gz: d63abc415f8eaad5ade7de6fc4ca424a8695b72016266a49a1d221f49530ca49
4
+ data.tar.gz: a6170648ed2663b769b123ae443c5d0863a4456ec39be35c2762186b93383cff
5
5
  SHA512:
6
- metadata.gz: 341783040e3c705d6ac1cb7875dbbb0088efd22439057ced5f9a21c5629eb6f9b4ea7e8e4a23a0368e5ef7c249ad0e6a578a5f0f8a57afb2cb3b649b2db0a22e
7
- data.tar.gz: fa40baa33a6626af128fdb14713300f55690ee407bec989b1f2bfca3e55a169377e2a0c5f9cefd6107a97ed7aceba290b52a382dcf5bdbf8c6c9389253896df7
6
+ metadata.gz: 7c7879bcf95f3e53c5186ec50592cf7e46b703b819c34e7d7e91229972652daf132b7a73b3f85051c6d86117f66278f83b5ac2f2b12c23272bb36130b0e7aa72
7
+ data.tar.gz: a04b20cbcf16eceb905798d1e5e2ea8dd60bb27b45bee9a0ab6f52aaed7d58e648a2f3139981117332a9824570db429f069ed749873dffd27ceb7cc274b3a7b4
@@ -11,11 +11,11 @@ jobs:
11
11
  - elasticsearch:5.4
12
12
  - docker.elastic.co/elasticsearch/elasticsearch:6.7.0
13
13
  - docker.elastic.co/elasticsearch/elasticsearch:7.0.0
14
- - docker.elastic.co/elasticsearch/elasticsearch:7.9.0
14
+ - docker.elastic.co/elasticsearch/elasticsearch:7.11.2
15
15
  ruby:
16
- - 2.5
17
16
  - 2.6
18
17
  - 2.7
18
+ - 3.0
19
19
  services:
20
20
  elasticsearch:
21
21
  image: ${{ matrix.elasticsearch }}
@@ -28,6 +28,7 @@ jobs:
28
28
  - uses: actions/setup-ruby@v1
29
29
  with:
30
30
  ruby-version: ${{ matrix.ruby }}
31
+ - run: gem install bundler
31
32
  - run: bundle
32
33
  - run: sleep 10
33
34
  - run: bundle exec rspec
data/.rubocop.yml CHANGED
@@ -1,6 +1,7 @@
1
1
  AllCops:
2
2
  NewCops: enable
3
- TargetRubyVersion: 2.4
3
+ TargetRubyVersion: 2.5
4
+ SuggestExtensions: false
4
5
 
5
6
  Style/CaseLikeIf:
6
7
  Enabled: false
data/CHANGELOG.md CHANGED
@@ -11,6 +11,20 @@
11
11
  * Added `SearchFlip::Connection#get_cluster_settings` and
12
12
  `#update_cluster_settings`
13
13
 
14
+ ## v3.4.0
15
+
16
+ * Expose `Http#timeout` via `SearchFlip::HTTPClient`
17
+
18
+ ## v3.3.0
19
+
20
+ * Update httprb
21
+ * Changed oj default options
22
+ * Allow to set oj json options
23
+
24
+ ## v3.2.1
25
+
26
+ * Fix `refresh` having a empty body breaking in elasticsearch 7.11
27
+
14
28
  ## v3.2.0
15
29
 
16
30
  * Fix `index_scope` not being passed in `each_record` without block
data/README.md CHANGED
@@ -51,7 +51,7 @@ CommentIndex.search("hello world").where(available: true).sort(id: "desc").aggre
51
51
 
52
52
  ```
53
53
 
54
- Finally, SearchFlip comes with a minimal set of dependencies (http-rb and oj only).
54
+ Finally, SearchFlip comes with a minimal set of dependencies.
55
55
 
56
56
  ## Reference Docs
57
57
 
@@ -756,7 +756,7 @@ end
756
756
  This allows to use different clusters per index e.g. when migrating indices to
757
757
  new versions of Elasticsearch.
758
758
 
759
- You can specify basic auth, additional headers, etc via:
759
+ You can specify basic auth, additional headers, request timeouts, etc via:
760
760
 
761
761
  ```ruby
762
762
  http_client = SearchFlip::HTTPClient.new
@@ -773,6 +773,9 @@ http_client = http_client.via("proxy.host", 8080)
773
773
  # Custom headers
774
774
  http_client = http_client.headers(key: "value")
775
775
 
776
+ # Timeouts
777
+ http_client = http_client.timeout(20)
778
+
776
779
  SearchFlip::Connection.new(base_url: "...", http_client: http_client)
777
780
  ```
778
781
 
@@ -882,52 +885,46 @@ Thus, if your ORM supports `.find_each`, `#id` and `#where` you are already
882
885
  good to go. Otherwise, simply add your custom implementation of those methods
883
886
  that work with whatever ORM you use.
884
887
 
885
- ## Date and Timestamps in JSON
886
-
887
- Elasticsearch requires dates and timestamps to have one of the formats listed
888
- here: [https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-date-format.html#strict-date-time](https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-date-format.html#strict-date-time).
888
+ ## JSON
889
889
 
890
- However, `JSON.generate` in ruby by default outputs something like:
890
+ SearchFlip is using the [Oj gem](https://github.com/ohler55/oj) to generate
891
+ JSON. More concretely, SearchFlip is using:
891
892
 
892
893
  ```ruby
893
- JSON.generate(time: Time.now.utc)
894
- # => "{\"time\":\"2018-02-22 18:19:33 UTC\"}"
894
+ Oj.dump({ key: "value" }, mode: :custom, use_to_json: true, time_format: :xmlschema, bigdecimal_as_decimal: false)
895
895
  ```
896
896
 
897
- This format is not compatible with Elasticsearch by default. If you're on
898
- Rails, ActiveSupport adds its own `#to_json` methods to `Time`, `Date`, etc.
899
- However, ActiveSupport checks whether they are used in combination with
900
- `JSON.generate` or not and adapt:
897
+ The `use_to_json` option is used for maximum compatibility, most importantly
898
+ when using rails `ActiveSupport::TimeWithZone` timestamps, which `oj` can not
899
+ serialize natively. However, `use_to_json` adds performance overhead. You can
900
+ change the json options via:
901
901
 
902
902
  ```ruby
903
- Time.now.utc.to_json
904
- => "\"2018-02-22T18:18:22.088Z\""
905
-
906
- JSON.generate(time: Time.now.utc)
907
- => "{\"time\":\"2018-02-22 18:18:59 UTC\"}"
903
+ SearchFlip::Config[:json_options] = {
904
+ mode: :custom,
905
+ use_to_json: false,
906
+ time_format: :xmlschema,
907
+ bigdecimal_as_decimal: false
908
+ }
908
909
  ```
909
910
 
910
- SearchFlip is using the [Oj gem](https://github.com/ohler55/oj) to generate
911
- JSON. More concretely, SearchFlip is using:
911
+ However, you then have to convert timestamps manually for indexation via e.g.:
912
912
 
913
913
  ```ruby
914
- Oj.dump({ key: "value" }, mode: :custom, use_to_json: true)
915
- ```
914
+ class MyIndex
915
+ # ...
916
916
 
917
- This mitigates the issues if you're on Rails:
917
+ def self.serialize(model)
918
+ {
919
+ # ...
918
920
 
919
- ```ruby
920
- Oj.dump(Time.now, mode: :custom, use_to_json: true)
921
- # => "\"2018-02-22T18:21:21.064Z\""
921
+ created_at: model.created_at.to_time
922
+ }
923
+ end
924
+ end
922
925
  ```
923
926
 
924
- However, if you're not on Rails, you need to add `#to_json` methods to `Time`,
925
- `Date` and `DateTime` to get proper serialization. You can either add them on
926
- your own, via other libraries or by simply using:
927
-
928
- ```ruby
929
- require "search_flip/to_json"
930
- ```
927
+ Please check out the oj docs for more details.
931
928
 
932
929
  ## Feature Support
933
930
 
data/lib/search_flip.rb CHANGED
@@ -2,6 +2,7 @@ require "ruby2_keywords"
2
2
  require "forwardable"
3
3
  require "http"
4
4
  require "thread"
5
+ require "json"
5
6
  require "oj"
6
7
  require "set"
7
8
 
@@ -143,7 +143,7 @@ module SearchFlip
143
143
 
144
144
  return if options[:raise] == false
145
145
 
146
- parsed_response = response.parse
146
+ parsed_response = SearchFlip::JSON.parse(response.to_s)
147
147
 
148
148
  return unless parsed_response["errors"]
149
149
 
@@ -5,6 +5,12 @@ module SearchFlip
5
5
  bulk_limit: 1_000,
6
6
  bulk_max_mb: 100,
7
7
  auto_refresh: false,
8
- instrumenter: NullInstrumenter.new
8
+ instrumenter: NullInstrumenter.new,
9
+ json_options: {
10
+ mode: :custom,
11
+ use_to_json: true,
12
+ time_format: :xmlschema,
13
+ bigdecimal_as_decimal: false
14
+ }
9
15
  }
10
16
  end
@@ -28,7 +28,9 @@ module SearchFlip
28
28
  # @return [Hash] The cluster settings
29
29
 
30
30
  def get_cluster_settings
31
- http_client.get("#{base_url}/_cluster/settings").parse
31
+ response = http_client.get("#{base_url}/_cluster/settings")
32
+
33
+ SearchFlip::JSON.parse(response.to_s)
32
34
  end
33
35
 
34
36
  # Updates the cluster settings according to the specified payload
@@ -55,7 +57,11 @@ module SearchFlip
55
57
 
56
58
  def version
57
59
  @version_mutex.synchronize do
58
- @version ||= http_client.headers(accept: "application/json").get("#{base_url}/").parse["version"]["number"]
60
+ @version ||= begin
61
+ response = http_client.headers(accept: "application/json").get("#{base_url}/")
62
+
63
+ SearchFlip::JSON.parse(response.to_s)["version"]["number"]
64
+ end
59
65
  end
60
66
  end
61
67
 
@@ -67,7 +73,9 @@ module SearchFlip
67
73
  # @return [Hash] The raw response
68
74
 
69
75
  def cluster_health
70
- http_client.headers(accept: "application/json").get("#{base_url}/_cluster/health").parse
76
+ response = http_client.headers(accept: "application/json").get("#{base_url}/_cluster/health")
77
+
78
+ SearchFlip::JSON.parse(response.to_s)
71
79
  end
72
80
 
73
81
  # Uses the Elasticsearch Multi Search API to execute multiple search requests
@@ -117,10 +125,11 @@ module SearchFlip
117
125
  # @return [Hash] The raw response
118
126
 
119
127
  def update_aliases(payload)
120
- http_client
128
+ response = http_client
121
129
  .headers(accept: "application/json", content_type: "application/json")
122
130
  .post("#{base_url}/_aliases", body: SearchFlip::JSON.generate(payload))
123
- .parse
131
+
132
+ SearchFlip::JSON.parse(response.to_s)
124
133
  end
125
134
 
126
135
  # Sends an analyze request to Elasticsearch. Raises
@@ -132,10 +141,11 @@ module SearchFlip
132
141
  # @return [Hash] The raw response
133
142
 
134
143
  def analyze(request, params = {})
135
- http_client
144
+ response = http_client
136
145
  .headers(accept: "application/json")
137
146
  .post("#{base_url}/_analyze", json: request, params: params)
138
- .parse
147
+
148
+ SearchFlip::JSON.parse(response.to_s)
139
149
  end
140
150
 
141
151
  # Fetches information about the specified index aliases. Raises
@@ -151,10 +161,11 @@ module SearchFlip
151
161
  # @return [Hash] The raw response
152
162
 
153
163
  def get_aliases(index_name: "*", alias_name: "*")
154
- http_client
164
+ response = http_client
155
165
  .headers(accept: "application/json", content_type: "application/json")
156
166
  .get("#{base_url}/#{index_name}/_alias/#{alias_name}")
157
- .parse
167
+
168
+ SearchFlip::JSON.parse(response.to_s)
158
169
  end
159
170
 
160
171
  # Returns whether or not the associated Elasticsearch alias already
@@ -186,10 +197,11 @@ module SearchFlip
186
197
  # @return [Array] The raw response
187
198
 
188
199
  def get_indices(name = "*", params: {})
189
- http_client
200
+ response = http_client
190
201
  .headers(accept: "application/json", content_type: "application/json")
191
202
  .get("#{base_url}/_cat/indices/#{name}", params: params)
192
- .parse
203
+
204
+ SearchFlip::JSON.parse(response.to_s)
193
205
  end
194
206
 
195
207
  alias_method :cat_indices, :get_indices
@@ -286,10 +298,11 @@ module SearchFlip
286
298
  # @return [Hash] The index settings
287
299
 
288
300
  def get_index_settings(index_name)
289
- http_client
301
+ response = http_client
290
302
  .headers(accept: "application/json")
291
303
  .get("#{index_url(index_name)}/_settings")
292
- .parse
304
+
305
+ SearchFlip::JSON.parse(response.to_s)
293
306
  end
294
307
 
295
308
  # Sends a refresh request to Elasticsearch. Raises
@@ -299,7 +312,7 @@ module SearchFlip
299
312
  # @return [Boolean] Returns true or raises SearchFlip::ResponseError
300
313
 
301
314
  def refresh(index_names = nil)
302
- http_client.post("#{index_names ? index_url(Array(index_names).join(",")) : base_url}/_refresh", json: {})
315
+ http_client.post("#{index_names ? index_url(Array(index_names).join(",")) : base_url}/_refresh")
303
316
 
304
317
  true
305
318
  end
@@ -337,7 +350,9 @@ module SearchFlip
337
350
  url = type_name ? type_url(index_name, type_name) : index_url(index_name)
338
351
  params = type_name && version.to_f >= 6.7 ? { include_type_name: true } : {}
339
352
 
340
- http_client.headers(accept: "application/json").get("#{url}/_mapping", params: params).parse
353
+ response = http_client.headers(accept: "application/json").get("#{url}/_mapping", params: params)
354
+
355
+ SearchFlip::JSON.parse(response.to_s)
341
356
  end
342
357
 
343
358
  # Deletes the specified index from Elasticsearch. Raises
@@ -1,7 +1,28 @@
1
1
  module SearchFlip
2
- # The SearchFlip::HTTPClient class wraps the http gem, is for internal use
3
- # and responsible for the http request/response handling, ie communicating
4
- # with Elasticsearch.
2
+ # The SearchFlip::HTTPClient class wraps the http gem and responsible for the
3
+ # http request/response handling, ie communicating with Elasticsearch. You
4
+ # only need to use it directly if you need authentication to communicate with
5
+ # Elasticsearch or if you want to set some custom http settings.
6
+ #
7
+ # @example
8
+ # http_client = SearchFlip::HTTPClient.new
9
+ #
10
+ # # Basic Auth
11
+ # http_client = http_client.basic_auth(user: "username", pass: "password")
12
+ #
13
+ # # Raw Auth Header
14
+ # http_client = http_client.auth("Bearer VGhlIEhUVFAgR2VtLCBST0NLUw")
15
+ #
16
+ # # Proxy Settings
17
+ # http_client = http_client.via("proxy.host", 8080)
18
+ #
19
+ # # Custom headers
20
+ # http_client = http_client.headers(key: "value")
21
+ #
22
+ # # Timeouts
23
+ # http_client = http_client.timeout(20)
24
+ #
25
+ # SearchFlip::Connection.new(base_url: "...", http_client: http_client)
5
26
 
6
27
  class HTTPClient
7
28
  attr_accessor :request, :plugins
@@ -14,11 +35,11 @@ module SearchFlip
14
35
  class << self
15
36
  extend Forwardable
16
37
 
17
- def_delegators :new, :headers, :via, :basic_auth, :auth
38
+ def_delegators :new, :headers, :via, :basic_auth, :auth, :timeout
18
39
  def_delegators :new, :get, :post, :put, :delete, :head
19
40
  end
20
41
 
21
- [:headers, :via, :basic_auth, :auth].each do |method|
42
+ [:headers, :via, :basic_auth, :auth, :timeout].each do |method|
22
43
  define_method method do |*args|
23
44
  dup.tap do |client|
24
45
  client.request = request.send(method, *args)
@@ -487,7 +487,9 @@ module SearchFlip
487
487
  # @return [Hash] The raw response
488
488
 
489
489
  def analyze(request, params = {})
490
- connection.http_client.headers(accept: "application/json").post("#{index_url}/_analyze", json: request, params: params).parse
490
+ response = connection.http_client.headers(accept: "application/json").post("#{index_url}/_analyze", json: request, params: params)
491
+
492
+ SearchFlip::JSON.parse(response.to_s)
491
493
  end
492
494
 
493
495
  # Sends a index refresh request to Elasticsearch. Raises
@@ -1,11 +1,11 @@
1
1
  module SearchFlip
2
2
  class JSON
3
3
  def self.generate(obj)
4
- Oj.dump(obj, mode: :custom, use_to_json: true)
4
+ Oj.dump(obj, SearchFlip::Config[:json_options])
5
5
  end
6
6
 
7
- def self.parse(str)
8
- Oj.load(str, mode: :compat)
7
+ def self.parse(json)
8
+ ::JSON.parse(json)
9
9
  end
10
10
  end
11
11
  end
@@ -1,29 +1 @@
1
- require "time"
2
- require "date"
3
- require "json"
4
-
5
- class Time
6
- def to_json(*args)
7
- iso8601(6).to_json
8
- end
9
- end
10
-
11
- class Date
12
- def to_json(*args)
13
- iso8601.to_json
14
- end
15
- end
16
-
17
- class DateTime
18
- def to_json(*args)
19
- iso8601(6).to_json
20
- end
21
- end
22
-
23
- if defined?(ActiveSupport)
24
- class ActiveSupport::TimeWithZone
25
- def to_json(*args)
26
- iso8601(6).to_json
27
- end
28
- end
29
- end
1
+ warn "[DEPRECATION] Using search_flip/to_json is not neccessary anymore"
@@ -1,3 +1,3 @@
1
1
  module SearchFlip
2
- VERSION = "4.0.0.beta3"
2
+ VERSION = "4.0.0.beta8"
3
3
  end
data/search_flip.gemspec CHANGED
@@ -36,6 +36,7 @@ Gem::Specification.new do |spec|
36
36
  spec.add_development_dependency "webmock"
37
37
 
38
38
  spec.add_dependency "http"
39
+ spec.add_dependency "json"
39
40
  spec.add_dependency "oj"
40
41
  spec.add_dependency "ruby2_keywords"
41
42
  end
@@ -7,7 +7,7 @@ class HttpTestRequest
7
7
  self.calls = []
8
8
  end
9
9
 
10
- [:via, :basic_auth, :auth].each do |method|
10
+ [:headers, :via, :basic_auth, :auth, :timeout].each do |method|
11
11
  define_method method do |*args|
12
12
  dup.tap do |request|
13
13
  request.calls = calls + [[method, args]]
@@ -20,7 +20,7 @@ RSpec.describe SearchFlip::HTTPClient do
20
20
  describe "delegation" do
21
21
  subject { SearchFlip::HTTPClient }
22
22
 
23
- [:headers, :via, :basic_auth, :auth].each do |method|
23
+ [:headers, :via, :basic_auth, :auth, :timeout].each do |method|
24
24
  it { should delegate(method).to(:new) }
25
25
  end
26
26
 
@@ -56,8 +56,12 @@ RSpec.describe SearchFlip::HTTPClient do
56
56
  end
57
57
  end
58
58
 
59
- [:via, :basic_auth, :auth].each do |method|
59
+ [:headers, :via, :basic_auth, :auth, :timeout].each do |method|
60
60
  describe "##{method}" do
61
+ it "is understood by HTTP" do
62
+ expect(HTTP.respond_to?(method)).to eq(true)
63
+ end
64
+
61
65
  it "creates a dupped instance" do
62
66
  client = SearchFlip::HTTPClient.new
63
67
  client.request = HttpTestRequest.new
@@ -2,6 +2,16 @@ require File.expand_path("../spec_helper", __dir__)
2
2
 
3
3
  RSpec.describe SearchFlip::JSON do
4
4
  describe ".generate" do
5
+ it "encodes timestamps correctly" do
6
+ Timecop.freeze "2020-06-01 12:00:00 UTC" do
7
+ expect(described_class.generate(timestamp: Time.now.utc)).to eq('{"timestamp":"2020-06-01T12:00:00.000Z"}')
8
+ end
9
+ end
10
+
11
+ it "encodes bigdecimals as string" do
12
+ expect(described_class.generate(value: BigDecimal(1))).to eq('{"value":"1.0"}')
13
+ end
14
+
5
15
  it "delegates to Oj" do
6
16
  allow(Oj).to receive(:dump)
7
17
 
@@ -9,7 +19,7 @@ RSpec.describe SearchFlip::JSON do
9
19
 
10
20
  described_class.generate(payload)
11
21
 
12
- expect(Oj).to have_received(:dump).with(payload, mode: :custom, use_to_json: true)
22
+ expect(Oj).to have_received(:dump).with(payload, mode: :custom, use_to_json: true, time_format: :xmlschema, bigdecimal_as_decimal: false)
13
23
  end
14
24
 
15
25
  it "generates json" do
@@ -18,14 +28,18 @@ RSpec.describe SearchFlip::JSON do
18
28
  end
19
29
 
20
30
  describe ".parse" do
21
- it "delegates to Oj" do
22
- allow(Oj).to receive(:load)
31
+ it "returns the parsed json payload" do
32
+ expect(described_class.parse('{"key":"value"}')).to eq("key" => "value")
33
+ end
34
+
35
+ it "delegates to JSON" do
36
+ allow(JSON).to receive(:parse)
23
37
 
24
38
  payload = '{"key":"value"}'
25
39
 
26
40
  described_class.parse(payload)
27
41
 
28
- expect(Oj).to have_received(:load).with(payload, mode: :compat)
42
+ expect(JSON).to have_received(:parse).with(payload)
29
43
  end
30
44
  end
31
45
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: search_flip
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.0.0.beta3
4
+ version: 4.0.0.beta8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Benjamin Vetter
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-03-05 00:00:00.000000000 Z
11
+ date: 2021-06-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -164,6 +164,20 @@ dependencies:
164
164
  - - ">="
165
165
  - !ruby/object:Gem::Version
166
166
  version: '0'
167
+ - !ruby/object:Gem::Dependency
168
+ name: json
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - ">="
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ type: :runtime
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - ">="
179
+ - !ruby/object:Gem::Version
180
+ version: '0'
167
181
  - !ruby/object:Gem::Dependency
168
182
  name: oj
169
183
  requirement: !ruby/object:Gem::Requirement
@@ -250,7 +264,6 @@ files:
250
264
  - spec/search_flip/null_instrumenter_spec.rb
251
265
  - spec/search_flip/response_spec.rb
252
266
  - spec/search_flip/result_spec.rb
253
- - spec/search_flip/to_json_spec.rb
254
267
  - spec/spec_helper.rb
255
268
  homepage: https://github.com/mrkamel/search_flip
256
269
  licenses:
@@ -292,5 +305,4 @@ test_files:
292
305
  - spec/search_flip/null_instrumenter_spec.rb
293
306
  - spec/search_flip/response_spec.rb
294
307
  - spec/search_flip/result_spec.rb
295
- - spec/search_flip/to_json_spec.rb
296
308
  - spec/spec_helper.rb
@@ -1,28 +0,0 @@
1
- require File.expand_path("../spec_helper", __dir__)
2
- require "search_flip/to_json"
3
-
4
- RSpec.describe "to_json" do
5
- it "uses the correct format for Time" do
6
- Timecop.freeze Time.parse("2018-01-01 12:00:00 UTC") do
7
- expect(Time.now.utc.to_json).to eq("\"2018-01-01T12:00:00.000000Z\"")
8
- end
9
- end
10
-
11
- it "uses the correct format for Date" do
12
- Timecop.freeze Time.parse("2018-01-01 12:00:00 UTC") do
13
- expect(Date.today.to_json).to eq("\"2018-01-01\"")
14
- end
15
- end
16
-
17
- it "uses the correct format for DateTime" do
18
- Timecop.freeze Time.parse("2018-01-01 12:00:00 UTC") do
19
- expect(Time.now.utc.to_json).to eq("\"2018-01-01T12:00:00.000000Z\"")
20
- end
21
- end
22
-
23
- it "uses the correct format for TimeWithZone" do
24
- Timecop.freeze Time.parse("2018-01-01 12:00:00 UTC") do
25
- expect(Time.find_zone("UTC").now.to_json).to eq("\"2018-01-01T12:00:00.000000Z\"")
26
- end
27
- end
28
- end