figaro 0.5.0 → 0.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/figaro.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |gem|
4
4
  gem.name = "figaro"
5
- gem.version = "0.5.0"
5
+ gem.version = "0.5.1"
6
6
 
7
7
  gem.authors = ["Steve Richert"]
8
8
  gem.email = ["steve.richert@gmail.com"]
data/lib/figaro.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require "figaro/env"
2
2
  require "figaro/railtie"
3
+ require "figaro/tasks"
3
4
 
4
5
  module Figaro
5
6
  extend self
@@ -1,9 +1,6 @@
1
1
  namespace :figaro do
2
2
  desc "Configure Heroku according to application.yml"
3
3
  task :heroku, [:app] => :environment do |_, args|
4
- app = args[:app] ? " --app #{args[:app]}" : ""
5
- rails_env = Kernel.system("heroku config:get RAILS_ENV#{app}").presence
6
- Rails.env = rails_env if rails_env
7
- Kernel.system("heroku config:add #{Figaro.vars}#{app}")
4
+ Figaro::Tasks.heroku(args[:app])
8
5
  end
9
6
  end
@@ -0,0 +1,14 @@
1
+ require "open3"
2
+
3
+ module Figaro
4
+ module Tasks
5
+ def self.heroku(app = nil)
6
+ with_app = app ? " --app #{app}" : ""
7
+
8
+ rails_env = Open3.capture2("heroku config:get RAILS_ENV#{with_app}")
9
+ vars = Figaro.vars(rails_env.presence)
10
+
11
+ Open3.capture2("heroku config:add #{vars}#{with_app}")
12
+ end
13
+ end
14
+ end
@@ -1,43 +1,61 @@
1
1
  require "spec_helper"
2
2
 
3
- describe "Figaro Rake tasks", :rake => true do
4
- describe "figaro:heroku" do
5
- before do
6
- @original_rails_env = ENV["RAILS_ENV"]
7
- ENV["RAILS_ENV"] = "development"
8
- end
3
+ describe Figaro::Tasks do
4
+ describe ".heroku" do
5
+ it "configures Heroku" do
6
+ Figaro.stub(:vars => "FOO=bar")
9
7
 
10
- after do
11
- ENV["RAILS_ENV"] = @original_rails_env
12
- Rails.send(:remove_instance_variable, :@_env)
13
- end
8
+ Open3.should_receive(:capture2).once.with("heroku config:get RAILS_ENV").
9
+ and_return("development")
10
+ Open3.should_receive(:capture2).once.with("heroku config:add FOO=bar")
14
11
 
15
- it "configures Heroku" do
16
- Figaro.stub(:env => {"HELLO" => "world", "FOO" => "bar"})
17
- Kernel.stub(:system).with("heroku config:get RAILS_ENV").and_return("development")
18
- Kernel.should_receive(:system).once.with("heroku config:add FOO=bar HELLO=world")
19
- task.invoke
12
+ Figaro::Tasks.heroku
20
13
  end
21
14
 
22
15
  it "configures a specific Heroku app" do
23
- Figaro.stub(:env => {"HELLO" => "world", "FOO" => "bar"})
24
- Kernel.stub(:system).with("heroku config:get RAILS_ENV --app my-app").and_return("development")
25
- Kernel.should_receive(:system).once.with("heroku config:add FOO=bar HELLO=world --app my-app")
26
- task.invoke("my-app")
16
+ Figaro.stub(:vars => "FOO=bar")
17
+
18
+ Open3.should_receive(:capture2).once.
19
+ with("heroku config:get RAILS_ENV --app my-app").
20
+ and_return("development")
21
+ Open3.should_receive(:capture2).once.
22
+ with("heroku config:add FOO=bar --app my-app")
23
+
24
+ Figaro::Tasks.heroku("my-app")
27
25
  end
28
26
 
29
27
  it "respects the Heroku's remote Rails environment" do
30
- Figaro.stub(:raw => {"development" => {"HELLO" => "developers"}, "production" => {"HELLO" => "world"}})
31
- Kernel.stub(:system).with("heroku config:get RAILS_ENV").and_return("production")
32
- Kernel.should_receive(:system).once.with("heroku config:add HELLO=world")
33
- task.invoke
28
+ Open3.stub(:capture2).with("heroku config:get RAILS_ENV").
29
+ and_return("production")
30
+
31
+ Figaro.should_receive(:vars).once.with("production").and_return("FOO=bar")
32
+ Open3.should_receive(:capture2).once.with("heroku config:add FOO=bar")
33
+
34
+ Figaro::Tasks.heroku
34
35
  end
35
36
 
36
37
  it "defaults to the local Rails environment if not set remotely" do
