require 'spec_helper' require 'rack/test' describe 'API v3 Render resource' do include Rack::Test::Methods let(:project) { FactoryGirl.create(:project, is_public: false) } let(:work_package) { FactoryGirl.create(:work_package, project: project) } let(:user) { FactoryGirl.create(:user, member_in_project: project) } let(:content_type) { 'text/plain, charset=UTF-8' } before(:each) do allow(User).to receive(:current).and_return(user) post post_path, params, 'CONTENT_TYPE' => content_type end shared_examples_for 'valid response' do it { expect(subject.status).to eq(200) } it { expect(subject.content_type).to eq('text/html') } it { expect(subject.body).to eq(text) } end describe 'textile' do describe '#post' do let(:path) { '/api/v3/render/textile' } subject(:response) { last_response } describe 'response' do describe 'valid' do context 'w/o context' do let(:post_path) { path } let(:params) do 'Hello World! This *is* textile with a ' + '"link":http://community.openproject.org and ümläutß.' end let(:text) do '
Hello World! This is textile with a ' + 'link ' + 'and ümläutß.
' end it_behaves_like 'valid response' end context 'with context' do let(:post_path) { "#{path}?context=/api/v3/work_packages/#{work_package.id}" } let(:params) { "Hello World! Have a look at ##{work_package.id}" } let(:id) { work_package.id } let(:href) { "/work_packages/#{id}" } let(:title) { "#{work_package.subject} (#{work_package.status})" } let(:text) { "Hello World! Have a look at ##{id}
" } it_behaves_like 'valid response' end end describe 'invalid' do context 'content type' do let(:content_type) { 'application/json' } let(:post_path) { path } let(:params) { "Hello World! Have a look at ##{work_package.id}" } it_behaves_like 'invalid request body', 'Expected content type \'text/plain\' but got \'application/json\'.' end context 'with context' do let(:params) { '' } describe 'work package does not exist' do let(:post_path) { "#{path}?context=/api/v3/work_packages/-1" } it_behaves_like 'invalid render context', 'Context does not exist!' end describe 'work package not visible' do let(:invisible_work_package) { FactoryGirl.create(:work_package) } let(:post_path) { "#{path}?context=/api/v3/work_packages/#{invisible_work_package.id}" } it_behaves_like 'invalid render context', 'Context does not exist!' end describe 'context does not exist' do let(:post_path) { "#{path}?context=/api/v3/" } it_behaves_like 'invalid render context', 'No context found.' end describe 'unsupported context found' do let(:post_path) { "#{path}?context=/api/v3/activities/2" } it_behaves_like 'invalid render context', 'Unsupported context found.' end end end end end end describe 'plain' do describe '#post' do let(:post_path) { '/api/v3/render/plain' } subject(:response) { last_response } describe 'response' do describe 'valid' do let(:params) { 'Hello World! Have a look at #1' } let(:text) { "#{params}
" } it_behaves_like 'valid response' end end end end end