2013-07-13 21:24:16 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
require_dependency 'site'
|
|
|
|
|
|
|
|
describe Site do
|
|
|
|
it "omits categories users can not write to from the category list" do
|
2015-09-28 02:49:39 -04:00
|
|
|
|
|
|
|
ActiveRecord::Base.observers.enable :anon_site_json_cache_observer
|
|
|
|
|
2013-07-13 21:24:16 -04:00
|
|
|
category = Fabricate(:category)
|
|
|
|
user = Fabricate(:user)
|
|
|
|
|
2015-01-05 11:04:23 -05:00
|
|
|
expect(Site.new(Guardian.new(user)).categories.count).to eq(2)
|
2013-07-13 21:24:16 -04:00
|
|
|
|
|
|
|
category.set_permissions(:everyone => :create_post)
|
|
|
|
category.save
|
|
|
|
|
2014-02-24 14:52:21 -05:00
|
|
|
guardian = Guardian.new(user)
|
|
|
|
|
2015-01-05 11:04:23 -05:00
|
|
|
expect(Site.new(guardian)
|
2013-10-23 19:05:51 -04:00
|
|
|
.categories
|
|
|
|
.keep_if{|c| c.name == category.name}
|
|
|
|
.first
|
2015-01-05 11:04:23 -05:00
|
|
|
.permission)
|
|
|
|
.not_to eq(CategoryGroup.permission_types[:full])
|
2014-02-24 14:52:21 -05:00
|
|
|
|
|
|
|
# If a parent category is not visible, the child categories should not be returned
|
|
|
|
category.set_permissions(:staff => :full)
|
|
|
|
category.save
|
|
|
|
|
|
|
|
sub_category = Fabricate(:category, parent_category_id: category.id)
|
2015-01-05 11:04:23 -05:00
|
|
|
expect(Site.new(guardian).categories).not_to include(sub_category)
|
2013-07-13 21:24:16 -04:00
|
|
|
end
|
2014-02-24 14:52:21 -05:00
|
|
|
|
2013-07-13 21:24:16 -04:00
|
|
|
end
|