Commit 0d22a94b authored by Dylan Griffith's avatar Dylan Griffith
Browse files

Switch to using ProjectCiCdSetting for group_runners_enabled and remove ProjectSettings

parent a6d564124b54
...@@ -53,7 +53,7 @@ def toggle_shared_runners ...@@ -53,7 +53,7 @@ def toggle_shared_runners
end end
def toggle_group_runners def toggle_group_runners
project.toggle_settings!(:group_runners_enabled) project.toggle_ci_cd_settings!(:group_runners_enabled)
redirect_to project_settings_ci_cd_path(@project) redirect_to project_settings_ci_cd_path(@project)
end end
......
...@@ -236,14 +236,6 @@ class Project < ActiveRecord::Base ...@@ -236,14 +236,6 @@ class Project < ActiveRecord::Base
has_many :project_badges, class_name: 'ProjectBadge' has_many :project_badges, class_name: 'ProjectBadge'
has_one :ci_cd_settings, class_name: 'ProjectCiCdSetting' has_one :ci_cd_settings, class_name: 'ProjectCiCdSetting'
has_one :settings, -> (project) {
query = where(project_id: project)
query.presence || begin
ProjectSettings.create(project_id: project.id)
query
end
}, class_name: 'ProjectSettings'
accepts_nested_attributes_for :variables, allow_destroy: true accepts_nested_attributes_for :variables, allow_destroy: true
accepts_nested_attributes_for :project_feature, update_only: true accepts_nested_attributes_for :project_feature, update_only: true
accepts_nested_attributes_for :import_data accepts_nested_attributes_for :import_data
...@@ -253,7 +245,7 @@ class Project < ActiveRecord::Base ...@@ -253,7 +245,7 @@ class Project < ActiveRecord::Base
delegate :members, to: :team, prefix: true delegate :members, to: :team, prefix: true
delegate :add_user, :add_users, to: :team delegate :add_user, :add_users, to: :team
delegate :add_guest, :add_reporter, :add_developer, :add_master, :add_role, to: :team delegate :add_guest, :add_reporter, :add_developer, :add_master, :add_role, to: :team
delegate :group_runners_enabled, :group_runners_enabled=, :group_runners_enabled?, to: :settings delegate :group_runners_enabled, :group_runners_enabled=, :group_runners_enabled?, to: :ci_cd_settings
# Validations # Validations
validates :creator, presence: true, on: :create validates :creator, presence: true, on: :create
...@@ -1879,8 +1871,8 @@ def licensed_features ...@@ -1879,8 +1871,8 @@ def licensed_features
[] []
end end
def toggle_settings!(settings_attribute) def toggle_ci_cd_settings!(settings_attribute)
settings.toggle!(settings_attribute) ci_cd_settings.toggle!(settings_attribute)
end end
def gitlab_deploy_token def gitlab_deploy_token
......
class ProjectSettings < ActiveRecord::Base
belongs_to :project
end
# See http://doc.gitlab.com/ce/development/migration_style_guide.html
# for more information on how to write migrations for GitLab.
class CreateProjectSettings < ActiveRecord::Migration
DOWNTIME = false
def change
create_table :project_settings do |t|
t.references :project, index: true, foreign_key: { on_delete: :cascade }
t.boolean :group_runners_enabled, default: true, index: true
end
end
end
...@@ -1511,14 +1511,6 @@ ...@@ -1511,14 +1511,6 @@
add_index "project_import_data", ["project_id"], name: "index_project_import_data_on_project_id", using: :btree add_index "project_import_data", ["project_id"], name: "index_project_import_data_on_project_id", using: :btree
create_table "project_settings", force: :cascade do |t|
t.integer "project_id"
t.boolean "group_runners_enabled", default: true
end
add_index "project_settings", ["group_runners_enabled"], name: "index_project_settings_on_group_runners_enabled", using: :btree
add_index "project_settings", ["project_id"], name: "index_project_settings_on_project_id", using: :btree
create_table "project_statistics", force: :cascade do |t| create_table "project_statistics", force: :cascade do |t|
t.integer "project_id", null: false t.integer "project_id", null: false
t.integer "namespace_id", null: false t.integer "namespace_id", null: false
...@@ -2200,7 +2192,6 @@ ...@@ -2200,7 +2192,6 @@
add_foreign_key "project_features", "projects", name: "fk_18513d9b92", on_delete: :cascade add_foreign_key "project_features", "projects", name: "fk_18513d9b92", on_delete: :cascade
add_foreign_key "project_group_links", "projects", name: "fk_daa8cee94c", on_delete: :cascade add_foreign_key "project_group_links", "projects", name: "fk_daa8cee94c", on_delete: :cascade
add_foreign_key "project_import_data", "projects", name: "fk_ffb9ee3a10", on_delete: :cascade add_foreign_key "project_import_data", "projects", name: "fk_ffb9ee3a10", on_delete: :cascade
add_foreign_key "project_settings", "projects", on_delete: :cascade
add_foreign_key "project_statistics", "projects", on_delete: :cascade add_foreign_key "project_statistics", "projects", on_delete: :cascade
add_foreign_key "protected_branch_merge_access_levels", "protected_branches", name: "fk_8a3072ccb3", on_delete: :cascade add_foreign_key "protected_branch_merge_access_levels", "protected_branches", name: "fk_8a3072ccb3", on_delete: :cascade
add_foreign_key "protected_branch_push_access_levels", "protected_branches", name: "fk_9ffc86a3d9", on_delete: :cascade add_foreign_key "protected_branch_push_access_levels", "protected_branches", name: "fk_9ffc86a3d9", on_delete: :cascade
......
...@@ -123,26 +123,6 @@ ...@@ -123,26 +123,6 @@
expect(subject.boards.size).to eq 1 expect(subject.boards.size).to eq 1
end end
end end
describe '#settings' do
it 'creates lazily a settings record when the project does not have one associated' do
project = create :project
expect(ProjectSettings.count).to eq 0
expect(project.settings).to be_a ProjectSettings
expect(ProjectSettings.count).to eq 1
end
it 'returns the associated record when the project has one associated' do
project = create :project, settings: create(:project_settings)
expect(ProjectSettings.count).to eq 1
expect(project.settings).to be_a ProjectSettings
expect(ProjectSettings.count).to eq 1
end
end
end end
describe 'modules' do describe 'modules' do
...@@ -3595,13 +3575,13 @@ def domain_variable ...@@ -3595,13 +3575,13 @@ def domain_variable
end end
end end
describe '#toggle_settings!' do describe '#toggle_ci_cd_settings!' do
it 'toggles the value on #settings' do it 'toggles the value on #settings' do
project = create :project, group_runners_enabled: false project = create :project, group_runners_enabled: false
expect(project.group_runners_enabled).to be false expect(project.group_runners_enabled).to be false
project.toggle_settings!(:group_runners_enabled) project.toggle_ci_cd_settings!(:group_runners_enabled)
expect(project.group_runners_enabled).to be true expect(project.group_runners_enabled).to be true
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