Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AO3-6587 Allow # as initial character in Ticket ID Field when editing a profile or pseud #4991

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open
10 changes: 9 additions & 1 deletion app/models/concerns/justifiable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,24 @@ module Justifiable
attr_accessor :ticket_number
attr_reader :ticket_url

before_validation :strip_octothorpe
validates :ticket_number,
presence: true,
numericality: { only_integer: true },
numericality: { only_integer: true,
message: :numeric_with_optional_hash },
scottsds marked this conversation as resolved.
Show resolved Hide resolved
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>
scottsds marked this conversation as resolved.
Show resolved Hide resolved
</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 @@ -94,6 +94,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 @@ -1594,7 +1594,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 @@ -1744,9 +1743,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
Loading