2014-07-30 21:39:59 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
|
|
describe GenericState do
|
|
|
|
|
|
|
|
|
|
def database_env (env)
|
|
|
|
|
singleton = GenericState.singleton
|
2014-07-31 02:05:59 +00:00
|
|
|
singleton.env = env
|
2014-07-30 21:39:59 +00:00
|
|
|
singleton.save!
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def rails_env (env)
|
|
|
|
|
JamRuby::Environment.should_receive(:mode).any_number_of_times.and_return(env)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
describe "allow_emails?" do
|
|
|
|
|
|
|
|
|
|
it "allows emails if database is production and env is production, with build number" do
|
|
|
|
|
database_env('production')
|
|
|
|
|
rails_env('production')
|
|
|
|
|
stub_const("ENV", {'BUILD_NUMBER' => 1})
|
|
|
|
|
|
|
|
|
|
GenericState.allow_emails?.should be_true
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it "no emails if database is production and env is production, no build number" do
|
|
|
|
|
database_env('production')
|
|
|
|
|
rails_env('production')
|
2014-07-30 22:29:26 +00:00
|
|
|
stub_const("ENV", {'BUILD_NUMBER' => nil})
|
2014-07-30 21:39:59 +00:00
|
|
|
|
|
|
|
|
GenericState.allow_emails?.should be_false
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it "allows emails if database is development and env is development" do
|
|
|
|
|
database_env('development')
|
|
|
|
|
rails_env('development')
|
|
|
|
|
|
|
|
|
|
GenericState.allow_emails?.should be_true
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it "no emails if database development, and environment is test" do
|
|
|
|
|
database_env('development')
|
|
|
|
|
rails_env('test')
|
|
|
|
|
GenericState.allow_emails?.should be_false
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it "no emails if database production, and environment is development" do
|
|
|
|
|
database_env('production')
|
|
|
|
|
rails_env('development')
|
|
|
|
|
stub_const("ENV", {'BUILD_NUMBER' => 1})
|
|
|
|
|
|
|
|
|
|
GenericState.allow_emails?.should be_false
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it "no emails if database production, and environment is test" do
|
|
|
|
|
database_env('production')
|
|
|
|
|
rails_env('development')
|
|
|
|
|
|
|
|
|
|
GenericState.allow_emails?.should be_false
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|