Skip to content

Commit

Permalink
AO3-6587 Allow # as initial character in Ticket ID Field when editing…
Browse files Browse the repository at this point in the history
… a profile or pseud (#4991)

* AO3-6587 Allow inclusion of the # in Ticket ID field when editing a profile or pseud

* AO3-6587 Fix justifiable spec, cucumber feature and Rubocop style guidance

* AO3-6587 Fix justifiable spec, cucumber feature and Rubocop style guidance

* AO3-6587 Fix additional Rubocop concern about my hamfisted coding skillz

* AO3-6587 New line after guard clause...

* AO3-6587 Another feature test update

* AO3-6587 Add in i188n and remove locale strings

* AO3-6587 Fixing i18n locale location

* AO3-6587 Fixing i18n locale location

* AO3-6587 Fixing i18n locale location
  • Loading branch information
scottsds authored Jan 22, 2025
1 parent f545651 commit 751d70f
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 12 deletions.
11 changes: 10 additions & 1 deletion app/models/concerns/justifiable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,25 @@ module Justifiable
attr_accessor :ticket_number
attr_reader :ticket_url

before_validation :strip_octothorpe
validates :ticket_number,
presence: true,
numericality: { only_integer: true },
# i18n-tasks-use t("activerecord.errors.messages.numeric_with_optional_hash")
numericality: { only_integer: true,
message: :numeric_with_optional_hash },
if: :enabled?

validate :ticket_number_exists_in_tracker, if: :enabled?
end

private

def strip_octothorpe
return if ticket_number.is_a?(Integer)

self.ticket_number = self.ticket_number.delete_prefix("#") unless self.ticket_number.nil?
end

def enabled?
# Only require a ticket if the record has been changed by an admin.
User.current_user.is_a?(Admin) && changed?
Expand Down
2 changes: 0 additions & 2 deletions app/views/pseuds/_pseuds_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,6 @@
<dt><%= f.label :ticket_number, class: "required" %></dt>
<dd>
<%= f.text_field :ticket_number, class: "required" %>
<%= live_validation_for_field("pseud_ticket_number", numericality: true) %>
<p class="footnote"><%= t(".ticket_footnote") %></p>
</dd>
<% end %>

Expand Down
2 changes: 0 additions & 2 deletions app/views/users/edit.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@
<dt><%= p.label :ticket_number, class: "required" %></dt>
<dd>
<%= p.text_field :ticket_number, class: "required" %>
<%= live_validation_for_field("profile_attributes_ticket_number", numericality: true) %>
<p class="footnote"><%= t(".admin.ticket_number.numbers_only") %></p>
</dd>
<% end %>

Expand Down
1 change: 1 addition & 0 deletions config/locales/models/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ en:
errors:
messages:
forbidden: "%{value} is not allowed"
numeric_with_optional_hash: 'may begin with an # and otherwise contain only numbers.'
models:
abuse_report:
attributes:
Expand Down
4 changes: 0 additions & 4 deletions config/locales/views/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1598,7 +1598,6 @@ en:
make_default: Make this name default
name: Name
submit: Submit
ticket_footnote: Numbers only.
skins:
confirm_delete:
confirm_html: Are you sure you want to <strong><em>delete</em></strong> the skin "%{skin_title}"?
Expand Down Expand Up @@ -1748,9 +1747,6 @@ en:
submit: Save
edit:
about_me: About Me
admin:
ticket_number:
numbers_only: Numbers only.
browser_title: Edit Profile
change_profile_landmark: Change Profile
date_of_birth: Date of Birth
Expand Down
2 changes: 1 addition & 1 deletion features/other_a/profile_edit.feature
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ Scenario: Change details as an admin
And I fill in "About Me" with "is it merely thy habit, to talk to dolls?"
And I fill in "Ticket ID" with "fine"
And I press "Update"
Then I should see "Ticket ID is not a number"
Then I should see "may begin with an # and otherwise contain only numbers."
And the field labeled "Ticket ID" should contain "fine"
When I fill in "Ticket ID" with "480000"
And I press "Update"
Expand Down
11 changes: 10 additions & 1 deletion features/other_a/pseuds.feature
Original file line number Diff line number Diff line change
Expand Up @@ -263,9 +263,18 @@ Scenario: Change details as an admin
And I fill in "Description" with "I'd probably be removing text."
And I fill in "Ticket ID" with "no 💜"
And I press "Update"
Then I should see "Ticket ID is not a number"
Then I should see "may begin with an # and otherwise contain only numbers"
And the field labeled "Ticket ID" should contain "no 💜"
When I fill in "Ticket ID" with "#4798454#331"
And I press "Update"
Then I should see "may begin with an # and otherwise contain only numbers"
And the field labeled "Ticket ID" should contain "4798454#331"
When I fill in "Ticket ID" with "47"
And I press "Update"
Then I should see "Pseud was successfully updated."
When I go to someone's pseuds page
And I follow "Edit alt"
When I fill in "Ticket ID" with "#47"
And I press "Update"
Then I should see "Pseud was successfully updated."
When I go to someone's pseuds page
Expand Down
2 changes: 1 addition & 1 deletion spec/models/concerns/justifiable_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

record.assign_attributes(attributes)
expect(record).not_to be_valid
expect(record.errors[:ticket_number]).to contain_exactly("can't be blank", "is not a number")
expect(record.errors[:ticket_number]).to contain_exactly("can't be blank", "may begin with an # and otherwise contain only numbers.")
expect(record.ticket_url).to be_nil
end

Expand Down

0 comments on commit 751d70f

Please sign in to comment.