Skip to content

Commit 49a9bb5

Browse files
committed
Add updatedAt and createdAt to Index
1 parent 28897d5 commit 49a9bb5

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

.rubocop_todo.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ Metrics/BlockLength:
2323
# Offense count: 1
2424
# Configuration parameters: CountComments, CountAsOne.
2525
Metrics/ClassLength:
26-
Max: 256
26+
Max: 260
2727

2828
# Offense count: 1
2929
Naming/AccessorMethodName:

lib/meilisearch/index.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
module MeiliSearch
77
class Index < HTTPRequest
8-
attr_reader :uid, :primary_key
8+
attr_reader :uid, :primary_key, :created_at, :updated_at
99

1010
def initialize(index_uid, url, api_key = nil, primary_key = nil, options = {})
1111
@uid = index_uid
@@ -16,12 +16,16 @@ def initialize(index_uid, url, api_key = nil, primary_key = nil, options = {})
1616
def fetch_info
1717
index_hash = http_get "/indexes/#{@uid}"
1818
@primary_key = index_hash['primaryKey']
19+
@created_at = Time.parse(index_hash['createdAt'])
20+
@updated_at = Time.parse(index_hash['updatedAt'])
1921
self
2022
end
2123

2224
def update(body)
2325
index_hash = http_put "/indexes/#{@uid}", body
2426
@primary_key = index_hash['primaryKey']
27+
@created_at = Time.parse(index_hash['createdAt'])
28+
@updated_at = Time.parse(index_hash['updatedAt'])
2529
self
2630
end
2731
alias update_index update

spec/meilisearch/index/base_spec.rb

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
index.fetch_info
77
expect(index).to be_a(MeiliSearch::Index)
88
expect(index.uid).to eq('new_index')
9+
expect(index.created_at).to be_a(Time)
10+
expect(index.created_at).to be_within(60).of(Time.now)
11+
expect(index.updated_at).to be_a(Time)
12+
expect(index.created_at).to be_within(60).of(Time.now)
913
expect(index.primary_key).to be_nil
1014
end
1115

@@ -33,6 +37,10 @@
3337
expect(index.uid).to eq('uid')
3438
expect(index.primary_key).to eq('new_primary_key')
3539
expect(index.fetch_primary_key).to eq('new_primary_key')
40+
expect(index.created_at).to be_a(Time)
41+
expect(index.created_at).to be_within(60).of(Time.now)
42+
expect(index.updated_at).to be_a(Time)
43+
expect(index.updated_at).to be_within(60).of(Time.now)
3644
end
3745

3846
it 'returns error if trying to update primary-key if it is already defined' do
@@ -60,7 +68,9 @@
6068
max_retries: 1,
6169
timeout: 2
6270
}
63-
).and_return(double(success?: true, parsed_response: ''))
71+
).and_return(double(success?: true,
72+
parsed_response: { 'createdAt' => '2021-10-16T14:57:35Z',
73+
'updatedAt' => '2021-10-16T14:57:35Z' }))
6474
index.fetch_info
6575
end
6676

0 commit comments

Comments
 (0)