Skip to content

Commit

Permalink
[#117] Limit locker application department field length to 70
Browse files Browse the repository at this point in the history
  • Loading branch information
sandbergja committed Aug 9, 2024
1 parent 76011a5 commit 50e7367
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 4 deletions.
2 changes: 2 additions & 0 deletions app/models/locker_application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ class LockerApplication < ApplicationRecord
.where('locker_assignments.locker_application_id = locker_applications.id'))
}

validates :department_at_application, length: { maximum: 70 }

def self.awaiting_assignment
where(complete: true).where.missing(:locker_assignment).order('locker_applications.created_at')
end
Expand Down
3 changes: 2 additions & 1 deletion app/views/locker_applications/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@
<grid-item columns="lg-6 md-6 sm-12">
<input-text id="locker_application_department_at_application"
name="locker_application[department_at_application]"
value="<%= locker_application.department_at_application %>"
value="<%= locker_application.department_at_application %>"
maxlength="70"
label="Department" width="expand"></input-text>
</grid-item>

Expand Down
12 changes: 12 additions & 0 deletions db/migrate/20240809225155_department_character_limit.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
class DepartmentCharacterLimit < ActiveRecord::Migration[7.0]
def up
LockerApplication.where('LENGTH(department_at_application) > 70').each do |application|
application.update(department_at_application: application.department_at_application.truncate(70, separator: /\s/))
end
change_column :locker_applications, :department_at_application, :string, limit: 70
end

def down
change_column :locker_applications, :department_at_application, :string
end
end
6 changes: 3 additions & 3 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: 2023_03_07_153224) do
ActiveRecord::Schema[7.0].define(version: 2024_08_09_225155) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"

Expand All @@ -35,13 +35,13 @@
t.boolean "accessible"
t.string "semester"
t.string "status_at_application"
t.string "department_at_application"
t.string "department_at_application", limit: 70
t.bigint "user_id"
t.datetime "created_at", precision: nil, null: false
t.datetime "updated_at", precision: nil, null: false
t.boolean "archived", default: false
t.bigint "building_id", default: 1
t.boolean "complete", default: false
t.boolean "archived", default: false
t.text "accessibility_needs", default: [], array: true
t.index ["building_id"], name: "index_locker_applications_on_building_id"
t.index ["user_id"], name: "index_locker_applications_on_user_id"
Expand Down
5 changes: 5 additions & 0 deletions spec/views/locker_applications/edit.html.erb_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@
end
end

it 'limits the length of the department field to 70' do
render
assert_select '#locker_application_department_at_application[maxlength="70"]'
end

context 'with an administrative user' do
let(:user) { FactoryBot.create(:user, :admin) }

Expand Down

0 comments on commit 50e7367

Please sign in to comment.