2013-02-05 14:16:51 -05:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe ListController do
|
|
|
|
|
2013-02-25 11:42:20 -05:00
|
|
|
# we need some data
|
|
|
|
before do
|
2013-02-05 14:16:51 -05:00
|
|
|
@user = Fabricate(:coding_horror)
|
2013-03-23 11:02:59 -04:00
|
|
|
@post = Fabricate(:post, user: @user)
|
2013-06-21 16:31:40 -04:00
|
|
|
|
|
|
|
# forces tests down some code paths
|
|
|
|
SiteSetting.stubs(:top_menu).returns('latest,-video|new|unread|favorited|categories|category/beer')
|
2013-02-05 14:16:51 -05:00
|
|
|
end
|
|
|
|
|
2013-03-28 09:01:13 -04:00
|
|
|
describe 'indexes' do
|
|
|
|
|
|
|
|
[:latest, :hot].each do |filter|
|
2013-06-21 16:31:40 -04:00
|
|
|
context "#{filter}" do
|
2013-03-28 09:01:13 -04:00
|
|
|
before { xhr :get, filter }
|
|
|
|
it { should respond_with(:success) }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
[:favorited, :read, :posted, :unread, :new].each do |filter|
|
2013-06-21 16:31:40 -04:00
|
|
|
context "#{filter}" do
|
2013-03-28 09:01:13 -04:00
|
|
|
it { expect { xhr :get, filter }.to raise_error(Discourse::NotLoggedIn) }
|
|
|
|
end
|
2013-02-05 14:16:51 -05:00
|
|
|
end
|
|
|
|
|
2013-05-28 03:52:52 -04:00
|
|
|
it 'allows users to filter on a set of topic ids' do
|
|
|
|
p = Fabricate(:post)
|
|
|
|
xhr :get, :latest, format: :json, topic_ids: "#{p.topic_id}"
|
|
|
|
response.should be_success
|
|
|
|
parsed = JSON.parse(response.body)
|
|
|
|
parsed["topic_list"]["topics"].length.should == 1
|
|
|
|
end
|
|
|
|
|
2013-02-05 14:16:51 -05:00
|
|
|
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
|
2013-02-14 16:51:48 -05:00
|
|
|
|
|
|
|
context 'with a link that includes an id' do
|
|
|
|
before do
|
2013-02-14 17:13:03 -05:00
|
|
|
xhr :get, :category, category: "#{category.id}-#{category.slug}"
|
2013-02-14 16:51:48 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it { should respond_with(:success) }
|
|
|
|
end
|
|
|
|
|
2013-02-27 22:36:12 -05:00
|
|
|
describe 'feed' do
|
|
|
|
it 'renders RSS' do
|
|
|
|
get :category_feed, category: category.slug, format: :rss
|
|
|
|
response.should be_success
|
|
|
|
response.content_type.should == 'application/rss+xml'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-02-05 14:16:51 -05:00
|
|
|
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
|
|
|
|
|
2013-06-27 16:16:06 -04:00
|
|
|
context 'SiteSetting.uncategorized_name is non standard' do
|
|
|
|
before do
|
|
|
|
SiteSetting.stubs(:uncategorized_name).returns('testing')
|
|
|
|
end
|
|
|
|
|
|
|
|
it "responds with success given SiteSetting.uncategorized_name" do
|
|
|
|
xhr :get, :category, category: SiteSetting.uncategorized_name
|
|
|
|
response.should be_success
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'responds with success given "uncategorized"' do
|
|
|
|
xhr :get, :category, category: 'uncategorized'
|
|
|
|
response.should be_success
|
|
|
|
end
|
2013-06-19 22:11:14 -04:00
|
|
|
end
|
2013-02-05 14:16:51 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
2013-03-27 16:17:49 -04:00
|
|
|
context 'hot' do
|
|
|
|
before do
|
|
|
|
xhr :get, :hot
|
|
|
|
end
|
|
|
|
|
|
|
|
it { should respond_with(:success) }
|
|
|
|
end
|
|
|
|
|
2013-02-05 14:16:51 -05:00
|
|
|
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
|
|
|
|
|
2013-03-27 16:17:49 -04:00
|
|
|
|
2013-02-05 14:16:51 -05:00
|
|
|
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
|