Skip to content

Commit

Permalink
StatusFetcher assigns TeamCityBuild published_at
Browse files Browse the repository at this point in the history
  • Loading branch information
Dirk Kelly & Matt Parker committed Mar 28, 2012
1 parent 0eba94d commit c08e1fd
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 12 deletions.
5 changes: 3 additions & 2 deletions app/models/team_city_build.rb
Expand Up @@ -34,12 +34,13 @@ def live_status
ProjectStatus.new.tap do |s|
s.online = build_status.online?
s.success = build_status.green?
s.published_at = publish_date
end
end

def parse_project_status(*)
live_status
live_status.tap do |s|
s.published_at = publish_date
end
end

def parse_building_status(*)
Expand Down
7 changes: 3 additions & 4 deletions lib/status_fetcher.rb
@@ -1,6 +1,5 @@
class StatusFetcher
def initialize(url_retriever = UrlRetriever)
@url_retriever = url_retriever
end

def fetch_all
Expand All @@ -17,18 +16,18 @@ def fetch_all
def retrieve_status_for(project)
status = ProjectStatus.new(:online => false, :success => false)
status.error = http_errors_for(project) do
content = @url_retriever.retrieve_content_at(project.feed_url, project.auth_username, project.auth_password)
content = UrlRetriever.retrieve_content_at(project.feed_url, project.auth_username, project.auth_password)
status = project.parse_project_status(content)
status.online = true
end
project.statuses.build(status.attributes).save unless project.status.match?(status)
end
handle_asynchronously :retrieve_status_for, :queue => 'project_status'
# handle_asynchronously :retrieve_status_for, :queue => 'project_status'

def retrieve_building_status_for(project)
status = BuildingStatus.new(false)
status.error = http_errors_for(project) do
content = @url_retriever.retrieve_content_at(project.build_status_url, project.auth_username, project.auth_password)
content = UrlRetriever.retrieve_content_at(project.build_status_url, project.auth_username, project.auth_password)
status = project.parse_building_status(content)
end
project.update_attribute(:building, status.building?)
Expand Down
19 changes: 13 additions & 6 deletions spec/models/team_city_build_spec.rb
Expand Up @@ -386,7 +386,7 @@

its(:online) { should be_true}
its(:success) { should be_false }
its(:published_at) { should be_present }
its(:published_at) { should_not be_present }
end

context "test boundary with default build status fetcher" do
Expand All @@ -408,17 +408,24 @@

its(:online) { should be_true }
its(:success) { should be_true }
its(:published_at) { should be_present }
its(:published_at) { should_not be_present }
end
end

describe "#parse_project_status" do
let(:live_status) { double(:live_status)}
before { build.stub(:live_status).and_return live_status }
let(:live_status) { ProjectStatus.new }
let(:publish_date) { Time.now }
let(:build_status) { double(:build_status, :publish_date => publish_date) }

subject { build.parse_project_status("foo")}
before do
build.build_status_fetcher = proc { build_status }
build.stub(:children).and_return []
build.stub(:live_status).and_return live_status
end

subject { build.parse_project_status("foo") }

it { should == live_status }
its(:published_at) { should == publish_date }
end

describe "#parse_building_status" do
Expand Down

0 comments on commit c08e1fd

Please sign in to comment.