Commit cb38e99d authored by Arturo Herrero's avatar Arturo Herrero Committed by Kamil Trzciński

Rename service model scopes

parent e6184680
...@@ -32,7 +32,7 @@ class Admin::ApplicationSettingsController < Admin::ApplicationController ...@@ -32,7 +32,7 @@ class Admin::ApplicationSettingsController < Admin::ApplicationController
end end
def integrations def integrations
@integrations = Service.find_or_initialize_all(Service.instances).sort_by(&:title) @integrations = Service.find_or_initialize_all(Service.for_instance).sort_by(&:title)
end end
def update def update
......
...@@ -8,7 +8,7 @@ class Admin::ServicesController < Admin::ApplicationController ...@@ -8,7 +8,7 @@ class Admin::ServicesController < Admin::ApplicationController
def index def index
@services = Service.find_or_create_templates.sort_by(&:title) @services = Service.find_or_create_templates.sort_by(&:title)
@existing_instance_types = Service.instances.pluck(:type) # rubocop: disable CodeReuse/ActiveRecord @existing_instance_types = Service.for_instance.pluck(:type) # rubocop: disable CodeReuse/ActiveRecord
end end
def edit def edit
......
...@@ -8,7 +8,7 @@ module Groups ...@@ -8,7 +8,7 @@ module Groups
before_action :authorize_admin_group! before_action :authorize_admin_group!
def index def index
@integrations = Service.find_or_initialize_all(Service.by_group(group)).sort_by(&:title) @integrations = Service.find_or_initialize_all(Service.for_group(group)).sort_by(&:title)
end end
private private
......
...@@ -2533,11 +2533,11 @@ class Project < ApplicationRecord ...@@ -2533,11 +2533,11 @@ class Project < ApplicationRecord
end end
def services_templates def services_templates
@services_templates ||= Service.templates @services_templates ||= Service.for_template
end end
def services_instances def services_instances
@services_instances ||= Service.instances @services_instances ||= Service.for_instance
end end
def closest_namespace_setting(name) def closest_namespace_setting(name)
......
...@@ -63,9 +63,9 @@ class Service < ApplicationRecord ...@@ -63,9 +63,9 @@ class Service < ApplicationRecord
scope :active, -> { where(active: true) } scope :active, -> { where(active: true) }
scope :by_type, -> (type) { where(type: type) } scope :by_type, -> (type) { where(type: type) }
scope :by_active_flag, -> (flag) { where(active: flag) } scope :by_active_flag, -> (flag) { where(active: flag) }
scope :by_group, -> (group) { where(group_id: group, type: available_services_types) } scope :for_group, -> (group) { where(group_id: group, type: available_services_types) }
scope :templates, -> { where(template: true, type: available_services_types) } scope :for_template, -> { where(template: true, type: available_services_types) }
scope :instances, -> { where(instance: true, type: available_services_types) } scope :for_instance, -> { where(instance: true, type: available_services_types) }
scope :push_hooks, -> { where(push_events: true, active: true) } scope :push_hooks, -> { where(push_events: true, active: true) }
scope :tag_push_hooks, -> { where(tag_push_events: true, active: true) } scope :tag_push_hooks, -> { where(tag_push_events: true, active: true) }
...@@ -291,11 +291,11 @@ class Service < ApplicationRecord ...@@ -291,11 +291,11 @@ class Service < ApplicationRecord
def self.find_or_create_templates def self.find_or_create_templates
create_nonexistent_templates create_nonexistent_templates
templates for_template
end end
private_class_method def self.create_nonexistent_templates private_class_method def self.create_nonexistent_templates
nonexistent_services = list_nonexistent_services_for(templates) nonexistent_services = list_nonexistent_services_for(for_template)
return if nonexistent_services.empty? return if nonexistent_services.empty?
# Create within a transaction to perform the lowest possible SQL queries. # Create within a transaction to perform the lowest possible SQL queries.
......
...@@ -4,7 +4,7 @@ require 'spec_helper' ...@@ -4,7 +4,7 @@ require 'spec_helper'
RSpec.describe 'Admin visits service templates' do RSpec.describe 'Admin visits service templates' do
let(:admin) { create(:user, :admin) } let(:admin) { create(:user, :admin) }
let(:slack_service) { Service.templates.find { |s| s.type == 'SlackService' } } let(:slack_service) { Service.for_template.find { |s| s.type == 'SlackService' } }
before do before do
sign_in(admin) sign_in(admin)
......
...@@ -92,12 +92,12 @@ RSpec.describe Service do ...@@ -92,12 +92,12 @@ RSpec.describe Service do
end end
end end
describe '.by_group' do describe '.for_group' do
let!(:service1) { create(:jira_service, project_id: nil, group_id: group.id) } let!(:service1) { create(:jira_service, project_id: nil, group_id: group.id) }
let!(:service2) { create(:jira_service) } let!(:service2) { create(:jira_service) }
it 'returns the right group service' do it 'returns the right group service' do
expect(described_class.by_group(group)).to match_array([service1]) expect(described_class.for_group(group)).to match_array([service1])
end end
end end
...@@ -215,11 +215,11 @@ RSpec.describe Service do ...@@ -215,11 +215,11 @@ RSpec.describe Service do
describe '.find_or_initialize_all' do describe '.find_or_initialize_all' do
shared_examples 'service instances' do shared_examples 'service instances' do
it 'returns the available service instances' do it 'returns the available service instances' do
expect(Service.find_or_initialize_all(Service.instances).pluck(:type)).to match_array(Service.available_services_types) expect(Service.find_or_initialize_all(Service.for_instance).pluck(:type)).to match_array(Service.available_services_types)
end end
it 'does not create service instances' do it 'does not create service instances' do
expect { Service.find_or_initialize_all(Service.instances) }.not_to change { Service.count } expect { Service.find_or_initialize_all(Service.for_instance) }.not_to change { Service.count }
end end
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