travis-surveillance 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,15 @@
1
1
  module Travis
2
2
  module Surveillance
3
+ class Builds < Array
4
+ def <<(item)
5
+ super
6
+
7
+ # A bit expensive, but for now it'll do.
8
+ self.sort_by! { |i| i.id }
9
+ self.slice!(0..-11) if self.size > 10
10
+ end
11
+ end
12
+
3
13
  class Project
4
14
  ATTRIBUTES = [:description, :id, :slug]
5
15
  attr_accessor *ATTRIBUTES
@@ -22,7 +32,6 @@ module Travis
22
32
 
23
33
  build = Build.new(json.merge({'project' => self}))
24
34
  builds << build
25
- builds.sort_by! { |b| b.id }
26
35
  build
27
36
  end
28
37
 
@@ -35,7 +44,7 @@ module Travis
35
44
  end
36
45
 
37
46
  def builds
38
- @builds ||= []
47
+ @builds ||= Builds.new
39
48
  end
40
49
 
41
50
  def failed?
@@ -87,7 +96,7 @@ module Travis
87
96
  def populate
88
97
  self.attributes = details = get_details
89
98
 
90
- get_builds.reverse.each do |build_json|
99
+ get_builds[0..9].reverse.each do |build_json|
91
100
  add_build(build_json)
92
101
  end if details['last_build_id']
93
102
  end
@@ -1,5 +1,5 @@
1
1
  module Travis
2
2
  module Surveillance
3
- VERSION = "0.0.4"
3
+ VERSION = "0.0.5"
4
4
  end
5
5
  end
@@ -25,6 +25,13 @@ describe Travis::Surveillance::Project do
25
25
  @project.url.must_equal "http://travis-ci.org/dylanegan/travis-surveillance"
26
26
  end
27
27
 
28
+ it "should limit the stored builds to 10" do
29
+ @project.stub :build_for, nil do
30
+ 21.times { @project.add_build({ 'id' => 1 }) }
31
+ @project.builds.size.must_equal 10
32
+ end
33
+ end
34
+
28
35
  describe "with history" do
29
36
  before do
30
37
  @history = Travis::Surveillance::Project.new("dylanegan/travis-surveillance-existing")
@@ -59,7 +59,8 @@ describe Travis::Surveillance::Surveyor do
59
59
  end
60
60
  end
61
61
 
62
- describe "when job:finished is received before OMFG I SHOULD JUST FIX THE INITIAL LOAD" do
62
+ # This should not be of concern now that the project is loaded on startup
63
+ describe "when job:finished is received before build:started" do
63
64
  it "should handle it well" do
64
65
  @surveyor.socket.simulate_received('job:finished', pusher_json_for(@project.slug, 'job:finished'), 'common')
65
66
  @project.builds.last.jobs.last.running?.must_equal false
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: travis-surveillance
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: