fixes #439, fixes dtext tests

This commit is contained in:
albert
2013-02-19 15:42:52 -05:00
parent 965321a8f4
commit 3baebcbb41
3 changed files with 17 additions and 13 deletions

View File

@@ -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

View File

@@ -14,7 +14,7 @@
<div class="input">
<label for="search_hide_empty">Hide Empty</label>
<%= select "search", "hide_empty", ["no", "yes"] %>
<%= select "search", "hide_empty", ["yes", "no"] %>
</div>
<div class="input">

View File

@@ -17,11 +17,11 @@ class DTextTest < ActiveSupport::TestCase
end
def test_spoilers
assert_equal("<p>this is <span class=\"spoiler\">an inline spoiler</span>.</p>", p("this is [spoiler]an inline spoiler[/spoiler]."))
assert_equal("<p>this is</p><p><span class=\"spoiler\"><br>a block spoiler</span><br>[/spoiler].</p>", p("this is\n\n[spoiler]\na block spoiler\n[/spoiler]."))
assert_equal("<p><span class=\"spoiler\">this is a spoiler with no closing tag</span></p><p>new text</p>", p("[spoiler]this is a spoiler with no closing tag\n\nnew text"))
assert_equal("<p><span class=\"spoiler\">this is a spoiler with no closing tag</span><br>new text</p>", p("[spoiler]this is a spoiler with no closing tag\nnew text"))
assert_equal("<p><span class=\"spoiler\">this is </span>a nested[/spoiler] spoiler[/spoiler]</p>", p("[spoiler]this is [spoiler]a nested[/spoiler] spoiler[/spoiler]"))
assert_equal("<p>this is</p><div class=\"spoiler\"><p>an inline spoiler</p></div><p>.</p>", p("this is [spoiler]an inline spoiler[/spoiler]."))
assert_equal("<p>this is</p><div class=\"spoiler\"><p>a block spoiler</p></div><p>.</p>", p("this is\n\n[spoiler]\na block spoiler\n[/spoiler]."))
assert_equal("<div class=\"spoiler\">\n<p>this is a spoiler with no closing tag</p>\n<p>new text</p>\n</div>", p("[spoiler]this is a spoiler with no closing tag\n\nnew text"))
assert_equal("<div class=\"spoiler\"><p>this is a spoiler with no closing tag<br>new text</p></div>", p("[spoiler]this is a spoiler with no closing tag\nnew text"))
assert_equal("<div class=\"spoiler\">\n<p>this is</p>\n<div class=\"spoiler\"><p>a nested</p></div>\n<p>spoiler</p>\n</div>", p("[spoiler]this is [spoiler]a nested[/spoiler] spoiler[/spoiler]"))
end
def test_paragraphs