traquitana 0.1.1 → 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
metadata.gz.sig CHANGED
Binary file
data/lib/migrator.rb DELETED
@@ -1,25 +0,0 @@
1
- require "yaml"
2
-
3
- module Traquitana
4
- class Migrator
5
- def run
6
- old_file = "./traq/config.yml"
7
- new_file = "./config/traq.yml"
8
-
9
- return false if !File.exists?(old_file) || File.exists?(new_file)
10
-
11
- STDOUT.puts "Migrating old config file ..."
12
- contents = YAML.load(File.read(old_file))
13
- contents = contents.inject({}) {|hash,val| hash[val.first.to_s] = val.last; hash}.reject { |k,v| k == "ignore"}.to_yaml
14
- File.open(new_file, "w") { |f| f << contents }
15
-
16
- File.unlink(old_file)
17
- first_run = "#{File.dirname(old_file)}/.first_run"
18
- File.unlink(first_run) if File.exists?(first_run)
19
-
20
- dir = "#{File.dirname(old_file)}"
21
- Dir.unlink(dir) if Dir.exists?(dir)
22
- true
23
- end
24
- end
25
- end
@@ -1,75 +0,0 @@
1
- require "minitest/autorun"
2
- require "#{File.expand_path(File.dirname(__FILE__))}/../lib/traquitana.rb"
3
-
4
- describe Traquitana::Migrator do
5
- before do
6
- @migrator = Traquitana::Migrator.new
7
-
8
- @old_file = "#{File.expand_path(File.dirname(__FILE__))}/../traq/config.yml"
9
- @old_cont = File.read(@old_file)
10
-
11
- @new_file = "#{File.expand_path(File.dirname(__FILE__))}/../config/traq.yml"
12
- @new_cont = File.read(@new_file)
13
-
14
- File.unlink(@new_file)
15
- end
16
-
17
- after do
18
- FileUtils.mkdir(File.dirname(@old_file)) if !Dir.exists?(File.dirname(@old_file))
19
- FileUtils.mkdir(File.dirname(@new_file)) if !Dir.exists?(File.dirname(@new_file))
20
-
21
- File.open(@new_file,"w") {|f| f<<@new_cont}
22
- File.open(@old_file,"w") {|f| f<<@old_cont}
23
- end
24
-
25
- it "should have a run method" do
26
- @migrator.must_respond_to(:run)
27
- end
28
-
29
- it "should return false when there isn't an old config file" do
30
- contents = File.read(@old_file)
31
- File.unlink(@old_file)
32
- assert !@migrator.run
33
- File.open(@old_file,"w") {|f| f<<contents}
34
- end
35
-
36
- it "should return false if there is a new config file" do
37
- File.open(@new_file,"w") {|f| f<<@new_cont}
38
- assert !@migrator.run
39
- end
40
-
41
- it "should return true when there is an old config file" do
42
- assert @migrator.run
43
- end
44
-
45
- it "should have the new file after run" do
46
- File.unlink(@new_file) if File.exists?(@new_file)
47
- @migrator.run
48
- assert File.exists?(@new_file)
49
- end
50
-
51
- it "should not have the old file after run" do
52
- @migrator.run
53
- assert !File.exists?(@old_file)
54
- end
55
-
56
- it "should not have the old dir after run" do
57
- @migrator.run
58
- assert !Dir.exists?(File.dirname(@old_file))
59
- end
60
-
61
- it "should not have the ignore clause on the new file" do
62
- @migrator.run
63
- assert !YAML.load(File.read(@new_file)).include?("ignore")
64
- end
65
-
66
- it "should have all the keys of the old file on the new one" do
67
- old_content = YAML.load(File.read(@old_file)).reject {|k,v| k==:ignore}
68
- @migrator.run
69
- new_content = YAML.load(File.read(@new_file))
70
- old_content.each do |key,val|
71
- assert new_content.include?(key.to_s)
72
- assert new_content[key.to_s].to_s==old_content[key].to_s
73
- end
74
- end
75
- end