diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2019-10-30 12:06:34 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2019-10-30 12:06:34 +0000 |
commit | 228d752ff09362002cc904d28edee7d63cc3cef2 (patch) | |
tree | 63e7ff466c0b0794f67c87c34e874f8682fb5de0 /spec/migrations | |
parent | b539ac1d619c0aafe5988ab8b125a8b43b14d87f (diff) | |
download | gitlab-ce-228d752ff09362002cc904d28edee7d63cc3cef2.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/migrations')
-rw-r--r-- | spec/migrations/remove_empty_github_service_templates_spec.rb | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/spec/migrations/remove_empty_github_service_templates_spec.rb b/spec/migrations/remove_empty_github_service_templates_spec.rb new file mode 100644 index 00000000000..c128c8538db --- /dev/null +++ b/spec/migrations/remove_empty_github_service_templates_spec.rb @@ -0,0 +1,55 @@ +# frozen_string_literal: true + +require 'spec_helper' +require Rails.root.join('db', 'post_migrate', '20191021101942_remove_empty_github_service_templates.rb') + +describe RemoveEmptyGithubServiceTemplates, :migration do + 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 |