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
e5a29b45
Commit
e5a29b45
authored
Jan 09, 2017
by
Rémy Coutable
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improve presenter factory
Signed-off-by:
Rémy Coutable
<
remy@rymai.me
>
parent
bf789ff5
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
64 additions
and
87 deletions
+64
-87
lib/gitlab/view/presenter/factory.rb
lib/gitlab/view/presenter/factory.rb
+22
-0
lib/gitlab/view/presenter_factory.rb
lib/gitlab/view/presenter_factory.rb
+0
-39
spec/lib/gitlab/view/presenter/factory_spec.rb
spec/lib/gitlab/view/presenter/factory_spec.rb
+42
-0
spec/lib/gitlab/view/presenter_factory_spec.rb
spec/lib/gitlab/view/presenter_factory_spec.rb
+0
-48
No files found.
lib/gitlab/view/presenter/factory.rb
0 → 100644
View file @
e5a29b45
module
Gitlab
module
View
module
Presenter
class
Factory
def
initialize
(
subject
,
**
attributes
)
@subject
=
subject
@attributes
=
attributes
end
def
fabricate!
presenter_class
.
new
(
@subject
,
@attributes
)
end
private
def
presenter_class
@subject
.
class
.
const_get
(
'Presenter'
)
end
end
end
end
end
lib/gitlab/view/presenter_factory.rb
deleted
100644 → 0
View file @
bf789ff5
module
Gitlab
module
View
class
PresenterFactory
def
initialize
(
subject
,
user:
nil
)
@subject
=
subject
@user
=
user
end
def
fabricate!
presenter
=
if
presenter_class
.
ancestors
.
include?
(
SimpleDelegator
)
delegator_presenter
else
simple_presenter
end
presenter
.
with_subject
(
subject
)
.
with_user
(
user
)
end
private
attr_reader
:subject
,
:user
def
presenter_class
"
#{
subject
.
class
.
name
.
demodulize
}
Presenter"
.
constantize
end
def
delegator_presenter
presenter_class
.
new
(
subject
)
end
def
simple_presenter
presenter_class
.
new
end
end
end
end
spec/lib/gitlab/view/presenter/factory_spec.rb
0 → 100644
View file @
e5a29b45
require
'spec_helper'
describe
Gitlab
::
View
::
Presenter
::
Factory
do
let
(
:variable
)
{
create
(
:ci_variable
)
}
describe
'#initialize'
do
context
'without optional parameters'
do
subject
do
described_class
.
new
(
variable
)
end
it
'takes a subject and optional params'
do
expect
{
subject
}.
not_to
raise_error
end
end
context
'with optional parameters'
do
subject
do
described_class
.
new
(
variable
,
user:
'user'
)
end
it
'takes a subject and optional params'
do
expect
{
subject
}.
not_to
raise_error
end
end
end
describe
'#fabricate!'
do
subject
do
described_class
.
new
(
variable
,
user:
'user'
,
foo:
'bar'
).
fabricate!
end
it
'exposes given params'
do
expect
(
subject
.
user
).
to
eq
(
'user'
)
expect
(
subject
.
foo
).
to
eq
(
'bar'
)
end
it
'detects the presenter based on the given subject'
do
expect
(
subject
).
to
be_a
(
Ci
::
Variable
::
Presenter
)
end
end
end
spec/lib/gitlab/view/presenter_factory_spec.rb
deleted
100644 → 0
View file @
bf789ff5
require
'spec_helper'
describe
Gitlab
::
View
::
PresenterFactory
do
let
(
:appearance
)
{
build
(
:appearance
)
}
let
(
:broadcast_message
)
{
build
(
:broadcast_message
)
}
before
do
class
AppearancePresenter
include
Gitlab
::
View
::
Presenter
end
class
BroadcastMessagePresenter
<
SimpleDelegator
include
Gitlab
::
View
::
Presenter
end
end
describe
'#initialize'
do
subject
do
described_class
.
new
(
appearance
)
end
it
'takes a subject and optional params'
do
expect
{
subject
}.
not_to
raise_error
end
end
describe
'#fabricate!'
do
context
'without delegation'
do
subject
do
described_class
.
new
(
appearance
).
fabricate!
end
it
'does not forward missing methods to subject'
do
expect
{
subject
.
title
}.
to
raise_error
(
NoMethodError
)
end
end
context
'with delegation'
do
subject
do
described_class
.
new
(
broadcast_message
).
fabricate!
end
it
'forwards missing methods to subject'
do
expect
(
subject
.
message
).
to
eq
(
broadcast_message
.
message
)
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