Commit 824d1749 authored by Tiger Watson's avatar Tiger Watson

Merge branch 'disable-terms-and-conditions' into 'master'

Add ability to remove and disable terms and conditions

See merge request gitlab-org/gitlab!65007
parents f0861b8f 4df3e5c5
......@@ -3,12 +3,14 @@
class ApplicationSetting
class Term < ApplicationRecord
include CacheMarkdownField
has_many :term_agreements
include NullifyIfBlank
validates :terms, presence: true
has_many :term_agreements
cache_markdown_field :terms
nullify_if_blank :terms
def self.latest
order(:id).last
end
......
......@@ -67,10 +67,8 @@ module ApplicationSettings
end
def update_terms(terms)
return unless terms.present?
# Avoid creating a new terms record if the text is exactly the same.
terms = terms.strip
terms = terms&.strip
return if terms == @application_setting.terms
ApplicationSetting::Term.create(terms: terms)
......
# frozen_string_literal: true
class RemoveNotNullConstraintFromTerms < ActiveRecord::Migration[6.1]
def up
change_column_null :application_setting_terms, :terms, true
end
def down
change_column_null :application_setting_terms, :terms, false
end
end
1367865e22f6129fa69f3c86dc72b88a9af0479a41f2029a446464aeeed9c18e
\ No newline at end of file
......@@ -9215,7 +9215,7 @@ ALTER SEQUENCE appearances_id_seq OWNED BY appearances.id;
CREATE TABLE application_setting_terms (
id integer NOT NULL,
cached_markdown_version integer,
terms text NOT NULL,
terms text,
terms_html text
);
......@@ -3,9 +3,7 @@
require 'spec_helper'
RSpec.describe ApplicationSetting::Term do
describe 'validations' do
it { is_expected.to validate_presence_of(:terms) }
end
it { is_expected.to nullify_if_blank(:terms) }
describe '.latest' do
it 'finds the latest terms' do
......
......@@ -23,8 +23,8 @@ RSpec.describe ApplicationSettings::UpdateService do
context 'when the passed terms are blank' do
let(:params) { { terms: '' } }
it 'does not create terms' do
expect { subject.execute }.not_to change { ApplicationSetting::Term.count }
it 'does create terms' do
expect { subject.execute }.to change { ApplicationSetting::Term.count }.by(1)
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