2015-10-11 05:41:23 -04:00
|
|
|
require 'rails_helper'
|
2013-07-13 21:24:16 -04:00
|
|
|
require_dependency 'site'
|
|
|
|
|
|
|
|
describe Site do
|
2017-04-12 10:52:52 -04:00
|
|
|
|
|
|
|
def expect_correct_themes(guardian)
|
|
|
|
json = Site.json_for(guardian)
|
|
|
|
parsed = JSON.parse(json)
|
|
|
|
|
|
|
|
expected = Theme.where('key = :default OR user_selectable',
|
|
|
|
default: SiteSetting.default_theme_key)
|
2017-07-27 21:20:09 -04:00
|
|
|
.order(:name)
|
|
|
|
.pluck(:key, :name)
|
|
|
|
.map { |k, n| { "theme_key" => k, "name" => n, "default" => k == SiteSetting.default_theme_key } }
|
2017-04-12 10:52:52 -04:00
|
|
|
|
|
|
|
expect(parsed["user_themes"]).to eq(expected)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "includes user themes and expires them as needed" do
|
|
|
|
default_theme = Theme.create!(user_id: -1, name: 'default')
|
|
|
|
SiteSetting.default_theme_key = default_theme.key
|
|
|
|
user_theme = Theme.create!(user_id: -1, name: 'user theme', user_selectable: true)
|
|
|
|
|
|
|
|
anon_guardian = Guardian.new
|
|
|
|
user_guardian = Guardian.new(Fabricate(:user))
|
|
|
|
|
|
|
|
expect_correct_themes(anon_guardian)
|
|
|
|
expect_correct_themes(user_guardian)
|
|
|
|
|
|
|
|
Theme.clear_default!
|
|
|
|
|
|
|
|
expect_correct_themes(anon_guardian)
|
|
|
|
expect_correct_themes(user_guardian)
|
|
|
|
|
|
|
|
user_theme.user_selectable = false
|
|
|
|
user_theme.save!
|
|
|
|
|
|
|
|
expect_correct_themes(anon_guardian)
|
|
|
|
expect_correct_themes(user_guardian)
|
|
|
|
|
|
|
|
end
|
|
|
|
|
2013-07-13 21:24:16 -04:00
|
|
|
it "omits categories users can not write to from the category list" do
|
|
|
|
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
|
|
|
|
2017-07-27 21:20:09 -04:00
|
|
|
category.set_permissions(everyone: :create_post)
|
2013-07-13 21:24:16 -04:00
|
|
|
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
|
2017-07-27 21:20:09 -04:00
|
|
|
.keep_if { |c| c.name == category.name }
|
2013-10-23 19:05:51 -04:00
|
|
|
.first
|
2015-01-05 11:04:23 -05:00
|
|
|
.permission)
|
2017-07-27 21:20:09 -04:00
|
|
|
.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
|
2017-07-27 21:20:09 -04:00
|
|
|
category.set_permissions(staff: :full)
|
2014-02-24 14:52:21 -05:00
|
|
|
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
|