magellan-cli 0.5.0 → 0.5.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3a862c5cf1dedeb965c1b9b903d17a1fe41012b3
4
- data.tar.gz: f7d879a8989894ac2d11fa04991ffa968052d672
3
+ metadata.gz: 9cc1cfe804181bf307d673744563f0c87ca43b26
4
+ data.tar.gz: ada7eb304a551d0d515020758e0f0cc2ab40507e
5
5
  SHA512:
6
- metadata.gz: b2800d3ce556d12eb77ec5849229e51a9e08044ce93a8a187f70d8160871a8c48bc270831f782ae21124b6ab5a95e6e54a75cb5d67872b64c53e62b83798d4fd
7
- data.tar.gz: 3e7b3d6f48da5e07015d7c72e44e3cfb14ce8512a2109d4ab11d143672c3a03c95cdc76ce4a7c0126324eaac3464d6022a9de49a03fe2c2b3d68067137b811b7
6
+ metadata.gz: 6bc4d0418e9795a74313d677ab79d3ed68eecc744d5eac394aed7ccd064f1aedb588fcc000ad8bf8eb7a56dadb63bfc0e8cefd671f17d312b9365bc906679ed0
7
+ data.tar.gz: 07bbce30a3b61dd1d4f96f6362228b686a3a497b7810c01ac256eeafcfde9cd0f144aa81f1279ca7643d4e6df3456b2990706af7deb61db973ef565a2dd709ac
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- magellan-cli (0.5.0)
4
+ magellan-cli (0.5.1)
5
5
  activesupport (~> 4.1.4)
6
6
  groovenauts-thor
7
7
  httpclient (~> 2.5)
@@ -6,7 +6,7 @@ module Magellan
6
6
  module Cli
7
7
  module FileAccess
8
8
 
9
- class NotSelected < StandardError
9
+ class NotSelected < Magellan::Cli::Error
10
10
  end
11
11
 
12
12
  DEFAULT_SELECTION_FILENAME = File.expand_path("~/.config/magellan/magellan-cli")
@@ -49,9 +49,8 @@ module Magellan
49
49
  if obj and obj.is_a?(Hash) and obj["message"]
50
50
  fatal(obj["message"])
51
51
  else
52
- msg = "HTTP Error: status=#{res.status}"
53
- msg << "\n#{res.body}" if verbose?
54
- log_error(msg)
52
+ msg = "HTTP Error: status=#{res.status}\n#{res.body}"
53
+ log_verbose(msg)
55
54
  end
56
55
  end
57
56
  end
@@ -69,7 +69,7 @@ en:
69
69
  default_query:
70
70
  not_selected: "No %{label} selected"
71
71
  get_first_result:
72
- not_found: "%{name} not found by using %{query}"
72
+ not_found: "%{resource_name} not found for %{name}"
73
73
  common:
74
74
  cmd:
75
75
  create: "Create a new %{resource_name} with NAME"
@@ -67,7 +67,7 @@ ja:
67
67
  default_query:
68
68
  not_selected: "%{label}が選択されていません"
69
69
  get_first_result:
70
- not_found: "%{name}は見つかりませんでした。クエリ %{query}"
70
+ not_found: "%{name}という%{resource_name}は見つかりませんでした"
71
71
  common:
72
72
  cmd:
73
73
  create: "NAMEを指定して%{resource_name}を登録します"
@@ -14,7 +14,7 @@ module Magellan
14
14
  module Cli
15
15
  module Resources
16
16
 
17
- class NotFound < StandardError
17
+ class NotFound < Magellan::Cli::Error
18
18
  end
19
19
 
20
20
  class Base < ::Magellan::Cli::Http
@@ -53,19 +53,19 @@ module Magellan
53
53
  end
54
54
  end
55
55
 
56
- def get_first_result!(name, path, query)
56
+ def get_first_result!(resource_name, name, path, query)
57
57
  results = get_json(path, query)
58
- raise NotFound, I18n.t(:not_found, scope: [:resources, :base, :get_first_result], name: name, query: query.inspect) if results.blank? || results.first.blank?
58
+ raise NotFound, I18n.t(:not_found, scope: [:resources, :base, :get_first_result], resource_name: resource_name, name: name) if results.blank? || results.first.blank?
59
59
  results.first
60
60
  end
61
61
 
62
- def update_first_result(name, path, query, fields = nil)
62
+ def update_first_result(resource_name, name, path, query, fields = nil)
63
63
  fields ||= ["id", self.class.caption_attr].compact
64
- r = get_first_result!(name, path, query)
64
+ r = get_first_result!(resource_name, name, path, query)
65
65
  obj = fields.each_with_object({}) do |f, d|
66
66
  d[f] = r[f]
67
67
  end
68
- update_selections!(name => obj)
68
+ update_selections!(resource_name => obj)
69
69
  return r
70
70
  end
71
71
 
@@ -168,7 +168,7 @@ module Magellan
168
168
 
169
169
  def select(name)
170
170
  q = build_query(self.class.caption_attr => name).update(default_query)
171
- update_first_result(self.class.parameter_name, "/admin/#{self.class.resource_key}.json", q)
171
+ update_first_result(self.class.parameter_name, name, "/admin/#{self.class.resource_key}.json", q)
172
172
  end
173
173
 
174
174
  def deselect
