Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions app/models/study/metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,11 @@ def delayed_for_long_time?
if: :data_release_timing_must_be_never?

def data_release_timing_must_be_never?
Flipper.enabled?(:y24_052_enable_data_release_timing_validation) && data_release_strategy.present? &&
strategy_not_applicable?
data_release_strategy.present? && strategy_not_applicable?
end

def data_release_timing_must_not_be_never?
Flipper.enabled?(:y24_052_enable_data_release_timing_validation) && data_release_strategy.present? &&
!strategy_not_applicable?
data_release_strategy.present? && !strategy_not_applicable?
end

def sanity_check_y_separation
Expand Down
2 changes: 0 additions & 2 deletions config/feature_flags.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,3 @@
# dpl202_enable_angry_cat_feature: When enabled this will add an angry cat to all pages that will try to catch the mouse pointer
# The key should be lower case and snake case, and prefixed with the issue number to allow easy identification
dpl_395_2_enable_advanced_search_tab: Shows the Search tab in the top navigation bar
# Below is flagged off until some existing data that would violate the rule is fixed. Should be re-enabled in Y24-058.
y24_052_enable_data_release_timing_validation: Enables server-side validation that enforces a relationship between the values of two study metadata fields
157 changes: 41 additions & 116 deletions spec/models/study_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -629,28 +629,12 @@
expect(study.study_metadata.dac_policy_title).to eq(metadata[:dac_policy_title])
end

context 'when the data_release_timing validation is switched on' do
before { Flipper.enable :y24_052_enable_data_release_timing_validation }

it 'errors if the data_release_timing is invalid' do
study.study_metadata.data_release_timing = 'never'
expect { study.save! }.to raise_error(
ActiveRecord::RecordInvalid,
/Study metadata data release timing is not included in the list/
)
end
end

context 'when the data_release_timing validation is switched off' do
before { Flipper.disable :y24_052_enable_data_release_timing_validation }

it 'does not error if the data_release_timing is invalid' do
study.study_metadata.data_release_timing = 'never'
expect { study.save! }.not_to raise_error(
ActiveRecord::RecordInvalid,
/Study metadata data release timing is not included in the list/
)
end
it 'errors if the data_release_timing is invalid' do
study.study_metadata.data_release_timing = 'never'
expect { study.save! }.to raise_error(
ActiveRecord::RecordInvalid,
/Study metadata data release timing is not included in the list/
)
end
end

Expand All @@ -663,28 +647,12 @@
)
end

context 'when the data_release_timing validation is switched on' do
before { Flipper.enable :y24_052_enable_data_release_timing_validation }

it 'errors if the data_release_timing is invalid' do
study.study_metadata.data_release_timing = Study::DATA_RELEASE_TIMING_NEVER
expect { study.save! }.to raise_error(
ActiveRecord::RecordInvalid,
/Study metadata data release timing is not included in the list/
)
end
end

context 'when the data_release_timing validation is switched off' do
before { Flipper.disable :y24_052_enable_data_release_timing_validation }

it 'does not error if the data_release_timing is invalid' do
study.study_metadata.data_release_timing = Study::DATA_RELEASE_TIMING_NEVER
expect { study.save! }.not_to raise_error(
ActiveRecord::RecordInvalid,
/Study metadata data release timing is not included in the list/
)
end
it 'errors if the data_release_timing is invalid' do
study.study_metadata.data_release_timing = Study::DATA_RELEASE_TIMING_NEVER
expect { study.save! }.to raise_error(
ActiveRecord::RecordInvalid,
/Study metadata data release timing is not included in the list/
)
end
end

Expand Down Expand Up @@ -760,82 +728,39 @@
)
end

context 'when the data_release_timing validation is switched on' do
before { Flipper.enable :y24_052_enable_data_release_timing_validation }

it 'errors if the data_release_timing is standard' do
study.study_metadata.data_release_timing = Study::DATA_RELEASE_TIMING_STANDARD
expect { study.save! }.to raise_error(
ActiveRecord::RecordInvalid,
/Study metadata data release timing is not included in the list/
)
end

