can not save category after adding a new custom group
This commit is contained in:
parent
0acc96c94e
commit
4b269de724
|
@ -28,6 +28,7 @@ class Group < ActiveRecord::Base
|
|||
def self.refresh_automatic_group!(name)
|
||||
|
||||
id = AUTO_GROUPS[name]
|
||||
return unless id
|
||||
|
||||
unless group = self.lookup_group(name)
|
||||
group = Group.new(name: name.to_s, automatic: true)
|
||||
|
@ -93,8 +94,15 @@ class Group < ActiveRecord::Base
|
|||
end
|
||||
|
||||
def self.lookup_group(name)
|
||||
raise ArgumentError, "unknown group" unless id = AUTO_GROUPS[name]
|
||||
Group.where(id: id).first
|
||||
id = AUTO_GROUPS[name]
|
||||
if id
|
||||
Group.where(id: id).first
|
||||
else
|
||||
unless group = Group.where(name: name).first
|
||||
raise ArgumentError, "unknown group" unless group
|
||||
end
|
||||
group
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
|
|
@ -134,4 +134,10 @@ describe Group do
|
|||
GroupUser.count.should == 0
|
||||
end
|
||||
|
||||
it "allows you to lookup a new group by name" do
|
||||
group = Fabricate(:group)
|
||||
group.id.should == Group[group.name].id
|
||||
group.id.should == Group[group.name.to_sym].id
|
||||
end
|
||||
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue