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.
@@ -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
- if entries = results[:entries]
8
- entries.map {|entry| new(entry) }
9
- else
10
- []
11
- end
17
+ results[:entries] || []
12
18
  end
13
19
  end
14
20
 
@@ -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
@@ -1,3 +1,3 @@
1
1
  module Freckly
2
- VERSION = "0.0.7"
2
+ VERSION = "0.0.8"
3
3
  end
@@ -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
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: freckly
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.7
5
+ version: 0.0.8
6
6
  platform: ruby
7
7
  authors:
8
8
  - Red Davis