can not save category after adding a new custom group
This commit is contained in:
Sam 2013-07-23 10:10:36 +10:00
parent 0acc96c94e
commit 4b269de724
2 changed files with 16 additions and 2 deletions

View File

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

View File

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