2019-10-30 08:06:34 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
require Rails.root.join('db', 'post_migrate', '20191021101942_remove_empty_github_service_templates.rb')
|
|
|
|
|
2020-03-11 17:09:19 -04:00
|
|
|
describe RemoveEmptyGithubServiceTemplates do
|
2019-10-30 08:06:34 -04:00
|
|
|
subject(:migration) { described_class.new }
|
|
|
|
|
|
|
|
let(:services) do
|
|
|
|
table(:services).tap do |klass|
|
|
|
|
klass.class_eval do
|
|
|
|
serialize :properties, JSON
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
before do
|
|
|
|
services.delete_all
|
|
|
|
|
|
|
|
create_service(properties: nil)
|
|
|
|
create_service(properties: {})
|
|
|
|
create_service(properties: { some: :value })
|
|
|
|
create_service(properties: {}, template: false)
|
|
|
|
create_service(properties: {}, type: 'SomeType')
|
|
|
|
end
|
|
|
|
|
|
|
|
def all_service_properties
|
|
|
|
services.where(template: true, type: 'GithubService').pluck(:properties)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'correctly migrates up and down service templates' do
|
|
|
|
reversible_migration do |migration|
|
|
|
|
migration.before -> do
|
|
|
|
expect(services.count).to eq(5)
|
|
|
|
|
|
|
|
expect(all_service_properties)
|
|
|
|
.to match(a_collection_containing_exactly(nil, {}, { 'some' => 'value' }))
|
|
|
|
end
|
|
|
|
|
|
|
|
migration.after -> do
|
|
|
|
expect(services.count).to eq(4)
|
|
|
|
|
|
|
|
expect(all_service_properties)
|
|
|
|
.to match(a_collection_containing_exactly(nil, { 'some' => 'value' }))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def create_service(params)
|
|
|
|
data = { template: true, type: 'GithubService' }
|
|
|
|
data.merge!(params)
|
|
|
|
|
|
|
|
services.create!(data)
|
|
|
|
end
|
|
|
|
end
|