mirror of
https://github.com/Growstuff/growstuff.git
synced 2026-10-31 19:29:26 -04:00
- Updated MemberLocationsController to use a hash for location updates, ensuring coordinates are not geocoded again. - Changed response status codes in member_locations_spec to use symbols for better readability. - Modified PlacesController to use parentheses for defining MEMBER_FIELDS. - Enhanced SuggestionsController to disable Rails/SkipsModelValidations for update_columns. - Updated SeasonsHelper to use compact_blank for cleaner output. - Refactored MemberDashboard service for improved readability and performance. - Adjusted migration files to use parentheses for index definitions. - Updated schema.rb to maintain consistency in index definitions. - Added SampleData class to generate sample data for development. - Cleaned up sample_data.rake task to utilize the new SampleData class. - Updated tests in member_dashboard_spec and place_suggester_spec for consistency and readability.
43 lines
1.5 KiB
Ruby
43 lines
1.5 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
require 'rails_helper'
|
|
|
|
describe PlaceSuggester do
|
|
before do
|
|
allow(Rails).to receive(:cache).and_return(ActiveSupport::Cache::MemoryStore.new)
|
|
Geocoder::Lookup::Test.add_stub(
|
|
'Wellington', [
|
|
{ 'coordinates' => [-41.2887, 174.7772], 'name' => 'Wellington',
|
|
'address' => { 'state' => 'Wellington', 'country' => 'New Zealand' } },
|
|
{ 'coordinates' => [26.6, -80.2], 'name' => 'Wellington', 'address' => { 'state' => 'Florida', 'country' => 'United States' } },
|
|
{ 'coordinates' => [26.6, -80.2], 'name' => 'Wellington', 'address' => { 'state' => 'Florida', 'country' => 'United States' } }
|
|
]
|
|
)
|
|
Geocoder::Lookup::Test.add_stub(
|
|
[-41.2866, 174.7756], [
|
|
{ 'coordinates' => [-41.2866, 174.7756], 'name' => 'Wellington', 'address' => { 'country' => 'New Zealand' } }
|
|
]
|
|
)
|
|
end
|
|
|
|
describe '.search' do
|
|
it 'names each place with its region and country' do
|
|
expect(described_class.search('Wellington').pluck(:name)).to eq ['Wellington, New Zealand', 'Wellington, Florida, United States']
|
|
end
|
|
|
|
it 'gives coordinates to save' do
|
|
expect(described_class.search('Wellington').first).to include(latitude: -41.2887, longitude: 174.7772)
|
|
end
|
|
|
|
it 'does not search for a single letter' do
|
|
expect(described_class.search('W')).to eq []
|
|
end
|
|
end
|
|
|
|
describe '.reverse' do
|
|
it 'names where a position is' do
|
|
expect(described_class.reverse(-41.2866, 174.7756).pluck(:name)).to eq ['Wellington, New Zealand']
|
|
end
|
|
end
|
|
end
|