@@ -32,7 +32,7 @@ module Magellan
32
32
  desc "delete VERSION", I18n.t(:delete, scope: [:resources, :client_version, :cmd], resource_name: resource_name)
33
33
  def delete(version)
34
34
  q = build_query("version" => version).update(default_query)
35
- r = get_first_result!(self.class.resource_name, "/admin/#{resource_key}.json", q)
35
+ r = get_first_result!(self.class.resource_name, version, "/admin/#{resource_key}.json", q)
36
36
  super("/admin/#{resource_key}/#{r['id']}/delete")
37
37
  log_success("OK")
38
38
  end
@@ -13,7 +13,7 @@ module Magellan
13
13
  desc "delete NAME", I18n.t(:delete, scope: [:resources, :common, :cmd], resource_name: resource_name)
14
14
  def delete(name)
15
15
  q = build_query("name" => name).update(default_query)
16
- r = get_first_result!(self.class.resource_name, "/admin/#{resource_key}.json", q)
16
+ r = get_first_result!(self.class.resource_name, name, "/admin/#{resource_key}.json", q)
17
17
  super("/admin/#{resource_key}/#{r['id']}/delete")
18
18
  log_success("OK")
19
19
  end
@@ -9,7 +9,7 @@ module Magellan
9
9
  include Deletable
10
10
 
11
11
  self.resource_key = "project"
12
- self.resource_dependency = nil
12
+ self.resource_dependency = { "organization" => Organization.parameter_name }
13
13
  self.hidden_fields = %w[default_nebula_id created_at updated_at].map(&:freeze).freeze
14
14
  self.field_associations = {"organization_id" => {name: "organization", class: "Organization"} }
15
15
 
@@ -43,15 +43,15 @@ module Magellan
43
43
  end
44
44
 
45
45
  q = build_query("name" => name).update(default_query)
46
- r = update_first_result(parameter_name, "/admin/stage~title.json", q)
46
+ r = update_first_result(parameter_name, name, "/admin/stage~title.json", q)
47
47
 
48
48
  # # current
49
49
  # q = build_query("title" => r["id"], "phase" => 2) # 2: current
50
- # update_first_result(VERSION_PARAMETER_NAME, "/admin/stage~version.json", q, %w[id])
50
+ # update_first_result(VERSION_PARAMETER_NAME, "phase=2", "/admin/stage~version.json", q, %w[id])
51
51
 
52
52
  # # workspace
53
53
  q = build_query("title" => r["id"], "phase" => 1) # 1: workspace
54
- update_first_result(VERSION_PARAMETER_NAME, "/admin/stage~version.json", q, %w[id])
54
+ update_first_result(VERSION_PARAMETER_NAME, "phase=1", "/admin/stage~version.json", q, %w[id])
55
55
  end
56
56
 
57
57
  desc "deselect", I18n.t(:deselect, scope: [:resources, :common, :cmd], res_name: resource_name)
@@ -77,7 +77,7 @@ module Magellan
77
77
  def switch_version(phase)
78
78
  s = load_selection!(self.class)
79
79
  q = build_query("title" => s["id"], "phase" => phase) # 1: workspace, 2: current, 3: used
80
- update_first_result(VERSION_PARAMETER_NAME, "/admin/stage~version.json", q, %w[id])
80
+ update_first_result(VERSION_PARAMETER_NAME, "phase=#{phase}", "/admin/stage~version.json", q, %w[id])
81
81
  end
82
82
  end
83
83
 
@@ -1,5 +1,5 @@
1
1
  module Magellan
2
2
  module Cli
3
- VERSION = "0.5.0"
3
+ VERSION = "0.5.1"
4
4
  end
5
5
  end
@@ -20,7 +20,7 @@ describe Magellan::Cli::Resources::Project do
20
20
 
21
21
  describe :list do
22
22
  it do
23
- expect(httpclient).to receive(:get).with("#{base_url}/admin/project.json").and_return(res)
23
+ expect(httpclient).to receive(:get).with(%r{\A#{base_url}/admin/project.json}).and_return(res)
24
24
  expect($stdout).to receive(:puts)
25
25
  cmd.list
26
26
  end
@@ -36,4 +36,32 @@ describe Magellan::Cli::Resources::Project do
36
36
  end
37
37
  end
38
38
 
39
+ describe :delete do
40
+ before do
41
+ @name = "dummyproject"
42
+ end
43
+ context "organization selected" do
44
+ before do
45
+ Magellan::Cli::FileAccess.update_selections(Magellan::Cli::FileAccess.load_selections.merge("magellan_auth_organization" => { id: 1, name: @name}))
46
+ allow(res).to receive(:body).and_return("")
47
+ allow(res).to receive(:status).and_return(401)
48
+ expect(httpclient).to receive(:get).and_return(res)
49
+ end
50
+ it "show not found error message" do
51
+ expect do
52
+ cmd.delete(@name)
53
+ end.to raise_error(Magellan::Cli::Resources::NotFound)
54
+ end
55
+ end
56
+ context "organization not selected" do
57
+ before do
58
+ Magellan::Cli::FileAccess.update_selections(Magellan::Cli::FileAccess.load_selections.merge("magellan_auth_organization" => nil))
59
+ end
60
+ it "show not selected error message" do
61
+ expect do
62
+ cmd.delete(@name)
63
+ end.to raise_error(Magellan::Cli::FileAccess::NotSelected)
64
+ end
65
+ end
66
+ end
39
67
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: magellan-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - akm2000