ruby_yacht 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (64) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +1 -1
  3. data/doc/TODO.md +1 -8
  4. data/lib/ruby_yacht/dsl/app.rb +37 -10
  5. data/lib/ruby_yacht/dsl/configuration.rb +21 -21
  6. data/lib/ruby_yacht/dsl/database.rb +53 -0
  7. data/lib/ruby_yacht/dsl/dsl.rb +14 -8
  8. data/lib/ruby_yacht/dsl/hook.rb +35 -15
  9. data/lib/ruby_yacht/dsl/project.rb +23 -10
  10. data/lib/ruby_yacht/dsl/{app_type.rb → server_type.rb} +39 -29
  11. data/lib/ruby_yacht/dsl.rb +1 -1
  12. data/lib/ruby_yacht/images/app/Dockerfile.erb +9 -5
  13. data/lib/ruby_yacht/images/app-dependencies/Dockerfile.erb +2 -2
  14. data/lib/ruby_yacht/images/database/Dockerfile.erb +12 -11
  15. data/lib/ruby_yacht/images/web/Dockerfile.erb +6 -2
  16. data/lib/ruby_yacht/images/web/add_app.rb +7 -1
  17. data/lib/ruby_yacht/images/web/app_config.erb +2 -0
  18. data/lib/ruby_yacht/plugins/mysql/scripts/setup.bash +11 -0
  19. data/lib/ruby_yacht/plugins/mysql.rb +27 -0
  20. data/lib/ruby_yacht/plugins/rails/scripts/install_gems.rb +6 -1
  21. data/lib/ruby_yacht/plugins/rails/scripts/load_seeds.rb +6 -4
  22. data/lib/ruby_yacht/plugins/rails/scripts/prepare_rails_for_launch.rb +1 -0
  23. data/lib/ruby_yacht/plugins/rails/scripts/update_rails_config.rb +1 -5
  24. data/lib/ruby_yacht/plugins/rails.rb +12 -4
  25. data/lib/ruby_yacht/plugins.rb +2 -1
  26. data/lib/ruby_yacht/runner/build_images.rb +32 -26
  27. data/lib/ruby_yacht/runner/checkout.rb +5 -4
  28. data/lib/ruby_yacht/runner/run_containers.rb +7 -6
  29. data/lib/ruby_yacht/runner/services.rb +2 -2
  30. data/lib/ruby_yacht/runner/shell.rb +5 -4
  31. data/lib/ruby_yacht/runner/update_hosts.rb +2 -1
  32. data/ruby_yacht.gemspec +1 -1
  33. data/spec/dsl/app_spec.rb +96 -10
  34. data/spec/dsl/configuration_spec.rb +53 -55
  35. data/spec/dsl/database_spec.rb +70 -12
  36. data/spec/dsl/hook_spec.rb +36 -19
  37. data/spec/dsl/project_spec.rb +26 -18
  38. data/spec/dsl/{app_type_spec.rb → server_type_spec.rb} +52 -28
  39. data/spec/fixtures/app-dependencies-dockerfile-rails +3 -0
  40. data/spec/fixtures/database-dockerfile +1 -8
  41. data/spec/fixtures/database-dockerfile-mysql +30 -0
  42. data/spec/fixtures/database-dockerfile-rails +1 -5
  43. data/spec/fixtures/database-dockerfile-with-seed-hooks +1 -8
  44. data/spec/fixtures/mars-before-startup-with-custom-file-copy +6 -0
  45. data/spec/fixtures/mars-dockerfile +0 -4
  46. data/spec/fixtures/mars-dockerfile-rails +2 -2
  47. data/spec/fixtures/mars-dockerfile-with-after-checkout-hooks +0 -4
  48. data/spec/fixtures/mars-dockerfile-with-before-startup-hooks +0 -4
  49. data/spec/fixtures/mars-dockerfile-with-custom-file-copy +23 -0
  50. data/spec/fixtures/mars-dockerfile-with-local-database +27 -0
  51. data/spec/fixtures/mars-dockerfile-with-remote-database +27 -0
  52. data/spec/fixtures/web-dockerfile-with-eponymous-app +20 -0
  53. data/spec/plugins/mysql_spec.rb +64 -0
  54. data/spec/plugins/rails_spec.rb +103 -43
  55. data/spec/runner/build_images_spec.rb +142 -11
  56. data/spec/runner/checkout_spec.rb +4 -4
  57. data/spec/runner/run_containers_spec.rb +21 -2
  58. data/spec/runner/runner_spec.rb +1 -1
  59. data/spec/runner/services_spec.rb +7 -2
  60. data/spec/runner/shell_spec.rb +3 -3
  61. data/spec/runner/update_hosts_spec.rb +26 -0
  62. data/spec/support/test_project.rb +16 -20
  63. metadata +20 -5
  64. data/lib/ruby_yacht/images/database/setup.bash +0 -15
