Commit 5b55bfdc authored by Heinrich Lee Yu's avatar Heinrich Lee Yu

Validate roadmap_epics_state

parent 535e403c
......@@ -51,3 +51,5 @@ class UserPreference < ActiveRecord::Base
"#{field_key}_notes_filter"
end
end
UserPreference.prepend(EE::UserPreference)
......@@ -38,10 +38,11 @@ module Groups
return unless current_user
preference = current_user.user_preference
state_id = Epic.states[params[:state]]
if params[:state].present? && state_id != preference.roadmap_epics_state
preference.update(roadmap_epics_state: state_id)
if params[:state].present?
preference.roadmap_epics_state = Epic.states[params[:state]]
preference.save if preference.changed? && Gitlab::Database.read_write?
end
Epic.states.key(preference.roadmap_epics_state)
......
module EE
module UserPreference
extend ActiveSupport::Concern
prepended do
validates :roadmap_epics_state, allow_nil: true, inclusion: {
in: ::Epic.states.values, message: "%{value} is not a valid epic state"
}
end
end
end
require 'spec_helper'
describe UserPreference do
let(:user_preference) { create(:user_preference) }
shared_examples 'updates roadmap_epics_state' do |state|
it 'saves roadmap_epics_state in user_preference' do
user_preference.update(roadmap_epics_state: state)
expect(user_preference.reload.roadmap_epics_state).to eq(state)
end
end
describe 'roadmap_epics_state' do
context 'when set to open epics' do
it_behaves_like 'updates roadmap_epics_state', Epic.states[:opened]
end
context 'when set to closed epics' do
it_behaves_like 'updates roadmap_epics_state', Epic.states[:closed]
end
context 'when reset to all epics' do
it_behaves_like 'updates roadmap_epics_state', nil
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