2011-03-01 2 views
2

'클라우드'스토리지 공급자 (Google, AWS, Rackspace)를 구성하는 맞춤 초기화 프로그램이 있습니다. 여러 개발자가 서로 다른 저장소 공급자를 사용하여 배포 할 수있는 응용 프로그램을 만들고 있는데 각 클라우드 공급자를 개별적으로 테스트 할 수 있기를 바랍니다. 현재 rake test을 실행하기 전에 이니셜 라이저 파일을 세 번 읽고 주석 처리/각 공급자의 주석 처리를 제거하십시오. rake test에 대한 옵션을 전달하여 컨트롤 초기화 (즉, 특정 이니셜 라이저로드)에 사용할 수 있습니까? 뭔가 같은 :레일 테스트를위한 맞춤 초기화 프로그램 변수

# config/initializers/attached.rb 

Attached::Attachment.options[:medium] = :aws 
Attached::Attachment.options[:credentials] = "#{Rails.root}/config/aws.yml" 

Attached::Attachment.options[:medium] = :google 
Attached::Attachment.options[:credentials] = "#{Rails.root}/config/google.yml" 

Attached::Attachment.options[:medium] = :rackspace 
Attached::Attachment.options[:credentials] = "#{Rails.root}/config/rackspace.yml" 

감사 :

rake test --attached aws 
rake test --attached google 
rake test --attached rackspace 

가 여기 내 이니셜 등이 모습입니다!

답변

2

env-vars를 사용하는 것이 좋습니다.

$ ATTACHED="aws" rake test 

다음

# config/initializers/attached.rb 

attached = ENV['ATTACHED'] || "aws" 

case attached 
when "aws" 
    Attached::Attachment.options[:medium] = :aws 
    Attached::Attachment.options[:credentials] = "#{Rails.root}/config/aws.yml" 
... 
+0

감사합니다! 단일 실행을위한 환경 변수를 지정할 수 있는지 알고 있습니까? –

+0

위의 예는 정확히 단일 실행입니다. –

+0

감사! 너는 록 스타 야! 이것은 내가 필요한 것입니다! –