Skip to content

Commit

Permalink
Merge pull request opf#15674 from opf/simpler-tests-queries
Browse files Browse the repository at this point in the history
Use shared_let and explicitly set user for `public_query`
  • Loading branch information
klaustopher authored May 27, 2024
2 parents 9b09a13 + 9f37add commit f336189
Showing 1 changed file with 11 additions and 16 deletions.
27 changes: 11 additions & 16 deletions spec/models/queries/projects/project_query_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -389,35 +389,30 @@
end

describe "scopes" do
shared_let(:public_query) { create(:project_query, user:, public: true) }
shared_let(:public_query_other_user) { create(:project_query, public: true) }
shared_let(:private_query) { create(:project_query, user:) }
shared_let(:private_query_other_user) { create(:project_query) }

describe ".public_lists" do
it "returns only public lists" do
public_query = create(:project_query, public: true)
public_query_other_user = create(:project_query, public: true)
create(:project_query, public: false)

expect(described_class.public_lists).to contain_exactly(public_query, public_query_other_user)
end
end

describe ".private_lists" do
it "returns only private lists owned by the user" do
create(:project_query, public: true)
private_query = create(:project_query, public: false)
create(:project_query, public: false)

expect(described_class.private_lists(user: private_query.user)).to contain_exactly(private_query)
expect(described_class.private_lists(user:)).to contain_exactly(private_query)
end
end

describe ".visible" do
it "returns public and private queries owned by the user" do
public_query = create(:project_query, public: true)
public_query_other_user = create(:project_query, public: true)
private_query = create(:project_query, public: false)
create(:project_query, public: false)

expect(described_class.visible(private_query.user)).to contain_exactly(public_query, public_query_other_user,
private_query)
expect(described_class.visible(user)).to contain_exactly(
public_query,
public_query_other_user,
private_query
)
end
end
end
Expand Down

0 comments on commit f336189

Please sign in to comment.