search_test.rb
2.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
require File.dirname(__FILE__) + '/test_helper'
class SearchTest < ActiveSupport::TestCase
def create_article_with_optional_category(name, profile, category = nil)
fast_create(Article, {:name => name, :profile_id => profile.id }, :search => true, :category => category)
end
should 'not list unpublished articles' do
person = fast_create(Person)
article = fast_create(Article, :profile_id => person.id, :name => "Some thing", :published => false)
assert !article.published?
get "/api/v1/search/article"
json = JSON.parse(last_response.body)
assert_empty json['results']
end
should 'list articles' do
person = fast_create(Person)
art = create_article_with_optional_category('an article to be found', person)
get "/api/v1/search/article"
json = JSON.parse(last_response.body)
assert_not_empty json['results']
end
should 'invalid search string articles' do
person = fast_create(Person)
art = create_article_with_optional_category('an article to be found', person)
get "/api/v1/search/article?query=test"
json = JSON.parse(last_response.body)
assert_empty json['results']
end
should 'do not list articles of wrong type' do
person = fast_create(Person)
art = create_article_with_optional_category('an article to be found', person)
get "/api/v1/search/article?type=TinyMceArticle"
json = JSON.parse(last_response.body)
assert_empty json['results']
end
should 'list articles of one type' do
person = fast_create(Person)
art = create_article_with_optional_category('an article to be found', person)
article = fast_create(TinyMceArticle, :profile_id => person.id, :name => "Some thing", :published => true)
get "/api/v1/search/article?type=TinyMceArticle"
json = JSON.parse(last_response.body)
assert_equal 1, json['results'].size
end
should 'list articles of one type and query string' do
person = fast_create(Person)
art = create_article_with_optional_category('an article to be found', person)
art1 = create_article_with_optional_category('article for query', person)
article = fast_create(TinyMceArticle, :profile_id => person.id, :name => "Some thing", :published => true)
get "/api/v1/search/article?type=TinyMceArticle&query=thing"
json = JSON.parse(last_response.body)
assert_equal 1, json['results'].size
end
end