diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-03-27 21:07:48 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-03-27 21:07:48 +0300 |
commit | e20baee820ea2c76ee16980a98e8080f255d9035 (patch) | |
tree | 6e13a73bee42b7ef310850d03982faebea17a0b1 /spec/models | |
parent | 71c5863d7b1ca9836a7d7703f35750cd726a9846 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/models')
-rw-r--r-- | spec/models/concerns/bulk_insert_safe_spec.rb | 6 | ||||
-rw-r--r-- | spec/models/project_services/irker_service_spec.rb | 2 | ||||
-rw-r--r-- | spec/models/service_spec.rb | 43 |
3 files changed, 47 insertions, 4 deletions
diff --git a/spec/models/concerns/bulk_insert_safe_spec.rb b/spec/models/concerns/bulk_insert_safe_spec.rb index 5ed1d6b9967..5d65d614ac5 100644 --- a/spec/models/concerns/bulk_insert_safe_spec.rb +++ b/spec/models/concerns/bulk_insert_safe_spec.rb @@ -7,7 +7,7 @@ describe BulkInsertSafe do include BulkInsertSafe include ShaAttribute - validates :name, :enum_value, :secret_value, :sha_value, presence: true + validates :name, :enum_value, :secret_value, :sha_value, :jsonb_value, presence: true ENUM_VALUES = { case_1: 1 @@ -26,6 +26,7 @@ describe BulkInsertSafe do default_value_for :enum_value, 'case_1' default_value_for :secret_value, 'my-secret' default_value_for :sha_value, '2fd4e1c67a2d28fced849ee1bb76e7391b93eb12' + default_value_for :jsonb_value, { "key" => "value" } def self.valid_list(count) Array.new(count) { |n| new(name: "item-#{n}") } @@ -60,6 +61,7 @@ describe BulkInsertSafe do t.text :encrypted_secret_value, null: false t.string :encrypted_secret_value_iv, null: false t.binary :sha_value, null: false, limit: 20 + t.jsonb :jsonb_value, null: false t.index :name, unique: true end @@ -114,7 +116,7 @@ describe BulkInsertSafe do described_class.bulk_insert!(items) - attribute_names = described_class.attribute_names - %w[id] + attribute_names = described_class.attribute_names - %w[id created_at updated_at] expect(described_class.last(items.size).pluck(*attribute_names)).to eq( items.pluck(*attribute_names)) end diff --git a/spec/models/project_services/irker_service_spec.rb b/spec/models/project_services/irker_service_spec.rb index 309dc51191b..badc964db16 100644 --- a/spec/models/project_services/irker_service_spec.rb +++ b/spec/models/project_services/irker_service_spec.rb @@ -64,7 +64,7 @@ describe IrkerService do irker.execute(sample_data) conn = @irker_server.accept - conn.readlines.each do |line| + conn.each_line do |line| msg = JSON.parse(line.chomp("\n")) expect(msg.keys).to match_array(%w(to privmsg)) expect(msg['to']).to match_array(["irc://chat.freenode.net/#commits", diff --git a/spec/models/service_spec.rb b/spec/models/service_spec.rb index cecd4f76fc5..d1a4924c07e 100644 --- a/spec/models/service_spec.rb +++ b/spec/models/service_spec.rb @@ -149,6 +149,47 @@ describe Service do end end + describe '.find_or_initialize_instances' do + shared_examples 'service instances' do + it 'returns the available service instances' do + expect(Service.find_or_initialize_instances.pluck(:type)).to match_array(Service.available_services_types) + end + + it 'does not create service instances' do + expect { Service.find_or_initialize_instances }.not_to change { Service.count } + end + end + + it_behaves_like 'service instances' + + context 'with all existing instances' do + before do + Service.insert_all( + Service.available_services_types.map { |type| { instance: true, type: type } } + ) + end + + it_behaves_like 'service instances' + + context 'with a previous existing service (Previous) and a new service (Asana)' do + before do + Service.insert(type: 'PreviousService', instance: true) + Service.delete_by(type: 'AsanaService', instance: true) + end + + it_behaves_like 'service instances' + end + end + + context 'with a few existing instances' do + before do + create(:jira_service, :instance) + end + + it_behaves_like 'service instances' + end + end + describe 'template' do let(:project) { create(:project) } @@ -173,7 +214,7 @@ describe Service do end it 'does not create service templates' do - expect { Service.find_or_create_templates }.to change { Service.count }.by(0) + expect { Service.find_or_create_templates }.not_to change { Service.count } end it_behaves_like 'retrieves service templates' |