shelly 0.0.9 → 0.0.10

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/lib/shelly/app.rb CHANGED
@@ -10,10 +10,15 @@ module Shelly
10
10
  @ruby_version = "MRI-1.9.2"
11
11
  end
12
12
 
13
- def add_git_remote
13
+ def add_git_remote(force = false)
14
+ system("git remote rm #{purpose}") if force
14
15
  system("git remote add #{purpose} #{git_url}")
15
16
  end
16
17
 
18
+ def remote_exists?
19
+ IO.popen("git remote").read.split("\n").include?(purpose)
20
+ end
21
+
17
22
  def git_url
18
23
  "git@git.shellycloud.com:#{code_name}.git"
19
24
  end
@@ -58,5 +63,9 @@ module Shelly
58
63
  url = "#{shelly.api_url}/apps/#{code_name}/edit_billing?api_key=#{current_user.token}"
59
64
  Launchy.open(url)
60
65
  end
66
+
67
+ def self.inside_git_repository?
68
+ system("git status &> /dev/null")
69
+ end
61
70
  end
62
71
  end
@@ -8,17 +8,30 @@ module Shelly
8
8
 
9
9
  desc "add", "Adds new application to Shelly Cloud"
10
10
  def add
11
+ say_error "Must be run inside your project git repository" unless App.inside_git_repository?
12
+
11
13
  @app = Shelly::App.new
12
14
  @app.purpose = ask_for_purpose
13
15
  @app.code_name = ask_for_code_name
14
16
  @app.databases = ask_for_databases
15
17
  @app.create
16
- say "Adding remote #{@app.purpose} #{@app.git_url}", :green
17
- @app.add_git_remote
18
+
19
+ unless @app.remote_exists?
20
+ say "Adding remote #{@app.purpose} #{@app.git_url}", :green
21
+ @app.add_git_remote
22
+ else
23
+ say "Remote #{@app.purpose} already exists"
24
+ if yes?("Would you like to overwrite remote #{@app.purpose} with #{@app.git_url} (Y/N)?:")
25
+ @app.add_git_remote(true)
26
+ end
27
+ end
28
+
18
29
  say "Creating Cloudfile", :green
19
30
  @app.create_cloudfile
31
+
20
32
  say "Provide billing details. Opening browser...", :green
21
33
  @app.open_billing_page
34
+
22
35
  info_adding_cloudfile_to_repository
23
36
  info_deploying_to_shellycloud
24
37
  rescue Client::APIError => e
@@ -1,3 +1,3 @@
1
1
  module Shelly
2
- VERSION = "0.0.9"
2
+ VERSION = "0.0.10"
3
3
  end
@@ -19,10 +19,16 @@ describe Shelly::App do
19
19
  end
20
20
 
21
21
  describe "#add_git_remote" do
22
+ before { @app.stub(:system) }
22
23
  it "should add git remote with proper name and git repository" do
23
24
  @app.should_receive(:system).with("git remote add staging git@git.shellycloud.com:foo-staging.git")
24
25
  @app.add_git_remote
25
26
  end
27
+
28
+ it "should remove existing git remote first if invoked with true as first argument" do
29
+ @app.should_receive(:system).with("git remote rm staging")
30
+ @app.add_git_remote(true)
31
+ end
26
32
  end
27
33
 
28
34
  describe "#generate_cloudfile" do
@@ -112,4 +118,22 @@ config
112
118
  @app.create
113
119
  end
114
120
  end
121
+
122
+ describe "#remote_exists?" do
123
+ context "remote with purpose as name exists" do
124
+ it "should return true" do
125
+ @app.purpose = "shelly-prod"
126
+ IO.stub_chain(:popen, :read => "origin\nshelly-prod\ntest")
127
+ @app.should be_remote_exists
128
+ end
129
+ end
130
+
131
+ context "remote with purpose as name doesn't exist" do
132
+ it "should return false" do
133
+ @app.purpose = "shelly"
134
+ IO.stub_chain(:popen, :read => "origin\nshelly-prod\ntest")
135
+ @app.should_not be_remote_exists
136
+ end
137
+ end
138
+ end
115
139
  end
@@ -17,9 +17,21 @@ describe Shelly::CLI::Apps do
17
17
  @app.stub(:create)
18
18
  @app.stub(:generate_cloudfile).and_return("Example Cloudfile")
19
19
  @app.stub(:open_billing_page)
20
+ @app.stub(:remote_exists?).and_return(false)
21
+ Shelly::App.stub(:inside_git_repository?).and_return(true)
20
22
  Shelly::App.stub(:new).and_return(@app)
21
23
  end
22
24
 
25
+ it "should exit with message if command run outside git repository" do
26
+ Shelly::App.stub(:inside_git_repository?).and_return(false)
27
+ $stdout.should_receive(:puts).with("Must be run inside your project git repository")
28
+ lambda {
29
+ fake_stdin(["staging", "", ""]) do
30
+ @apps.add
31
+ end
32
+ }.should raise_error(SystemExit)
33
+ end
34
+
23
35
  it "should ask user how he will use application" do
24
36
  $stdout.should_receive(:print).with("How will you use this system (production - default,staging): ")
25
37
  @app.should_receive(:purpose=).with("staging")
@@ -101,10 +113,41 @@ describe Shelly::CLI::Apps do
101
113
  }.should raise_error(SystemExit)
102
114
  end
103
115
 
104
- it "should add git remote" do
105
- @app.should_receive(:add_git_remote)
106
- fake_stdin(["staging", "foooo", ""]) do
107
- @apps.add
116
+ context "git remote doesn't exist" do
117
+ it "should add git remote" do
118
+ $stdout.should_receive(:puts).with("\e[32mAdding remote staging git@git.shellycloud.com:foooo.git\e[0m")
119
+ @app.should_receive(:add_git_remote)
120
+ fake_stdin(["staging", "foooo", ""]) do
121
+ @apps.add
122
+ end
123
+ end
124
+ end
125
+
126
+ context "git remote exist" do
127
+ before do
128
+ @app.stub(:remote_exists?).and_return(true)
129
+ end
130
+
131
+ it "should ask user if he wants to overwrite existing git remote" do
132
+ $stdout.should_receive(:puts).with("Remote staging already exists")
133
+ $stdout.should_receive(:print).with("Would you like to overwrite remote staging with git@git.shellycloud.com:foooo.git (Y/N)?: ")
134
+ fake_stdin(["staging", "foooo", "", "y"]) do
135
+ @apps.add
136
+ end
137
+ end
138
+
139
+ it "should overwrite existing git remote on 'yes' from user" do
140
+ @app.should_receive(:add_git_remote).with(true)
141
+ fake_stdin(["staging", "foooo", "", "y"]) do
142
+ @apps.add
143
+ end
144
+ end
145
+
146
+ it "should not overwrite existing git remote on 'no' from user" do
147
+ @app.should_not_receive(:add_git_remote).with(true)
148
+ fake_stdin(["staging", "foooo", "", "n"]) do
149
+ @apps.add
150
+ end
108
151
  end
109
152
  end
110
153
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shelly
3
3
  version: !ruby/object:Gem::Version
4
- hash: 13
4
+ hash: 11
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 9
10
- version: 0.0.9
9
+ - 10
10
+ version: 0.0.10
11
11
  platform: ruby
12
12
  authors:
13
13
  - Shelly Cloud team
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-10-05 00:00:00 +02:00
18
+ date: 2011-10-06 00:00:00 +02:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency