Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
2c459fb3
Commit
2c459fb3
authored
Dec 03, 2020
by
Vitali Tatarintev
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow to customize keys for timezone_data helper
Allow to pick different sets of attributes for timezone_data helper
parent
795b4598
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
81 additions
and
26 deletions
+81
-26
app/helpers/time_zone_helper.rb
app/helpers/time_zone_helper.rb
+21
-2
ee/app/helpers/incident_management/oncall_schedule_helper.rb
ee/app/helpers/incident_management/oncall_schedule_helper.rb
+1
-1
ee/spec/helpers/incident_management/oncall_schedule_helper_spec.rb
...elpers/incident_management/oncall_schedule_helper_spec.rb
+1
-1
spec/helpers/time_zone_helper_spec.rb
spec/helpers/time_zone_helper_spec.rb
+58
-22
No files found.
app/helpers/time_zone_helper.rb
View file @
2c459fb3
# frozen_string_literal: true
module
TimeZoneHelper
def
timezone_data
TIME_ZONE_FORMAT_ATTRS
=
{
short:
%i[identifier name offset]
,
full:
%i[identifier name abbr offset formatted_offset]
}.
freeze
private_constant
:TIME_ZONE_FORMAT_ATTRS
# format:
# * :full - all available fields
# * :short (default)
#
# Example:
# timezone_data # :short by default
# timezone_data(format: :full)
#
def
timezone_data
(
format: :short
)
attrs
=
TIME_ZONE_FORMAT_ATTRS
.
fetch
(
format
)
do
valid_formats
=
TIME_ZONE_FORMAT_ATTRS
.
keys
.
map
{
|
k
|
":
#{
k
}
"
}.
join
(
", "
)
raise
ArgumentError
.
new
(
"Invalid format :
#{
format
}
. Valid formats are
#{
valid_formats
}
."
)
end
ActiveSupport
::
TimeZone
.
all
.
map
do
|
timezone
|
{
identifier:
timezone
.
tzinfo
.
identifier
,
...
...
@@ -9,7 +28,7 @@ module TimeZoneHelper
abbr:
timezone
.
tzinfo
.
strftime
(
'%Z'
),
offset:
timezone
.
now
.
utc_offset
,
formatted_offset:
timezone
.
now
.
formatted_offset
}
}
.
slice
(
*
attrs
)
end
end
end
ee/app/helpers/incident_management/oncall_schedule_helper.rb
View file @
2c459fb3
...
...
@@ -6,7 +6,7 @@ module IncidentManagement
{
'project-path'
=>
project
.
full_path
,
'empty-oncall-schedules-svg-path'
=>
image_path
(
'illustrations/empty-state/empty-on-call.svg'
),
'timezones'
=>
timezone_data
.
to_json
'timezones'
=>
timezone_data
(
format: :full
)
.
to_json
}
end
end
...
...
ee/spec/helpers/incident_management/oncall_schedule_helper_spec.rb
View file @
2c459fb3
...
...
@@ -12,7 +12,7 @@ RSpec.describe IncidentManagement::OncallScheduleHelper do
is_expected
.
to
eq
(
'project-path'
=>
project
.
full_path
,
'empty-oncall-schedules-svg-path'
=>
helper
.
image_path
(
'illustrations/empty-state/empty-on-call.svg'
),
'timezones'
=>
helper
.
timezone_data
.
to_json
'timezones'
=>
helper
.
timezone_data
(
format: :full
)
.
to_json
)
end
end
...
...
spec/helpers/time_zone_helper_spec.rb
View file @
2c459fb3
...
...
@@ -4,8 +4,35 @@ require 'spec_helper'
RSpec
.
describe
TimeZoneHelper
,
:aggregate_failures
do
describe
'#timezone_data'
do
context
'with short format'
do
subject
(
:timezone_data
)
{
helper
.
timezone_data
}
it
'matches schema'
do
expect
(
timezone_data
).
not_to
be_empty
timezone_data
.
each_with_index
do
|
timezone_hash
,
i
|
expect
(
timezone_hash
.
keys
).
to
contain_exactly
(
:identifier
,
:name
,
:offset
),
"Failed at index
#{
i
}
"
end
end
it
'formats for display'
do
tz
=
ActiveSupport
::
TimeZone
.
all
[
0
]
expect
(
timezone_data
[
0
]).
to
eq
(
identifier:
tz
.
tzinfo
.
identifier
,
name:
tz
.
name
,
offset:
tz
.
now
.
utc_offset
)
end
end
context
'with full format'
do
subject
(
:timezone_data
)
{
helper
.
timezone_data
(
format: :full
)
}
it
'matches schema'
do
expect
(
timezone_data
).
not_to
be_empty
...
...
@@ -32,4 +59,13 @@ RSpec.describe TimeZoneHelper, :aggregate_failures do
)
end
end
context
'with unknown format'
do
subject
(
:timezone_data
)
{
helper
.
timezone_data
(
format: :unknown
)
}
it
'raises an exception'
do
expect
{
timezone_data
}.
to
raise_error
ArgumentError
,
'Invalid format :unknown. Valid formats are :short, :full.'
end
end
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment