I'm trying to run a spec that creates a list of models (configured in a factory) that contains a method called address, which is used by the Geocoder gem, to encapsulate the address fields.
When running, the error appears:
NoMethodError: undefined method `address=' for #<BusinessEstablishment:0x000055fea90c0c08>
Did you mean? address
I couldn't find a solution.
My model:
class BusinessEstablishment < ApplicationRecord
reverse_geocoded_by :latitude, :longitude
after_validation :reverse_geocode
def get_establishment_by_current_location(location)
BusinessEstablishment.near([location[:latitude], location[:longitude]], 5, units: :km)
end
def address
[street, number, neighborhood, zip_code, city_ibge_code, city, latitude, longitude].compact.join(', ')
end
end
My factory:
FactoryBot.define do
factory :business_establishment, class: 'BusinessEstablishment' do
cnpj { Faker::IDNumber.brazilian_citizen_number }
company_name { Faker::Company.name }
trade_name { Faker::Company.suffix }
phone { Faker::PhoneNumber.phone_number }
street { Faker::Address.street_name }
number { Faker::Address.building_number }
neighborhood { Faker::Address.community }
zip_code { Faker::Address.zip_code }
city_ibge_code { Faker::Address.city_suffix }
city { Faker::Address.city }
state { Faker::Address.state }
latitude { Faker::Address.latitude }
longitude { Faker::Address.longitude }
end
end
My spec:
describe 'GET /v1/search_prices/products/prices' do
subject(:get_prices) do
get '/v1/search_prices/products/prices',
params: params
end
let!(:business_establishment) { create_list(:business_establishment, 20) }
context 'when searches prices' do
it 'returns all prices' do
get_prices
end
end
end