Add specs for issuable states sync
This commit is contained in:
parent
37741c59a4
commit
d4a5d8d070
2 changed files with 31 additions and 0 deletions
|
@ -4,6 +4,7 @@ module IssuableStates
|
||||||
# The state:string column is being migrated to state_id:integer column
|
# The state:string column is being migrated to state_id:integer column
|
||||||
# This is a temporary hook to populate state_id column with new values
|
# This is a temporary hook to populate state_id column with new values
|
||||||
# and can be removed after the state column is removed.
|
# and can be removed after the state column is removed.
|
||||||
|
# Check https://gitlab.com/gitlab-org/gitlab-ce/issues/51789 for more information
|
||||||
included do
|
included do
|
||||||
before_save :set_state_id
|
before_save :set_state_id
|
||||||
end
|
end
|
||||||
|
|
30
spec/models/concerns/issuable_states_spec.rb
Normal file
30
spec/models/concerns/issuable_states_spec.rb
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
require 'spec_helper'
|
||||||
|
|
||||||
|
# This spec checks if state_id column of issues and merge requests
|
||||||
|
# are being synced on every save.
|
||||||
|
# It can be removed in the next release. Check https://gitlab.com/gitlab-org/gitlab-ce/issues/51789 for more information.
|
||||||
|
describe IssuableStates do
|
||||||
|
[Issue, MergeRequest].each do |klass|
|
||||||
|
it "syncs state_id column when #{klass.model_name.human} gets created" do
|
||||||
|
klass.available_states.each do |state, state_id|
|
||||||
|
issuable = build(klass.model_name.param_key, state: state.to_s)
|
||||||
|
|
||||||
|
issuable.save!
|
||||||
|
|
||||||
|
expect(issuable.state_id).to eq(state_id)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
it "syncs state_id column when #{klass.model_name.human} gets updated" do
|
||||||
|
klass.available_states.each do |state, state_id|
|
||||||
|
issuable = create(klass.model_name.param_key, state: state.to_s)
|
||||||
|
|
||||||
|
issuable.update(state: state)
|
||||||
|
|
||||||
|
expect(issuable.state_id).to eq(state_id)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in a new issue