0
Я тестирую один метод в модели. Он называется last_photo
, я заполнил данные базы данных и попытаюсь вернуть первый элемент, но у меня есть ошибка udefined method 'latest'
. Что бы это могло быть? Как я могу это исправить?rspec: undefined method 'latest'
Метод latest
это: сфера: последние, -> {порядка ('created_at DESC')}
def last_photo
@last_photo ||= user_updates.latest.where("photo_front IS NOT NULL and photo_front != ''").first.try(:photo_front)
end
context "instance method" do
let(:user) { create :user }
context "last photo" do
before { create_list(:user_update, 3, user: user) }
let(:user_updates){ UserUpdate.all }
describe "#last_photo" do
subject { user.last_photo }
it { should eq user_updates.latest.first.photo_front }
end
describe "#last_photo_side" do
subject { user.last_photo_side }
it { should eq user_updates.latest.first.photo_side}
end
end
end
Спасибо.
Да, точно, спасибо. У меня есть еще один вопрос. Как здесь использовать метод 'where'? – user3458697
Я не понимаю, что вы имеете в виду – apneadiving
'где (" photo_front IS NOT NULL и photo_front! = '' ")' Как в тестах для использования? – user3458697