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
f5e80ed6
Commit
f5e80ed6
authored
Feb 26, 2019
by
Rémy Coutable
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Reduce differences in spec/support/helpers/javascript_fixtures_helpers.rb
Signed-off-by:
Rémy Coutable
<
remy@rymai.me
>
parent
68b7f99f
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
27 additions
and
22 deletions
+27
-22
spec/javascripts/fixtures/static_fixtures.rb
spec/javascripts/fixtures/static_fixtures.rb
+11
-11
spec/support/helpers/javascript_fixtures_helpers.rb
spec/support/helpers/javascript_fixtures_helpers.rb
+16
-11
No files found.
spec/javascripts/fixtures/static_fixtures.rb
View file @
f5e80ed6
...
@@ -7,23 +7,23 @@ describe ApplicationController, '(Static JavaScript fixtures)', type: :controlle
...
@@ -7,23 +7,23 @@ describe ApplicationController, '(Static JavaScript fixtures)', type: :controlle
clean_frontend_fixtures
(
'static/'
)
clean_frontend_fixtures
(
'static/'
)
end
end
fixtures_path
=
File
.
expand_path
(
JavaScriptFixturesHelpers
::
FIXTURE_PATH
,
Rails
.
root
)
JavaScriptFixturesHelpers
::
FIXTURE_PATHS
.
each
do
|
fixture_path
|
haml_fixtures
=
Dir
.
glob
(
File
.
expand_path
(
'**/*.haml'
,
fixtures_path
)).
map
do
|
file_path
|
fixtures_path
=
File
.
expand_path
(
fixture_path
,
Rails
.
root
)
file_path
.
sub
(
/\A
#{
fixtures_path
}#{
File
::
SEPARATOR
}
/
,
''
)
end
Dir
.
glob
(
File
.
expand_path
(
'**/*.haml'
,
fixtures_path
)).
map
do
|
file_path
|
template_file_name
=
file_path
.
sub
(
/\A
#{
fixtures_path
}#{
File
::
SEPARATOR
}
/
,
''
)
haml_fixtures
.
each
do
|
template_file_nam
e
|
it
"static/
#{
template_file_name
.
sub
(
/\.haml\z/
,
'.raw'
)
}
"
do
|
exampl
e
|
it
"static/
#{
template_file_name
.
sub
(
/\.haml\z/
,
'.raw'
)
}
"
do
|
example
|
fixture_file_name
=
example
.
description
fixture_file_name
=
example
.
description
rendered
=
render_template
(
fixture_path
,
template_file_name
)
rendered
=
render_template
(
templat
e_file_name
)
store_frontend_fixture
(
rendered
,
fixtur
e_file_name
)
store_frontend_fixture
(
rendered
,
fixture_file_name
)
end
end
end
end
end
private
private
def
render_template
(
template_file_name
)
def
render_template
(
fixture_path
,
template_file_name
)
fixture_path
=
JavaScriptFixturesHelpers
::
FIXTURE_PATH
controller
=
ApplicationController
.
new
controller
=
ApplicationController
.
new
controller
.
prepend_view_path
(
fixture_path
)
controller
.
prepend_view_path
(
fixture_path
)
controller
.
render_to_string
(
template:
template_file_name
,
layout:
false
)
controller
.
render_to_string
(
template:
template_file_name
,
layout:
false
)
...
...
spec/support/helpers/javascript_fixtures_helpers.rb
View file @
f5e80ed6
...
@@ -2,11 +2,12 @@ require 'action_dispatch/testing/test_request'
...
@@ -2,11 +2,12 @@ require 'action_dispatch/testing/test_request'
require
'fileutils'
require
'fileutils'
module
JavaScriptFixturesHelpers
module
JavaScriptFixturesHelpers
extend
ActiveSupport
::
Concern
include
Gitlab
::
Popen
include
Gitlab
::
Popen
FIXTURE_PATH
=
'spec/javascripts/fixtures'
.
freeze
FIXTURE_PATH
S
=
%w[spec/javascripts/fixtures ee/spec/javascripts/fixtures]
.
freeze
def
self
.
included
(
base
)
included
do
|
base
|
base
.
around
do
|
example
|
base
.
around
do
|
example
|
# pick an arbitrary date from the past, so tests are not time dependent
# pick an arbitrary date from the past, so tests are not time dependent
Timecop
.
freeze
(
Time
.
utc
(
2015
,
7
,
3
,
10
))
{
example
.
run
}
Timecop
.
freeze
(
Time
.
utc
(
2015
,
7
,
3
,
10
))
{
example
.
run
}
...
@@ -15,26 +16,30 @@ module JavaScriptFixturesHelpers
...
@@ -15,26 +16,30 @@ module JavaScriptFixturesHelpers
# Public: Removes all fixture files from given directory
# Public: Removes all fixture files from given directory
#
#
# directory_name - directory of the fixtures (relative to FIXTURE_PATH)
# directory_name - directory of the fixtures (relative to FIXTURE_PATH
S
)
#
#
def
clean_frontend_fixtures
(
directory_name
)
def
clean_frontend_fixtures
(
directory_name
)
directory_name
=
File
.
expand_path
(
directory_name
,
FIXTURE_PATH
)
FIXTURE_PATHS
.
each
do
|
fixture_path
|
Dir
[
File
.
expand_path
(
'*.html.raw'
,
directory_name
)].
each
do
|
file_name
|
directory_name
=
File
.
expand_path
(
directory_name
,
fixture_path
)
FileUtils
.
rm
(
file_name
)
Dir
[
File
.
expand_path
(
'*.html.raw'
,
directory_name
)].
each
do
|
file_name
|
FileUtils
.
rm
(
file_name
)
end
end
end
end
end
# Public: Store a response object as fixture file
# Public: Store a response object as fixture file
#
#
# response - string or response object to store
# response - string or response object to store
# fixture_file_name - file name to store the fixture in (relative to FIXTURE_PATH)
# fixture_file_name - file name to store the fixture in (relative to FIXTURE_PATH
S
)
#
#
def
store_frontend_fixture
(
response
,
fixture_file_name
)
def
store_frontend_fixture
(
response
,
fixture_file_name
)
fixture_file_name
=
File
.
expand_path
(
fixture_file_name
,
FIXTURE_PATH
)
FIXTURE_PATHS
.
each
do
|
fixture_path
|
fixture
=
response
.
respond_to?
(
:body
)
?
parse_response
(
response
)
:
response
fixture_file_name
=
File
.
expand_path
(
fixture_file_name
,
fixture_path
)
fixture
=
response
.
respond_to?
(
:body
)
?
parse_response
(
response
)
:
response
FileUtils
.
mkdir_p
(
File
.
dirname
(
fixture_file_name
))
FileUtils
.
mkdir_p
(
File
.
dirname
(
fixture_file_name
))
File
.
write
(
fixture_file_name
,
fixture
)
File
.
write
(
fixture_file_name
,
fixture
)
end
end
end
def
remove_repository
(
project
)
def
remove_repository
(
project
)
...
...
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