Add Geo::HashedStorageMigratedEvent model

parent 925f3f78
...@@ -22,6 +22,10 @@ module Geo ...@@ -22,6 +22,10 @@ module Geo
class_name: 'Geo::RepositoriesChangedEvent', class_name: 'Geo::RepositoriesChangedEvent',
foreign_key: :repositories_changed_event_id foreign_key: :repositories_changed_event_id
belongs_to :hashed_storage_migrated_event,
class_name: 'Geo::HashedStorageMigratedEvent',
foreign_key: :hashed_storage_migrated_event_id
def self.latest_event def self.latest_event
order(id: :desc).first order(id: :desc).first
end end
...@@ -31,7 +35,8 @@ module Geo ...@@ -31,7 +35,8 @@ module Geo
repository_updated_event || repository_updated_event ||
repository_deleted_event || repository_deleted_event ||
repository_renamed_event || repository_renamed_event ||
repositories_changed_event repositories_changed_event ||
hashed_storage_migrated_event
end end
def project_id def project_id
......
module Geo
class HashedStorageMigratedEvent < ActiveRecord::Base
include Geo::Model
belongs_to :project
validates :project, :repository_storage_name, :repository_storage_path,
:old_disk_path, :new_disk_path, :old_wiki_disk_path,
:new_wiki_disk_path, :new_storage_version, presence: true
end
end
...@@ -73,4 +73,16 @@ FactoryGirl.define do ...@@ -73,4 +73,16 @@ FactoryGirl.define do
old_path { project.path } old_path { project.path }
new_path { project.path + '_new' } new_path { project.path + '_new' }
end end
factory :geo_hashed_storage_migrated_event, class: Geo::HashedStorageMigratedEvent do
project { create(:project, :repository) }
repository_storage_name { project.repository_storage }
repository_storage_path { project.repository_storage_path }
old_disk_path { project.path_with_namespace }
new_disk_path { project.path_with_namespace + '_new' }
old_wiki_disk_path { project.wiki.path_with_namespace }
new_wiki_disk_path { project.wiki.path_with_namespace + '_new' }
new_storage_version { Project::LATEST_STORAGE_VERSION }
end
end end
...@@ -7,6 +7,7 @@ RSpec.describe Geo::EventLog, type: :model do ...@@ -7,6 +7,7 @@ RSpec.describe Geo::EventLog, type: :model do
it { is_expected.to belong_to(:repository_deleted_event).class_name('Geo::RepositoryDeletedEvent').with_foreign_key('repository_deleted_event_id') } it { is_expected.to belong_to(:repository_deleted_event).class_name('Geo::RepositoryDeletedEvent').with_foreign_key('repository_deleted_event_id') }
it { is_expected.to belong_to(:repository_renamed_event).class_name('Geo::RepositoryRenamedEvent').with_foreign_key('repository_renamed_event_id') } it { is_expected.to belong_to(:repository_renamed_event).class_name('Geo::RepositoryRenamedEvent').with_foreign_key('repository_renamed_event_id') }
it { is_expected.to belong_to(:repository_updated_event).class_name('Geo::RepositoryUpdatedEvent').with_foreign_key('repository_updated_event_id') } it { is_expected.to belong_to(:repository_updated_event).class_name('Geo::RepositoryUpdatedEvent').with_foreign_key('repository_updated_event_id') }
it { is_expected.to belong_to(:hashed_storage_migrated_event).class_name('Geo::HashedStorageMigratedEvent').with_foreign_key('hashed_storage_migrated_event_id') }
end end
describe '#event' do describe '#event' do
...@@ -48,6 +49,13 @@ RSpec.describe Geo::EventLog, type: :model do ...@@ -48,6 +49,13 @@ RSpec.describe Geo::EventLog, type: :model do
expect(subject.event).to eq repositories_changed_event expect(subject.event).to eq repositories_changed_event
end end
it 'returns hashed_storage_migrated_event when set' do
hashed_storage_migrated_event = build(:geo_hashed_storage_migrated_event)
subject.hashed_storage_migrated_event = hashed_storage_migrated_event
expect(subject.event).to eq hashed_storage_migrated_event
end
end end
describe '#project_id' do describe '#project_id' do
......
require 'spec_helper'
RSpec.describe Geo::HashedStorageMigratedEvent, type: :model do
describe 'relationships' do
it { is_expected.to belong_to(:project) }
end
describe 'validations' do
it { is_expected.to validate_presence_of(:project) }
it { is_expected.to validate_presence_of(:repository_storage_name) }
it { is_expected.to validate_presence_of(:repository_storage_path) }
it { is_expected.to validate_presence_of(:old_disk_path) }
it { is_expected.to validate_presence_of(:new_disk_path) }
it { is_expected.to validate_presence_of(:old_wiki_disk_path) }
it { is_expected.to validate_presence_of(:new_wiki_disk_path) }
it { is_expected.to validate_presence_of(:new_storage_version) }
end
end
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