Browse Source

Add a model to hold a search result from Bragi

develop
Bèr Kessels 3 months ago
parent
commit
fb7ae4f775
2 changed files with 58 additions and 0 deletions
  1. 22
    0
      app/models/search_result.rb
  2. 36
    0
      test/models/search_result_test.rb

+ 22
- 0
app/models/search_result.rb View File

@@ -0,0 +1,22 @@
# frozen_string_literal: true

require_relative 'base.rb'
require_relative 'place_index.rb'

module Hours
module Models
##
# Region is a collection of Places belonging to one region.
# It is, therefore, a decorator for a list of places.
class SearchResult < PlaceIndex
attr_reader :query, :error

## TODO: PlaceIndex and other models need initialize with keyword args
def initialize(dataset: [], paginator: nil, query: '', error: nil)
@query = query
@error = error
super(dataset, paginator)
end
end
end
end

+ 36
- 0
test/models/search_result_test.rb View File

@@ -0,0 +1,36 @@
# frozen_string_literal: true

require 'test_helper'

describe Hours::Models::Region do
let(:row) { { id: 'PK' } }
let(:dataset) { [row] }

subject do
Hours::Models::SearchResult.new(dataset: dataset)
end

it 'is a collection of places' do
assert_kind_of Hours::Models::Place, subject.first
end

describe '#query' do
subject do
Hours::Models::SearchResult.new(dataset: dataset, query: 'Smullers')
end

it 'returns the passed-in query' do
assert_equal 'Smullers', subject.query
end
end

describe '#error' do
subject do
Hours::Models::SearchResult.new(dataset: dataset, error: 'An Error')
end

it 'returns the passed-in error' do
assert_equal 'An Error', subject.error
end
end
end

Loading…
Cancel
Save