-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Create tokens for groups #15
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #15 +/- ##
==========================================
+ Coverage 97.18% 98.29% +1.11%
==========================================
Files 21 24 +3
Lines 355 411 +56
==========================================
+ Hits 345 404 +59
+ Misses 10 7 -3 ☔ View full report in Codecov by Sentry. |
app/controllers/decidim/anonymous_codes/admin/codes_controller.rb
Outdated
Show resolved
Hide resolved
app/controllers/decidim/anonymous_codes/admin/codes_controller.rb
Outdated
Show resolved
Hide resolved
…dule-anonymous_codes into feat/generate_tokens
…dule-anonymous_codes into feat/generate_tokens
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Excelent Job Elvia,
left you some simple comments only.
I'd like to add a test for the CreateTokensJob, to check if an generated token is already in the database, let's make sure that it works correctly.
Here's a spec that we could be using (to be placed under spec/jobs/create_tokens_job_spec.rb
):
# frozen_string_literal: true
require "spec_helper"
module Decidim
module AnonymousCodes
describe CreateTokensJob do
subject { described_class.perform_now(code_group, num_tokens) }
let(:organization) { create(:organization) }
let(:code_group) { create :anonymous_codes_group }
let(:num_tokens) { 2 }
let(:token1) { "TOKEN1" }
let(:token2) { "TOKEN2" }
let(:token3) { "TOKEN3" }
before do
allow(Decidim::AnonymousCodes).to receive(:token_generator).and_return(token1, token2, token3)
end
it "generates 2 tokens" do
expect { subject }.to change { Token.count }.by(2)
expect(Token.all.pluck(:token)).to match_array([token1, token2])
end
context "when token is repeated" do
let!(:existing_token) { create(:anonymous_codes_token, token: token2, group: code_group) }
it "skips the repeated" do
expect { subject }.to change { Token.count }.by(2)
expect(Token.all.pluck(:token)).to match_array([token1, token2, token3])
end
end
end
end
end
fixes #3
tests: