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
ad38e120
Commit
ad38e120
authored
Feb 02, 2018
by
Matija Čupić
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove dismissed_state from Callout model
parent
4ff0cfe5
Changes
8
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
20 additions
and
25 deletions
+20
-25
app/controllers/callouts_controller.rb
app/controllers/callouts_controller.rb
+6
-14
app/helpers/callouts_helper.rb
app/helpers/callouts_helper.rb
+1
-1
app/models/callout.rb
app/models/callout.rb
+3
-0
db/migrate/20180125214301_create_callouts.rb
db/migrate/20180125214301_create_callouts.rb
+1
-2
db/schema.rb
db/schema.rb
+1
-2
spec/controllers/callouts_controller_spec.rb
spec/controllers/callouts_controller_spec.rb
+0
-4
spec/factories/callouts.rb
spec/factories/callouts.rb
+0
-1
spec/models/callout_spec.rb
spec/models/callout_spec.rb
+8
-1
No files found.
app/controllers/callouts_controller.rb
View file @
ad38e120
class
CalloutsController
<
ApplicationController
before_action
:callout
,
only:
[
:dismiss
]
def
dismiss
respond_to
do
|
format
|
format
.
json
do
if
@callout
@callout
.
update
(
dismissed_state:
true
)
if
ensure_callout
respond_to
{
|
format
|
format
.
json
{
head
:ok
}
}
else
Callout
.
create
(
feature_name:
callout_param
,
dismissed_state:
true
,
user:
current_user
)
end
head
:ok
end
respond_to
{
|
format
|
format
.
json
{
head
:bad_request
}
}
end
end
private
def
callout
@callout
=
Callout
.
find_by
(
user:
current_user
,
feature_name:
callout_param
)
def
ensure_
callout
current_user
.
callouts
.
find_or_create_by
(
feature_name:
callout_param
)
end
def
callout_param
...
...
app/helpers/callouts_helper.rb
View file @
ad38e120
...
...
@@ -15,6 +15,6 @@ module CalloutsHelper
private
def
user_dismissed?
(
feature_name
)
Callout
.
find_by
(
user:
current_user
,
feature_name:
feature_name
)
&
.
dismissed_state?
current_user
&
.
callouts
&
.
find_by
(
feature_name:
feature_name
)
end
end
app/models/callout.rb
View file @
ad38e120
class
Callout
<
ActiveRecord
::
Base
belongs_to
:user
validates
:user
,
presence:
true
validates
:feature_name
,
presence:
true
,
uniqueness:
{
scope: :user_id
}
end
db/migrate/20180125214301_create_callouts.rb
View file @
ad38e120
...
...
@@ -8,12 +8,11 @@ class CreateCallouts < ActiveRecord::Migration
def
change
create_table
:callouts
do
|
t
|
t
.
string
:feature_name
,
null:
false
t
.
boolean
:dismissed_state
,
null:
false
t
.
references
:user
,
index:
true
,
foreign_key:
{
on_delete: :cascade
},
null:
false
t
.
timestamps_with_timezone
null:
false
end
add_index
:callouts
,
:feature_name
,
unique:
true
add_index
:callouts
,
[
:user_id
,
:feature_name
]
,
unique:
true
end
end
db/schema.rb
View file @
ad38e120
...
...
@@ -205,13 +205,12 @@ ActiveRecord::Schema.define(version: 20180125214301) do
create_table
"callouts"
,
force: :cascade
do
|
t
|
t
.
string
"feature_name"
,
null:
false
t
.
boolean
"dismissed_state"
,
null:
false
t
.
integer
"user_id"
,
null:
false
t
.
datetime_with_timezone
"created_at"
,
null:
false
t
.
datetime_with_timezone
"updated_at"
,
null:
false
end
add_index
"callouts"
,
[
"
feature_name"
],
name:
"index_callouts_on
_feature_name"
,
unique:
true
,
using: :btree
add_index
"callouts"
,
[
"
user_id"
,
"feature_name"
],
name:
"index_callouts_on_user_id_and
_feature_name"
,
unique:
true
,
using: :btree
add_index
"callouts"
,
[
"user_id"
],
name:
"index_callouts_on_user_id"
,
using: :btree
create_table
"chat_names"
,
force: :cascade
do
|
t
|
...
...
spec/controllers/callouts_controller_spec.rb
View file @
ad38e120
...
...
@@ -25,10 +25,6 @@ describe CalloutsController do
context
'when callout entry already exists'
do
let!
(
:callout
)
{
create
(
:callout
,
feature_name:
'feature_name'
,
user:
user
)
}
it
'should update it with a dismissed state'
do
expect
{
subject
}.
to
change
{
callout
.
reload
.
dismissed_state
}.
from
(
false
).
to
(
true
)
end
it
'should return success'
do
subject
...
...
spec/factories/callouts.rb
View file @
ad38e120
FactoryBot
.
define
do
factory
:callout
do
feature_name
'test_callout'
dismissed_state
false
user
end
...
...
spec/models/callout_spec.rb
View file @
ad38e120
require
'rails_helper'
describe
Callout
do
let
(
:callout
)
{
create
(
:callout
)
}
let
!
(
:callout
)
{
create
(
:callout
)
}
describe
'relationships'
do
it
{
is_expected
.
to
belong_to
(
:user
)
}
end
describe
'validations'
do
it
{
is_expected
.
to
validate_presence_of
(
:user
)
}
it
{
is_expected
.
to
validate_presence_of
(
:feature_name
)
}
it
{
is_expected
.
to
validate_uniqueness_of
(
:feature_name
).
scoped_to
(
:user_id
)
}
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