Commit 33ded5c1 by Rocky Duan

changed url for api

parent e364618b
...@@ -129,12 +129,7 @@ delete '/api/v1/users/:user_id/subscriptions' do |user_id| ...@@ -129,12 +129,7 @@ delete '/api/v1/users/:user_id/subscriptions' do |user_id|
user.unsubscribe(source).to_hash.to_json user.unsubscribe(source).to_hash.to_json
end end
# GET /api/v1/search get '/api/v1/search/threads' do
# params:
# text: text to search for
# commentable_id: search within a commentable
#
get '/api/v1/search' do
if params["text"] if params["text"]
CommentThread.solr_search do CommentThread.solr_search do
fulltext(params["text"]) fulltext(params["text"])
...@@ -147,7 +142,7 @@ get '/api/v1/search' do ...@@ -147,7 +142,7 @@ get '/api/v1/search' do
end end
end end
post '/api/v1/search/tags' do post '/api/v1/search/threads/tags' do
CommentThread.tagged_with_all(params["tags"]).map(&:to_hash).to_json CommentThread.tagged_with_all(params["tags"]).map(&:to_hash).to_json
end end
......
...@@ -3,7 +3,7 @@ require 'spec_helper' ...@@ -3,7 +3,7 @@ require 'spec_helper'
describe "app" do describe "app" do
describe "search" do describe "search" do
before(:each) { init_without_subscriptions } before(:each) { init_without_subscriptions }
describe "GET /api/v1/search/tags" do describe "GET /api/v1/search/threads/tags" do
it "returns all threads tagged with all tags" do it "returns all threads tagged with all tags" do
require 'uri' require 'uri'
thread1 = CommentThread.all.to_a.first thread1 = CommentThread.all.to_a.first
...@@ -18,33 +18,33 @@ describe "app" do ...@@ -18,33 +18,33 @@ describe "app" do
thread2.tags = [ai, ml, random2].join "," thread2.tags = [ai, ml, random2].join ","
thread2.save thread2.save
post "/api/v1/search/tags", tags: [ai, ml] post "/api/v1/search/threads/tags", tags: [ai, ml]
last_response.should be_ok last_response.should be_ok
threads = parse last_response.body threads = parse last_response.body
threads.length.should == 2 threads.length.should == 2
threads.select{|t| t["id"] == thread1.id.to_s}.first.should_not be_nil threads.select{|t| t["id"] == thread1.id.to_s}.first.should_not be_nil
threads.select{|t| t["id"] == thread2.id.to_s}.first.should_not be_nil threads.select{|t| t["id"] == thread2.id.to_s}.first.should_not be_nil
post "/api/v1/search/tags", tags: [ai] post "/api/v1/search/threads/tags", tags: [ai]
last_response.should be_ok last_response.should be_ok
threads = parse last_response.body threads = parse last_response.body
threads.length.should == 2 threads.length.should == 2
threads.select{|t| t["id"] == thread1.id.to_s}.first.should_not be_nil threads.select{|t| t["id"] == thread1.id.to_s}.first.should_not be_nil
threads.select{|t| t["id"] == thread2.id.to_s}.first.should_not be_nil threads.select{|t| t["id"] == thread2.id.to_s}.first.should_not be_nil
post "/api/v1/search/tags", tags: [ai, random1] post "/api/v1/search/threads/tags", tags: [ai, random1]
last_response.should be_ok last_response.should be_ok
threads = parse last_response.body threads = parse last_response.body
threads.length.should == 1 threads.length.should == 1
threads.select{|t| t["id"] == thread1.id.to_s}.first.should_not be_nil threads.select{|t| t["id"] == thread1.id.to_s}.first.should_not be_nil
post "/api/v1/search/tags", tags: [random1] post "/api/v1/search/threads/tags", tags: [random1]
last_response.should be_ok last_response.should be_ok
threads = parse last_response.body threads = parse last_response.body
threads.length.should == 1 threads.length.should == 1
threads.select{|t| t["id"] == thread1.id.to_s}.first.should_not be_nil threads.select{|t| t["id"] == thread1.id.to_s}.first.should_not be_nil
post "/api/v1/search/tags", tags: [random1, random2] post "/api/v1/search/threads/tags", tags: [random1, random2]
last_response.should be_ok last_response.should be_ok
threads = parse last_response.body threads = parse last_response.body
threads.length.should == 0 threads.length.should == 0
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment