incline 0.2.3 → 0.2.4

Sign up to get free protection for your applications and to get access to all the features.
data/lib/incline/cli.rb CHANGED
@@ -6,6 +6,7 @@ require 'incline/cli/helpers/yaml'
6
6
 
7
7
  require 'incline/cli/version'
8
8
  require 'incline/cli/usage'
9
+ require 'incline/cli/prepare'
9
10
 
10
11
 
11
12
  module Incline
@@ -18,14 +19,14 @@ module Incline
18
19
 
19
20
  def execute(*args)
20
21
  begin
21
- if args.empty? || %w(usage help /? -? -help --help).include?(args.first)
22
+ if args.empty? || %w(help /? -? -help --help).include?(args.first)
22
23
  process_command(:usage)
23
24
  else
24
25
  process_command(*args)
25
26
  end
26
27
  rescue UsageError => err
27
28
  STDERR.puts err.message
28
- process_command(:usage)
29
+ process_command(:usage, err.command)
29
30
  rescue CliError => err
30
31
  STDERR.puts ANSI.code(:red) { 'ERROR:' }
31
32
  STDERR.puts err.message
@@ -40,27 +41,27 @@ module Incline
40
41
  cmd_info = self.class.command_list.find{|c| c[:method] == command}
41
42
  if cmd_info
42
43
  args = args.dup
43
- args = []
44
+ command_args = []
44
45
  cmd_info[:new_params].each do |(type,name)|
45
46
  if type == :rest
46
- args += args
47
+ command_args += args
47
48
  break
48
49
  elsif type == :req
49
50
  if args.empty?
50
51
  raise UsageError, "Missing required parameter '#{name}' for command '#{command}'."
51
52
  end
52
- args << args.delete_at(0)
53
+ command_args << args.delete_at(0)
53
54
  elsif type == :opt
54
55
  if args.empty?
55
56
  break
56
57
  else
57
- args << args.delete_at(0)
58
+ command_args << args.delete_at(0)
58
59
  end
59
60
  else
60
61
  raise UsageError, "Unknown parameter type '#{type}' for command '#{command}'."
61
62
  end
62
63
  end
63
- cmd_object = cmd_info[:klass].new(*args)
64
+ cmd_object = cmd_info[:klass].new(*command_args)
64
65
  cmd_object.send(:run)
65
66
  else
66
67
  raise UsageError, "Unknown command '#{command}'."
@@ -80,9 +81,9 @@ module Incline
80
81
  begin
81
82
  constants.map do |c|
82
83
  klass = const_get c
83
- # class must have a :new class method and a :run instance method.
84
+ # class must have a :new class method (:initialize instance method) and a :run instance method.
84
85
  if klass.instance_methods.include?(:run) && klass.methods.include?(:new)
85
- m = klass.method(:new)
86
+ m = klass.instance_method(:initialize)
86
87
  new_params = m.parameters.select{ |p| p[1] && (p[0] == :req || p[0] == :opt || p[0] == :rest) }.freeze
87
88
  m = klass.instance_method(:run)
88
89
  run_params = m.parameters.select{ |p| p[1] && (p[0] == :req || p[0] == :opt || p[0] == :rest) }.freeze
@@ -1,3 +1,3 @@
1
1
  module Incline
2
- VERSION = "0.2.3"
2
+ VERSION = "0.2.4"
3
3
  end
