2013-02-15 01:10:53 +08:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe EducationController do
|
|
|
|
|
|
|
|
it "requires you to be logged in" do
|
|
|
|
lambda { xhr :get, :show, id: 'topic' }.should raise_error(Discourse::NotLoggedIn)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when logged in' do
|
|
|
|
|
|
|
|
let!(:user) { log_in(:user) }
|
|
|
|
|
|
|
|
it "returns 404 from a missing id" do
|
|
|
|
xhr :get, :show, id: 'made-up'
|
|
|
|
response.response_code.should == 404
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'raises an error with a weird id' do
|
|
|
|
xhr :get, :show, id: '../some-path'
|
|
|
|
response.should_not be_success
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with a valid id' do
|
2013-02-26 00:42:20 +08:00
|
|
|
|
2013-02-15 01:10:53 +08:00
|
|
|
let(:markdown_content) { "Education *markdown* content" }
|
|
|
|
let(:html_content) {"HTML Content"}
|
|
|
|
|
|
|
|
before do
|
2013-04-06 04:47:20 +08:00
|
|
|
SiteContent.expects(:content_for).with(:education_new_topic, anything).returns(markdown_content)
|
2013-02-15 01:10:53 +08:00
|
|
|
PrettyText.expects(:cook).with(markdown_content).returns(html_content)
|
|
|
|
xhr :get, :show, id: 'new-topic'
|
|
|
|
end
|
|
|
|
|
|
|
|
it "succeeds" do
|
|
|
|
response.should be_success
|
|
|
|
end
|
|
|
|
|
|
|
|
it "converts markdown into HTML" do
|
|
|
|
response.body.should == html_content
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|