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
6243a93b
Commit
6243a93b
authored
Jul 29, 2020
by
Mike Kozono
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Extract ReplicableModel tests against Dummy
instead of writing these tests inside of replicator_spec.rb.
parent
4e9f2bf1
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
217 additions
and
155 deletions
+217
-155
ee/spec/lib/gitlab/geo/replicable_model_spec.rb
ee/spec/lib/gitlab/geo/replicable_model_spec.rb
+45
-0
ee/spec/lib/gitlab/geo/replicator_spec.rb
ee/spec/lib/gitlab/geo/replicator_spec.rb
+103
-155
ee/spec/support/helpers/ee/geo_helpers.rb
ee/spec/support/helpers/ee/geo_helpers.rb
+62
-0
ee/spec/support/shared_examples/models/concerns/replicable_model_shared_examples.rb
...mples/models/concerns/replicable_model_shared_examples.rb
+7
-0
No files found.
ee/spec/lib/gitlab/geo/replicable_model_spec.rb
0 → 100644
View file @
6243a93b
# frozen_string_literal: true
require
'spec_helper'
# Also see ee/spec/support/shared_examples/models/concerns/replicable_model_shared_examples.rb:
#
# - Place tests here in replicable_model_spec.rb if you want to run them once,
# against a DummyModel.
# - Place tests in replicable_model_shared_examples.rb if you want them to be
# run against every real Model.
RSpec
.
describe
Gitlab
::
Geo
::
ReplicableModel
do
include
::
EE
::
GeoHelpers
let_it_be
(
:primary_node
)
{
create
(
:geo_node
,
:primary
)
}
let_it_be
(
:secondary_node
)
{
create
(
:geo_node
)
}
before
(
:all
)
do
create_dummy_model_table
end
after
(
:all
)
do
drop_dummy_model_table
end
before
do
stub_dummy_replicator_class
stub_dummy_model_class
end
subject
{
DummyModel
.
new
}
it_behaves_like
'a replicable model'
do
let
(
:model_record
)
{
subject
}
end
describe
'#replicator'
do
it
'adds replicator method to the model'
do
expect
(
subject
).
to
respond_to
(
:replicator
)
end
it
'instantiates a replicator into the model'
do
expect
(
subject
.
replicator
).
to
be_a
(
Geo
::
DummyReplicator
)
end
end
end
ee/spec/lib/gitlab/geo/replicator_spec.rb
View file @
6243a93b
...
@@ -21,37 +21,15 @@ RSpec.describe Gitlab::Geo::Replicator do
...
@@ -21,37 +21,15 @@ RSpec.describe Gitlab::Geo::Replicator do
end
end
before
(
:all
)
do
before
(
:all
)
do
ActiveRecord
::
Schema
.
define
do
create_dummy_model_table
create_table
:dummy_models
,
force:
true
do
|
t
|
t
.
binary
:verification_checksum
end
end
end
end
after
(
:all
)
do
after
(
:all
)
do
ActiveRecord
::
Schema
.
define
do
drop_dummy_model_table
drop_table
:dummy_models
,
force:
true
end
end
end
context
'with defined events'
do
before
do
before
do
stub_const
(
'Geo::DummyReplicator'
,
Class
.
new
(
Gitlab
::
Geo
::
Replicator
))
stub_dummy_replicator_class
Geo
::
DummyReplicator
.
class_eval
do
event
:test
event
:another_test
def
self
.
model
::
DummyModel
end
protected
def
consume_event_test
(
user
:,
other
:)
true
end
end
end
end
context
'event DSL'
do
context
'event DSL'
do
...
@@ -74,35 +52,6 @@ RSpec.describe Gitlab::Geo::Replicator do
...
@@ -74,35 +52,6 @@ RSpec.describe Gitlab::Geo::Replicator do
end
end
end
end
context
'model DSL'
do
before
do
stub_const
(
'DummyModel'
,
Class
.
new
(
ApplicationRecord
))
DummyModel
.
class_eval
do
include
ActiveModel
::
Model
def
self
.
after_create_commit
(
*
args
)
end
include
Gitlab
::
Geo
::
ReplicableModel
with_replicator
Geo
::
DummyReplicator
end
DummyModel
.
reset_column_information
end
subject
{
DummyModel
.
new
}
it
'adds replicator method to the model'
do
expect
(
subject
).
to
respond_to
(
:replicator
)
end
it
'instantiates a replicator into the model'
do
expect
(
subject
.
replicator
).
to
be_a
(
Geo
::
DummyReplicator
)
end
end
describe
'#publish'
do
describe
'#publish'
do
subject
{
Geo
::
DummyReplicator
.
new
}
subject
{
Geo
::
DummyReplicator
.
new
}
...
@@ -237,5 +186,4 @@ RSpec.describe Gitlab::Geo::Replicator do
...
@@ -237,5 +186,4 @@ RSpec.describe Gitlab::Geo::Replicator do
describe
'#in_replicables_for_geo_node?'
do
describe
'#in_replicables_for_geo_node?'
do
it
{
is_expected
.
to
delegate_method
(
:in_replicables_for_geo_node?
).
to
(
:model_record
)
}
it
{
is_expected
.
to
delegate_method
(
:in_replicables_for_geo_node?
).
to
(
:model_record
)
}
end
end
end
end
end
ee/spec/support/helpers/ee/geo_helpers.rb
View file @
6243a93b
...
@@ -55,5 +55,67 @@ module EE
...
@@ -55,5 +55,67 @@ module EE
# will appear as though the tracking DB were not available
# will appear as though the tracking DB were not available
allow
(
::
Gitlab
::
Geo
).
to
receive
(
:geo_database_configured?
).
and_call_original
allow
(
::
Gitlab
::
Geo
).
to
receive
(
:geo_database_configured?
).
and_call_original
end
end
def
stub_dummy_replicator_class
stub_const
(
'Geo::DummyReplicator'
,
Class
.
new
(
::
Gitlab
::
Geo
::
Replicator
))
Geo
::
DummyReplicator
.
class_eval
do
event
:test
event
:another_test
def
self
.
model
::
DummyModel
end
def
handle_after_create_commit
true
end
protected
def
consume_event_test
(
user
:,
other
:)
true
end
end
end
def
stub_dummy_model_class
stub_const
(
'DummyModel'
,
Class
.
new
(
ApplicationRecord
))
DummyModel
.
class_eval
do
include
::
Gitlab
::
Geo
::
ReplicableModel
with_replicator
Geo
::
DummyReplicator
def
self
.
replicables_for_geo_node
self
.
all
end
end
DummyModel
.
reset_column_information
end
# Example:
#
# before(:all) do
# create_dummy_model_table
# end
#
# after(:all) do
# drop_dummy_model_table
# end
def
create_dummy_model_table
ActiveRecord
::
Schema
.
define
do
create_table
:dummy_models
,
force:
true
do
|
t
|
t
.
binary
:verification_checksum
end
end
end
def
drop_dummy_model_table
ActiveRecord
::
Schema
.
define
do
drop_table
:dummy_models
,
force:
true
end
end
end
end
end
end
ee/spec/support/shared_examples/models/concerns/replicable_model_shared_examples.rb
View file @
6243a93b
...
@@ -6,6 +6,13 @@
...
@@ -6,6 +6,13 @@
#
#
# We do not use `described_class` here, so we can include this in replicator
# We do not use `described_class` here, so we can include this in replicator
# strategy shared examples instead of in *every* model spec.
# strategy shared examples instead of in *every* model spec.
#
# Also see ee/spec/lib/gitlab/geo/replicable_model_spec.rb:
#
# - Place tests in replicable_model_spec.rb if you want to run them once,
# against a DummyModel.
# - Place tests here in replicable_model_shared_examples.rb if you want them to
# be run against every real Model.
RSpec
.
shared_examples
'a replicable model'
do
RSpec
.
shared_examples
'a replicable model'
do
include
EE
::
GeoHelpers
include
EE
::
GeoHelpers
...
...
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