Skip to content

Commit

Permalink
FIX: Allow longer TLDs
Browse files Browse the repository at this point in the history
  • Loading branch information
eviltrout committed Apr 8, 2016
1 parent ab11cea commit adb3810
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
2 changes: 1 addition & 1 deletion app/models/group.rb
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ def automatic_membership_email_domains_format_validator
domains.each do |domain|
domain.sub!(/^https?:\/\//, '')
domain.sub!(/\/.*$/, '')
self.errors.add :base, (I18n.t('groups.errors.invalid_domain', domain: domain)) unless domain =~ /\A[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(:[0-9]{1,5})?(\/.*)?\Z/i
self.errors.add :base, (I18n.t('groups.errors.invalid_domain', domain: domain)) unless domain =~ /\A[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,24}(:[0-9]{1,5})?(\/.*)?\Z/i
end
self.automatic_membership_email_domains = domains.join("|")
end
Expand Down
13 changes: 9 additions & 4 deletions spec/models/group_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@
expect(group.valid?).to eq true
end

it "is valid for newer TLDs" do
group.automatic_membership_email_domains = "discourse.institute"
expect(group.valid?).to eq true
end

it "is invalid for bad incoming email" do
group.incoming_email = "foo.bar.org"
expect(group.valid?).to eq(false)
Expand Down Expand Up @@ -234,20 +239,20 @@ def real_staff
groups = Group.includes(:users).to_a
expect(groups.count).to eq Group::AUTO_GROUPS.count

g = groups.find{|g| g.id == Group::AUTO_GROUPS[:admins]}
g = groups.find{|grp| grp.id == Group::AUTO_GROUPS[:admins]}
expect(g.users.count).to eq 2
expect(g.user_count).to eq 2

g = groups.find{|g| g.id == Group::AUTO_GROUPS[:staff]}
g = groups.find{|grp| grp.id == Group::AUTO_GROUPS[:staff]}
expect(g.users.count).to eq 2
expect(g.user_count).to eq 2

g = groups.find{|g| g.id == Group::AUTO_GROUPS[:trust_level_1]}
g = groups.find{|grp| grp.id == Group::AUTO_GROUPS[:trust_level_1]}
# admin, system and user
expect(g.users.count).to eq 3
expect(g.user_count).to eq 3

g = groups.find{|g| g.id == Group::AUTO_GROUPS[:trust_level_2]}
g = groups.find{|grp| grp.id == Group::AUTO_GROUPS[:trust_level_2]}
# system and user
expect(g.users.count).to eq 2
expect(g.user_count).to eq 2
Expand Down

0 comments on commit adb3810

Please sign in to comment.