FIX: Forcing permissions of seeded categories shouldn't fail

Less restrictive permissions of subcategories could make the seeding of categories fail.
This commit is contained in:
Gerhard Schlager 2019-03-26 10:39:07 +01:00
parent dae0bb4c67
commit dc90133d29
2 changed files with 20 additions and 1 deletions

View File

@ -120,7 +120,7 @@ module SeedData
if force_permissions
category.set_permissions(permissions)
category.save! if category.changed?
category.save!(validate: false) if category.changed?
end
end
end

View File

@ -71,6 +71,25 @@ describe SeedData::Categories do
expect(category.category_groups.count).to eq(1)
expect(category.category_groups.first).to have_attributes(permissions(:staff, :full))
end
it "overwrites permissions even when subcategory has less restrictive permissions" do
category = Category.last
category.set_permissions(everyone: :full)
category.save!
group = Fabricate(:group)
subcategory = Fabricate(:category, name: "child", parent_category_id: category.id)
subcategory.set_permissions(group => :full)
subcategory.save!
expect { create_category }
.to change { CategoryGroup.count }.by(1)
category.reload
expect(category.category_groups.count).to eq(1)
expect(category.category_groups.first).to have_attributes(permissions(:staff, :full))
end
end
it "does not override permissions of existing category when not forced" do