Test that WP description is formattable

pull/2316/head
Hagen Schink 10 years ago
parent 762fbbf058
commit 2ed1bdf06f
  1. 39
      spec/lib/api/v3/support/api_v3_formattable.rb
  2. 7
      spec/lib/api/v3/work_packages/form/work_package_payload_representer_spec.rb
  3. 7
      spec/lib/api/v3/work_packages/work_package_representer_spec.rb
  4. 25
      spec/requests/api/v3/work_package_resource_spec.rb
  5. 37
      spec/requests/api/v3/work_packages/form/work_package_form_resource_spec.rb

@ -0,0 +1,39 @@
#-- copyright
# OpenProject is a project management system.
# Copyright (C) 2012-2014 the OpenProject Foundation (OPF)
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License version 3.
#
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
# Copyright (C) 2006-2013 Jean-Philippe Lang
# Copyright (C) 2010-2013 the ChiliProject Team
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# See doc/COPYRIGHT.rdoc for more details.
#++
require 'spec_helper'
shared_examples_for 'API V3 formattable' do |property|
it { is_expected.to have_json_path(property) }
it { is_expected.to be_json_eql(format.to_json).at_path(property + '/format') }
it { is_expected.to be_json_eql(raw.to_json).at_path(property + '/raw') }
it { is_expected.to be_json_eql(html.to_json).at_path(property + '/html') }
end

@ -45,7 +45,12 @@ describe ::API::V3::WorkPackages::Form::WorkPackagePayloadRepresenter do
describe 'work_package' do
it { is_expected.to have_json_path('subject') }
it { is_expected.to have_json_path('rawDescription') }
it_behaves_like 'API V3 formattable', 'description' do
let(:format) { 'textile' }
let(:raw) { work_package.description }
let(:html) { '<p>' + work_package.description + '</p>' }
end
describe 'lock version' do
it { is_expected.to have_json_path('lockVersion') }

@ -70,8 +70,11 @@ describe ::API::V3::WorkPackages::WorkPackageRepresenter do
describe 'work_package' do
it { is_expected.to have_json_path('id') }
it { is_expected.to have_json_path('description') }
it { is_expected.to have_json_path('rawDescription') }
it_behaves_like 'API V3 formattable', 'description' do
let(:format) { 'textile' }
let(:raw) { work_package.description }
let(:html) { '<p>' + work_package.description + '</p>' }
end
it { is_expected.to have_json_path('dueDate') }

@ -151,7 +151,8 @@ h4. things we like
end
it 'should resolve links' do
expect(parsed_response['description']).to have_selector("a[href='/work_packages/#{other_wp.id}']")
expect(parsed_response['description']['html'])
.to have_selector("a[href='/work_packages/#{other_wp.id}']")
end
it 'should resolve simple macros' do
@ -337,32 +338,40 @@ h4. things we like
end
context 'description' do
shared_examples_for 'description updated' do |description|
it 'should respond with updated work package description' do
expect(subject.body).to be_json_eql(description.to_json).at_path('description')
shared_examples_for 'description updated' do
it_behaves_like 'API V3 formattable', 'description' do
let(:format) { 'textile' }
subject { response.body }
end
it_behaves_like 'lock version updated'
end
context 'w/o value (empty)' do
let(:params) { valid_params.merge(rawDescription: nil) }
let(:raw) { nil }
let(:html) { '' }
let(:params) { valid_params.merge(description: { raw: nil }) }
include_context 'patch request'
it { expect(response.status).to eq(200) }
it_behaves_like 'description updated', ''
it_behaves_like 'description updated'
end
context 'with value' do
let(:params) { valid_params.merge(rawDescription: '*Some text* _describing_ *something*...') }
let(:raw) { '*Some text* _describing_ *something*...' }
let(:html) {
'<p><strong>Some text</strong> <em>describing</em> <strong>something</strong>...</p>'
}
let(:params) { valid_params.merge(description: { raw: raw }) }
include_context 'patch request'
it { expect(response.status).to eq(200) }
it_behaves_like 'description updated', '<p><strong>Some text</strong> <em>describing</em> <strong>something</strong>...</p>'
it_behaves_like 'description updated'
end
end

@ -81,15 +81,23 @@ describe 'API v3 Work package form resource', type: :request do
context 'existing work package' do
shared_examples_for 'valid payload' do
subject { response.body }
it { expect(response.status).to eq(200) }
it { expect(subject.body).to have_json_path('_embedded/payload') }
it { is_expected.to have_json_path('_embedded/payload') }
it { expect(subject.body).to have_json_path('_embedded/payload/lockVersion') }
it { is_expected.to have_json_path('_embedded/payload/lockVersion') }
it { expect(subject.body).to have_json_path('_embedded/payload/subject') }
it { is_expected.to have_json_path('_embedded/payload/subject') }
it { expect(subject.body).to have_json_path('_embedded/payload/rawDescription') }
it_behaves_like 'API V3 formattable', '_embedded/payload/description' do
let(:format) { 'textile' }
let(:raw) { defined?(raw_value) ? raw_value : work_package.description.to_s }
let(:html) {
defined?(html_value) ? html_value : ('<p>' + work_package.description.to_s + '</p>')
}
end
end
shared_examples_for 'valid payload with initial values' do
@ -102,11 +110,6 @@ describe 'API v3 Work package form resource', type: :request do
expect(subject.body).to be_json_eql(work_package.subject.to_json)
.at_path('_embedded/payload/subject')
}
it {
expect(subject.body).to be_json_eql(work_package.description.to_json)
.at_path('_embedded/payload/rawDescription')
}
end
shared_examples_for 'having no errors' do
@ -231,19 +234,21 @@ describe 'API v3 Work package form resource', type: :request do
end
describe 'description' do
let(:path) { '_embedded/payload/rawDescription' }
let(:path) { '_embedded/payload/description/raw' }
let(:description) { '*Some text* _describing_ *something*...' }
let(:params) { valid_params.merge(rawDescription: description) }
let(:params) { valid_params.merge(description: { raw: description }) }
include_context 'post request'
it_behaves_like 'valid payload'
it_behaves_like 'valid payload' do
let(:raw_value) { description }
let(:html_value) {
'<p><strong>Some text</strong> <em>describing</em> ' \
'<strong>something</strong>...</p>'
}
end
it_behaves_like 'having no errors'
it 'should respond with updated work package description' do
expect(subject.body).to be_json_eql(description.to_json).at_path(path)
end
end
describe 'status' do

Loading…
Cancel
Save