Skip to content

Commit

Permalink
Fix User_cleanup_Job (#510)
Browse files Browse the repository at this point in the history
* Intial commit

* Fixed tests & fixed shema.rb

* Fixed tests v2
  • Loading branch information
lodewiges authored Mar 3, 2025
1 parent 488c3e8 commit 7f63d81
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
2 changes: 1 addition & 1 deletion app/models/form/response.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def destroyable?
end

def form_allows_responses?
return true if form.try(:allows_responses?)
return true if form.try(:allows_responses?) || user_id&.zero?

errors.add(:form, 'does not allow responses')
false
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
class RemoveUniqueIndexFromFormResponses < ActiveRecord::Migration[7.0]
def change
reversible do |dir|
dir.up do
remove_index :form_responses, name: 'index_form_responses_on_form_id_and_user_id'

add_index :form_responses, %i[form_id user_id],
unique: true,
name: 'index_form_responses_on_form_id_and_user_id_partial',
where: 'user_id != 0'
end

dir.down do
remove_index :form_responses, name: 'index_form_responses_on_form_id_and_user_id_partial'

add_index :form_responses, %i[form_id user_id],
unique: true,
name: 'index_form_responses_on_form_id_and_user_id'
end
end
end
end
4 changes: 2 additions & 2 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

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

Expand Down Expand Up @@ -229,7 +229,7 @@
t.datetime "updated_at", precision: nil, null: false
t.boolean "completed", default: false, null: false
t.integer "lock_version"
t.index ["form_id", "user_id"], name: "index_form_responses_on_form_id_and_user_id", unique: true
t.index ["form_id", "user_id"], name: "index_form_responses_on_form_id_and_user_id_partial", unique: true, where: "(user_id <> 0)"
t.index ["user_id"], name: "index_form_responses_on_user_id"
end

Expand Down

0 comments on commit 7f63d81

Please # to comment.