Skip to content

Commit

Permalink
Revert "Merge pull request zendesk#272 from zendesk/grosser/cache"
Browse files Browse the repository at this point in the history
This reverts commit 519561c, reversing
changes made to 3557017.
  • Loading branch information
grosser committed Mar 6, 2015
1 parent 519561c commit 780455d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 41 deletions.
9 changes: 3 additions & 6 deletions app/models/stage.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,18 +60,15 @@ def self.where_reference_being_deployed(reference)
end

def current_deploy
return @current_deploy if defined?(@current_deploy)
@current_deploy = deploys.active.first
@current_deploy ||= deploys.active.first
end

def last_deploy
return @last_deploy if defined?(@last_deploy)
@last_deploy = deploys.first
@last_deploy ||= deploys.first
end

def last_successful_deploy
return @last_successful_deploy if defined?(@last_successful_deploy)
@last_successful_deploy = deploys.successful.first
@last_successful_deploy ||= deploys.successful.first
end

def locked?
Expand Down
41 changes: 6 additions & 35 deletions test/models/stage_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

describe Stage do
subject { stages(:test_staging) }
let(:stage) { subject }

describe ".where_reference_being_deployed" do
it "returns stages where the reference is currently being deployed" do
Expand Down Expand Up @@ -61,12 +60,12 @@
let(:project) { projects(:test) }
let(:stage) { stages(:test_staging) }

it 'caches nil' do
stage
ActiveRecord::Relation.any_instance.expects(:first).returns nil
stage.last_deploy.must_equal nil
ActiveRecord::Relation.any_instance.expects(:first).never
stage.last_deploy.must_equal nil
it 'returns the last successful deploy for the stage' do
successful_job = project.jobs.create!(command: 'cat foo', user: users(:deployer), status: 'succeeded')
stage.deploys.create!(reference: 'master', job: successful_job)
job = project.jobs.create!(command: 'cat foo', user: users(:deployer), status: 'failed')
deploy = stage.deploys.create!(reference: 'master', job: successful_job)
assert_equal deploy, stage.last_successful_deploy
end

it 'returns the last deploy for the stage' do
Expand All @@ -78,26 +77,6 @@
end
end

describe '#last_successful_deploy' do
let(:project) { projects(:test) }

it 'caches nil' do
subject
ActiveRecord::Relation.any_instance.expects(:first).returns nil
stage.last_successful_deploy.must_equal nil
ActiveRecord::Relation.any_instance.expects(:first).never
stage.last_successful_deploy.must_equal nil
end

it 'returns the last successful deploy for the stage' do
successful_job = project.jobs.create!(command: 'cat foo', user: users(:deployer), status: 'succeeded')
stage.deploys.create!(reference: 'master', job: successful_job)
job = project.jobs.create!(command: 'cat foo', user: users(:deployer), status: 'failed')
deploy = stage.deploys.create!(reference: 'master', job: successful_job)
assert_equal deploy, stage.last_successful_deploy
end
end

describe "#current_release?" do
let(:project) { projects(:test) }
let(:stage) { stages(:test_staging) }
Expand Down Expand Up @@ -151,14 +130,6 @@
subject.current_deploy.must_equal nil
end

it 'caches nil' do
subject
ActiveRecord::Relation.any_instance.expects(:first).returns nil
subject.current_deploy.must_equal nil
ActiveRecord::Relation.any_instance.expects(:first).never
subject.current_deploy.must_equal nil
end

it "is there when deploying" do
subject.deploys.first.job.update_column(:status, 'running')
subject.current_deploy.must_equal subject.deploys.first
Expand Down

0 comments on commit 780455d

Please sign in to comment.