-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7f3ebd7
commit 00b6f90
Showing
1 changed file
with
67 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,9 @@ | |
|
||
module Decidim | ||
describe RegistrationForm do | ||
subject do | ||
subject { form } | ||
|
||
let(:form) do | ||
described_class.from_params( | ||
attributes | ||
).with_context( | ||
|
@@ -14,10 +16,10 @@ module Decidim | |
|
||
let(:organization) { create(:organization) } | ||
let(:name) { "User" } | ||
let(:nickname) { "justme" } | ||
let(:email) { "[email protected]" } | ||
let(:password) { "S4CGQ9AM4ttJdPKS" } | ||
let(:tos_agreement) { "1" } | ||
let(:newsletter) { "1" } | ||
let(:country) { "Argentina" } | ||
let(:date_of_birth) { "01/01/2000" } | ||
let(:gender) { "other" } | ||
|
@@ -28,10 +30,10 @@ module Decidim | |
let(:attributes) do | ||
{ | ||
name:, | ||
nickname:, | ||
email:, | ||
password:, | ||
tos_agreement:, | ||
newsletter:, | ||
country:, | ||
postal_code:, | ||
date_of_birth:, | ||
|
@@ -63,12 +65,6 @@ module Decidim | |
it { is_expected.not_to be_valid } | ||
end | ||
|
||
context "when the nickname is not present" do | ||
let(:nickname) { nil } | ||
|
||
it { is_expected.not_to be_valid } | ||
end | ||
|
||
context "when the email is not present" do | ||
let(:email) { nil } | ||
|
||
|
@@ -95,44 +91,12 @@ module Decidim | |
end | ||
end | ||
|
||
context "when the nickname already exists" do | ||
context "and a user has the nickname" do | ||
let!(:user) { create(:user, organization:, nickname: nickname.upcase) } | ||
|
||
it { is_expected.not_to be_valid } | ||
|
||
context "and is pending to accept the invitation" do | ||
let!(:user) { create(:user, organization:, nickname:, invitation_token: "foo", invitation_accepted_at: nil) } | ||
|
||
it { is_expected.to be_valid } | ||
end | ||
end | ||
|
||
context "and a user_group has the nickname" do | ||
let!(:user_group) { create(:user_group, organization:, nickname:) } | ||
|
||
it { is_expected.not_to be_valid } | ||
end | ||
end | ||
|
||
context "when the nickname is too long" do | ||
let(:nickname) { "verylongnicknamethatcreatesanerror" } | ||
|
||
it { is_expected.not_to be_valid } | ||
end | ||
|
||
context "when the name is an email" do | ||
let(:name) { "[email protected]" } | ||
|
||
it { is_expected.not_to be_valid } | ||
end | ||
|
||
context "when the nickname has spaces" do | ||
let(:nickname) { "test example" } | ||
|
||
it { is_expected.not_to be_valid } | ||
end | ||
|
||
context "when the password is not present" do | ||
let(:password) { nil } | ||
|
||
|
@@ -150,5 +114,67 @@ module Decidim | |
|
||
it { is_expected.not_to be_valid } | ||
end | ||
|
||
describe "#newsletter_at" do | ||
subject { form.newsletter_at } | ||
|
||
let(:current_time) { Time.current } | ||
|
||
it { is_expected.to be_between(current_time - 1.minute, current_time + 1.minute) } | ||
|
||
context "when newsletter was not ordered" do | ||
let(:newsletter) { "0" } | ||
|
||
it { is_expected.to be_nil } | ||
end | ||
end | ||
|
||
describe "nickname" do | ||
let(:name) { "justme" } | ||
|
||
context "when the nickname already exists" do | ||
context "and a user has the nickname" do | ||
let!(:another_user) { create(:user, organization:, nickname: name.upcase) } | ||
|
||
it { is_expected.to be_valid } | ||
|
||
it "adds a suffix in the nickname" do | ||
expect(subject.nickname).to eq("justme_2") | ||
end | ||
|
||
context "and is pending to accept the invitation" do | ||
let!(:another_user) { create(:user, organization:, nickname: name, invitation_token: "foo", invitation_accepted_at: nil) } | ||
|
||
it { is_expected.to be_valid } | ||
end | ||
end | ||
|
||
context "and a user_group has the nickname" do | ||
let!(:user_group) { create(:user_group, organization:, nickname: name) } | ||
|
||
it { is_expected.to be_valid } | ||
end | ||
end | ||
|
||
context "when the nickname is too long" do | ||
let(:name) { "verylongnicknamethatcreatesanerror" } | ||
|
||
it { is_expected.to be_valid } | ||
|
||
it "truncates the nickname" do | ||
expect(subject.nickname).to eq("verylongnicknamethat") | ||
end | ||
end | ||
|
||
context "when the name has spaces" do | ||
let(:name) { "test example" } | ||
|
||
it { is_expected.to be_valid } | ||
|
||
it "replaces the space in the nickname" do | ||
expect(subject.nickname).to eq("test_example") | ||
end | ||
end | ||
end | ||
end | ||
end |