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
Jérome Perrin
gitlab-ce
Commits
20714ee9
Commit
20714ee9
authored
Feb 03, 2018
by
Matija Čupić
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Change UserCallout feautre_name to enum
parent
79efb9d0
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
42 additions
and
22 deletions
+42
-22
app/controllers/user_callouts_controller.rb
app/controllers/user_callouts_controller.rb
+5
-1
app/helpers/user_callouts_helper.rb
app/helpers/user_callouts_helper.rb
+0
-5
app/models/user_callout.rb
app/models/user_callout.rb
+8
-1
db/migrate/20180125214301_create_user_callouts.rb
db/migrate/20180125214301_create_user_callouts.rb
+1
-1
db/schema.rb
db/schema.rb
+1
-1
spec/controllers/user_callouts_controller_spec.rb
spec/controllers/user_callouts_controller_spec.rb
+25
-11
spec/factories/user_callouts.rb
spec/factories/user_callouts.rb
+1
-1
spec/models/user_callout_spec.rb
spec/models/user_callout_spec.rb
+1
-1
No files found.
app/controllers/user_callouts_controller.rb
View file @
20714ee9
class
UserCalloutsController
<
ApplicationController
class
UserCalloutsController
<
ApplicationController
def
create
def
create
if
ensure_callout
if
check_feature_name
&&
ensure_callout
respond_to
do
|
format
|
respond_to
do
|
format
|
format
.
json
{
head
:ok
}
format
.
json
{
head
:ok
}
end
end
...
@@ -13,6 +13,10 @@ class UserCalloutsController < ApplicationController
...
@@ -13,6 +13,10 @@ class UserCalloutsController < ApplicationController
private
private
def
check_feature_name
UserCallout
.
feature_names
.
keys
.
include?
(
callout_param
)
end
def
ensure_callout
def
ensure_callout
current_user
.
callouts
.
find_or_create_by
(
feature_name:
callout_param
)
current_user
.
callouts
.
find_or_create_by
(
feature_name:
callout_param
)
end
end
...
...
app/helpers/user_callouts_helper.rb
View file @
20714ee9
module
UserCalloutsHelper
module
UserCalloutsHelper
GKE_CLUSTER_INTEGRATION
=
'gke_cluster_integration'
.
freeze
GKE_CLUSTER_INTEGRATION
=
'gke_cluster_integration'
.
freeze
# Higher value = higher priority
PRIORITY
=
{
GKE_CLUSTER_INTEGRATION
:
0
}.
freeze
def
show_gke_cluster_integration_callout?
(
project
)
def
show_gke_cluster_integration_callout?
(
project
)
current_user
&&
!
user_dismissed?
(
GKE_CLUSTER_INTEGRATION
)
&&
current_user
&&
!
user_dismissed?
(
GKE_CLUSTER_INTEGRATION
)
&&
can?
(
current_user
,
:create_cluster
,
project
)
can?
(
current_user
,
:create_cluster
,
project
)
...
...
app/models/user_callout.rb
View file @
20714ee9
class
UserCallout
<
ActiveRecord
::
Base
class
UserCallout
<
ActiveRecord
::
Base
belongs_to
:user
belongs_to
:user
enum
feature_name:
{
gke_cluster_integration:
0
}
validates
:user
,
presence:
true
validates
:user
,
presence:
true
validates
:feature_name
,
presence:
true
,
uniqueness:
{
scope: :user_id
}
validates
:feature_name
,
presence:
true
,
uniqueness:
{
scope: :user_id
},
inclusion:
{
in:
UserCallout
.
feature_names
.
keys
}
end
end
db/migrate/20180125214301_create_user_callouts.rb
View file @
20714ee9
...
@@ -7,7 +7,7 @@ class CreateUserCallouts < ActiveRecord::Migration
...
@@ -7,7 +7,7 @@ class CreateUserCallouts < ActiveRecord::Migration
def
change
def
change
create_table
:user_callouts
do
|
t
|
create_table
:user_callouts
do
|
t
|
t
.
string
:feature_name
,
null:
false
t
.
integer
:feature_name
,
null:
false
t
.
references
:user
,
index:
true
,
foreign_key:
{
on_delete: :cascade
},
null:
false
t
.
references
:user
,
index:
true
,
foreign_key:
{
on_delete: :cascade
},
null:
false
end
end
...
...
db/schema.rb
View file @
20714ee9
...
@@ -1770,7 +1770,7 @@ ActiveRecord::Schema.define(version: 20180202111106) do
...
@@ -1770,7 +1770,7 @@ ActiveRecord::Schema.define(version: 20180202111106) do
add_index
"user_agent_details"
,
[
"subject_id"
,
"subject_type"
],
name:
"index_user_agent_details_on_subject_id_and_subject_type"
,
using: :btree
add_index
"user_agent_details"
,
[
"subject_id"
,
"subject_type"
],
name:
"index_user_agent_details_on_subject_id_and_subject_type"
,
using: :btree
create_table
"user_callouts"
,
force: :cascade
do
|
t
|
create_table
"user_callouts"
,
force: :cascade
do
|
t
|
t
.
string
"feature_name"
,
null:
false
t
.
integer
"feature_name"
,
null:
false
t
.
integer
"user_id"
,
null:
false
t
.
integer
"user_id"
,
null:
false
end
end
...
...
spec/controllers/user_callouts_controller_spec.rb
View file @
20714ee9
...
@@ -8,27 +8,41 @@ describe UserCalloutsController do
...
@@ -8,27 +8,41 @@ describe UserCalloutsController do
end
end
describe
"POST #create"
do
describe
"POST #create"
do
subject
{
post
:create
,
feature_name:
'feature_name'
,
format: :json
}
subject
{
post
:create
,
feature_name:
feature_name
,
format: :json
}
context
'when callout entry does not exist'
do
context
'with valid feature name'
do
it
'should create a callout entry with dismissed state'
do
let
(
:feature_name
)
{
UserCallout
.
feature_names
.
keys
.
first
}
expect
{
subject
}.
to
change
{
UserCallout
.
count
}.
by
(
1
)
context
'when callout entry does not exist'
do
it
'should create a callout entry with dismissed state'
do
expect
{
subject
}.
to
change
{
UserCallout
.
count
}.
by
(
1
)
end
it
'should return success'
do
subject
expect
(
response
).
to
have_gitlab_http_status
(
:ok
)
end
end
end
it
'should return success'
do
context
'when callout entry already exists'
do
subject
let!
(
:callout
)
{
create
(
:user_callout
,
feature_name:
UserCallout
.
feature_names
.
keys
.
first
,
user:
user
)
}
it
'should return success'
do
subject
expect
(
response
).
to
have_gitlab_http_status
(
:ok
)
expect
(
response
).
to
have_gitlab_http_status
(
:ok
)
end
end
end
end
end
context
'w
hen callout entry already exists
'
do
context
'w
ith invalid feature name
'
do
let
!
(
:callout
)
{
create
(
:user_callout
,
feature_name:
'feature_name'
,
user:
user
)
}
let
(
:feature_name
)
{
'bogus_feature_name'
}
it
'should return
success
'
do
it
'should return
bad request
'
do
subject
subject
expect
(
response
).
to
have_gitlab_http_status
(
:
ok
)
expect
(
response
).
to
have_gitlab_http_status
(
:
bad_request
)
end
end
end
end
end
end
...
...
spec/factories/user_callouts.rb
View file @
20714ee9
FactoryBot
.
define
do
FactoryBot
.
define
do
factory
:user_callout
do
factory
:user_callout
do
feature_name
'test_callout'
feature_name
:gke_cluster_integration
user
user
end
end
...
...
spec/models/user_callout_spec.rb
View file @
20714ee9
...
@@ -11,6 +11,6 @@ describe UserCallout do
...
@@ -11,6 +11,6 @@ describe UserCallout do
it
{
is_expected
.
to
validate_presence_of
(
:user
)
}
it
{
is_expected
.
to
validate_presence_of
(
:user
)
}
it
{
is_expected
.
to
validate_presence_of
(
:feature_name
)
}
it
{
is_expected
.
to
validate_presence_of
(
:feature_name
)
}
it
{
is_expected
.
to
validate_uniqueness_of
(
:feature_name
).
scoped_to
(
:user_id
)
}
it
{
is_expected
.
to
validate_uniqueness_of
(
:feature_name
).
scoped_to
(
:user_id
)
.
ignoring_case_sensitivity
}
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