freckly 0.0.7 → 0.0.8
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.
- data/lib/freckly/entry.rb +12 -6
- data/lib/freckly/project.rb +10 -0
- data/lib/freckly/version.rb +1 -1
- data/spec/freckly/entry_spec.rb +31 -0
- data/spec/freckly/project_spec.rb +16 -0
- metadata +1 -1
data/lib/freckly/entry.rb
CHANGED
@@ -1,14 +1,20 @@
|
|
1
1
|
module Freckly
|
2
2
|
class Entry
|
3
3
|
class << self
|
4
|
-
def all(options={})
|
4
|
+
def all(options = {})
|
5
|
+
get_all(options).map {|entry| new(entry) }
|
6
|
+
end
|
7
|
+
|
8
|
+
def count(options = {})
|
9
|
+
get_all(options).size
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
def get_all(options = {})
|
5
15
|
results = Freckly.authed_get("/api/entries.xml", :search => options)
|
6
16
|
|
7
|
-
|
8
|
-
entries.map {|entry| new(entry) }
|
9
|
-
else
|
10
|
-
[]
|
11
|
-
end
|
17
|
+
results[:entries] || []
|
12
18
|
end
|
13
19
|
end
|
14
20
|
|
data/lib/freckly/project.rb
CHANGED
@@ -2,6 +2,16 @@ module Freckly
|
|
2
2
|
class Project
|
3
3
|
class << self
|
4
4
|
def all
|
5
|
+
get_all.map {|entry| new(entry) }
|
6
|
+
end
|
7
|
+
|
8
|
+
def count
|
9
|
+
get_all.size
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
def get_all
|
5
15
|
Freckly.authed_get("/api/projects.xml").projects.map {|project| new(project) }
|
6
16
|
end
|
7
17
|
end
|
data/lib/freckly/version.rb
CHANGED
data/spec/freckly/entry_spec.rb
CHANGED
@@ -41,6 +41,37 @@ describe Freckly::Entry do
|
|
41
41
|
it { should be_empty }
|
42
42
|
end
|
43
43
|
end
|
44
|
+
|
45
|
+
describe "#count" do
|
46
|
+
before do
|
47
|
+
@response = Freckly::Entry.count(:projects => %w{123 192})
|
48
|
+
end
|
49
|
+
|
50
|
+
describe "the request" do
|
51
|
+
subject { WebMock::API }
|
52
|
+
|
53
|
+
it { should have_requested(:get, "https://test.letsfreckle.com/api/entries.xml").with(:headers => {"X-FreckleToken" => "aaa"},
|
54
|
+
:query => {:search => {
|
55
|
+
:projects => "123,192"}
|
56
|
+
}) }
|
57
|
+
end
|
58
|
+
|
59
|
+
context "when returning something" do
|
60
|
+
describe "the response" do
|
61
|
+
subject { @response }
|
62
|
+
|
63
|
+
it { should eql(2) }
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
context "when returning nothing" do
|
68
|
+
before { stub_request(:any, /entries/) }
|
69
|
+
|
70
|
+
subject { Freckly::Entry.count(:projects => %w{123 192}) }
|
71
|
+
|
72
|
+
it { should eql(0) }
|
73
|
+
end
|
74
|
+
end
|
44
75
|
end
|
45
76
|
|
46
77
|
describe "Initialization" do
|
@@ -25,6 +25,22 @@ describe Freckly::Project do
|
|
25
25
|
specify { subject.first.should be_a(Freckly::Project) }
|
26
26
|
end
|
27
27
|
end
|
28
|
+
|
29
|
+
describe "#count" do
|
30
|
+
describe "the request" do
|
31
|
+
before { Freckly::Project.count }
|
32
|
+
subject { WebMock }
|
33
|
+
|
34
|
+
it { should have_requested(:get, "https://test.letsfreckle.com/api/projects.xml").with(:headers => {"X-FreckleToken" => "aaa"}) }
|
35
|
+
end
|
36
|
+
|
37
|
+
describe "the response" do
|
38
|
+
before { @response = Freckly::Project.count }
|
39
|
+
subject { @response }
|
40
|
+
|
41
|
+
it { should eql(2) }
|
42
|
+
end
|
43
|
+
end
|
28
44
|
end
|
29
45
|
|
30
46
|
describe "Initialization" do
|