@@ -13,7 +13,7 @@ module RubyYacht::Runner
13
13
  attr_accessor :project_name
14
14
 
15
15
  # The name of the app that we are opening a shell in.
16
- attr_accessor :app
16
+ attr_accessor :app_name
17
17
 
18
18
  # The name of the command that we are invoking in the shell.
19
19
  attr_accessor :command
@@ -39,7 +39,7 @@ module RubyYacht::Runner
39
39
  #
40
40
  # * **arguments: Array** The command-line arguments.
41
41
  def parse_positional_arguments(arguments)
42
- self.app = arguments.shift
42
+ self.app_name = arguments.shift
43
43
  self.command = arguments.join(' ')
44
44
  if self.command == ''
45
45
  self.command = 'bash'
@@ -48,7 +48,7 @@ module RubyYacht::Runner
48
48
 
49
49
  # This method runs the logic for the command.
50
50
  def run
51
- if app.nil?
51
+ if app_name.nil?
52
52
  log "You must provide an app name"
53
53
  log "Run #{Command.short_script_name} help shell for more information"
54
54
  return false
@@ -57,7 +57,8 @@ module RubyYacht::Runner
57
57
  project = self.project_named(project_name)
58
58
  return false unless project
59
59
 
60
- container = "#{project.system_prefix}-#{app}"
60
+ app = project.apps.find { |a| a.name == app_name.to_sym }
61
+ container = app.container_name(project)
61
62
  exec("docker exec -it #{container} bash -c 'cd /var/code; TERM=xterm #{command}'")
62
63
  true
63
64
  end
@@ -60,7 +60,8 @@ module RubyYacht::Runner
60
60
  main_domain = project.domain
61
61
 
62
62
  domains = [main_domain]
63
- domains += project.apps.map { |app| "#{app.name}.#{main_domain}" }
63
+ apps = project.apps.select { |app| app.name != system_prefix }
64
+ domains += apps.map { |app| "#{app.name}.#{main_domain}" }
64
65
 
65
66
  header = "# #{system_prefix} docker containers"
66
67
  new_hosts = ["", header]
data/ruby_yacht.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = 'ruby_yacht'
3
- spec.version = '0.3.0'
3
+ spec.version = '0.4.0'
4
4
  spec.date = '2016-04-19'
5
5
  spec.description = "A DSL for building docker containers for a family of Rails apps"
6
6
  spec.summary = "A DSL for building docker containers for a family of Rails apps"
data/spec/dsl/app_spec.rb CHANGED
@@ -8,7 +8,8 @@ RSpec.describe RubyYacht::App do
8
8
  before do
9
9
  RubyYacht.configuration.clear
10
10
  RubyYacht.configure do
11
- app_type :test do
11
+ server_type :test do
12
+ container_type :app
12
13
  baseline_image 'ubuntu'
13
14
  end
14
15
  end
@@ -17,50 +18,84 @@ RSpec.describe RubyYacht::App do
17
18
  it "creates an app with all fields" do
