Skip to content

Commit

Permalink
Fix failing specs
Browse files Browse the repository at this point in the history
  • Loading branch information
alecslupu committed May 16, 2024
1 parent 691dfe3 commit fc3abcc
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ class BaseOrganizationForm < Form

validates :host, :users_registration_mode, presence: true
validate :validate_organization_uniqueness
validate :validate_secret_key_base_for_encryption
validates :users_registration_mode, inclusion: { in: Decidim::Organization.users_registration_modes }

def map_model(model)
Expand Down Expand Up @@ -106,6 +107,14 @@ def encrypted_omniauth_settings

private

# We need a valid secret key base for encrypting the SMTP password with it
# It is also necessary for other things in Rails (like Cookies encryption)
def validate_secret_key_base_for_encryption
return if Rails.application.secrets.secret_key_base&.length == 128

errors.add(:password, I18n.t("activemodel.errors.models.organization.attributes.password.secret_key"))
end

def validate_organization_uniqueness
raise "#{self.class.name} is expected to implement #validate_organization_uniqueness"
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,11 @@ class RegisterOrganizationForm < BaseOrganizationForm
attribute :users_registration_mode, String
attribute :force_users_to_authenticate_before_access_organization, Boolean

validates :organization_admin_email, :organization_admin_name, :name, :host, :reference_prefix, :users_registration_mode, presence: true
validates :organization_admin_email, :organization_admin_name, :name, :reference_prefix, presence: true
validates :name, presence: true
validates :available_locales, presence: true
validates :default_locale, presence: true
validates :default_locale, inclusion: { in: :available_locales }
validates :users_registration_mode, inclusion: { in: Decidim::Organization.users_registration_modes }

private

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ class UpdateOrganizationForm < BaseOrganizationForm
translatable_attribute :name, String

validate :validate_organization_name_presence
validate :validate_secret_key_base_for_encryption

private

Expand Down Expand Up @@ -39,14 +38,6 @@ def validate_organization_uniqueness

errors.add(:host, :taken) if Decidim::Organization.where(host:).where.not(id:).exists?
end

# We need a valid secret key base for encrypting the SMTP password with it
# It is also necessary for other things in Rails (like Cookies encryption)
def validate_secret_key_base_for_encryption
return if Rails.application.secrets.secret_key_base&.length == 128

errors.add(:password, I18n.t("activemodel.errors.models.organization.attributes.password.secret_key"))
end
end
end
end
2 changes: 1 addition & 1 deletion decidim-system/spec/system/organizations_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@
end

it "shows the error message" do
fill_in "Name", with: "Citizens Rule!"
fill_in_i18n :update_organization_name, "#update_organization-name-tabs", en: "Citizens Rule!"
fill_in "Host", with: "www.example.org"
click_on "Save"

Expand Down

0 comments on commit fc3abcc

Please sign in to comment.