mirror of
https://github.com/discourse/discourse.git
synced 2025-05-24 03:36:18 +08:00
Merge pull request #1249 from sir-pinecone/strip-spaces-from-group
Strip spaces from group names upon creation
This commit is contained in:
@ -31,7 +31,7 @@ class Admin::GroupsController < Admin::AdminController
|
|||||||
|
|
||||||
def create
|
def create
|
||||||
group = Group.new
|
group = Group.new
|
||||||
group.name = params[:group][:name]
|
group.name = params[:group][:name].strip
|
||||||
group.usernames = params[:group][:usernames] if params[:group][:usernames]
|
group.usernames = params[:group][:usernames] if params[:group][:usernames]
|
||||||
if group.save
|
if group.save
|
||||||
render_serialized(group, BasicGroupSerializer)
|
render_serialized(group, BasicGroupSerializer)
|
||||||
|
@ -48,9 +48,12 @@ describe Admin::GroupsController do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context '.create' do
|
||||||
|
let(:usernames) { @admin.username }
|
||||||
|
|
||||||
it "is able to create a group" do
|
it "is able to create a group" do
|
||||||
xhr :post, :create, group: {
|
xhr :post, :create, group: {
|
||||||
usernames: @admin.username,
|
usernames: usernames,
|
||||||
name: "bob"
|
name: "bob"
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -59,10 +62,21 @@ describe Admin::GroupsController do
|
|||||||
groups = Group.where(name: "bob").to_a
|
groups = Group.where(name: "bob").to_a
|
||||||
|
|
||||||
groups.count.should == 1
|
groups.count.should == 1
|
||||||
groups[0].usernames.should == @admin.username
|
groups[0].usernames.should == usernames
|
||||||
groups[0].name.should == "bob"
|
groups[0].name.should == "bob"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "strips spaces from group name" do
|
||||||
|
lambda {
|
||||||
|
xhr :post, :create, group: {
|
||||||
|
usernames: usernames,
|
||||||
|
name: " bob "
|
||||||
|
}
|
||||||
|
}.should_not raise_error(ActiveRecord::RecordInvalid)
|
||||||
|
Group.where(name: "bob").count.should == 1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
it "is able to update group members" do
|
it "is able to update group members" do
|
||||||
user1 = Fabricate(:user)
|
user1 = Fabricate(:user)
|
||||||
user2 = Fabricate(:user)
|
user2 = Fabricate(:user)
|
||||||
|
Reference in New Issue
Block a user