Commit 6243a93b authored by Mike Kozono's avatar Mike Kozono

Extract ReplicableModel tests against Dummy

instead of writing these tests inside of replicator_spec.rb.
parent 4e9f2bf1
# 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
This diff is collapsed.
...@@ -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
...@@ -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
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment