cdq 0.1.2 → 0.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,120 +0,0 @@
1
-
2
- module CDQ
3
- describe "CDQ Targeted Query" do
4
-
5
- before do
6
- CDQ.cdq.setup
7
- end
8
-
9
- after do
10
- CDQ.cdq.reset!
11
- end
12
-
13
- it "reflects a base state" do
14
- tq = CDQTargetedQuery.new(Author.entity_description, Author)
15
- tq.count.should == 0
16
- tq.array.should == []
17
- end
18
-
19
- it "can count objects" do
20
- tq = CDQTargetedQuery.new(Author.entity_description, Author)
21
- Author.create(name: "eecummings")
22
- tq.count.should == 1
23
- Author.create(name: "T. S. Eliot")
24
- tq.count.should == 2
25
- end
26
-
27
- it "can fetch objects" do
28
- tq = CDQTargetedQuery.new(Author.entity_description, Author)
29
- eecummings = Author.create(name: "eecummings")
30
- tseliot = Author.create(name: "T. S. Eliot")
31
- tq.array.sort_by(&:name).should == [tseliot, eecummings]
32
- end
33
-
34
- it "can create objects" do
35
- tq = CDQTargetedQuery.new(Author.entity_description, Author)
36
- maya = tq.create(name: "maya angelou")
37
- tq.where(:name).eq("maya angelou").first.should == maya
38
- end
39
-
40
- end
41
-
42
- describe "CDQ Targeted Query with data" do
43
-
44
- before do
45
- CDQ.cdq.setup
46
-
47
- class << self
48
- include CDQ
49
- end
50
-
51
- @tq = cdq(Author)
52
- @eecummings = Author.create(name: "eecummings")
53
- @tseliot = Author.create(name: "T. S. Eliot")
54
- @dante = Author.create(name: "dante")
55
- cdq.save
56
- end
57
-
58
- after do
59
- CDQ.cdq.reset!
60
- end
61
-
62
- it "performs a sorted fetch" do
63
- @tq.sort_by(:name).array.should == [@tseliot, @dante, @eecummings]
64
- end
65
-
66
- it "performs a limited fetch" do
67
- @tq.sort_by(:name).limit(1).array.should == [@tseliot]
68
- end
69
-
70
- it "performs an offset fetch" do
71
- @tq.sort_by(:name).offset(1).array.should == [@dante, @eecummings]
72
- @tq.sort_by(:name).offset(1).limit(1).array.should == [@dante]
73
- end
74
-
75
- it "performs a restricted search" do
76
- @tq.where(:name).eq("dante").array.should == [@dante]
77
- end
78
-
79
- it "gets the first entry" do
80
- @tq.sort_by(:name).first.should == @tseliot
81
- end
82
-
83
- it "gets entries by index" do
84
- @tq.sort_by(:name)[0].should == @tseliot
85
- @tq.sort_by(:name)[1].should == @dante
86
- @tq.sort_by(:name)[2].should == @eecummings
87
- end
88
-
89
- it "can iterate over entries" do
90
- entries = [@tseliot, @dante, @eecummings]
91
-
92
- @tq.sort_by(:name).each do |e|
93
- e.should == entries.shift
94
- end
95
- end
96
-
97
- it "can map over entries" do
98
- entries = [@tseliot, @dante, @eecummings]
99
-
100
- @tq.sort_by(:name).map { |e| e }.should == entries
101
- end
102
-
103
- it "can create a named scope" do
104
- @tq.scope :two_sorted_by_name, @tq.sort_by(:name).limit(2)
105
- @tq.two_sorted_by_name.array.should == [@tseliot, @dante]
106
- end
107
-
108
- it "can create a dynamic named scope" do
109
- tq = cdq(Article)
110
- a = tq.create(publishedAt: Time.local(2001))
111
- b = tq.create(publishedAt: Time.local(2002))
112
- c = tq.create(publishedAt: Time.local(2003))
113
- d = tq.create(publishedAt: Time.local(2004))
114
-
115
- tq.scope :date_span { |start_date, end_date| cdq(:publishedAt).lt(end_date).and.ge(start_date) }
116
- tq.date_span(Time.local(2002), Time.local(2004)).sort_by(:publishedAt).array.should == [b, c]
117
- Article.published_since(Time.local(2003)).sort_by(:publishedAt).array.should == [c, d]
118
- end
119
- end
120
- end
@@ -1,16 +0,0 @@
1
- module Bacon
2
- class Context
3
- # Executes a given block on an async concurrent GCD queue (which is a
4
- # different thread) and returns the return value of the block, which is
5
- # expected to be either true or false.
6
- def on_thread(&block)
7
- @result = false
8
- group = Dispatch::Group.new
9
- Dispatch::Queue.concurrent.async(group) do
10
- @result = block.call
11
- end
12
- group.wait
13
- @result
14
- end
15
- end
16
- end
@@ -1,38 +0,0 @@
1
-
2
- describe "Integration Tests" do
3
-
4
- before do
5
-
6
- class << self
7
- include CDQ
8
- end
9
-
10
- cdq.setup
11
-
12
- @author = Author.create(name: "Albert Einstein")
13
-
14
- @fundamentals = @author.articles.create(body: "...", published: true, publishedAt: Time.local(1940),
15
- title: "Considerations concering the fundamentals of theoretical physics")
16
-
17
- @gravitation = @author.articles.create(body: "...", published: true, publishedAt: Time.local(1937),
18
- title: "On gravitational waves")
19
-
20
- @fcite = @fundamentals.citations.create(journal: "Science", timestamp: Time.local(1940))
21
- @gcite = @gravitation.citations.create(journal: "Nature", timestamp: Time.local(1941))
22
-
23
- cdq.save(always_wait: true)
24
- end
25
-
26
- after do
27
- cdq.reset!
28
- end
29
-
30
- it "should be able to combine simple queries" do
31
- @author.articles.count.should == 2
32
- @author.articles.first.citations.count.should == 1
33
- @author.articles.where(:title).matches('.*fundamentals.*').first.citations.array.should == [@fcite]
34
-
35
- @gcite.article.author.should == @author
36
- end
37
-
38
- end