2
アクティブなレコードスコープのテストを作成するにはどうすればよいですか?私はあなたが適切な器具を設定していると仮定するとアクティブなレコードスコープのテストを書き込む方法は?
RSpec.feature Post, :type => :model do
let(:post) { build(:post) }
describe 'test scopes' do
end
end
アクティブなレコードスコープのテストを作成するにはどうすればよいですか?私はあなたが適切な器具を設定していると仮定するとアクティブなレコードスコープのテストを書き込む方法は?
RSpec.feature Post, :type => :model do
let(:post) { build(:post) }
describe 'test scopes' do
end
end
をテストするためには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