mason-server 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/lib/mason_server.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require "pathname"
2
+ require "uri"
2
3
 
3
4
  require "dm-core"
4
5
  require "dm-aggregates"
@@ -11,15 +12,19 @@ require "open4"
11
12
  require "mason_server/build"
12
13
  require "mason_server/app"
13
14
  require "mason_server/command_runner"
14
- require "mason_server/deployment"
15
15
 
16
16
  module MasonServer
17
17
  class Error < StandardError; end
18
18
 
19
19
  Request = Struct.new(:repo, :ref, :command, :callback)
20
20
 
21
- def self.setup(environment, url, db_config, directory)
22
- @deployment = Deployment.new(environment, url, db_config, directory)
21
+ class << self
22
+ attr_reader :url, :directory
23
+ end
24
+
25
+ def self.setup(url, directory)
26
+ @url = URI(url)
27
+ @directory = Pathname(directory)
23
28
  end
24
29
 
25
30
  def self.app
@@ -28,28 +33,4 @@ module MasonServer
28
33
 
29
34
  def self.enable_mock!
30
35
  end
31
-
32
- def self.url
33
- @deployment.url
34
- end
35
-
36
- def self.setup_db
37
- @deployment.setup_db
38
- end
39
-
40
- def self.reset_db
41
- @deployment.reset_db
42
- end
43
-
44
- def self.directory
45
- @deployment.directory
46
- end
47
-
48
- def self.deployment
49
- unless @deployment
50
- raise Error, "call setup first"
51
- end
52
-
53
- @deployment
54
- end
55
36
  end
@@ -32,7 +32,7 @@ module MasonServer
32
32
  end
33
33
 
34
34
  def url
35
- "#{MasonServer.url}/#{id}"
35
+ MasonServer.url + id.to_s
36
36
  end
37
37
 
38
38
  def run
@@ -5,7 +5,7 @@ module MasonServer
5
5
  end
6
6
 
7
7
  def initialize(directory, command, handler)
8
- @directory = Pathname(directory)
8
+ @directory = directory
9
9
  @command = command
10
10
  @handler = handler
11
11
  end
data/mason-server.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "mason-server"
3
- s.version = "0.0.2"
3
+ s.version = "0.0.3"
4
4
  s.summary = "builds things"
5
5
 
6
6
  s.add_dependency "dm-core", "~>1.0.2"
@@ -1,10 +1,14 @@
1
1
  require "helper"
2
2
 
3
3
  class CommandRunnerTest < Test::Unit::TestCase
4
+ setup do
5
+ @dir = Pathname("tmp").expand_path
6
+ end
7
+
4
8
  test "output" do
5
9
  output = ""
6
10
 
7
- MasonServer::CommandRunner.run("tmp", "echo suck") do |chunk|
11
+ MasonServer::CommandRunner.run(@dir, "echo suck") do |chunk|
8
12
  output << chunk
9
13
  end
10
14
 
@@ -12,12 +16,12 @@ class CommandRunnerTest < Test::Unit::TestCase
12
16
  end
13
17
 
14
18
  test "success" do
15
- result = MasonServer::CommandRunner.run("tmp", "true")
19
+ result = MasonServer::CommandRunner.run(@dir, "true")
16
20
  assert_equal 0, result
17
21
  end
18
22
 
19
23
  test "fail" do
20
- result = MasonServer::CommandRunner.run("tmp", "false")
24
+ result = MasonServer::CommandRunner.run(@dir, "false")
21
25
  assert_equal 1, result
22
26
  end
23
27
  end
data/test/helper.rb CHANGED
@@ -7,3 +7,34 @@ require "helper/mock_receiver"
7
7
 
8
8
  require "mason_client"
9
9
  require "mason_server"
10
+
11
+ module Mason
12
+ module TestHelper
13
+ def db_setup
14
+ DataMapper.setup(:default, ("postgres://%s:%s@%s/%s" % db_config))
15
+ end
16
+
17
+ def db_reset
18
+ DataMapper.auto_migrate!
19
+ end
20
+
21
+ def app
22
+ @app ||= Rack::Builder.new {
23
+ map "/callback" do
24
+ run MasonClient.app
25
+ end
26
+
27
+ map "/" do
28
+ run MasonServer.app
29
+ end
30
+ }
31
+ end
32
+
33
+ def db_config
34
+ @db_config ||=
35
+ YAML.load_file("config/database.yml").
36
+ fetch("test").
37
+ values_at("username", "password", "host", "database")
38
+ end
39
+ end
40
+ end
@@ -1,27 +1,14 @@
1
1
  require "helper"
2
2
 
3
3
  class MasonServerTest < Test::Unit::TestCase
4
- include Rack::Test::Methods
5
-
6
- def app
7
- @app ||= Rack::Builder.new {
8
- map "/callback" do
9
- run MasonClient.app
10
- end
11
-
12
- map "/" do
13
- run MasonServer.app
14
- end
15
- }
16
- end
4
+ include Mason::TestHelper
17
5
 
18
6
  setup do
19
- @receiver = MockReceiver.new
7
+ MasonServer.setup("http://mason.example.com", "tmp")
8
+ db_setup
9
+ db_reset
20
10
 
21
- MasonServer.setup("test", "http://mason.example.com", "config/database.yml", "tmp")
22
- MasonServer.setup_db
23
- MasonServer.reset_db
24
- MasonServer.enable_mock!
11
+ @receiver = MockReceiver.new
25
12
 
26
13
  MasonClient.setup("http://mason.example.com/") do |result|
27
14
  @receiver.handle(result)
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 2
9
- version: 0.0.2
8
+ - 3
9
+ version: 0.0.3
10
10
  platform: ruby
11
11
  authors: []
12
12
 
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-09-18 00:00:00 +02:00
17
+ date: 2010-09-19 00:00:00 +02:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -146,7 +146,6 @@ files:
146
146
  - lib/mason_server/app.rb
147
147
  - lib/mason_server/build.rb
148
148
  - lib/mason_server/command_runner.rb
149
- - lib/mason_server/deployment.rb
150
149
  - mason-server.gemspec
151
150
  - test/command_runner_test.rb
152
151
  - test/helper.rb
@@ -1,26 +0,0 @@
1
- module MasonServer
2
- class Deployment
3
- def initialize(environment, url, db_config_file, directory)
4
- @environment = environment
5
- @url = url
6
- @db_config_file = db_config_file
7
- @directory = directory
8
- end
9
-
10
- attr_reader :url, :directory
11
-
12
- def setup_db
13
- DataMapper.setup(:default, ("postgres://%s:%s@%s/%s" % db_config))
14
- end
15
-
16
- def reset_db
17
- DataMapper.auto_migrate!
18
- end
19
-
20
- def db_config
21
- @db_config ||= YAML.load_file(@db_config_file).
22
- fetch(@environment).
23
- values_at("username", "password", "host", "database")
24
- end
25
- end
26
- end