mirror of
https://github.com/discourse/discourse.git
synced 2025-05-25 00:32:52 +08:00
Initial release of Discourse
This commit is contained in:
82
spec/controllers/excerpt_controller_spec.rb
Normal file
82
spec/controllers/excerpt_controller_spec.rb
Normal file
@ -0,0 +1,82 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe ExcerptController do
|
||||
|
||||
describe 'show' do
|
||||
it 'raises an error without the url param' do
|
||||
lambda { xhr :get, :show }.should raise_error(Discourse::InvalidParameters)
|
||||
end
|
||||
|
||||
it 'returns 404 with a non-existant url' do
|
||||
xhr :get, :show, url: 'http://madeup.com/url'
|
||||
response.status.should == 404
|
||||
end
|
||||
|
||||
it 'returns 404 from an invalid url' do
|
||||
xhr :get, :show, url: 'asdfasdf'
|
||||
response.status.should == 404
|
||||
end
|
||||
|
||||
describe 'user excerpt' do
|
||||
|
||||
before do
|
||||
@user = Fabricate(:user)
|
||||
@url = "http://test.host/users/#{@user.username}"
|
||||
xhr :get, :show, url: @url
|
||||
end
|
||||
|
||||
it 'returns a valid status' do
|
||||
response.should be_success
|
||||
end
|
||||
|
||||
it 'returns an excerpt type for the forum topic' do
|
||||
parsed = JSON.parse(response.body)
|
||||
parsed['type'].should == 'User'
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe 'forum topic excerpt' do
|
||||
|
||||
before do
|
||||
@post = Fabricate(:post)
|
||||
@url = "http://test.host#{@post.topic.relative_url}"
|
||||
xhr :get, :show, url: @url
|
||||
end
|
||||
|
||||
it 'returns a valid status' do
|
||||
response.should be_success
|
||||
end
|
||||
|
||||
it 'returns an excerpt type for the forum topic' do
|
||||
parsed = JSON.parse(response.body)
|
||||
parsed['type'].should == 'Post'
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe 'post excerpt' do
|
||||
|
||||
before do
|
||||
@post = Fabricate(:post)
|
||||
@url = "http://test.host#{@post.topic.relative_url}/1"
|
||||
xhr :get, :show, url: @url
|
||||
end
|
||||
|
||||
it 'returns a valid status' do
|
||||
response.should be_success
|
||||
end
|
||||
|
||||
it 'returns an excerpt type for the forum topic' do
|
||||
parsed = JSON.parse(response.body)
|
||||
parsed['type'].should == 'Post'
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
||||
|
||||
|
||||
end
|
Reference in New Issue
Block a user