Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 89 lines (74 sloc) 2.604 kB
78c39ae @adelevie test queries!
authored
1 require 'helper'
2
3 Parse.init
4
5 class TestQuery < Test::Unit::TestCase
fd7d50d @adelevie testing basic queries
authored
6
7 def test_get
58b7da6 @adelevie using VCR for most tests
authored
8 VCR.use_cassette('test_get', :record => :new_episodes) do
9 post = Parse::Object.new "Post"
10 post["title"] = "foo"
11 post.save
fd7d50d @adelevie testing basic queries
authored
12
58b7da6 @adelevie using VCR for most tests
authored
13 q = Parse.get("Post", post.id)
fd7d50d @adelevie testing basic queries
authored
14
58b7da6 @adelevie using VCR for most tests
authored
15 assert_equal q.id, post.id
16 assert_equal q["title"], post["title"]
17 end
fd7d50d @adelevie testing basic queries
authored
18 end
19
78c39ae @adelevie test queries!
authored
20 def test_add_contraint
21 # I know this method *should* be private.
22 # But then it would be a PITA to test.
23 # I'd rather test this one method than pointlessly test many others.
24 # Thus is life.
25
26 q = Parse::Query.new "TestQuery"
27 q.add_constraint("points", 5)
28 assert_equal q.where["points"], 5
29 q.add_constraint("player", { "$regex" => "regex voodoo"})
30 assert_equal q.where["player"], { "$regex" => "regex voodoo"}
31 end
bca18b6 @ericcj Include skip in query, test using mocha
ericcj authored
32
78c39ae @adelevie test queries!
authored
33 def test_eq
34 q = Parse::Query.new "TestQuery"
35 q.eq("points", 5)
36 assert_equal q.where, {"points" => 5}
37 q.eq("player", "michael@jordan.com")
38 assert_equal q.where, {"points" => 5, "player" => "michael@jordan.com"}
39 end
bca18b6 @ericcj Include skip in query, test using mocha
ericcj authored
40
41 def test_limit_skip
58b7da6 @adelevie using VCR for most tests
authored
42 VCR.use_cassette('test_limit_skip', :record => :new_episodes) do
43 q = Parse::Query.new "TestQuery"
44 q.limit = 2
45 q.skip = 3
46 query_matcher = has_entries(:limit => 2, :skip => 3)
47 Parse::Client.any_instance.expects(:request).with(anything, :get, nil, query_matcher).returns({}.to_json)
48 q.get
49 end
bca18b6 @ericcj Include skip in query, test using mocha
ericcj authored
50 end
51
52 def test_count
58b7da6 @adelevie using VCR for most tests
authored
53 VCR.use_cassette('test_count', :record => :new_episodes) do
54 q = Parse::Query.new "TestQuery"
55 q.count = true
56 query_matcher = has_entries(:count => true)
57 Parse::Client.any_instance.expects(:request).with(anything, :get, nil, query_matcher).returns({}.to_json)
58 q.get
59 end
bca18b6 @ericcj Include skip in query, test using mocha
ericcj authored
60 end
b1bea92 @ericcj support $inQuery
ericcj authored
61
3502364 @ericcj support $or (note that it's currently broken for all system-generated…
ericcj authored
62 def test_or
58b7da6 @adelevie using VCR for most tests
authored
63 #VCR.use_cassette('test_or', :record => :new_episodes) do
64 foo = Parse::Object.new "Post"
65 foo["random"] = rand
66 foo.save
67 foo_query = Parse::Query.new("Post").eq("random", foo["random"])
68 assert_equal 1, foo_query.get.size
3502364 @ericcj support $or (note that it's currently broken for all system-generated…
ericcj authored
69
58b7da6 @adelevie using VCR for most tests
authored
70 bar = Parse::Object.new "Post"
71 bar["random"] = rand
72 bar.save
73 bar_query = Parse::Query.new("Post").eq("random", bar["random"])
74 assert_equal 1, foo_query.get.size
3502364 @ericcj support $or (note that it's currently broken for all system-generated…
ericcj authored
75
58b7da6 @adelevie using VCR for most tests
authored
76 query = foo_query.or(bar_query)
77 assert_equal 2, query.get.size
78 #end
3502364 @ericcj support $or (note that it's currently broken for all system-generated…
ericcj authored
79 end
80
b1bea92 @ericcj support $inQuery
ericcj authored
81 def test_in_query
82 outer_query = Parse::Query.new "Outer"
83 inner_query = Parse::Query.new "Inner"
84 inner_query.eq("foo", "bar")
85 outer_query.in_query("inner", inner_query)
86 assert_equal({"inner"=>{"$inQuery"=>{"className"=>"Inner", "where"=>{"foo"=>"bar"}}}}, outer_query.where)
87 end
78c39ae @adelevie test queries!
authored
88 end
Something went wrong with that request. Please try again.