public
Rubygem
Description: Take FogBugz offline with you
Clone URL: git://github.com/francois/fogbugz_offline.git
Search Repo:
Reintroduced FogbugzOffline::Config, but it is a base class for 
GlobalConfig and LocalConfig.
francois (author)
Thu May 15 13:31:31 -0700 2008
commit  8ac223ce4e400667f391c217c4c8be1aa5ad8fab
tree    1c2208fe9253b93b74ce4baa0c7e2d5440eaf604
parent  acee378c9ef246ae3a2622835a8b7903ed70e67f
...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
0
@@ -0,0 +1,24 @@
0
+require "yaml"
0
+
0
+module FogbugzOffline
0
+ class Config
0
+ attr_reader :path, :config
0
+
0
+ def initialize(path)
0
+ @path = path
0
+
0
+ begin
0
+ @config = YAML.load_file(@path)
0
+ rescue SystemCallError
0
+ @config = Hash.new
0
+ end
0
+ end
0
+
0
+ def write
0
+ @path.dirname.mkdir unless @path.dirname.directory?
0
+ File.open(@path, "wb") do |io|
0
+ YAML.dump(@config, io)
0
+ end
0
+ end
0
+ end
0
+end
...
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
 
17
18
19
...
33
34
35
36
37
38
39
40
41
42
43
44
...
1
2
3
4
 
 
 
 
 
 
 
 
 
 
 
 
 
5
6
7
8
...
22
23
24
 
 
 
 
 
 
 
25
26
0
@@ -1,19 +1,8 @@
0
+require "fogbugz_offline/config"
0
 require "yaml"
0
 
0
 module FogbugzOffline
0
- class GlobalConfig
0
- attr_reader :path, :config
0
-
0
- def initialize(path)
0
- @path = path
0
-
0
- begin
0
- @config = YAML.load_file(@path)
0
- rescue SystemCallError
0
- @config = Hash.new
0
- end
0
- end
0
-
0
+ class GlobalConfig < FogbugzOffline::Config
0
     def add_project(project_url)
0
       projects[project_url] = Array.new
0
     end
0
@@ -33,12 +22,5 @@ module FogbugzOffline
0
     def project(url)
0
       projects[project_url] ||= []
0
     end
0
-
0
- def write
0
- @path.dirname.mkdir unless @path.dirname.directory?
0
- File.open(@path, "wb") do |io|
0
- YAML.dump(@config, io)
0
- end
0
- end
0
   end
0
 end
...
1
2
 
3
4
...
1
 
2
3
4
0
@@ -1,4 +1,4 @@
0
 module FogbugzOffline
0
- class LocalConfig
0
+ class LocalConfig < FogbugzOffline::Config
0
   end
0
 end
...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
0
@@ -0,0 +1,55 @@
0
+require File.dirname(__FILE__) + "/spec_helper"
0
+require "yaml"
0
+
0
+describe FogbugzOffline::Config, "#initialize" do
0
+ before do
0
+ YAML.stub!(:load_file).and_return(@config = {"http://my.project.com/" => []})
0
+ end
0
+
0
+ it "should read the config file as YAML" do
0
+ YAML.should_receive(:load_file).with(path = mock("config file path")).and_return({})
0
+ FogbugzOffline::GlobalConfig.new(path)
0
+ end
0
+
0
+ it "should rescue Errno::ENOENT and not raise any exception" do
0
+ YAML.stub!(:load_file).and_raise(Errno::ENOENT)
0
+ lambda { FogbugzOffline::GlobalConfig.new(mock("config file path")) }.should_not raise_error
0
+ end
0
+
0
+ it "should make the config available in #config" do
0
+ global = FogbugzOffline::GlobalConfig.new(mock("config file path"))
0
+ global.config.should == @config
0
+ end
0
+
0
+ it "should remember the original path in #path" do
0
+ global = FogbugzOffline::GlobalConfig.new(path = mock("config file path"))
0
+ global.path.should == path
0
+ end
0
+end
0
+
0
+describe FogbugzOffline::Config, "#write" do
0
+ before do
0
+ YAML.stub!(:load_file).and_return(@config = {"config" => "value"})
0
+ @global = FogbugzOffline::GlobalConfig.new(@path = Pathname.new("config file path"))
0
+ @path.stub!(:dirname).and_return(@dir = mock("config file dir"))
0
+ @dir.stub!(:directory?).and_return(true)
0
+ File.stub!(:open).and_yield(@io = mock("io"))
0
+ YAML.stub!(:dump)
0
+ end
0
+
0
+ it "should open a File for writing on the original path" do
0
+ File.should_receive(:open).with(@path, "wb")
0
+ @global.write
0
+ end
0
+
0
+ it "should call YAML#dump with @config and @io" do
0
+ YAML.should_receive(:dump).with(@config, @io)
0
+ @global.write
0
+ end
0
+
0
+ it "should create missing directories in the path" do
0
+ @dir.stub!(:directory?).and_return(false)
0
+ @dir.should_receive(:mkdir)
0
+ @global.write
0
+ end
0
+end
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0
@@ -1,55 +0,0 @@
0
-require File.dirname(__FILE__) + "/spec_helper"
0
-require "yaml"
0
-
0
-describe FogbugzOffline::GlobalConfig, "#initialize" do
0
- before do
0
- YAML.stub!(:load_file).and_return(@config = {"http://my.project.com/" => []})
0
- end
0
-
0
- it "should read the config file as YAML" do
0
- YAML.should_receive(:load_file).with(path = mock("config file path")).and_return({})
0
- FogbugzOffline::GlobalConfig.new(path)
0
- end
0
-
0
- it "should rescue Errno::ENOENT and not raise any exception" do
0
- YAML.stub!(:load_file).and_raise(Errno::ENOENT)
0
- lambda { FogbugzOffline::GlobalConfig.new(mock("config file path")) }.should_not raise_error
0
- end
0
-
0
- it "should make the config available in #config" do
0
- global = FogbugzOffline::GlobalConfig.new(mock("config file path"))
0
- global.config.should == @config
0
- end
0
-
0
- it "should remember the original path in #path" do
0
- global = FogbugzOffline::GlobalConfig.new(path = mock("config file path"))
0
- global.path.should == path
0
- end
0
-end
0
-
0
-describe FogbugzOffline::GlobalConfig, "#write" do
0
- before do
0
- YAML.stub!(:load_file).and_return(@config = {"config" => "value"})
0
- @global = FogbugzOffline::GlobalConfig.new(@path = Pathname.new("config file path"))
0
- @path.stub!(:dirname).and_return(@dir = mock("config file dir"))
0
- @dir.stub!(:directory?).and_return(true)
0
- File.stub!(:open).and_yield(@io = mock("io"))
0
- YAML.stub!(:dump)
0
- end
0
-
0
- it "should open a File for writing on the original path" do
0
- File.should_receive(:open).with(@path, "wb")
0
- @global.write
0
- end
0
-
0
- it "should call YAML#dump with @config and @io" do
0
- YAML.should_receive(:dump).with(@config, @io)
0
- @global.write
0
- end
0
-
0
- it "should create missing directories in the path" do
0
- @dir.stub!(:directory?).and_return(false)
0
- @dir.should_receive(:mkdir)
0
- @global.write
0
- end
0
-end

Comments

    No one has commented yet.