Fix conflict between normalize and array_attribute macros.

Fix the `normalize` and `array_attribute` macros conflicting with each
other on the WikiPage model. This meant code like
`wiki_page.other_names = "foo bar"` didn't work. Both macros defined a
`other_names=` method, but one method overrode the other.

The fix is to use anonymous modules and prepend so we can chain method
calls with super.
This commit is contained in:
evazion
2021-01-10 00:10:59 -06:00
parent 5962152ee3
commit 0899194f6b
5 changed files with 50 additions and 35 deletions

View File

@@ -101,6 +101,10 @@ class WikiPageTest < ActiveSupport::TestCase
should normalize_attribute(:other_names).from([""]).to(["ABC"])
should normalize_attribute(:other_names).from(["foo", "foo"]).to(["foo"])
should normalize_attribute(:other_names).from(%w[foo*bar baz baz 加賀(艦これ)]).to(%w[foo*bar baz 加賀(艦これ)])
should normalize_attribute(:other_names).from("foo foo").to(["foo"])
should normalize_attribute(:other_names).from("foo bar").to(["foo", "bar"])
should normalize_attribute(:other_names).from("_foo_ Bar").to(["foo", "Bar"])
end
context "during title validation" do