18
19
  @builder = Proc.new do
19
20
  repository_name 'brownleej/test-app'
20
- app_type :test
21
+ database_name :database
22
+ server_type :test
21
23
  port 3000
22
24
  end
23
25
  expect(app.name).to eq :test_app
24
26
  expect(app.repository_name).to eq 'brownleej/test-app'
25
- expect(app.app_type).to eq :test
27
+ expect(app.database_name).to eq :database
28
+ expect(app.server_type).to eq :test
26
29
  expect(app.port).to eq 3000
27
30
  end
28
31
 
29
32
  it "requires the repository name" do
30
33
  @builder = Proc.new do
31
34
  port 3000
32
- app_type :test
35
+ server_type :test
36
+ database_name :database
33
37
  end
34
38
  expect do
35
39
  self.app
36
40
  end.to raise_exception("Missing required attribute repository_name for RubyYacht::App::DSL")
37
41
  end
38
42
 
39
- it "requires the app type" do
43
+ it "requires the server type" do
40
44
  @builder = Proc.new do
41
45
  repository_name 'brownleej/test-app'
42
46
  port 3000
47
+ database_name :database
43
48
  end
44
49
  expect do
45
50
  self.app
46
- end.to raise_exception("Missing required attribute app_type for RubyYacht::App::DSL")
51
+ end.to raise_exception("Missing required attribute server_type for RubyYacht::App::DSL")
47
52
  end
48
53
 
49
- it "requires a defined app type" do
54
+ it "does not require the database name" do
50
55
  @builder = Proc.new do
51
- app_type :invalid
52
56
  repository_name 'brownleej/test-app'
57
+ server_type :test
53
58
  port 3000
54
59
  end
60
+ expect(app.database_name).to be_nil
61
+ end
62
+
63
+ it "requires a defined server type" do
64
+ @builder = Proc.new do
65
+ server_type :invalid
66
+ repository_name 'brownleej/test-app'
67
+ port 3000
68
+ database_name :database
69
+ end
70
+ expect do
71
+ self.app
72
+ end.to raise_exception("App has invalid server type `invalid`")
73
+ end
74
+
75
+ it "requires a defined server type for apps" do
76
+ RubyYacht.configure do
77
+ server_type :sqlite do
78
+ container_type :database
79
+ baseline_image 'ubuntu'
80
+ end
81
+ end
82
+
83
+ @builder = Proc.new do
84
+ server_type :sqlite
85
+ repository_name 'brownleej/test-app'
86
+ port 3000
87
+ database_name :database
88
+ end
55
89
  expect do
56
90
  self.app
57
- end.to raise_exception("App has invalid app type `invalid`")
91
+ end.to raise_exception("App has invalid server type `sqlite`")
58
92
  end
59
93
 
60
94
  it "defaults the port to 8080" do
61
95
  @builder = Proc.new do
62
96
  repository_name 'brownleej/test-app'
63
- app_type :test
97
+ server_type :test
98
+ database_name :database
64
99
  end
65
100
  expect(app.port).to eq 8080
66
101
  end
@@ -77,5 +112,56 @@ RSpec.describe RubyYacht::App do
77
112
 
78
113
  expect(app.container_name(project)).to eq 'tests-app1'
79
114
  end
115
+
116
+ context "with the same name as the project's system_prefix" do
117
+ it "is just the project's system prefix" do
118
+ project = RubyYacht::Project.new
119
+ project.name = :test_project
120
+ project.system_prefix = :tests
121
+
122
+ app = RubyYacht::App.new
123
+ app.name = :tests
124
+
125
+ expect(app.container_name(project)).to eq 'tests'
126
+ end
127
+ end
128
+ end
129
+
130
+ describe "database" do
131
+ before do
132
+ @project = RubyYacht::Project.new
133
+ @project.name = :test_project
134
+ @project.system_prefix = :tests
135
+
136
+ database1 = RubyYacht::Database.new
137
+ database1.name = 'main_db'
138
+ database1.host = 'localhost'
139
+
140
+ database2 = RubyYacht::Database.new
141
+ database2.name = 'second_db'
142
+ database2.host = 'db2.test.com'
143
+
144
+ @project.databases = [database1, database2]
145
+
146
+ @app = RubyYacht::App.new
147
+ @app.name = 'app1'
148
+ @app.database_name = 'second_db'
149
+ end
150
+
151
+ it "is the database with the app's database_name" do
152
+ database = @app.database(@project)
153
+ expect(database).not_to be_nil
154
+ expect(database.host).to eq 'db2.test.com'
155
+ end
156
+
157
+ context "with no matching database" do
158
+ before do
159
+ @project.databases.pop
160
+ end
161
+
162
+ it "is nil" do
163
+ expect(@app.database(@project)).to be_nil
164
+ end
165
+ end
80
166
  end
81
167
  end
@@ -10,26 +10,28 @@ describe RubyYacht::Configuration do
10
10
  describe "fetch_hooks" do
11
11
  before do
12
12
  RubyYacht.configure do
13
- app_type :test do
13
+ server_type :test do
14
+ container_type :app
14
15
  baseline_image 'ubuntu'
15
16
  end
16
- app_type :php do
17
+ server_type :php do
18
+ container_type :app
17
19
  baseline_image 'ubuntu'
18
20
  end
19
21
  end
20
22
 
21
23
  RubyYacht.configure do
22
- add_hooks app_type: :test, folder: '.' do
24
+ add_hooks server_type: :test, folder: '.' do
23
25
  before(:startup) { run_script 'a.rb' }
24
26
  before(:install_libraries) { run_script 'a.rb' }
25
27
 
26
28
  before :startup do
27
- app_type :php
29
+ server_type :php
28
30
  run_script 'c.rb'
29
31
  end
30
32
 
31
33
  before :startup do
32
- app_type :test
34
+ server_type :test
33
35
  run_script 'd.rb'
34
36
  end
35
37
  end
@@ -37,23 +39,30 @@ describe RubyYacht::Configuration do
37
39
  end
38
40
 
39
41
  it "returns hooks with the matching attributes" do
40
- hooks = RubyYacht.configuration.fetch_hooks(app_type: :test, event_type: :startup)
42
+ hooks = RubyYacht.configuration.fetch_hooks(server_type: :test, event_type: :startup)
41
43
  expect(hooks.count).to eq 2
42
- expect(hooks[0].script_path).to eq './a.rb'
43
- expect(hooks[1].script_path).to eq './d.rb'
44
+ expect(hooks[0].copied_file_path).to eq './a.rb'
45
+ expect(hooks[1].copied_file_path).to eq './d.rb'
44
46
  end
45
47
  end
46
48
 
47
- describe "find_app_type" do
49
+ describe "find_server_type" do
48
50
  before do
49
51
  RubyYacht.configure do
50
- app_type(:generic) { baseline_image 'ubuntu' }
51
- app_type(:debian) { baseline_image 'debian' }
52
+ server_type :generic do
53
+ container_type :app
54
+ baseline_image 'ubuntu'
55
+ end
56
+
57
+ server_type :debian do
58
+ container_type :app
59
+ baseline_image 'debian'
60
+ end
52
61
  end
53
62
  end
54
63
 
55
64
  it "returns the app type with that name" do
56
- type = RubyYacht.configuration.find_app_type(:debian)
65
+ type = RubyYacht.configuration.find_server_type(:debian)
57
66
  expect(type.baseline_image).to eq 'debian'
58
67
  end
59
68
  end
@@ -66,33 +75,19 @@ describe RubyYacht::Configuration do
66
75
  system_prefix :a
67
76
  domain "a.test.com"
68
77
  repository "github.com"
69
-
70
- database do
71
- host "localhost"
72
- name "project1"
73
- username "test"
74
- password "test"
75
- end
76
78
  end
