m2config 0.3.0 → 0.4.0
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.
- checksums.yaml +4 -4
- data/Gemfile +3 -1
- data/lib/m2config/host.rb +8 -2
- data/lib/m2config/route.rb +7 -1
- data/lib/m2config/version.rb +1 -1
- data/lib/m2config.rb +4 -7
- data/spec/dir_spec.rb +3 -18
- data/spec/env.rb +13 -0
- data/spec/handler_spec.rb +6 -18
- data/spec/host_spec.rb +30 -24
- data/spec/m2config_spec.rb +5 -27
- data/spec/proxy_spec.rb +3 -13
- data/spec/route_spec.rb +40 -32
- data/spec/server_spec.rb +12 -22
- data/spec/setting_spec.rb +4 -16
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 409e5df6b21362f88633bc922d489f2c17ec6a46
|
4
|
+
data.tar.gz: a97d5200c35196fac07995abc668330bfe8bf9f7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c916730148ca203090fb412222e5f7386bb8c65c51b6b91b63f8d0c9a6f134165d76fc3ee862ff2d0a1df961e9d380af56a638564d22c48ff8cbf208bd52f709
|
7
|
+
data.tar.gz: e79f22f6bb17f04321cf68de59bdb33e2c5def72ed632a34cdb59338190e4e87d875c9dc641066aa471725dc4d441c7113dcd8b1ddd50c5a0e2e25c79ba6db41
|
data/Gemfile
CHANGED
data/lib/m2config/host.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
module M2Config
|
2
2
|
class Host < Sequel::Model(:host)
|
3
|
-
one_to_many :routes
|
3
|
+
one_to_many :routes, {class: "M2Config::Route"}
|
4
4
|
|
5
5
|
def initialize( fields )
|
6
6
|
s = resolveServer fields
|
@@ -11,7 +11,13 @@ module M2Config
|
|
11
11
|
end
|
12
12
|
|
13
13
|
def check_routes
|
14
|
-
paths = routes.map {
|
14
|
+
paths = routes(true).map {
|
15
|
+
|route|
|
16
|
+
route.path
|
17
|
+
}
|
18
|
+
# return true if paths.empty?
|
19
|
+
|
20
|
+
# return "#{paths.uniq.to_s} == #{paths.to_s}"
|
15
21
|
paths.uniq.size == paths.size
|
16
22
|
end
|
17
23
|
|
data/lib/m2config/route.rb
CHANGED
@@ -9,7 +9,13 @@ module M2Config
|
|
9
9
|
super(fields, false)
|
10
10
|
save
|
11
11
|
end
|
12
|
-
|
12
|
+
|
13
|
+
def self.elect!( route66 )
|
14
|
+
toMatch = {path: route66.path, host_id: route66.host_id}
|
15
|
+
toExclude = {id: route66.id}
|
16
|
+
Route.where(toMatch).exclude(toExclude).delete
|
17
|
+
end
|
18
|
+
|
13
19
|
def host=( hostOrId )
|
14
20
|
self.host_id = hostOrId.kind_of?(Host) ? hostOrId.id : hostOrId
|
15
21
|
save
|
data/lib/m2config/version.rb
CHANGED
data/lib/m2config.rb
CHANGED
@@ -7,6 +7,8 @@ module M2Config
|
|
7
7
|
|
8
8
|
DEFAULT_CONFIG = "config.sqlite"
|
9
9
|
SCHEMA = File.read("#{File.dirname __FILE__}/m2config/schema.sql")
|
10
|
+
|
11
|
+
attr_reader :db
|
10
12
|
|
11
13
|
@@foundTables = []
|
12
14
|
|
@@ -28,20 +30,15 @@ module M2Config
|
|
28
30
|
|
29
31
|
@db.run SCHEMA if creating
|
30
32
|
|
33
|
+
Sequel::Model.db = @db
|
34
|
+
|
31
35
|
require "m2config/server"
|
32
|
-
M2Config::Server.db = @db
|
33
36
|
require "m2config/host"
|
34
|
-
M2Config::Host.db = @db
|
35
37
|
require "m2config/dir"
|
36
|
-
M2Config::Dir.db = @db
|
37
38
|
require "m2config/route"
|
38
|
-
M2Config::Route.db = @db
|
39
39
|
require "m2config/proxy"
|
40
|
-
M2Config::Proxy.db = @db
|
41
40
|
require "m2config/handler"
|
42
|
-
M2Config::Handler.db = @db
|
43
41
|
require "m2config/setting"
|
44
|
-
M2Config::Setting.db = @db
|
45
42
|
end
|
46
43
|
|
47
44
|
def add_server( settings = {} )
|
data/spec/dir_spec.rb
CHANGED
@@ -1,36 +1,21 @@
|
|
1
1
|
require "env"
|
2
2
|
|
3
|
-
M2Config::Config.new # Dummy call to ensure that model classes are required (cf. M2Config::new)
|
4
|
-
|
5
3
|
describe M2Config::Dir do
|
6
|
-
before(:each) do
|
7
|
-
File.delete DEFAULT_DB_NAME rescue nil
|
8
|
-
@cfg = M2Config::Config.new
|
9
|
-
@db = SQLite3::Database.new DEFAULT_DB_NAME
|
10
|
-
@db.results_as_hash = true
|
11
|
-
end
|
12
|
-
|
13
|
-
after(:each) do
|
14
|
-
@db.close if @db && !@db.closed?
|
15
|
-
end
|
16
4
|
|
17
5
|
describe "::new" do
|
18
6
|
it "needs to know the base path to handle" do
|
19
7
|
M2Config::Dir.new({base:"images/"})
|
20
|
-
|
21
|
-
res["base"].should eq("images/")
|
8
|
+
CFG.db[:directory].first[:base].should eq("images/")
|
22
9
|
end
|
23
10
|
|
24
11
|
it "defaults to application/octet-stream for the default content type" do
|
25
12
|
M2Config::Dir.new({base:"images/"})
|
26
|
-
|
27
|
-
res["default_ctype"].should eq("application/octet-stream")
|
13
|
+
CFG.db[:directory].first[:default_ctype].should eq("application/octet-stream")
|
28
14
|
end
|
29
15
|
|
30
16
|
it "defaults to index.html for the index file" do
|
31
17
|
dir = M2Config::Dir.new({base:"/"})
|
32
|
-
|
33
|
-
res["index_file"].should eq("index.html")
|
18
|
+
CFG.db[:directory].first[:index_file].should eq("index.html")
|
34
19
|
end
|
35
20
|
|
36
21
|
describe "helps you spot common mistakes" do
|
data/spec/env.rb
CHANGED
@@ -2,7 +2,20 @@ require "bundler/setup"
|
|
2
2
|
require "m2config" # rspec automatically adds ./lib to LOAD_PATH
|
3
3
|
require "sqlite3"
|
4
4
|
require "pp"
|
5
|
+
require "pry"
|
6
|
+
require "pry-nav"
|
5
7
|
|
6
8
|
DEFAULT_DB_NAME = "config.sqlite"
|
7
9
|
CUSTOM_DB_NAME = "custom.sqlite"
|
8
10
|
EXISTING_DB_NAME = "empty.sqlite"
|
11
|
+
|
12
|
+
RSpec.configure do |config|
|
13
|
+
File.delete DEFAULT_DB_NAME rescue nil
|
14
|
+
CFG = M2Config::Config.new
|
15
|
+
config.around(:each) do |example|
|
16
|
+
CFG.db.transaction do
|
17
|
+
example.call
|
18
|
+
raise Sequel::Error::Rollback
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
data/spec/handler_spec.rb
CHANGED
@@ -1,37 +1,25 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
2
|
require "env"
|
3
3
|
|
4
|
-
M2Config::Config.new # Dummy call to ensure that model classes are required (cf. M2Config::new)
|
5
|
-
|
6
4
|
describe M2Config::Handler do
|
7
|
-
before(:each) do
|
8
|
-
File.delete DEFAULT_DB_NAME rescue nil
|
9
|
-
@cfg = M2Config::Config.new
|
10
|
-
@db = SQLite3::Database.new DEFAULT_DB_NAME
|
11
|
-
@db.results_as_hash = true
|
12
|
-
end
|
13
|
-
|
14
|
-
after(:each) do
|
15
|
-
@db.close if @db && !@db.closed?
|
16
|
-
end
|
17
5
|
|
18
6
|
describe "::new" do
|
19
7
|
it "needs the ØMQ addresses and a send identifier" do
|
20
8
|
M2Config::Handler.new({ send_spec:"tcp://10.0.0.1:8989",
|
21
9
|
recv_spec:"tcp://10.0.0.1:9898",
|
22
10
|
send_ident: "dev.example.com ID"})
|
23
|
-
res =
|
24
|
-
res[
|
25
|
-
res[
|
26
|
-
res[
|
11
|
+
res = CFG.db[:handler].first
|
12
|
+
res[:send_spec].should eq("tcp://10.0.0.1:8989")
|
13
|
+
res[:recv_spec].should eq("tcp://10.0.0.1:9898")
|
14
|
+
res[:send_ident].should eq("dev.example.com ID")
|
27
15
|
end
|
28
16
|
|
29
17
|
it "turns nil into empty string when recv_ident is not set" do
|
30
18
|
M2Config::Handler.new({ send_spec:"tcp://10.0.0.1:8989",
|
31
19
|
recv_spec:"tcp://10.0.0.1:9898",
|
32
20
|
send_ident: "dev.example.com ID"})
|
33
|
-
res =
|
34
|
-
res[
|
21
|
+
res = CFG.db[:handler].first
|
22
|
+
res[:recv_ident].should be_empty
|
35
23
|
end
|
36
24
|
|
37
25
|
describe "helps you spot common mistakes" do
|
data/spec/host_spec.rb
CHANGED
@@ -1,39 +1,29 @@
|
|
1
1
|
require "env"
|
2
2
|
|
3
|
-
M2Config::Config.new # Dummy call to ensure that model classes are required (cf. M2Config::new)
|
4
|
-
|
5
3
|
describe M2Config::Host do
|
6
4
|
before(:each) do
|
7
|
-
|
8
|
-
@cfg = M2Config::Config.new
|
9
|
-
@db = SQLite3::Database.new DEFAULT_DB_NAME
|
10
|
-
@db.results_as_hash = true
|
11
|
-
@srv = @cfg.add_server
|
5
|
+
@srv = CFG.add_server
|
12
6
|
end
|
13
|
-
|
14
|
-
after(:each) do
|
15
|
-
@db.close if @db && !@db.closed?
|
16
|
-
end
|
17
|
-
|
7
|
+
|
18
8
|
describe "::new" do
|
19
9
|
it "needs to know the domain name served" do
|
20
10
|
M2Config::Host.new({matching:"example.com", name: "ex"})
|
21
|
-
res =
|
22
|
-
res[
|
11
|
+
res = CFG.db[:host].first
|
12
|
+
res[:matching].should eq("example.com")
|
23
13
|
end
|
24
14
|
|
25
15
|
it "can use the uuid of a server" do
|
26
16
|
host = M2Config::Host.new({matching:"example.com", name: "ex", srvUuid: @srv.uuid})
|
27
|
-
res =
|
28
|
-
res[
|
29
|
-
res[
|
17
|
+
res = CFG.db[:host].where(id: host.id).first
|
18
|
+
res[:server_id].should eq(@srv.id)
|
19
|
+
res[:matching].should eq("example.com")
|
30
20
|
end
|
31
21
|
|
32
22
|
it "can use a server instance" do
|
33
23
|
host = M2Config::Host.new({matching:"example.com", name: "ex", srv: @srv})
|
34
|
-
res =
|
35
|
-
res[
|
36
|
-
res[
|
24
|
+
res = CFG.db[:host].where(id: host.id).first
|
25
|
+
res[:server_id].should eq(@srv.id)
|
26
|
+
res[:matching].should eq("example.com")
|
37
27
|
end
|
38
28
|
|
39
29
|
it "enforces mongrel2 constraint about nil name" do
|
@@ -49,8 +39,8 @@ describe M2Config::Host do
|
|
49
39
|
dirH = M2Config::Dir.new({base: "static/"})
|
50
40
|
dirR = M2Config::Route.new({path:"/blog", target: dirH})
|
51
41
|
host.add_route dirR
|
52
|
-
res =
|
53
|
-
res[
|
42
|
+
res = CFG.db[:route].first
|
43
|
+
res[:host_id].should eq(host.id)
|
54
44
|
end
|
55
45
|
end
|
56
46
|
|
@@ -59,10 +49,26 @@ describe M2Config::Host do
|
|
59
49
|
host = M2Config::Host.new({matching:"example.com", name: "ex"})
|
60
50
|
dir1 = M2Config::Dir.new({base: "static/"})
|
61
51
|
dir2 = M2Config::Dir.new({base: "images/"})
|
62
|
-
host.add_route M2Config::Route.new({path:"/
|
63
|
-
host.add_route M2Config::Route.new({path:"/
|
52
|
+
host.add_route M2Config::Route.new({path:"/blog1", target: dir1})
|
53
|
+
host.add_route M2Config::Route.new({path:"/blog1", target: dir2})
|
64
54
|
host.check_routes.should be_false
|
65
55
|
end
|
56
|
+
|
57
|
+
it 'returns true if all routes have different paths' do
|
58
|
+
host = M2Config::Host.new({matching:"example2.com", name: "ex"})
|
59
|
+
dir1 = M2Config::Dir.new({base: "static/"})
|
60
|
+
dir2 = M2Config::Dir.new({base: "images/"})
|
61
|
+
r1 = M2Config::Route.new({path:"/blog3", target: dir1})
|
62
|
+
r2 = M2Config::Route.new({path:"/images", target: dir2})
|
63
|
+
host.add_route r1
|
64
|
+
host.add_route r2
|
65
|
+
host.check_routes.should be_true
|
66
|
+
end
|
67
|
+
|
68
|
+
it 'withstands the idea of not having any routes' do # , {focus: true}
|
69
|
+
host = M2Config::Host.new({matching:"example.com", name: "ex"})
|
70
|
+
host.check_routes.should be_true
|
71
|
+
end
|
66
72
|
end
|
67
73
|
|
68
74
|
end
|
data/spec/m2config_spec.rb
CHANGED
@@ -1,18 +1,12 @@
|
|
1
1
|
require "env"
|
2
2
|
|
3
3
|
TABLES = %w(directory handler host log mimetype proxy route server setting statistic filter)
|
4
|
-
|
5
|
-
File.delete EXISTING_DB_NAME rescue nil
|
6
|
-
emptyDB = SQLite3::Database.new EXISTING_DB_NAME
|
7
|
-
|
4
|
+
|
8
5
|
describe M2Config do
|
9
6
|
|
10
|
-
before(:
|
11
|
-
File.delete DEFAULT_DB_NAME rescue nil
|
12
|
-
File.delete CUSTOM_DB_NAME rescue nil
|
13
|
-
@cfg = M2Config::Config.new
|
7
|
+
before(:all) do
|
14
8
|
end
|
15
|
-
|
9
|
+
|
16
10
|
after(:each) do
|
17
11
|
@db.close if @db && !@db.closed?
|
18
12
|
end
|
@@ -21,11 +15,6 @@ describe M2Config do
|
|
21
15
|
File.should exist DEFAULT_DB_NAME
|
22
16
|
end
|
23
17
|
|
24
|
-
it 'can create the database in a specific file' do
|
25
|
-
@cfg = M2Config::Config.new CUSTOM_DB_NAME
|
26
|
-
File.should exist CUSTOM_DB_NAME
|
27
|
-
end
|
28
|
-
|
29
18
|
it 'learns the DB schema from the official schema dump' do
|
30
19
|
for table in TABLES do
|
31
20
|
M2Config::Config.tables.should include table
|
@@ -39,23 +28,12 @@ describe M2Config do
|
|
39
28
|
end
|
40
29
|
end
|
41
30
|
|
42
|
-
it 'does not change the schema if the database file pre-exists' do
|
43
|
-
@cfg = M2Config::Config.new EXISTING_DB_NAME
|
44
|
-
expect {emptyDB.execute("SELECT * FROM server;")}.to raise_error
|
45
|
-
end
|
46
|
-
|
47
31
|
describe '#[]=' do
|
48
|
-
|
49
32
|
it 'creates or modifies the value of a setting' do
|
50
|
-
|
51
|
-
db.
|
52
|
-
@cfg["zeromq.threads"] = 8
|
53
|
-
res = db.get_first_row("SELECT * FROM setting WHERE key=?;", "zeromq.threads")
|
54
|
-
res["value"].should eq("8")
|
33
|
+
CFG["zeromq.threads"] = 8
|
34
|
+
CFG.db[:setting].where(key:"zeromq.threads").first[:value].should eq("8")
|
55
35
|
end
|
56
|
-
|
57
36
|
end
|
58
|
-
|
59
37
|
|
60
38
|
end
|
61
39
|
|
data/spec/proxy_spec.rb
CHANGED
@@ -3,23 +3,13 @@ require "env"
|
|
3
3
|
M2Config::Config.new # Dummy call to ensure that model classes are required (cf. M2Config::new)
|
4
4
|
|
5
5
|
describe M2Config::Proxy do
|
6
|
-
before(:each) do
|
7
|
-
File.delete DEFAULT_DB_NAME rescue nil
|
8
|
-
@cfg = M2Config::Config.new
|
9
|
-
@db = SQLite3::Database.new DEFAULT_DB_NAME
|
10
|
-
@db.results_as_hash = true
|
11
|
-
end
|
12
|
-
|
13
|
-
after(:each) do
|
14
|
-
@db.close if @db && !@db.closed?
|
15
|
-
end
|
16
6
|
|
17
7
|
describe "::new" do
|
18
8
|
it "needs an address and a port number" do
|
19
9
|
M2Config::Proxy.new({addr:"legacy.local", port: 8080})
|
20
|
-
res=
|
21
|
-
res[
|
22
|
-
res[
|
10
|
+
res = CFG.db[:proxy].first
|
11
|
+
res[:addr].should eq("legacy.local")
|
12
|
+
res[:port].should eq(8080)
|
23
13
|
end
|
24
14
|
end
|
25
15
|
|
data/spec/route_spec.rb
CHANGED
@@ -1,51 +1,57 @@
|
|
1
1
|
require "env"
|
2
2
|
|
3
|
-
M2Config::Config.new # Dummy call to ensure that model classes are required (cf. M2Config::new)
|
4
|
-
|
5
3
|
describe M2Config::Route do
|
6
|
-
before(:each) do
|
7
|
-
File.delete DEFAULT_DB_NAME rescue nil
|
8
|
-
@cfg = M2Config::Config.new
|
9
|
-
@dirH = M2Config::Dir.new({base: "static/"})
|
10
|
-
@db = SQLite3::Database.new DEFAULT_DB_NAME
|
11
|
-
@db.results_as_hash = true
|
12
|
-
end
|
13
|
-
|
14
|
-
after(:each) do
|
15
|
-
@db.close if @db && !@db.closed?
|
16
|
-
end
|
17
4
|
|
18
5
|
describe "::new" do
|
19
6
|
it "needs to know the path pattern and the target handler" do
|
20
|
-
M2Config::
|
21
|
-
|
22
|
-
res[
|
23
|
-
res[
|
24
|
-
res[
|
7
|
+
dirH = M2Config::Dir.new({base: "static/"})
|
8
|
+
M2Config::Route.new({path:"/blog", target: dirH})
|
9
|
+
res = CFG.db[:route].first
|
10
|
+
res[:path].should eq("/blog")
|
11
|
+
res[:target_id].should eq(dirH.id)
|
12
|
+
res[:target_type].should eq(dirH.type)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
describe "::elect!" do
|
17
|
+
it "makes a route the exclusive matcher for its path by deleting all other matching routes (on the same host)" do
|
18
|
+
host = M2Config::Host.new({name:"main",matching:"actime.biz"})
|
19
|
+
dirH = M2Config::Dir.new({base: "static/"})
|
20
|
+
dir2 = M2Config::Dir.new({base: "ManceRayder/"})
|
21
|
+
r1 = M2Config::Route.new({path:"/king", target: dirH})
|
22
|
+
r2 = M2Config::Route.new({path:"/king", target: dir2})
|
23
|
+
r3 = M2Config::Route.new({path:"/king", target: dirH})
|
24
|
+
M2Config::Route.elect!(r2)
|
25
|
+
host.check_routes.should be_true
|
26
|
+
king = M2Config::Route.where(path: "/king").first
|
27
|
+
king.target.base.should eq("ManceRayder/")
|
25
28
|
end
|
26
29
|
end
|
27
30
|
|
28
31
|
describe "#host=" do
|
29
32
|
it "can be used if the host is not known at creation" do
|
30
33
|
host = M2Config::Host.new({matching:"example.com", name: "ex"})
|
31
|
-
|
34
|
+
dirH = M2Config::Dir.new({base: "static/"})
|
35
|
+
r = M2Config::Route.new({path:"/blog", target: dirH})
|
32
36
|
r.host = host.id
|
33
|
-
res =
|
34
|
-
res[
|
37
|
+
res = CFG.db[:route].first
|
38
|
+
res[:host_id].should eq(host.id)
|
35
39
|
end
|
36
40
|
|
37
41
|
it "can take a Host instance" do
|
38
42
|
host = M2Config::Host.new({matching:"example.com", name: "ex"})
|
39
|
-
|
43
|
+
dirH = M2Config::Dir.new({base: "static/"})
|
44
|
+
r = M2Config::Route.new({path:"/blog", target: dirH})
|
40
45
|
r.host = host
|
41
|
-
res =
|
42
|
-
res[
|
46
|
+
res = CFG.db[:route].first
|
47
|
+
res[:host_id].should eq(host.id)
|
43
48
|
end
|
44
49
|
end
|
45
50
|
|
46
|
-
describe '#host' do #
|
51
|
+
describe '#host' do #
|
47
52
|
it 'returns the associated Host object' do
|
48
|
-
|
53
|
+
dirH = M2Config::Dir.new({base: "static/"})
|
54
|
+
r = M2Config::Route.new({path:"/blog", target: dirH})
|
49
55
|
r.host = M2Config::Host.new({matching:"example.com", name: "ex"})
|
50
56
|
r.host.matching.should eq("example.com")
|
51
57
|
end
|
@@ -53,19 +59,21 @@ describe M2Config::Route do
|
|
53
59
|
|
54
60
|
describe '#target=' do
|
55
61
|
it 'reassigns the target object' do
|
56
|
-
|
62
|
+
dirH = M2Config::Dir.new({base: "static/"})
|
63
|
+
r = M2Config::Route.new({path:"/blog", target: dirH})
|
57
64
|
newTarget = M2Config::Proxy.new({addr:"127.0.0.1", port: 15970})
|
58
65
|
r.target = newTarget
|
59
|
-
res =
|
60
|
-
res[
|
61
|
-
res[
|
66
|
+
res = CFG.db[:route].first
|
67
|
+
res[:target_id].should eq(newTarget.id)
|
68
|
+
res[:target_type].should eq(newTarget.type)
|
62
69
|
end
|
63
70
|
end
|
64
71
|
|
65
72
|
describe '#target' do
|
66
73
|
it 'returns the Target object' do
|
67
|
-
|
68
|
-
r.target
|
74
|
+
dirH = M2Config::Dir.new({base: "static/"})
|
75
|
+
r = M2Config::Route.new({path:"/blog", target: dirH})
|
76
|
+
r.target.base.should eq dirH.base
|
69
77
|
end
|
70
78
|
end
|
71
79
|
|
data/spec/server_spec.rb
CHANGED
@@ -1,33 +1,23 @@
|
|
1
1
|
require "env"
|
2
2
|
|
3
|
-
M2Config::Config.new # Dummy call to ensure that model classes are required (cf. M2Config::new)
|
4
|
-
|
5
3
|
describe M2Config::Server do
|
6
4
|
before(:each) do
|
7
|
-
File.delete DEFAULT_DB_NAME rescue nil
|
8
|
-
@cfg = M2Config::Config.new
|
9
|
-
@db = SQLite3::Database.new DEFAULT_DB_NAME
|
10
|
-
@db.results_as_hash = true
|
11
5
|
@srv = M2Config::Server.new
|
12
6
|
@host = M2Config::Host.new({matching:"example.com", name: "ex", server_id:(rand 42)})
|
13
7
|
end
|
14
|
-
|
15
|
-
after(:each) do
|
16
|
-
@db.close if @db && !@db.closed?
|
17
|
-
end
|
18
8
|
|
19
9
|
describe '::new' do
|
20
10
|
it 'creates a server entry with reasonable default settings' do
|
21
|
-
res=
|
22
|
-
res[
|
23
|
-
res[
|
24
|
-
res[
|
25
|
-
res[
|
26
|
-
res[
|
27
|
-
res[
|
28
|
-
res[
|
29
|
-
res[
|
30
|
-
res[
|
11
|
+
res = CFG.db[:server].first
|
12
|
+
res[:access_log].should eq(M2Config::Server::ACCESS_LOG)
|
13
|
+
res[:error_log].should eq(M2Config::Server::ERROR_LOG)
|
14
|
+
res[:pid_file].should eq(M2Config::Server::PID_FILE)
|
15
|
+
res[:chroot].should eq(M2Config::Server::CHROOT)
|
16
|
+
res[:default_host].should eq(M2Config::Server::DEFAULT_HOST)
|
17
|
+
res[:name].should eq(M2Config::Server::NAME)
|
18
|
+
res[:bind_addr].should eq(M2Config::Server::BIND_ADDR)
|
19
|
+
res[:port].should eq(M2Config::Server::PORT)
|
20
|
+
res[:use_ssl].should eq(M2Config::Server::USE_SSL)
|
31
21
|
end
|
32
22
|
|
33
23
|
end
|
@@ -47,8 +37,8 @@ describe M2Config::Server do
|
|
47
37
|
describe '#add_host (assigns the given host to the server)' do
|
48
38
|
it 'accepts an existing Host instance' do
|
49
39
|
@srv.add_host @host
|
50
|
-
res=
|
51
|
-
res[
|
40
|
+
res = CFG.db[:host].where(id: @host.id).first
|
41
|
+
res[:server_id].should eq(@srv.id)
|
52
42
|
end
|
53
43
|
end
|
54
44
|
end
|
data/spec/setting_spec.rb
CHANGED
@@ -1,32 +1,20 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
2
|
require "env"
|
3
3
|
|
4
|
-
M2Config::Config.new # Dummy call to ensure that model classes are required (cf. M2Config::new)
|
5
|
-
|
6
4
|
describe M2Config::Setting do
|
7
|
-
before(:each) do
|
8
|
-
File.delete DEFAULT_DB_NAME rescue nil
|
9
|
-
@cfg = M2Config::Config.new
|
10
|
-
@db = SQLite3::Database.new DEFAULT_DB_NAME
|
11
|
-
@db.results_as_hash = true
|
12
|
-
end
|
13
|
-
|
14
|
-
after(:each) do
|
15
|
-
@db.close if @db && !@db.closed?
|
16
|
-
end
|
17
5
|
|
18
6
|
describe "::new" do
|
19
7
|
it "stores the given value under the given key" do
|
20
8
|
M2Config::Setting.new("answer",42)
|
21
|
-
res =
|
22
|
-
res[
|
9
|
+
res = CFG.db[:setting].first
|
10
|
+
res[:value].should eq("42")
|
23
11
|
end
|
24
12
|
|
25
13
|
it "updates the existing value if the given key is already present" do
|
26
14
|
M2Config::Setting.new("answer",41)
|
27
15
|
M2Config::Setting.new("answer",42)
|
28
|
-
res =
|
29
|
-
res[
|
16
|
+
res = CFG.db[:setting].first
|
17
|
+
res[:value].should eq("42")
|
30
18
|
end
|
31
19
|
end
|
32
20
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: m2config
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Arnaud Meuret
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-03-
|
11
|
+
date: 2013-03-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sqlite3
|