mirror of
https://github.com/Growstuff/growstuff.git
synced 2026-10-31 11:21:06 -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.
74 lines
2.6 KiB
Ruby
74 lines
2.6 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
require 'rails_helper'
|
|
|
|
# The dialog on the home page that asks where someone gardens: it looks places
|
|
# up with GET /places/suggest and saves the one they pick with PATCH /my/location.
|
|
describe 'Setting where a member gardens' do
|
|
include Devise::Test::IntegrationHelpers
|
|
|
|
let(:member) { create(:member) }
|
|
let(:json_headers) { { 'CONTENT_TYPE' => 'application/json', 'ACCEPT' => 'application/json' } }
|
|
let(:place) { { name: 'Wellington, New Zealand', latitude: -41.2887, longitude: 174.7772 } }
|
|
|
|
def save(location)
|
|
patch member_location_path(format: :json), params: { location: }.to_json, headers: json_headers
|
|
end
|
|
|
|
context 'when signed in' do
|
|
before { sign_in member }
|
|
|
|
it 'saves the place and its coordinates' do
|
|
save(place)
|
|
expect(member.reload).to have_attributes(location: 'Wellington, New Zealand', latitude: -41.2887, longitude: 174.7772)
|
|
end
|
|
|
|
it 'gives gardens without a place the same one' do
|
|
member.gardens.first.update_columns(location: nil)
|
|
save(place)
|
|
expect(member.gardens.first.reload.location).to eq 'Wellington, New Zealand'
|
|
end
|
|
|
|
it 'leaves a garden that already has a place alone' do
|
|
member.gardens.first.update_columns(location: 'Dunedin')
|
|
save(place)
|
|
expect(member.gardens.first.reload.location).to eq 'Dunedin'
|
|
end
|
|
|
|
it 'refuses coordinates that are not on Earth' do
|
|
save(place.merge(latitude: 120))
|
|
expect(response).to have_http_status(:unprocessable_entity)
|
|
end
|
|
|
|
it 'refuses a place without a name' do
|
|
save(place.merge(name: ''))
|
|
expect(response).to have_http_status(:unprocessable_entity)
|
|
end
|
|
|
|
it 'suggests places for a search' do
|
|
Geocoder::Lookup::Test.add_stub('Wellington',
|
|
[{ 'coordinates' => [-41.2887, 174.7772], 'name' => 'Wellington',
|
|
'address' => { 'country' => 'New Zealand' } }])
|
|
get suggest_places_path(format: :json, q: 'Wellington')
|
|
expect(response.parsed_body.pluck('name')).to eq ['Wellington, New Zealand']
|
|
end
|
|
|
|
it 'suggests nothing for a position that is not a number' do
|
|
get suggest_places_path(format: :json, lat: 'north', lng: 'east')
|
|
expect(response).to have_http_status(:unprocessable_entity)
|
|
end
|
|
end
|
|
|
|
context 'when signed out' do
|
|
it 'does not save a place' do
|
|
save(place)
|
|
expect(response).to have_http_status(:unauthorized)
|
|
end
|
|
|
|
it 'does not look places up' do
|
|
get suggest_places_path(format: :json, q: 'Wellington')
|
|
expect(response).to have_http_status(:unauthorized)
|
|
end
|
|
end
|
|
end
|