Skip to content

Commit

Permalink
memoize @apps when using 'extra' behaviors
Browse files Browse the repository at this point in the history
  • Loading branch information
kmayer committed Mar 30, 2012
1 parent 02c04b1 commit aadd88f
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 19 deletions.
2 changes: 1 addition & 1 deletion features/step_definitions/remote_steps.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
World(Aruba::Api)

Given /^I have a new Rails project$/ do
cmd = "rails new heroku_san_test --quiet --force --database=postgresql --skip-bundle --skip-javascript --skip-test-unit --skip-sprockets" #" --template #{template}"
cmd = "rails new heroku_san_test --quiet --force --database=postgresql --skip-bundle --skip-javascript --skip-test-unit --skip-sprockets"
run_simple unescape(cmd)
end

Expand Down
2 changes: 1 addition & 1 deletion lib/heroku_san/project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def apps
if !@apps.empty?
@apps
else
case all.size
@apps = case all.size
when 1
$stdout.puts "Defaulting to #{all.first.inspect} since only one app is defined"
all
Expand Down
38 changes: 21 additions & 17 deletions spec/heroku_san/project_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
end
end

describe "Adding an app to the deploy list" do
describe "#apps adds an app to the deploy list" do
it "appends known shorthands to apps" do
heroku_san.apps.should == []
heroku_san << 'production'
Expand All @@ -41,25 +41,29 @@
heroku_san << heroku_san.all
heroku_san.apps.should == heroku_san.all
end
end

describe "#apps extra default behaviors" do
specify "on a git branch that matches an app name" do
heroku_san.should_receive(:git_active_branch) { "staging" }
$stdout.should_receive(:puts).with("Defaulting to 'staging' as it matches the current branch")
heroku_san.apps.should == %w[staging]
end
describe "#apps extra default behaviors" do
specify "on a git branch that matches an app name" do
heroku_san.should_receive(:git_active_branch) { "staging" }
$stdout.should_receive(:puts).with("Defaulting to 'staging' as it matches the current branch")
expect {
heroku_san.apps.should == %w[staging]
}.to change{heroku_san.instance_variable_get('@apps')}.from([]).to(%w[staging])
end

specify "on a git branch that doesn't matches an app name" do
heroku_san.should_receive(:git_active_branch) { "master" }
heroku_san.apps.should == %w[]
end
specify "on a git branch that doesn't matches an app name" do
heroku_san.should_receive(:git_active_branch) { "master" }
heroku_san.apps.should == %w[]
end

context "but only a single configured app" do
let(:heroku_san) { HerokuSan::Project.new(File.join(SPEC_ROOT, "fixtures", "single_app.yml")) }
it "returns the app" do
$stdout.should_receive(:puts).with('Defaulting to "production" since only one app is defined')
heroku_san.apps.should == %w[production]
context "but only a single configured app" do
let(:heroku_san) { HerokuSan::Project.new(File.join(SPEC_ROOT, "fixtures", "single_app.yml")) }
it "returns the app" do
$stdout.should_receive(:puts).with('Defaulting to "production" since only one app is defined')
expect {
heroku_san.apps.should == %w[production]
}.to change{heroku_san.instance_variable_get('@apps')}.from([]).to(%w[production])
end
end
end
end
Expand Down

0 comments on commit aadd88f

Please sign in to comment.