@@ -0,0 +1,60 @@
1
+ require 'test_helper'
2
+
3
+ <% module_namespacing do -%>
4
+ class <%= controller_class_name %>ControllerTest < ActionController::TestCase
5
+ setup do
6
+ @<%= singular_table_name %> = <%= fixture_name %>(:one)
7
+ <% if mountable_engine? -%>
8
+ @routes = Engine.routes
9
+ <% end -%>
10
+ # Log in as the admin to ensure full access.
11
+ # You may want to test accessibility separately.
12
+ log_in_as incline_users(:admin)
13
+ end
14
+
15
+ test "should get index" do
16
+ get :index
17
+ assert_response :success
18
+ end
19
+
20
+ test "should get new" do
21
+ get :new
22
+ assert_response :success
23
+ end
24
+
25
+ test "should create <%= singular_table_name %>" do
26
+ # To avoid issues with uniqueness, we destroy the item first.
27
+ @<%= singular_table_name %>.destroy
28
+
29
+ # Now we should be able to create an item with the same info.
30
+ assert_difference('<%= class_name %>.count') do
31
+ post :create, <%= "#{singular_table_name}: { #{attributes_hash} }" %>
32
+ end
33
+
34
+ assert_redirected_to <%= index_helper %>_path
35
+ end
36
+
37
+ test "should show <%= singular_table_name %>" do
38
+ get :show, id: <%= "@#{singular_table_name}" %>
39
+ assert_response :success
40
+ end
41
+
42
+ test "should get edit" do
43
+ get :edit, id: <%= "@#{singular_table_name}" %>
44
+ assert_response :success
45
+ end
46
+
47
+ test "should update <%= singular_table_name %>" do
48
+ patch :update, id: <%= "@#{singular_table_name}" %>, <%= "#{singular_table_name}: { #{attributes_hash} }" %>
49
+ assert_redirected_to <%= index_helper %>_path
50
+ end
51
+
52
+ test "should destroy <%= singular_table_name %>" do
53
+ assert_difference('<%= class_name %>.count', -1) do
54
+ delete :destroy, id: <%= "@#{singular_table_name}" %>
55
+ end
56
+
57
+ assert_redirected_to <%= index_helper %>_path
58
+ end
59
+ end
60
+ <% end -%>
@@ -49,6 +49,47 @@ two:
49
49
  bravo: 2
50
50
  echo: 5
51
51
 
52
+ three:
53
+ charlie: 3
54
+ foxtrot: 6
55
+ YAML
56
+
57
+ PRE_REMOVE_YAML = <<-YAML.strip
58
+ # Top of file.
59
+
60
+ one:
61
+ alpha: 1
62
+ delta: 4
63
+
64
+ two: # the second section
65
+ bravo: 2
66
+ echo: <%= 'hello' %> # just a simple embedded ruby command.
67
+
68
+ three:
69
+ charlie: 3
70
+ foxtrot: 6
71
+ YAML
72
+
73
+ POST_REMOVE_RESULT = <<-YAML.strip
74
+ # Top of file.
75
+
76
+ one:
77
+ alpha: 1
78
+ delta: 4
79
+
80
+
81
+ three:
82
+ charlie: 3
83
+ foxtrot: 6
84
+ YAML
85
+
86
+ POST_POST_REMOVE_RESULT = <<-YAML.strip
87
+ # Top of file.
88
+
89
+ one:
90
+ delta: 4
91
+
92
+
52
93
  three:
53
94
  charlie: 3
54
95
  foxtrot: 6
@@ -84,5 +125,47 @@ three:
84
125
 
85
126
  assert_equal MULTIPLE_ADD_RESULT, contents.to_s.strip
86
127
  end
128
+
129
+ test 'remove_key works as expected' do
130
+ contents = Incline::CliHelpers::Yaml::YamlContents.new(PRE_REMOVE_YAML)
131
+
132
+ extracted = contents.remove_key %w(two)
133
+
134
+ assert_equal POST_REMOVE_RESULT, contents.to_s.strip
135
+
136
+ # there should be three items in the extracted contents.
137
+ assert_equal 3, extracted.length
138
+
139
+ # the first item should be the base key.
140
+ assert_equal %w(two), extracted[0][:key]
141
+ assert_equal '', extracted[0][:value]
142
+ assert_equal 'the second section', extracted[0][:comment]
143
+ assert extracted[0][:safe]
144
+
145
+ # followed by bravo.
146
+ assert_equal %w(two bravo), extracted[1][:key]
147
+ assert_equal '2', extracted[1][:value]
148
+ assert_nil extracted[1][:comment]
149
+ assert extracted[1][:safe]
150
+
151
+ # and finally echo.
152
+ assert_equal %w(two echo), extracted[2][:key]
153
+ assert_equal '<%= \'hello\' %>', extracted[2][:value]
154
+ assert_equal 'just a simple embedded ruby command.', extracted[2][:comment]
155
+ assert extracted[2][:safe]
156
+
157
+ # one more test just to ensure we can remove subkeys safely.
158
+ extracted = contents.remove_key %w(one alpha)
159
+
160
+ assert_equal POST_POST_REMOVE_RESULT, contents.to_s.strip
161
+ assert_equal 1, extracted.length
162
+
163
+ extracted = extracted.first
164
+ assert_equal %w(one alpha), extracted[:key]
165
+ assert_equal '1', extracted[:value]
166
+ assert_nil extracted[:comment]
167
+ assert extracted[:safe]
168
+
169
+ end
87
170
 
