Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
cs_comments_service
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
cs_comments_service
Commits
33ded5c1
Commit
33ded5c1
authored
Jul 29, 2012
by
Rocky Duan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
changed url for api
parent
e364618b
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
8 additions
and
13 deletions
+8
-13
app.rb
+2
-7
spec/api/search_spec.rb
+6
-6
No files found.
app.rb
View file @
33ded5c1
...
@@ -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/t
hreads/t
ags'
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
...
...
spec/api/search_spec.rb
View file @
33ded5c1
...
@@ -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/t
hreads/t
ags"
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/t
hreads/t
ags"
,
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/t
hreads/t
ags"
,
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/t
hreads/t
ags"
,
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/t
hreads/t
ags"
,
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/t
hreads/t
ags"
,
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
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment