Permalink
Browse files

Allowing filtering of tags by type (eg. Section)

As we look at sharing lists of topics, sections, etc. between Inside
Government and Mainstream we will want to be able to quickly access a
list of tags of a given type.

GET /tags.json will still return all tags (at least until we paginate
the list)
GET /tags.json?type=section will return all section tags

We considered the fact that we use 'tag_type' in some places and 'type'
here but decided not to change that yet as there are implications for
how inheritance works that are too significant to dig into here. 'type'
would clash with rails (activerecord/mongoid) STI implementation.
  • Loading branch information...
1 parent f8e2dd9 commit 6e2e81901cdcf66a762b74a50dcb6a12deb756f5 @heathd heathd committed Jun 21, 2012
Showing with 12 additions and 2 deletions.
  1. +1 −2 app/controllers/tags_controller.rb
  2. +11 −0 test/functional/tags_controller_test.rb
@@ -2,8 +2,7 @@ class TagsController < ApplicationController
respond_to :json
def index
- @tags = TagRepository.load_all
- # TODO: links: [next_page, prev_page]
+ @tags = TagRepository.load_all(tag_type: params[:type])
respond_with(status: 'ok', total: @tags.count, from: 0, to: @tags.count - 1,
pagesize: @tags.count, results: @tags)
end
@@ -37,4 +37,15 @@ class TagsControllerTest < ActionController::TestCase
end
end
+ context "GET /tags?type=X" do
+ should "return only tags of a particular type" do
+ TagRepository.put(tag_id: "minister-of-silly", title: "Minister of Silly", tag_type: "role")
+ get :index, format: "json", type: "section"
+ parsed = JSON.parse(response.body)
+ assert_equal 2, parsed["results"].count
+ refute parsed["results"].any? { |result| result["id"] == "minister-of-silly" }
+ end
+ end
+
+
end

0 comments on commit 6e2e819

Please sign in to comment.