88
171
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: incline
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Beau Barker
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-08-05 00:00:00.000000000 Z
11
+ date: 2017-08-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -156,14 +156,14 @@ dependencies:
156
156
  requirements:
157
157
  - - "~>"
158
158
  - !ruby/object:Gem::Version
159
- version: 0.1.9
159
+ version: 0.1.15
160
160
  type: :runtime
161
161
  prerelease: false
162
162
  version_requirements: !ruby/object:Gem::Requirement
163
163
  requirements:
164
164
  - - "~>"
165
165
  - !ruby/object:Gem::Version
166
- version: 0.1.9
166
+ version: 0.1.15
167
167
  - !ruby/object:Gem::Dependency
168
168
  name: ansi
169
169
  requirement: !ruby/object:Gem::Requirement
@@ -398,6 +398,22 @@ files:
398
398
  - lib/incline/cli.rb
399
399
  - lib/incline/cli/errors.rb
400
400
  - lib/incline/cli/helpers/yaml.rb
401
+ - lib/incline/cli/prepare.rb
402
+ - lib/incline/cli/prepare/add_deploy_user.rb
403
+ - lib/incline/cli/prepare/config_passenger.rb
404
+ - lib/incline/cli/prepare/config_ssh.rb
405
+ - lib/incline/cli/prepare/create_nginx_utils.rb
406
+ - lib/incline/cli/prepare/extend_shell.rb
407
+ - lib/incline/cli/prepare/install_db.rb
408
+ - lib/incline/cli/prepare/install_flytrap.rb
409
+ - lib/incline/cli/prepare/install_passenger.rb
410
+ - lib/incline/cli/prepare/install_prereqs.rb
411
+ - lib/incline/cli/prepare/install_rails.rb
412
+ - lib/incline/cli/prepare/install_rbenv.rb
413
+ - lib/incline/cli/prepare/install_ruby.rb
414
+ - lib/incline/cli/prepare/restart_nginx.rb
415
+ - lib/incline/cli/prepare/ssh_copy_id.rb
416
+ - lib/incline/cli/prepare/update_system.rb
401
417
  - lib/incline/cli/usage.rb
402
418
  - lib/incline/cli/version.rb
403
419
  - lib/incline/data_tables_request.rb
@@ -453,6 +469,7 @@ files:
453
469
  - lib/templates/jbuilder/scaffold/index.json.jbuilder
454
470
  - lib/templates/jbuilder/scaffold/show.json.jbuilder
455
471
  - lib/templates/rails/scaffold_controller/controller.rb
472
+ - lib/templates/test_unit/scaffold/functional_test.rb
456
473
  - test/cli/yaml_contents_test.rb
457
474
  - test/controllers/incline/access_groups_controller_test.rb
458
475
  - test/controllers/incline/access_test_controller_test.rb
@@ -587,7 +604,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
587
604
  version: '0'
588
605
  requirements: []
589
606
  rubyforge_project:
590
- rubygems_version: 2.6.11
607
+ rubygems_version: 2.5.2
591
608
  signing_key:
592
609
  specification_version: 4
593
610
  summary: A gem designed to get off to an even quicker start with Rails.