From 3baebcbb41a53d4a251232ee497ddd34b6f38a4e Mon Sep 17 00:00:00 2001 From: albert Date: Tue, 19 Feb 2013 15:42:52 -0500 Subject: [PATCH] fixes #439, fixes dtext tests --- app/models/tag.rb | 18 +++++++++++------- app/views/tags/search.html.erb | 2 +- test/unit/dtext_test.rb | 10 +++++----- 3 files changed, 17 insertions(+), 13 deletions(-) diff --git a/app/models/tag.rb b/app/models/tag.rb index f4d656457..39f07decd 100644 --- a/app/models/tag.rb +++ b/app/models/tag.rb @@ -29,7 +29,7 @@ class Tag < ActiveRecord::Base end def value_for(string) - Danbooru.config.tag_category_mapping[string.downcase] || 0 + Danbooru.config.tag_category_mapping[string.to_s.downcase] || 0 end end @@ -95,26 +95,30 @@ class Tag < ActiveRecord::Base def find_or_create_by_name(name, options = {}) name = normalize_name(name) - category = categories.general + category = nil if name =~ /\A(#{categories.regexp}):(.+)\Z/ - category = categories.value_for($1) + category = $1 name = $2 end tag = find_by_name(name) if tag - if category != tag.category - tag.update_column(:category, category) - tag.update_category_cache + if category + category_id = categories.value_for(category) + + if category_id != tag.category + tag.update_column(:category, category_id) + tag.update_category_cache + end end tag else Tag.new.tap do |t| t.name = name - t.category = category + t.category = categories.value_for(category) t.save end end diff --git a/app/views/tags/search.html.erb b/app/views/tags/search.html.erb index 9e5bb28f6..d11aa306a 100644 --- a/app/views/tags/search.html.erb +++ b/app/views/tags/search.html.erb @@ -14,7 +14,7 @@
- <%= select "search", "hide_empty", ["no", "yes"] %> + <%= select "search", "hide_empty", ["yes", "no"] %>
diff --git a/test/unit/dtext_test.rb b/test/unit/dtext_test.rb index 426d5a1dd..7cd654bef 100644 --- a/test/unit/dtext_test.rb +++ b/test/unit/dtext_test.rb @@ -17,11 +17,11 @@ class DTextTest < ActiveSupport::TestCase end def test_spoilers - assert_equal("

this is an inline spoiler.

", p("this is [spoiler]an inline spoiler[/spoiler].")) - assert_equal("

this is


a block spoiler

[/spoiler].

", p("this is\n\n[spoiler]\na block spoiler\n[/spoiler].")) - assert_equal("

this is a spoiler with no closing tag

new text

", p("[spoiler]this is a spoiler with no closing tag\n\nnew text")) - assert_equal("

this is a spoiler with no closing tag
new text

", p("[spoiler]this is a spoiler with no closing tag\nnew text")) - assert_equal("

this is a nested[/spoiler] spoiler[/spoiler]

", p("[spoiler]this is [spoiler]a nested[/spoiler] spoiler[/spoiler]")) + assert_equal("

this is

an inline spoiler

.

", p("this is [spoiler]an inline spoiler[/spoiler].")) + assert_equal("

this is

a block spoiler

.

", p("this is\n\n[spoiler]\na block spoiler\n[/spoiler].")) + assert_equal("
\n

this is a spoiler with no closing tag

\n

new text

\n
", p("[spoiler]this is a spoiler with no closing tag\n\nnew text")) + assert_equal("

this is a spoiler with no closing tag
new text

", p("[spoiler]this is a spoiler with no closing tag\nnew text")) + assert_equal("
\n

this is

\n

a nested

\n

spoiler

\n
", p("[spoiler]this is [spoiler]a nested[/spoiler] spoiler[/spoiler]")) end def test_paragraphs