discourse/spec/models/site_spec.rb

35 lines
954 B
Ruby
Raw Normal View History

2016-04-01 05:33:25 +08:00
require 'rails_helper'
require_dependency 'site'
describe Site do
it "omits categories users can not write to from the category list" do
2016-04-01 05:33:25 +08:00
ActiveRecord::Base.observers.enable :anon_site_json_cache_observer
category = Fabricate(:category)
user = Fabricate(:user)
2015-01-06 00:04:23 +08:00
expect(Site.new(Guardian.new(user)).categories.count).to eq(2)
category.set_permissions(:everyone => :create_post)
category.save
guardian = Guardian.new(user)
2015-01-06 00:04:23 +08:00
expect(Site.new(guardian)
.categories
.keep_if{|c| c.name == category.name}
.first
2015-01-06 00:04:23 +08:00
.permission)
.not_to eq(CategoryGroup.permission_types[:full])
# 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-06 00:04:23 +08:00
expect(Site.new(guardian).categories).not_to include(sub_category)
end
end