Skip to content

Commit

Permalink
Test #to_h and #to_hash
Browse files Browse the repository at this point in the history
  • Loading branch information
ellnix committed Oct 10, 2023
1 parent 34aad92 commit afec958
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions spec/meilisearch/models/task_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@
let(:create_index_task_hash) { client.http_post '/indexes', { 'uid' => new_index_uid } }
let(:task_hash) { create_index_task_hash }
let(:endpoint) { MeiliSearch::Task.new(URL, MASTER_KEY, client.options) }
let(:logger) { instance_double(Logger, warn: nil) }
before { MeiliSearch::Utils.logger = logger }

subject { described_class.new task_hash, endpoint }

let(:logger) { instance_double(Logger, warn: nil) }
before { MeiliSearch::Utils.logger = logger }

describe '.initialize' do
it 'requires a uid in the task hash' do
task_hash.delete 'taskUid'
Expand Down Expand Up @@ -217,12 +218,21 @@
'type' => 'invalid_request',
'link' => 'https://docs.meilisearch.com/errors#index_already_exists' }
end

let(:task_hash) { create_index_task_hash.merge('error' => error, 'status' => 'failed') }

it 'returns errors' do
expect(subject.error).to match(error)
end
end

describe '#to_h' do end
describe '#to_h' do
it 'returns the underlying task hash' do
expect(subject.to_h).to be(task_hash)
end

it 'is aliased as #to_hash' do
expect(subject.to_hash).to be(subject.to_h)
end
end
end

0 comments on commit afec958

Please sign in to comment.