summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFelipe Artur <felipefac@gmail.com>2019-02-14 14:24:23 -0200
committerFelipe Artur <felipefac@gmail.com>2019-02-14 14:24:23 -0200
commitd4a5d8d07069acb6f068990633baaf56d20bc18b (patch)
tree1003bf9a5c6f8f5c0feb3c4ab6c5eb57be584c15
parent37741c59a4daf1b0d6d9f7a6a51337e9d8effb66 (diff)
downloadgitlab-ce-d4a5d8d07069acb6f068990633baaf56d20bc18b.tar.gz
Add specs for issuable states sync
-rw-r--r--app/models/concerns/issuable_states.rb1
-rw-r--r--spec/models/concerns/issuable_states_spec.rb30
2 files changed, 31 insertions, 0 deletions
diff --git a/app/models/concerns/issuable_states.rb b/app/models/concerns/issuable_states.rb
index d7992f8e6db..a39a0ef77ed 100644
--- a/app/models/concerns/issuable_states.rb
+++ b/app/models/concerns/issuable_states.rb
@@ -4,6 +4,7 @@ module IssuableStates
# 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
# 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
before_save :set_state_id
end
diff --git a/spec/models/concerns/issuable_states_spec.rb b/spec/models/concerns/issuable_states_spec.rb
new file mode 100644
index 00000000000..70450159cc0
--- /dev/null
+++ b/spec/models/concerns/issuable_states_spec.rb
@@ -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