77
79
 
78
80
  project :project2 do
79
81
  system_prefix :b
80
82
  domain "b.test.com"
81
83
  repository "github.com"
82
-
83
- database do
84
- host "localhost"
85
- name "project2"
86
- username "test"
87
- password "test"
88
- end
89
84
  end
90
85
  end
91
86
  end
92
87
 
93
88
  let(:hook_creation_block) do
94
89
  Proc.new do
95
- add_hooks app_type: :configuration_test, folder: './scripts' do
90
+ add_hooks server_type: :configuration_test, folder: './scripts' do
96
91
  before :startup do
97
92
  run_script 'update_config.rb'
98
93
  end
@@ -100,18 +95,20 @@ describe RubyYacht::Configuration do
100
95
  end
101
96
  end
102
97
 
103
- let(:app_type_creation_block) do
98
+ let(:server_type_creation_block) do
104
99
  Proc.new do
105
- app_type :second_configuration_test do
100
+ server_type :second_configuration_test do
101
+ container_type :app
106
102
  baseline_image 'debian'
107
- app_attribute :test_attribute
103
+ server_attribute :test_attribute
108
104
  end
109
105
  end
110
106
  end
111
107
 
112
108
  before do
113
109
  RubyYacht.configure do
114
- app_type :configuration_test do
110
+ server_type :configuration_test do
111
+ container_type :app
115
112
  baseline_image 'ubuntu'
116
113
  end
117
114
  end
@@ -129,20 +126,20 @@ describe RubyYacht::Configuration do
129
126
  expect(configuration.hooks.count).to eq 1
130
127
  expect(configuration.hooks[0].event_time).to eq :before
131
128
  expect(configuration.hooks[0].event_type).to eq :startup
132
- expect(configuration.hooks[0].script_path).to eq './scripts/update_config.rb'
129
+ expect(configuration.hooks[0].copied_file_path).to eq './scripts/update_config.rb'
133
130
  end
134
131
 
135
- it "can add types" do
136
- configuration = RubyYacht::Configuration::DSL.new.run(app_type_creation_block).create_object
137
- expect(configuration.app_types.count).to eq 1
138
- expect(configuration.app_types[0].name).to eq :second_configuration_test
139
- expect(configuration.app_types[0].project_attributes.count).to eq 0
140
- expect(configuration.app_types[0].app_attributes.count).to eq 1
132
+ it "can server types" do
133
+ configuration = RubyYacht::Configuration::DSL.new.run(server_type_creation_block).create_object
134
+ expect(configuration.server_types.count).to eq 1
135
+ expect(configuration.server_types[0].name).to eq :second_configuration_test
136
+ expect(configuration.server_types[0].project_attributes.count).to eq 0
137
+ expect(configuration.server_types[0].server_attributes.count).to eq 1
141
138
  end
142
139
 
143
140
  it "can add `during` hooks" do
