Skip to content
Browse files

Send section slugs to Rummager, not titles.

Rummager was interpreting the sections sent to it as slugs and trying to
link users to broken section links.
  • Loading branch information...
1 parent a5f8ae2 commit 4c5e902a9fc8bcf48a27e86c1430a95c28e44470 @fatbusinessman fatbusinessman committed Jul 10, 2012
Showing with 29 additions and 5 deletions.
  1. +7 −2 app/models/rummageable_artefact.rb
  2. +22 −3 test/unit/rummageable_artefact_test.rb
View
9 app/models/rummageable_artefact.rb
@@ -55,11 +55,11 @@ def artefact_hash
end
def artefact_section
- @artefact.section.split(":")[0]
+ section_parts[0]
end
def artefact_subsection
- @artefact.section.split(":")[1]
+ section_parts[1]
end
def artefact_format
@@ -73,4 +73,9 @@ def artefact_title
def artefact_link
"/#{@artefact.slug}"
end
+
+private
+ def section_parts
+ (@artefact.primary_section || "").split("/")
+ end
end
View
25 test/unit/rummageable_artefact_test.rb
@@ -60,6 +60,25 @@ class RummageableArtefactTest < ActiveSupport::TestCase
assert_equal expected, RummageableArtefact.new(artefact).artefact_hash
end
+ test "should work with no primary section" do
+ artefact = Artefact.new do |artefact|
+ artefact.name = "My artefact"
+ artefact.slug = "my-artefact"
+ artefact.kind = "guide"
+ artefact.indexable_content = "Blah blah blah index this"
+ artefact.sections = []
+ artefact.primary_section = nil
+ end
+ expected = {
+ "link" => "/my-artefact",
+ "title" => "My artefact",
+ "format" => "guide",
+ "section" => nil,
+ "subsection" => nil,
+ "indexable_content" => "Blah blah blah index this"
+ }
+ end
+
test "should include section information" do
artefact = Artefact.new do |artefact|
artefact.name = "My artefact"
@@ -73,7 +92,7 @@ class RummageableArtefactTest < ActiveSupport::TestCase
"link" => "/my-artefact",
"title" => "My artefact",
"format" => "guide",
- "section" => "Crime",
+ "section" => "crime",
"subsection" => nil,
"indexable_content" => "Blah blah blah index this"
}
@@ -93,8 +112,8 @@ class RummageableArtefactTest < ActiveSupport::TestCase
"link" => "/my-artefact",
"title" => "My artefact",
"format" => "guide",
- "section" => "Crime",
- "subsection" => "Batman",
+ "section" => "crime",
+ "subsection" => "batman",
"indexable_content" => "Blah blah blah index this"
}
assert_equal expected, RummageableArtefact.new(artefact).artefact_hash

0 comments on commit 4c5e902

Please sign in to comment.
Something went wrong with that request. Please try again.