mirror of
https://github.com/discourse/discourse.git
synced 2024-11-27 19:53:44 +08:00
88 lines
1.9 KiB
Ruby
88 lines
1.9 KiB
Ruby
require 'spec_helper'
|
|
|
|
describe ListController do
|
|
|
|
# we need some data
|
|
before do
|
|
@user = Fabricate(:coding_horror)
|
|
@post = Fabricate(:post, :user => @user)
|
|
end
|
|
|
|
context 'index' do
|
|
before do
|
|
xhr :get, :index
|
|
end
|
|
|
|
it { should respond_with(:success) }
|
|
end
|
|
|
|
context 'category' do
|
|
|
|
context 'in a category' do
|
|
let(:category) { Fabricate(:category) }
|
|
|
|
it "raises an invalid access error when the user can't see the category" do
|
|
Guardian.any_instance.expects(:can_see?).with(category).returns(false)
|
|
xhr :get, :category, category: category.slug
|
|
response.should be_forbidden
|
|
end
|
|
|
|
context 'with access to see the category' do
|
|
before do
|
|
xhr :get, :category, category: category.slug
|
|
end
|
|
|
|
it { should respond_with(:success) }
|
|
end
|
|
end
|
|
|
|
context 'uncategorized' do
|
|
|
|
it "doesn't check access to see the category, since we didn't provide one" do
|
|
Guardian.any_instance.expects(:can_see?).never
|
|
xhr :get, :category, category: SiteSetting.uncategorized_name
|
|
end
|
|
|
|
it "responds with success" do
|
|
xhr :get, :category, category: SiteSetting.uncategorized_name
|
|
response.should be_success
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
context 'favorited' do
|
|
it 'raises an error when not logged in' do
|
|
lambda { xhr :get, :favorited }.should raise_error(Discourse::NotLoggedIn)
|
|
end
|
|
|
|
context 'when logged in' do
|
|
before do
|
|
log_in_user(@user)
|
|
xhr :get, :favorited
|
|
end
|
|
|
|
it { should respond_with(:success) }
|
|
end
|
|
end
|
|
|
|
context 'read' do
|
|
it 'raises an error when not logged in' do
|
|
lambda { xhr :get, :read }.should raise_error(Discourse::NotLoggedIn)
|
|
end
|
|
|
|
context 'when logged in' do
|
|
before do
|
|
log_in_user(@user)
|
|
xhr :get, :read
|
|
end
|
|
|
|
it { should respond_with(:success) }
|
|
end
|
|
end
|
|
|
|
end
|