144
141
  configuration = RubyYacht::Configuration::DSL.new.run(Proc.new do
145
- add_hooks app_type: :configuration_test, folder: './scripts' do
142
+ add_hooks server_type: :configuration_test, folder: './scripts' do
146
143
  during :startup do
147
144
  run_script 'start_app.rb'
148
145
  end
@@ -151,12 +148,12 @@ describe RubyYacht::Configuration do
151
148
  expect(configuration.hooks.count).to eq 1
152
149
  expect(configuration.hooks[0].event_time).to eq :during
153
150
  expect(configuration.hooks[0].event_type).to eq :startup
154
- expect(configuration.hooks[0].script_path).to eq './scripts/start_app.rb'
151
+ expect(configuration.hooks[0].copied_file_path).to eq './scripts/start_app.rb'
155
152
  end
156
153
 
157
154
  it "can add `after` hooks" do
158
155
  configuration = RubyYacht::Configuration::DSL.new.run(Proc.new do
159
- add_hooks app_type: :configuration_test, folder: './scripts' do
156
+ add_hooks server_type: :configuration_test, folder: './scripts' do
160
157
  after :startup do
161
158
  run_script 'start_app.rb'
162
159
  end
@@ -165,7 +162,7 @@ describe RubyYacht::Configuration do
165
162
  expect(configuration.hooks.count).to eq 1
166
163
  expect(configuration.hooks[0].event_time).to eq :after
167
164
  expect(configuration.hooks[0].event_type).to eq :startup
168
- expect(configuration.hooks[0].script_path).to eq './scripts/start_app.rb'
165
+ expect(configuration.hooks[0].copied_file_path).to eq './scripts/start_app.rb'
169
166
  end
170
167
 
171
168
  describe "configure method" do
@@ -186,36 +183,37 @@ describe RubyYacht::Configuration do
186
183
  hook = RubyYacht::Hook.new
187
184
  hook.event_time = :after
188
185
  hook.event_type = :restart_application
189
- hook.script_path = './scripts/log_success.rb'
186
+ hook.copied_file_path = './scripts/log_success.rb'
190
187
  RubyYacht.configuration.hooks << hook
191
188
  RubyYacht.configure(&hook_creation_block)
192
189
 
193
190
  configuration = RubyYacht.configuration
194
191
  expect(configuration.hooks.count).to eq 2
195
- expect(configuration.hooks[0].script_path).to eq './scripts/log_success.rb'
196
- expect(configuration.hooks[1].script_path).to eq './scripts/update_config.rb'
192
+ expect(configuration.hooks[0].copied_file_path).to eq './scripts/log_success.rb'
193
+ expect(configuration.hooks[1].copied_file_path).to eq './scripts/update_config.rb'
197
194
  end
198
195
 
199
- it "adds to the list of app types" do
200
- RubyYacht.configure(&app_type_creation_block)
196
+ it "adds to the list of server types" do
197
+ RubyYacht.configure(&server_type_creation_block)
201
198
 
202
199
  configuration = RubyYacht.configuration
203
- expect(configuration.app_types.count).to eq 2
204
- expect(configuration.app_types[0].name).to eq :configuration_test
205
- expect(configuration.app_types[1].name).to eq :second_configuration_test
200
+ expect(configuration.server_types.count).to eq 2
201
+ expect(configuration.server_types[0].name).to eq :configuration_test
202
+ expect(configuration.server_types[1].name).to eq :second_configuration_test
206
203
  end
207
204
 
208
- context "with an app type that is already registered" do
205
+ context "with a server type that is already registered" do
209
206
  before do
210
- type = RubyYacht::AppType.new
207
+ type = RubyYacht::ServerType.new
211
208
  type.name = :second_configuration_test
212
- RubyYacht.configuration.app_types << type
209
+ type.server_attributes = []
210
+ RubyYacht.configuration.server_types << type
213
211
  end
214
212
 
215
213
  it "raises an exception" do
216
214
  expect(lambda do
217
- RubyYacht.configure(&app_type_creation_block)
218
- end).to raise_exception "App type already registered: second_configuration_test"
215
+ RubyYacht.configure(&server_type_creation_block)
216
+ end).to raise_exception "Server type already registered: second_configuration_test"
219
217
  end
220
218
  end
221
219
  end
@@ -1,61 +1,104 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe RubyYacht::Database do
4
+ before do
5
+ RubyYacht.configuration.clear
6
+ RubyYacht.configure do
7
+ server_type :sqlite do
8
+ container_type :database
9
+ baseline_image 'ubuntu'
10
+ end
11
+ end
12
+ end
13
+
4
14
  describe "dsl" do
5
- let(:database) { RubyYacht::Database::DSL.new.run(@builder).create_object }
15
+ let(:database) { RubyYacht::Database::DSL.new(:apps, :sqlite).run(@builder).create_object }
6
16
 
7
17
  it "creates a database with all the fields" do
8
18
  @builder = Proc.new do
9
19
  host 'db1.test.com'
10
- name 'apps'
11
20
  username 'test-user'
12
21
  password 'test-pass'
22
+ container_label :database
13
23
  end
14
24
 
15
25
  expect(database.host).to eq 'db1.test.com'
16
- expect(database.name).to eq 'apps'
26
+ expect(database.name).to eq :apps
27
+ expect(database.server_type).to eq :sqlite
17
28
  expect(database.username).to eq 'test-user'
18
29
  expect(database.password).to eq 'test-pass'
30
+ expect(database.container_label).to eq :database
19
31
  end
20
32
 
21
33
  it "requires the host" do
22
34
  @builder = Proc.new do
23
- name 'apps'
24
35
  username 'test-user'
25
36
  password 'test-pass'
37
+ container_label :database
26
38
  end
27
39
 
28
40
  expect { database }.to raise_exception "Missing required attribute host for RubyYacht::Database::DSL"
29
41
  end
30
42
 
31
- it "requires the name" do
43
+ it "requires the username" do
44
+ @builder = Proc.new do
45
+ host 'db1.test.com'
46
+ password 'test-pass'
47
+ container_label :database
48
+ end
49
+
50
+ expect { database }.to raise_exception "Missing required attribute username for RubyYacht::Database::DSL"
51
+ end
52
+
53
+ it "requires the password" do
54
+ @builder = Proc.new do
55
+ host 'db1.test.com'
56
+ username 'test-user'
57
+ container_label :database
58
+ end
59
+
60
+ expect { database }.to raise_exception "Missing required attribute password for RubyYacht::Database::DSL"
61
+ end
62
+
63
+ it "uses 'database' as the default container label" do
32
64
  @builder = Proc.new do
33
65
  host 'db1.test.com'
34
66
  username 'test-user'
35
67
  password 'test-pass'
36
68
  end
37
69
 
38
- expect { database }.to raise_exception "Missing required attribute name for RubyYacht::Database::DSL"
70
+ expect(database.container_label).to eq :database
39
71
  end
40
72
 
41
- it "requires the username" do
73
+ it "requires a defined server type" do
42
74
  @builder = Proc.new do
43
75
  host 'db1.test.com'
44
- name 'apps'
76
+ username 'test-user'
45
77
  password 'test-pass'
78
+ container_label :database
79
+ server_type :invalid
46
80
  end
47
81
 
48
- expect { database }.to raise_exception "Missing required attribute username for RubyYacht::Database::DSL"
82
+ expect { database }.to raise_exception "Database has invalid server type `invalid`"
49
83
  end
50
84
 
51
- it "requires the password" do
85
+ it "requires a defined server type for a database" do
86
+ RubyYacht.configure do
87
+ server_type :generic do
88
+ container_type :app
89
+ baseline_image 'ruby:2.3'
90
+ end
91
+ end
92
+
52
93
  @builder = Proc.new do
53
94
  host 'db1.test.com'
54
- name 'apps'
55
95
  username 'test-user'
96
+ password 'test-pass'
97
+ container_label :database
98
+ server_type :generic
56
99
  end
57
100
 
58
- expect { database }.to raise_exception "Missing required attribute password for RubyYacht::Database::DSL"
101
+ expect { database }.to raise_exception "Database has invalid server type `generic`"
59
102
  end
60
103
  end
61
104
 
@@ -72,4 +115,19 @@ describe RubyYacht::Database do
72
115
  expect(database).not_to be_local
73
116
  end
74
117
  end
118
+
119
+ describe "container_name" do
120
+ before do
121
+ @project = RubyYacht::Project.new
122
+ @project.name = :test_project
123
+ @project.system_prefix = :tests
124
+
125
+ @database = RubyYacht::Database.new
126
+ @database.container_label = 'mysql'
127
+ end
128
+
129
+ it "combines the project's prefix with the database's container label" do
130
+ expect(@database.container_name(@project)).to eq 'tests-mysql'
131
+ end
132
+ end
75
133
  end