37
- Figaro.stub(:raw => {"development" => {"HELLO" => "developers"}, "production" => {"HELLO" => "world"}})
38
- Kernel.stub(:system).with("heroku config:get RAILS_ENV").and_return("\n")
39
- Kernel.should_receive(:system).once.with("heroku config:add HELLO=developers")
40
- task.invoke
38
+ Open3.stub(:capture2).with("heroku config:get RAILS_ENV").
39
+ and_return("\n")
40
+
41
+ Figaro.should_receive(:vars).once.with(nil).and_return("FOO=bar")
42
+ Open3.should_receive(:capture2).once.with("heroku config:add FOO=bar")
43
+
44
+ Figaro::Tasks.heroku
45
+ end
46
+
47
+ describe "figaro:heroku", :rake => true do
48
+ it "configures Heroku" do
49
+ Figaro::Tasks.should_receive(:heroku).once.with(nil)
50
+
51
+ task.invoke
52
+ end
53
+
54
+ it "configures a specific Heroku app" do
55
+ Figaro::Tasks.should_receive(:heroku).once.with("my-app")
56
+
57
+ task.invoke("my-app")
58
+ end
41
59
  end
42
60
  end
43
61
  end
data/spec/figaro_spec.rb CHANGED
@@ -3,29 +3,43 @@ require "spec_helper"
3
3
  describe Figaro do
4
4
  describe ".vars" do
5
5
  it "dumps and sorts env" do
6
- Figaro.stub(:raw => {"HELLO" => "world", "FOO" => "bar"})
6
+ Figaro.stub(:env => Figaro::Env.from("HELLO" => "world", "FOO" => "bar"))
7
+
7
8
  Figaro.vars.should == "FOO=bar HELLO=world"
8
9
  end
9
10
 
10
11
  it "allows access to a particular environment" do
11
- Figaro.stub(:raw => {"development" => {"HELLO" => "developers"}, "production" => {"HELLO" => "world"}})
12
- Figaro.vars(:development).should == "HELLO=developers"
13
- Figaro.vars(:production).should == "HELLO=world"
12
+ Figaro.stub(:env).with("development").
13
+ and_return(Figaro::Env.from("HELLO" => "developers"))
14
+ Figaro.stub(:env).with("production").
15
+ and_return(Figaro::Env.from("HELLO" => "world"))
16
+
17
+ Figaro.vars("development").should == "HELLO=developers"
18
+ Figaro.vars("production").should == "HELLO=world"
14
19
  end
15
20
  end
16
21
 
17
22
  describe ".env" do
18
- it "makes ENV values accessible" do
19
- ENV["HELLO"] = "world"
20
- Figaro.stub(:raw => {})
21
- Figaro.env.hello.should == "world"
22
- ENV.delete("HELLO")
23
+ it "is a Figaro env instance" do
24
+ Figaro.stub(:raw => {"FOO" => "bar"})
25
+
26
+ Figaro.env.should be_a(Figaro::Env)
23
27
  end
24
28
 
25
29
  it "allows access to a particular environment" do
26
- Figaro.stub(:raw => {"development" => {"HELLO" => "developers"}, "production" => {"HELLO" => "world"}})
30
+ Figaro.stub(:raw).and_return(
31
+ "development" => {"HELLO" => "developers"},
32
+ "production" => {"HELLO" => "world"}
33
+ )
34
+
27
35
  Figaro.env(:development).should == {"HELLO" => "developers"}
28
36
  Figaro.env(:production).should == {"HELLO" => "world"}
29
37
  end
38
+
39
+ it "stringifies keys and values" do
40
+ Figaro.stub(:raw).and_return(:LUFTBALLOONS => 99)
41
+
42
+ Figaro.env.should == {"LUFTBALLOONS" => "99"}
43
+ end
30
44
  end
31
45
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: figaro
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.5.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-10-28 00:00:00.000000000 Z
12
+ date: 2013-01-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -136,6 +136,7 @@ files:
136
136
  - lib/figaro/env.rb
137
137
  - lib/figaro/railtie.rb
138
138
  - lib/figaro/tasks.rake
139
+ - lib/figaro/tasks.rb
139
140
  - lib/generators/figaro/install/install_generator.rb
140
141
  - lib/generators/figaro/install/templates/application.yml
141
142
  - spec/figaro/env_spec.rb
@@ -157,7 +158,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
157
158
  version: '0'
158
159
  segments:
159
160
  - 0
160
- hash: 3428766527844493391
161
+ hash: -996973026754623645
161
162
  required_rubygems_version: !ruby/object:Gem::Requirement
162
163
  none: false
163
164
  requirements:
@@ -166,7 +167,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
166
167
  version: '0'
167
168
  segments:
168
169
  - 0
169
- hash: 3428766527844493391
170
+ hash: -996973026754623645
170
171
  requirements: []
171
172
  rubyforge_project:
172
173
  rubygems_version: 1.8.24