Skip to content

Commit 7f63d81

Browse files
authored
Fix User_cleanup_Job (#510)
* Intial commit * Fixed tests & fixed shema.rb * Fixed tests v2
1 parent 488c3e8 commit 7f63d81

3 files changed

Lines changed: 25 additions & 3 deletions

File tree

app/models/form/response.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def destroyable?
4040
end
4141

4242
def form_allows_responses?
43-
return true if form.try(:allows_responses?)
43+
return true if form.try(:allows_responses?) || user_id&.zero?
4444

4545
errors.add(:form, 'does not allow responses')
4646
false
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
class RemoveUniqueIndexFromFormResponses < ActiveRecord::Migration[7.0]
2+
def change
3+
reversible do |dir|
4+
dir.up do
5+
remove_index :form_responses, name: 'index_form_responses_on_form_id_and_user_id'
6+
7+
add_index :form_responses, %i[form_id user_id],
8+
unique: true,
9+
name: 'index_form_responses_on_form_id_and_user_id_partial',
10+
where: 'user_id != 0'
11+
end
12+
13+
dir.down do
14+
remove_index :form_responses, name: 'index_form_responses_on_form_id_and_user_id_partial'
15+
16+
add_index :form_responses, %i[form_id user_id],
17+
unique: true,
18+
name: 'index_form_responses_on_form_id_and_user_id'
19+
end
20+
end
21+
end
22+
end

db/schema.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#
1111
# It's strongly recommended that you check this file into your version control system.
1212

13-
ActiveRecord::Schema[7.0].define(version: 2025_02_18_204807) do
13+
ActiveRecord::Schema[7.0].define(version: 2025_02_19_195453) do
1414
# These are extensions that must be enabled in order to support this database
1515
enable_extension "plpgsql"
1616

@@ -229,7 +229,7 @@
229229
t.datetime "updated_at", precision: nil, null: false
230230
t.boolean "completed", default: false, null: false
231231
t.integer "lock_version"
232-
t.index ["form_id", "user_id"], name: "index_form_responses_on_form_id_and_user_id", unique: true
232+
t.index ["form_id", "user_id"], name: "index_form_responses_on_form_id_and_user_id_partial", unique: true, where: "(user_id <> 0)"
233233
t.index ["user_id"], name: "index_form_responses_on_user_id"
234234
end
235235

0 commit comments

Comments
 (0)