在rspec-rails中测试.where查询

时间:2016-08-19 09:30:52

标签: ruby ruby-on-rails-4 rspec rspec-rails ruby-on-rails-5

我对Rails中的Rspec测试很新,我正在尝试测试以下内容:

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

  def hosting_company
    company = host_details.first.company
  end
end

我有以下规范,但我不确定我应该期待的host_details方法的结果。我正在使用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

0 个答案:

没有答案