Skip to content

Commit

Permalink
Adapt test to 0.28 release
Browse files Browse the repository at this point in the history
  • Loading branch information
entantoencuanto committed Apr 17, 2024
1 parent 7f3ebd7 commit 00b6f90
Showing 1 changed file with 67 additions and 41 deletions.
108 changes: 67 additions & 41 deletions spec/forms/decidim/registration_form_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

module Decidim
describe RegistrationForm do
subject do
subject { form }

let(:form) do
described_class.from_params(
attributes
).with_context(
Expand All @@ -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" }
Expand All @@ -28,10 +30,10 @@ module Decidim
let(:attributes) do
{
name:,
nickname:,
email:,
password:,
tos_agreement:,
newsletter:,
country:,
postal_code:,
date_of_birth:,
Expand Down Expand Up @@ -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 }

Expand All @@ -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 }

Expand All @@ -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

0 comments on commit 00b6f90

Please sign in to comment.