Use ID literal for comparisons in grapql tests

While this is potentially very dangerous because assigning the ID does
not increase the ID sequence, it's safe to do so in tests where we
assign the ID to every record created on a certain table.

Even so, I'd consider it a bad practice which must be used with care. In
this case I'm using it because we look for IDs in the response, and
most tests in this file use literals to compare the response.

This changes makes it possible to remove unused variables while keeping
the test readable.
This commit is contained in:
Javi Martín
2019-09-28 02:52:48 +02:00
parent 3af958bc92
commit d856bb4ab7

View File

@@ -546,59 +546,59 @@ describe "Consul Schema" do
end end
it "does not include votes from hidden debates" do it "does not include votes from hidden debates" do
visible_debate = create(:debate, voters: [create(:user)]) create(:debate, id: 1, voters: [create(:user)])
hidden_debate = create(:debate, :hidden, voters: [create(:user)]) create(:debate, :hidden, id: 2, voters: [create(:user)])
response = execute("{ votes { edges { node { votable_id } } } }") response = execute("{ votes { edges { node { votable_id } } } }")
received_debates = extract_fields(response, "votes", "votable_id") received_debates = extract_fields(response, "votes", "votable_id")
expect(received_debates).to match_array [visible_debate.id] expect(received_debates).to match_array [1]
end end
it "does not include votes of hidden proposals" do it "does not include votes of hidden proposals" do
visible_proposal = create(:proposal, voters: [create(:user)]) create(:proposal, id: 1, voters: [create(:user)])
hidden_proposal = create(:proposal, :hidden, voters: [create(:user)]) create(:proposal, :hidden, id: 2, voters: [create(:user)])
response = execute("{ votes { edges { node { votable_id } } } }") response = execute("{ votes { edges { node { votable_id } } } }")
received_proposals = extract_fields(response, "votes", "votable_id") received_proposals = extract_fields(response, "votes", "votable_id")
expect(received_proposals).to match_array [visible_proposal.id] expect(received_proposals).to match_array [1]
end end
it "does not include votes of hidden comments" do it "does not include votes of hidden comments" do
visible_comment = create(:comment, voters: [create(:user)]) create(:comment, id: 1, voters: [create(:user)])
hidden_comment = create(:comment, :hidden, voters: [create(:user)]) create(:comment, :hidden, id: 2, voters: [create(:user)])
response = execute("{ votes { edges { node { votable_id } } } }") response = execute("{ votes { edges { node { votable_id } } } }")
received_comments = extract_fields(response, "votes", "votable_id") received_comments = extract_fields(response, "votes", "votable_id")
expect(received_comments).to match_array [visible_comment.id] expect(received_comments).to match_array [1]
end end
it "does not include votes of comments from a hidden proposal" do it "does not include votes of comments from a hidden proposal" do
visible_proposal = create(:proposal) visible_proposal = create(:proposal)
hidden_proposal = create(:proposal, :hidden) hidden_proposal = create(:proposal, :hidden)
visible_proposal_comment = create(:comment, commentable: visible_proposal, voters: [create(:user)]) create(:comment, id: 1, commentable: visible_proposal, voters: [create(:user)])
hidden_proposal_comment = create(:comment, commentable: hidden_proposal, voters: [create(:user)]) create(:comment, id: 2, commentable: hidden_proposal, voters: [create(:user)])
response = execute("{ votes { edges { node { votable_id } } } }") response = execute("{ votes { edges { node { votable_id } } } }")
received_votables = extract_fields(response, "votes", "votable_id") received_votables = extract_fields(response, "votes", "votable_id")
expect(received_votables).to match_array [visible_proposal_comment.id] expect(received_votables).to match_array [1]
end end
it "does not include votes of comments from a hidden debate" do it "does not include votes of comments from a hidden debate" do
visible_debate = create(:debate) visible_debate = create(:debate)
hidden_debate = create(:debate, :hidden) hidden_debate = create(:debate, :hidden)
visible_debate_comment = create(:comment, commentable: visible_debate, voters: [create(:user)]) create(:comment, id: 1, commentable: visible_debate, voters: [create(:user)])
hidden_debate_comment = create(:comment, commentable: hidden_debate, voters: [create(:user)]) create(:comment, id: 2, commentable: hidden_debate, voters: [create(:user)])
response = execute("{ votes { edges { node { votable_id } } } }") response = execute("{ votes { edges { node { votable_id } } } }")
received_votables = extract_fields(response, "votes", "votable_id") received_votables = extract_fields(response, "votes", "votable_id")
expect(received_votables).to match_array [visible_debate_comment.id] expect(received_votables).to match_array [1]
end end
it "does not include votes of debates that are not public" do it "does not include votes of debates that are not public" do