2017-02-26 5 views

答えて

4

をテストするためにはRSpecを使用してい

class Post < ActiveRecord::Base 
    scope :recent, -> { order("posts.created_at DESC") } 
    scope :published, -> { where("status = 1") } 
end 

例えば、私は通常、私はスコープからの結果を期待してクエリを実行し、1 Iドン't。例:

describe '#published' do 
    it "returns a published post" do 
    expect(Post.published.count).to be(1) 
    # or inspect to see if it's published, but that's a bit redundant 
    end 

    it "does not return unpublished posts" do 
    expect(Post.published).to_not include(Post.where("status = 0")) 
    end 
end 
関連する問題