it 'errors if the data_release_timing is immediate' do
study.study_metadata.data_release_timing = Study::DATA_RELEASE_TIMING_IMMEDIATE
expect { study.save! }.to raise_error(
ActiveRecord::RecordInvalid,
/Study metadata data release timing is not included in the list/
)
end

it 'errors if the data_release_timing is delayed' do
study.study_metadata.data_release_timing = Study::DATA_RELEASE_TIMING_DELAYED
study.study_metadata.data_release_delay_reason = Study::DATA_RELEASE_DELAY_REASONS_STANDARD[0]
study.study_metadata.data_release_delay_period = Study::DATA_RELEASE_DELAY_PERIODS[0]
study.study_metadata.data_release_delay_approval = Study::YES
expect { study.save! }.to raise_error(
ActiveRecord::RecordInvalid,
/Study metadata data release timing is not included in the list/
)
end

it 'is valid if the data_release_timing is never' do
study.study_metadata.data_release_timing = Study::DATA_RELEASE_TIMING_NEVER
expect { study.save! }.not_to raise_error(
ActiveRecord::RecordInvalid,
/Study metadata data release timing is not included in the list/
)
end
it 'errors if the data_release_timing is standard' do
study.study_metadata.data_release_timing = Study::DATA_RELEASE_TIMING_STANDARD
expect { study.save! }.to raise_error(
ActiveRecord::RecordInvalid,
/Study metadata data release timing is not included in the list/
)
end

context 'when the data_release_timing validation is switched off' do
before { Flipper.disable :y24_052_enable_data_release_timing_validation }

it 'does not error if the data_release_timing is standard' do
study.study_metadata.data_release_timing = Study::DATA_RELEASE_TIMING_STANDARD
expect { study.save! }.not_to raise_error(
ActiveRecord::RecordInvalid,
/Study metadata data release timing is not included in the list/
)
end

it 'does not error if the data_release_timing is immediate' do
study.study_metadata.data_release_timing = Study::DATA_RELEASE_TIMING_IMMEDIATE
expect { study.save! }.not_to raise_error(
ActiveRecord::RecordInvalid,
/Study metadata data release timing is not included in the list/
)
end
it 'errors if the data_release_timing is immediate' do
study.study_metadata.data_release_timing = Study::DATA_RELEASE_TIMING_IMMEDIATE
expect { study.save! }.to raise_error(
ActiveRecord::RecordInvalid,
/Study metadata data release timing is not included in the list/
)
end

it 'does not error if the data_release_timing is delayed' do
study.study_metadata.data_release_timing = Study::DATA_RELEASE_TIMING_DELAYED
study.study_metadata.data_release_delay_reason = Study::DATA_RELEASE_DELAY_REASONS_STANDARD[0]
study.study_metadata.data_release_delay_period = Study::DATA_RELEASE_DELAY_PERIODS[0]
study.study_metadata.data_release_delay_approval = Study::YES
expect { study.save! }.not_to raise_error(
ActiveRecord::RecordInvalid,
/Study metadata data release timing is not included in the list/
)
end
it 'errors if the data_release_timing is delayed' do
study.study_metadata.data_release_timing = Study::DATA_RELEASE_TIMING_DELAYED
study.study_metadata.data_release_delay_reason = Study::DATA_RELEASE_DELAY_REASONS_STANDARD[0]
study.study_metadata.data_release_delay_period = Study::DATA_RELEASE_DELAY_PERIODS[0]
study.study_metadata.data_release_delay_approval = Study::YES
expect { study.save! }.to raise_error(
ActiveRecord::RecordInvalid,
/Study metadata data release timing is not included in the list/
)
end

it 'is still valid if the data_release_timing is never' do
study.study_metadata.data_release_timing = Study::DATA_RELEASE_TIMING_NEVER
expect { study.save! }.not_to raise_error(
ActiveRecord::RecordInvalid,
/Study metadata data release timing is not included in the list/
)
end
it 'is valid if the data_release_timing is never' do
study.study_metadata.data_release_timing = Study::DATA_RELEASE_TIMING_NEVER
expect { study.save! }.not_to raise_error(
ActiveRecord::RecordInvalid,
/Study metadata data release timing is not included in the list/
)
end
end
end
Expand Down