In the scenario where we want to test scopes and use `match_array`, we usually declare variables we never use, which raises a warning in the Ruby interpreter (since the main cause for an unused variable is a typo). So I've decided to just split the tests into cases where every record is returned and cases were no records are returned, just like we do in other places. There are several other options we've considered: 1. Don't declare unused variables, but declare the ones we use 2. Prefix unused variables with un underscore 3. Declare just one variable being an array containing all elements, and access the elements using Array#[] 4. Don't declare any variables, and compare results against attributes such as titles None of these options was met with enthusiasm.
24 lines
539 B
Ruby
24 lines
539 B
Ruby
require "rails_helper"
|
|
|
|
describe Document do
|
|
|
|
it_behaves_like "document validations", "budget_investment_document"
|
|
it_behaves_like "document validations", "proposal_document"
|
|
|
|
context "scopes" do
|
|
describe "#admin" do
|
|
it "returns admin documents" do
|
|
admin_document = create(:document, :admin)
|
|
|
|
expect(Document.admin).to eq [admin_document]
|
|
end
|
|
|
|
it "does not return user documents" do
|
|
create(:document, admin: false)
|
|
|
|
expect(Document.admin).to be_empty
|
|
end
|
|
end
|
|
end
|
|
end
|