OpenProject is the leading open source project management software.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
openproject/spec/lib/api/v3/configuration/configuration_representer_s...

236 lines
7.4 KiB

#-- copyright
# OpenProject is an open source project management software.
# Copyright (C) 2012-2020 the OpenProject GmbH
#
# 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-2017 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 docs/COPYRIGHT.rdoc for more details.
#++
require 'spec_helper'
describe ::API::V3::Configuration::ConfigurationRepresenter do
include ::API::V3::Utilities::PathHelper
let(:represented) { Setting }
let(:current_user) do
FactoryBot.build_stubbed(:user).tap do |user|
allow(user)
.to receive(:preference)
.and_return(FactoryBot.build_stubbed(:user_preference))
end
end
let(:embed_links) { false }
let(:representer) do
described_class.new(represented, current_user: current_user, embed_links: embed_links)
end
context 'generation' do
subject { representer.to_json }
describe '_links' do
it_behaves_like 'has an untitled link' do
let(:link) { 'self' }
let(:href) { api_v3_paths.configuration }
end
context 'userPreferences' do
context 'if logged in' do
it_behaves_like 'has an untitled link' do
let(:link) { 'userPreferences' }
let(:href) { api_v3_paths.my_preferences }
end
end
context 'if not logged in' do
let(:current_user) { FactoryBot.build_stubbed(:anonymous) }
it_behaves_like 'has an untitled link' do
let(:link) { 'userPreferences' }
let(:href) { api_v3_paths.my_preferences }
end
end
end
end
it 'indicates its type' do
is_expected.to be_json_eql('Configuration'.to_json).at_path('_type')
end
it 'indicates maximumAttachmentFileSize in Bytes' do
allow(Setting).to receive(:attachment_max_size).and_return('1024')
is_expected.to be_json_eql((1024 * 1024).to_json).at_path('maximumAttachmentFileSize')
end
it 'indicates perPageOptions as array of integers' do
allow(Setting).to receive(:per_page_options).and_return('1, 50 , 100 ')
is_expected.to be_json_eql([1, 50, 100].to_json).at_path('perPageOptions')
end
context 'timeFormat' do
context 'with time format', with_settings: { time_format: '%I:%M %p' } do
it 'indicates the timeFormat' do
is_expected
.to be_json_eql('hh:mm a'.to_json)
.at_path('timeFormat')
end
end
context 'with time format', with_settings: { time_format: '%H:%M' } do
it 'indicates the timeFormat' do
is_expected
.to be_json_eql('HH:mm'.to_json)
.at_path('timeFormat')
end
end
context 'with a time format', with_settings: { time_format: '' } do
it 'indicates the timeFormat' do
is_expected
.to be_json_eql(nil.to_json)
.at_path('timeFormat')
end
end
end
context 'dateFormat' do
context 'without a date format', with_settings: { date_format: '' } do
it 'indicates the dateFormat' do
is_expected
.to be_json_eql(nil.to_json)
.at_path('dateFormat')
end
end
context 'with date format (%Y-%m-%d)', with_settings: { date_format: '%Y-%m-%d' } do
it 'indicates the dateFormat' do
is_expected
.to be_json_eql('YYYY-MM-DD'.to_json)
.at_path('dateFormat')
end
end
context 'with date format (%d/%m/%Y)', with_settings: { date_format: '%Y-%m-%d' } do
it 'indicates the dateFormat' do
is_expected
.to be_json_eql('YYYY-MM-DD'.to_json)
.at_path('dateFormat')
end
end
context 'with date format (%d.%m.%Y)', with_settings: { date_format: '%d.%m.%Y' } do
it 'indicates the dateFormat' do
is_expected
.to be_json_eql('DD.MM.YYYY'.to_json)
.at_path('dateFormat')
end
end
context 'with date format (%d-%m-%Y)', with_settings: { date_format: '%d-%m-%Y' } do
it 'indicates the dateFormat' do
is_expected
.to be_json_eql('DD-MM-YYYY'.to_json)
.at_path('dateFormat')
end
end
context 'with date format (%m/%d/%Y)', with_settings: { date_format: '%m/%d/%Y' } do
it 'indicates the dateFormat' do
is_expected
.to be_json_eql('MM/DD/YYYY'.to_json)
.at_path('dateFormat')
end
end
context 'with date format (%d %b %Y)', with_settings: { date_format: '%d %b %Y' } do
it 'indicates the dateFormat' do
is_expected
.to be_json_eql('DD MMM YYYY'.to_json)
.at_path('dateFormat')
end
end
context 'with date format (%d %B %Y)', with_settings: { date_format: '%d %B %Y' } do
it 'indicates the dateFormat' do
is_expected
.to be_json_eql('DD MMMM YYYY'.to_json)
.at_path('dateFormat')
end
end
context 'with date format (%b %d, %Y)', with_settings: { date_format: '%b %d, %Y' } do
it 'indicates the dateFormat' do
is_expected
.to be_json_eql('MMM DD, YYYY'.to_json)
.at_path('dateFormat')
end
end
context 'with date format (%B %d, %Y)', with_settings: { date_format: '%B %d, %Y' } do
it 'indicates the dateFormat' do
is_expected
.to be_json_eql('MMMM DD, YYYY'.to_json)
.at_path('dateFormat')
end
end
end
context 'startOfWeek' do
context 'without a setting', with_settings: { start_of_week: '' } do
it 'is null' do
is_expected
.to be_json_eql(nil.to_json)
.at_path('startOfWeek')
end
end
context 'with `Monday` being set', with_settings: { start_of_week: '1' } do
it 'indicates the dateFormat' do
is_expected
.to be_json_eql(1.to_json)
.at_path('startOfWeek')
end
end
end
describe '_embedded' do
context 'userPreferences' do
context 'if embedding' do
let(:embed_links) { true }
it 'embedds the user preferences' do
is_expected
.to be_json_eql('UserPreferences'.to_json)
.at_path('_embedded/userPreferences/_type')
end
end
context 'if not embedding' do
it 'embedds the user preferences' do
is_expected
.not_to have_json_path('_embedded/userPreferences/_type')
end
end
end
end
end
end