Testing .where queries in rspec-rails

南楼画角 提交于 2019-12-11 04:36:01

问题


I'm quite new to Rspec testing in Rails and I'm trying to test the following:

class Event < ApplicationRecord
  def host_details
    query ||= User.where(id: self.user_id)
  end

  def hosting_company
    company = host_details.first.company
  end
end

I have the following spec but I'm not sure exactly what I'm supposed to be expecting back for the results of the host_details method. I'm using FactoryGirl.

describe "gets information about the host of an event" do
  before(:each) do
    @event = build(:event)
  end

  context "host_details" do
    it "querys the event data and finds the associated user" do

    end
  end

  context "hosting_company" do
    it "gets the company that is hosting the event" do
      expect(@event.hosting_company).to eq "Attnd"
    end
  end

end

来源:https://stackoverflow.com/questions/39035668/testing-where-queries-in-rspec-rails

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!