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
0
Merge Requests
0
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
Boxiang Sun
gitlab-ce
Commits
0ac65b6c
Commit
0ac65b6c
authored
Jan 20, 2017
by
Rémy Coutable
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Don't override presentee methods for Gitlab::View::Presenter::Delegated
Signed-off-by:
Rémy Coutable
<
remy@rymai.me
>
parent
b60de9c0
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
27 additions
and
22 deletions
+27
-22
app/controllers/projects/builds_controller.rb
app/controllers/projects/builds_controller.rb
+1
-1
app/presenters/README.md
app/presenters/README.md
+3
-3
lib/gitlab/view/presenter/delegated.rb
lib/gitlab/view/presenter/delegated.rb
+3
-1
spec/lib/gitlab/view/presenter/delegated_spec.rb
spec/lib/gitlab/view/presenter/delegated_spec.rb
+10
-5
spec/lib/gitlab/view/presenter/factory_spec.rb
spec/lib/gitlab/view/presenter/factory_spec.rb
+0
-7
spec/lib/gitlab/view/presenter/simple_spec.rb
spec/lib/gitlab/view/presenter/simple_spec.rb
+10
-5
No files found.
app/controllers/projects/builds_controller.rb
View file @
0ac65b6c
...
...
@@ -94,7 +94,7 @@ class Projects::BuildsController < Projects::ApplicationController
private
def
build
@build
||=
project
.
builds
.
find_by!
(
id:
params
[
:id
]).
present
(
user:
current_user
)
@build
||=
project
.
builds
.
find_by!
(
id:
params
[
:id
]).
present
(
current_
user:
current_user
)
end
def
build_path
(
build
)
...
...
app/presenters/README.md
View file @
0ac65b6c
...
...
@@ -113,7 +113,7 @@ detects the presenter based on the presented subject's class.
class
Projects::LabelsController
<
Projects
::
ApplicationController
def
edit
@label
=
Gitlab
::
View
::
Presenter
::
Factory
.
new
(
@label
,
user:
current_user
)
.
new
(
@label
,
current_
user:
current_user
)
.
fabricate!
end
end
...
...
@@ -132,7 +132,7 @@ and then in the controller:
```
ruby
class
Projects::LabelsController
<
Projects
::
ApplicationController
def
edit
@label
=
@label
.
present
(
user:
current_user
)
@label
=
@label
.
present
(
current_
user:
current_user
)
end
end
```
...
...
@@ -147,7 +147,7 @@ end
You can also present the model in the view:
```
ruby
-
label
=
@label
.
present
(
current_user
)
-
label
=
@label
.
present
(
current_user
:
current_user
)
%
div
{
class:
label
.
text_color
}
=
render
partial:
label
,
label:
label
...
...
lib/gitlab/view/presenter/delegated.rb
View file @
0ac65b6c
...
...
@@ -8,7 +8,9 @@ module Gitlab
@subject
=
subject
attributes
.
each
do
|
key
,
value
|
define_singleton_method
(
key
)
{
value
}
unless
subject
.
respond_to?
(
key
)
define_singleton_method
(
key
)
{
value
}
end
end
super
(
subject
)
...
...
spec/lib/gitlab/view/presenter/delegated_spec.rb
View file @
0ac65b6c
require
'spec_helper'
describe
Gitlab
::
View
::
Presenter
::
Delegated
do
let
(
:project
)
{
double
(
:project
,
bar:
'baz
'
)
}
let
(
:project
)
{
double
(
:project
,
user:
'John Doe
'
)
}
let
(
:presenter_class
)
do
Class
.
new
(
described_class
)
end
...
...
@@ -12,10 +12,15 @@ describe Gitlab::View::Presenter::Delegated do
describe
'#initialize'
do
it
'takes arbitrary key/values and exposes them'
do
presenter
=
presenter_class
.
new
(
project
,
user:
'user'
,
foo:
'bar
'
)
presenter
=
presenter_class
.
new
(
project
,
current_user:
'Jane Doe
'
)
expect
(
presenter
.
user
).
to
eq
(
'user'
)
expect
(
presenter
.
foo
).
to
eq
(
'bar'
)
expect
(
presenter
.
current_user
).
to
eq
(
'Jane Doe'
)
end
it
'does not override the presentee attributes'
do
presenter
=
presenter_class
.
new
(
project
,
user:
'Jane Doe'
)
expect
(
presenter
.
user
).
to
eq
(
'John Doe'
)
end
end
...
...
@@ -23,7 +28,7 @@ describe Gitlab::View::Presenter::Delegated do
it
'forwards missing methods to subject'
do
presenter
=
presenter_class
.
new
(
project
)
expect
(
presenter
.
bar
).
to
eq
(
'baz
'
)
expect
(
presenter
.
user
).
to
eq
(
'John Doe
'
)
end
end
end
spec/lib/gitlab/view/presenter/factory_spec.rb
View file @
0ac65b6c
...
...
@@ -22,13 +22,6 @@ describe Gitlab::View::Presenter::Factory do
end
describe
'#fabricate!'
do
it
'exposes given params'
do
presenter
=
described_class
.
new
(
build
,
user:
'user'
,
foo:
'bar'
).
fabricate!
expect
(
presenter
.
user
).
to
eq
(
'user'
)
expect
(
presenter
.
foo
).
to
eq
(
'bar'
)
end
it
'detects the presenter based on the given subject'
do
presenter
=
described_class
.
new
(
build
).
fabricate!
...
...
spec/lib/gitlab/view/presenter/simple_spec.rb
View file @
0ac65b6c
require
'spec_helper'
describe
Gitlab
::
View
::
Presenter
::
Simple
do
let
(
:project
)
{
double
(
:project
)
}
let
(
:project
)
{
double
(
:project
,
user:
'John Doe'
)
}
let
(
:presenter_class
)
do
Class
.
new
(
described_class
)
end
...
...
@@ -12,10 +12,15 @@ describe Gitlab::View::Presenter::Simple do
describe
'#initialize'
do
it
'takes arbitrary key/values and exposes them'
do
presenter
=
presenter_class
.
new
(
project
,
user:
'user'
,
foo:
'bar
'
)
presenter
=
presenter_class
.
new
(
project
,
current_user:
'Jane Doe
'
)
expect
(
presenter
.
user
).
to
eq
(
'user'
)
expect
(
presenter
.
foo
).
to
eq
(
'bar'
)
expect
(
presenter
.
current_user
).
to
eq
(
'Jane Doe'
)
end
it
'override the presentee attributes'
do
presenter
=
presenter_class
.
new
(
project
,
user:
'Jane Doe'
)
expect
(
presenter
.
user
).
to
eq
(
'Jane Doe'
)
end
end
...
...
@@ -23,7 +28,7 @@ describe Gitlab::View::Presenter::Simple do
it
'does not forward missing methods to subject'
do
presenter
=
presenter_class
.
new
(
project
)
expect
{
presenter
.
foo
}.
to
raise_error
(
NoMethodError
)
expect
{
presenter
.
user
}.
to
raise_error
(
NoMethodError
)
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