basiszwo-reflection 0.5.1

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.
Files changed (72) hide show
  1. data/.document +5 -0
  2. data/.gitignore +21 -0
  3. data/.yardoc +0 -0
  4. data/History.rdoc +21 -0
  5. data/LICENSE +20 -0
  6. data/README.rdoc +117 -0
  7. data/Rakefile +75 -0
  8. data/Reflection.gemspec +135 -0
  9. data/TODO.rdoc +38 -0
  10. data/VERSION +1 -0
  11. data/bin/reflection +5 -0
  12. data/doc/Reflection/CLI.html +153 -0
  13. data/doc/Reflection/Command/Apply.html +266 -0
  14. data/doc/Reflection/Command/Base.html +385 -0
  15. data/doc/Reflection/Command/Stash.html +342 -0
  16. data/doc/Reflection/Command.html +85 -0
  17. data/doc/Reflection/Config.html +902 -0
  18. data/doc/Reflection/ConfigArgumentError.html +92 -0
  19. data/doc/Reflection/Directory/Base.html +657 -0
  20. data/doc/Reflection/Directory/Stash.html +411 -0
  21. data/doc/Reflection/Directory.html +85 -0
  22. data/doc/Reflection/Rails.html +409 -0
  23. data/doc/Reflection/Repository.html +745 -0
  24. data/doc/Reflection/Support/Home.html +182 -0
  25. data/doc/Reflection/Support/Log.html +222 -0
  26. data/doc/Reflection/Support.html +141 -0
  27. data/doc/Reflection/Validations.html +135 -0
  28. data/doc/Reflection.html +285 -0
  29. data/doc/_index.html +267 -0
  30. data/doc/class_list.html +197 -0
  31. data/doc/css/common.css +1 -0
  32. data/doc/css/full_list.css +23 -0
  33. data/doc/css/style.css +261 -0
  34. data/doc/file.README.html +200 -0
  35. data/doc/file_list.html +29 -0
  36. data/doc/index.html +200 -0
  37. data/doc/js/app.js +91 -0
  38. data/doc/js/full_list.js +39 -0
  39. data/doc/js/jquery.js +19 -0
  40. data/doc/method_list.html +572 -0
  41. data/doc/top-level-namespace.html +80 -0
  42. data/lib/reflection/cli.rb +35 -0
  43. data/lib/reflection/command/apply.rb +71 -0
  44. data/lib/reflection/command/base.rb +28 -0
  45. data/lib/reflection/command/stash.rb +64 -0
  46. data/lib/reflection/command.rb +7 -0
  47. data/lib/reflection/config.rb +139 -0
  48. data/lib/reflection/directory/base.rb +58 -0
  49. data/lib/reflection/directory/stash.rb +30 -0
  50. data/lib/reflection/directory.rb +6 -0
  51. data/lib/reflection/rails/database.rb +96 -0
  52. data/lib/reflection/rails.rb +40 -0
  53. data/lib/reflection/repository.rb +71 -0
  54. data/lib/reflection/support/home.rb +17 -0
  55. data/lib/reflection/support/log.rb +20 -0
  56. data/lib/reflection/support.rb +12 -0
  57. data/lib/reflection/validations.rb +23 -0
  58. data/lib/reflection.rb +32 -0
  59. data/spec/reflection/cli_spec.rb +41 -0
  60. data/spec/reflection/command/stash_spec.rb +104 -0
  61. data/spec/reflection/config_spec.rb +126 -0
  62. data/spec/reflection/directory/base_spec.rb +38 -0
  63. data/spec/reflection/directory/stash_spec.rb +39 -0
  64. data/spec/reflection/rails/database_spec.rb +161 -0
  65. data/spec/reflection/rails_spec.rb +62 -0
  66. data/spec/reflection/repository_spec.rb +71 -0
  67. data/spec/reflection/support/home_spec.rb +30 -0
  68. data/spec/reflection/support_spec.rb +4 -0
  69. data/spec/reflection_spec.rb +21 -0
  70. data/spec/spec.opts +1 -0
  71. data/spec/spec_helper.rb +15 -0
  72. metadata +157 -0
data/lib/reflection.rb ADDED
@@ -0,0 +1,32 @@
1
+ require 'rubygems'
2
+
3
+ module Reflection
4
+ autoload :CLI, 'reflection/cli'
5
+ autoload :Config, 'reflection/config'
6
+ autoload :Command, 'reflection/command'
7
+ autoload :Directory, 'reflection/directory'
8
+ autoload :Rails, 'reflection/rails'
9
+ autoload :Repository, 'reflection/repository'
10
+ autoload :Support, 'reflection/support'
11
+ autoload :Validations, 'reflection/validations'
12
+
13
+ class << self
14
+
15
+ attr_accessor :home
16
+ attr_accessor :log
17
+ attr_accessor :verbose
18
+
19
+ def boot!(args)
20
+ @log = Reflection::Support::Log.new
21
+ @home = Reflection::Support::Home.new
22
+ @home.create
23
+ Reflection::CLI.run!(args)
24
+ end
25
+
26
+ def version
27
+ File.open(File.expand_path(File.join(__FILE__, '../..', 'VERSION')), 'r') do |f|
28
+ f.readlines.first.to_s
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,41 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe Reflection::CLI do
4
+ before(:all) do
5
+ @subject = Reflection::CLI
6
+ end
7
+
8
+ describe '#run!' do
9
+ before(:each) do
10
+ @config = mock('Reflection::Config', :command => :stash)
11
+ Reflection::Config.stub!(:parse).and_return(@config)
12
+ @subject.stub!(:verify_config).and_return(true)
13
+ end
14
+
15
+ it 'should create a config object, holding the parsed commandline options' do
16
+ Reflection::Config.should_receive(:parse).with("args").and_return(@config)
17
+ Reflection::Command::Stash.stub!(:run!)
18
+ @subject.run!("args")
19
+ end
20
+
21
+ it 'should verify the config and fail gracefully displaying a message if verification fails' do
22
+ Reflection::Support.should_receive(:exit_with_error).with(/reflection --help/)
23
+ @subject.stub!(:verify_config).and_return(false)
24
+ @subject.run!("args")
25
+ end
26
+
27
+ context 'successfully parsed options' do
28
+ it 'should call the Stash command if parse_options returned succesfull with command :stash' do
29
+ Reflection::Command::Stash.should_receive(:run!).with(@config)
30
+ @config.stub!(:command).and_return(:stash)
31
+ @subject.run!
32
+ end
33
+
34
+ it 'should call the Apply command if parse_options returned succesfull with command :apply' do
35
+ Reflection::Command::Apply.should_receive(:run!).with(@config)
36
+ @config.stub!(:command).and_return(:apply)
37
+ @subject.run!
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,104 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
+
3
+ describe Reflection::Command::Stash do
4
+ before(:each) do
5
+ @config = OpenStruct.new({ :directory => '/home/tmp/fu_asset_directory', :command => :stash })
6
+ @subject = Reflection::Command::Stash.new(@config)
7
+ end
8
+
9
+ describe 'validations' do
10
+ it 'should validate the existence of the directory' do
11
+ Reflection::Validations.should_receive(:existence_of).with('/home/tmp/fu_asset_directory')
12
+ @subject.validate!
13
+ end
14
+ end
15
+
16
+ describe '#run!' do
17
+ before(:each) do
18
+ Reflection::Repository.stub!(:exists?).and_return(false)
19
+ @subject.stub!(:prepare_stash_repository)
20
+ @subject.stub!(:stash_directory_into_repository)
21
+ end
22
+
23
+ it 'should fail if the directory is a repository' do
24
+ Reflection::Repository.stub!(:exists?).and_return(true)
25
+ Reflection::Support.should_receive(:exit_with_error)
26
+ @subject.run!
27
+ end
28
+
29
+ it 'should prepare the stash repository' do
30
+ @subject.should_receive(:prepare_stash_repository)
31
+ @subject.run!
32
+ end
33
+
34
+ it 'should stash the directory into the repository' do
35
+ @subject.should_receive(:stash_directory_into_repository)
36
+ @subject.run!
37
+ end
38
+ end
39
+
40
+ describe '#prepare_stash_repository' do
41
+ before(:each) do
42
+ @mock_stash_repository = mock('StashRepository')
43
+ @mock_stash_directory = mock('Directory::Stash', :repository => @mock_stash_repository)
44
+ end
45
+
46
+ context 'stash directory exists' do
47
+ before(:each) do
48
+ @mock_stash_directory.stub!(:exists?).and_return(true)
49
+ end
50
+
51
+ it 'should validate the repository' do
52
+ @mock_stash_directory.should_receive(:validate_repository)
53
+ @subject.prepare_stash_repository(@mock_stash_directory)
54
+ end
55
+ end
56
+
57
+ context 'stash directory does not exist' do
58
+ before(:each) do
59
+ @mock_stash_directory.stub!(:exists?).and_return(false)
60
+ end
61
+
62
+ it 'should clone the --repository into the stash path' do
63
+ @mock_stash_directory.should_receive(:clone_repository)
64
+ @subject.prepare_stash_repository(@mock_stash_directory)
65
+ end
66
+ end
67
+ end
68
+
69
+ describe '#stash_directory_into_repository' do
70
+ before(:each) do
71
+ @mock_stash_repository = mock('StashRepository')
72
+ @mock_stash_directory = mock('Directory::Stash', :git_index => '/home/stash/path/.git', :path => '/home/stash/path')
73
+ @mock_stash_repository.stub!(:repository).and_return(@mock_stash_repository)
74
+ @mock_target_directory = mock('Directory::Base', :name => 'assets', :path => '/home/tmp/assets', :git_index => '/home/tmp/assets/.git')
75
+
76
+ @subject.stub!(:move_stash_repository_git_index_to_target)
77
+ @subject.stub!(:commit_and_push_files)
78
+ @subject.stub!(:move_stash_repository_git_index_back)
79
+ end
80
+
81
+ it "should move the stash-repository-directory (.git) one level above the asset directory path" do
82
+ @subject.should_receive(:move_stash_repository_git_index_to_target).with("/home/stash/path/.git", "/home/tmp/assets")
83
+ @subject.stash_directory_into_repository(@mock_stash_directory, @mock_target_directory)
84
+ end
85
+
86
+ it 'should call the stash command on the database dumper if enabled' do
87
+ @config.rails_root = "/rails/root"
88
+ Reflection::Rails.stub!(:clean_target)
89
+ Reflection::Rails.should_receive(:stash).with(@config, @mock_target_directory)
90
+ @subject.stash_directory_into_repository(@mock_stash_directory, @mock_target_directory)
91
+ end
92
+
93
+
94
+ it "should add and push the contents of directory to the repository" do
95
+ @subject.should_receive(:commit_and_push_files).with("/home/tmp/assets", "assets")
96
+ @subject.stash_directory_into_repository(@mock_stash_directory, @mock_target_directory)
97
+ end
98
+
99
+ it "should move the directory's .git directory back to stash-directory-repository" do
100
+ @subject.should_receive(:move_stash_repository_git_index_back).with("/home/tmp/assets/.git", "/home/stash/path")
101
+ @subject.stash_directory_into_repository(@mock_stash_directory, @mock_target_directory)
102
+ end
103
+ end
104
+ end
@@ -0,0 +1,126 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe Reflection::Config do
4
+ before(:each) do
5
+ @valid_options = {
6
+ :command => :stash,
7
+ :repository => 'repo',
8
+ :directory => 'dir',
9
+ :rails_root => "rails_root",
10
+ :rails_environment => 'development',
11
+ :verbose => true,
12
+ :force => false
13
+ }
14
+ end
15
+
16
+ describe 'parse' do
17
+ before(:each) do
18
+ @mock_config = mock('Reflection::Config', :store_configuration_path => nil)
19
+ Reflection::Config.stub!(:new).and_return(@mock_config)
20
+ end
21
+
22
+ it 'should parse a yaml file if the first arg is an existing file' do
23
+ @mock_config.should_receive(:read!).with('/tmp')
24
+ Reflection::Config.parse(['/tmp'])
25
+ end
26
+
27
+ it 'should parse args as options' do
28
+ @mock_config.should_receive(:parse_command_line_options).with(['-s', '-d'])
29
+ Reflection::Config.parse(['-s', '-d'])
30
+ end
31
+
32
+ it 'should write options to configuration file if --write params is set' do
33
+ @mock_config.should_receive(:write).with('/test/path')
34
+ @mock_config.stub!(:parse_command_line_options)
35
+ @mock_config.stub!(:store_configuration_path).and_return('/test/path')
36
+ Reflection::Config.parse(['-s','-d', '--write /test/path'])
37
+ end
38
+
39
+ it 'should expect a reflection.yml config file in path if args are empty' do
40
+ Dir.stub!(:pwd).and_return('/current_dir')
41
+ @mock_config.should_receive(:read!).with('/current_dir/reflection.yml')
42
+ Reflection::Config.parse
43
+ end
44
+ end
45
+
46
+ describe '#to_hash' do
47
+ it 'should turn its attributes into a hash' do
48
+ @config = Reflection::Config.new
49
+ @config.command = :stash
50
+ @config.repository = 'repo'
51
+ @config.directory = 'dir'
52
+ @config.rails_root = 'rails_root'
53
+ @config.rails_environment = 'development'
54
+ @config.verbose = true
55
+ @config.force = false
56
+ @config.to_hash.should == @valid_options
57
+ end
58
+ end
59
+
60
+ describe '#from_hash' do
61
+ it 'should assign attributes from a hash' do
62
+ @config = Reflection::Config.new
63
+ @config.from_hash( @valid_options )
64
+ @config.command.should eql(:stash)
65
+ @config.repository.should eql('repo')
66
+ @config.directory.should eql('dir')
67
+ @config.rails_root.should eql('rails_root')
68
+ @config.rails_environment.should eql('development')
69
+ @config.verbose.should be_true
70
+ @config.force.should be_false
71
+ end
72
+ end
73
+
74
+ describe '#write' do
75
+ before(:each) do
76
+ @config = Reflection::Config.new
77
+ @mock_file = mock('File')
78
+ @mock_file.stub!(:close)
79
+ end
80
+
81
+ it 'should dump the config values to a file at the given path' do
82
+ @config.stub!(:to_hash).and_return( @valid_options )
83
+ YAML.should_receive(:dump).with( @valid_options, @mock_file )
84
+ File.should_receive(:open).with('/test/path', 'w').and_return(@mock_file)
85
+ @config.write('/test/path')
86
+ end
87
+
88
+ it 'should gracefully fail if it cannot dump the yaml file' do
89
+ Reflection::Support.should_receive(:exit_with_error)
90
+ File.should_receive(:open).with('/test/path', 'w').and_raise(StandardError)
91
+ @config.write('/test/path')
92
+ end
93
+ end
94
+
95
+ describe '#read!' do
96
+ before(:each) do
97
+ File.stub!(:exist?).and_return(true)
98
+ @config = Reflection::Config.new
99
+ end
100
+
101
+ it 'should get the config attributes from a yaml file' do
102
+ YAML.should_receive(:load_file).with('/tmp/test').and_return( @valid_options )
103
+ @config.should_receive(:from_hash).with(@valid_options)
104
+ @config.read!('/tmp/test')
105
+ end
106
+
107
+ it "should not try to load a yaml file if it doesn't exist" do
108
+ YAML.should_not_receive(:load_file)
109
+ File.stub!(:exist?).and_return(false)
110
+ @config.read!('/tmp/test')
111
+ end
112
+
113
+ it "should gracefully fail if yaml file loading crashed" do
114
+ Reflection::Support.should_receive(:exit_with_error)
115
+ YAML.stub!(:load_file).and_raise(StandardError)
116
+ @config.read!('/tmp/test')
117
+ end
118
+
119
+ it "should gracefully fail if parsing result is not a hash" do
120
+ Reflection::Support.should_receive(:exit_with_error)
121
+ YAML.stub!(:load_file).and_return("String Instead Of Hash")
122
+ @config.read!('/tmp/test')
123
+ end
124
+ end
125
+
126
+ end
@@ -0,0 +1,38 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
+
3
+ describe Reflection::Directory::Base do
4
+ before(:each) do
5
+ @subject = Reflection::Directory::Base.new("/test/home/path")
6
+ end
7
+
8
+ describe '#exists?' do
9
+ it 'should now if the path exists' do
10
+ File.stub!(:exist?).and_return(true)
11
+ @subject.exists?.should be_true
12
+ end
13
+ end
14
+
15
+ describe '#parent' do
16
+ it 'should find the parent of the last directory living in path' do
17
+ @subject.parent.path.should eql('/test/home')
18
+ end
19
+ end
20
+
21
+ describe '#name' do
22
+ it 'should find the name of the directory living at the end of path' do
23
+ @subject.name.should eql('path')
24
+ end
25
+ end
26
+
27
+ describe '#git_index' do
28
+ it 'should join an .git index directory to path' do
29
+ @subject.git_index.should eql('/test/home/path/.git')
30
+ end
31
+ end
32
+
33
+ describe '#to_s' do
34
+ it 'should resolve as path' do
35
+ @subject.to_s.should eql('/test/home/path')
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,39 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
+
3
+ describe Reflection::Directory::Stash do
4
+ before(:each) do
5
+ Reflection.home = mock('Home', :path => '/HOME_DIR/.reflection')
6
+ @mock_repository = mock("Repository", :identifier => '_identifier_', :url => 'git.rubyphunk.com')
7
+ @stash_directory = Reflection::Directory::Stash.new(@mock_repository, 'stash')
8
+ end
9
+
10
+ describe '#path' do
11
+ it 'should generate the path to the stash repository-directory ~/.reflection/stash/-md5_hash-' do
12
+ @stash_directory.path.should eql("/HOME_DIR/.reflection/stash/_identifier_")
13
+ end
14
+ end
15
+
16
+ describe '#validate_repository' do
17
+ before(:each) do
18
+ Reflection::Repository.stub!(:exists?).and_return(true)
19
+ end
20
+
21
+ it 'should compare the existing repository with the instance' do
22
+ @mock_repository.should_receive(:same_in_path?).and_return(true)
23
+ @stash_directory.validate_repository
24
+ end
25
+
26
+ it 'should fail if the repository is not the existing one in the path' do
27
+ Reflection::Support.should_receive(:exit_with_error)
28
+ @mock_repository.stub!(:same_in_path?).and_return(false)
29
+ @stash_directory.validate_repository
30
+ end
31
+ end
32
+
33
+ describe '#clone_repository' do
34
+ it 'should call clone on the repository instance' do
35
+ @mock_repository.should_receive(:clone).with(@stash_directory.path)
36
+ @stash_directory.clone_repository
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,161 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
+
3
+ describe Reflection::Rails::Database do
4
+ before(:each) do
5
+ YAML.stub!(:load_file).and_return({ 'development' => {} })
6
+ @database = Reflection::Rails::Database.new('/rails_root', 'development')
7
+ end
8
+
9
+ describe '#initialize' do
10
+ it 'should read the configuration file during init' do
11
+ YAML.should_receive(:load_file)
12
+ Reflection::Rails::Database.new('/rails_root', 'development')
13
+ end
14
+
15
+ it 'should exit with error if initialization failed' do
16
+ Reflection::Support.should_receive(:exit_with_error)
17
+ YAML.stub!(:load_file).and_raise(StandardError)
18
+ Reflection::Rails::Database.new('/rails_root', 'development')
19
+ end
20
+ end
21
+
22
+ describe '#create' do
23
+ before(:each) do
24
+ @database.configuration = { "database" => "test" }
25
+ @database.stub!(:command_line_options).and_return('options')
26
+ end
27
+
28
+ it 'should create the database' do
29
+ @database.should_receive(:run).with(/^echo "CREATE DATABASE test;"/)
30
+ @database.create
31
+ end
32
+ end
33
+
34
+ describe '#drop' do
35
+ before(:each) do
36
+ @database.configuration = { "database" => "test" }
37
+ @database.stub!(:command_line_options).and_return('options')
38
+ end
39
+
40
+ it 'should drop the database' do
41
+ @database.should_receive(:run).with(/^echo "DROP DATABASE test;"/)
42
+ @database.drop
43
+ end
44
+ end
45
+
46
+ describe '#recreate!' do
47
+ before(:each) do
48
+ @database.stub!(:create)
49
+ @database.stub!(:drop)
50
+ end
51
+
52
+ it 'should drop the database' do
53
+ @database.should_receive(:drop)
54
+ @database.recreate!
55
+ end
56
+
57
+ it 'should create the database' do
58
+ @database.should_receive(:create)
59
+ @database.recreate!
60
+ end
61
+ end
62
+
63
+ describe '#migrate!' do
64
+ before(:each) do
65
+ end
66
+
67
+ it 'should run the migrate command' do
68
+ @database.should_receive(:run).with(/rake db:migrate/)
69
+ @database.migrate!
70
+ end
71
+
72
+ it 'should temporarily cd into the rails root' do
73
+ @database.should_receive(:run).with(/cd \/rails_root/)
74
+ @database.migrate!
75
+ end
76
+
77
+ it 'should instrument the specified environment' do
78
+ @database.should_receive(:run).with(/RAILS_ENV=development/)
79
+ @database.migrate!
80
+ end
81
+ end
82
+
83
+ describe '#dump_to_directory' do
84
+ before(:each) do
85
+ @database.stub!(:command_line_options).and_return('options')
86
+ end
87
+
88
+ it 'should dump the database into the target directory' do
89
+ @database.should_receive(:run).with(/mysqldump options/)
90
+ @database.dump_to_directory('path')
91
+ end
92
+
93
+ it 'should dump the database into a special dump file' do
94
+ @database.should_receive(:run).with(/> path\/_rails_database_dump.sql$/)
95
+ @database.dump_to_directory('path')
96
+ end
97
+ end
98
+
99
+ describe '#load_dump_from_file' do
100
+ before(:each) do
101
+ @database.stub!(:command_line_options).and_return('options')
102
+ end
103
+
104
+ it 'should load the dump into the database' do
105
+ @database.should_receive(:run).with(/mysql options/)
106
+ @database.load_dump_from_file('path')
107
+ end
108
+
109
+ it 'should dump the database into a special dump file' do
110
+ @database.should_receive(:run).with(/< path\/_rails_database_dump.sql$/)
111
+ @database.load_dump_from_file('path')
112
+ end
113
+ end
114
+
115
+ describe '#read_configuration_yml' do
116
+ before(:each) do
117
+ @db_config = { "host" => "localhost", "username" => "root" }
118
+ end
119
+
120
+ it 'should read the configuration for the specified environment' do
121
+ YAML.should_receive(:load_file).with('/rails_root/config/database.yml').and_return({ "production" => {}, "development" => @db_config })
122
+ @database.read_configuration_yml.should == @db_config
123
+ end
124
+
125
+ it 'should not load the configuration twice' do
126
+ YAML.should_receive(:load_file).once.and_return({ "production" => {}, "development" => @db_config })
127
+ @database.read_configuration_yml
128
+ @database.read_configuration_yml
129
+ end
130
+
131
+ it "should #exit_with_error if the environment isn't configured" do
132
+ Reflection::Support.should_receive(:exit_with_error).with(/available/)
133
+ YAML.stub!(:load_file).and_return({ "production" => {} })
134
+ @database.read_configuration_yml
135
+ end
136
+
137
+ it "should #exit_with_error if the database.yml cannot be found" do
138
+ Reflection::Support.should_receive(:exit_with_error).with(/Error/)
139
+ YAML.stub!(:load_file).and_raise(StandardError)
140
+ @database.read_configuration_yml
141
+ end
142
+ end
143
+
144
+ describe '#command_line_options' do
145
+ before(:each) do
146
+ @database.configuration = { "host" => "localhost", "database" => "test", "username" => "root", "password" => "secret" }
147
+ end
148
+
149
+ it 'should create options for the mysql command' do
150
+ @database.command_line_options.should == "-h localhost -uroot -psecret test"
151
+ end
152
+
153
+ it 'should ignore the password option if its not available' do
154
+ @database.configuration['password'] = ""
155
+ @database.command_line_options.should == "-h localhost -uroot test"
156
+
157
+ @database.configuration['password'] = nil
158
+ @database.command_line_options.should == "-h localhost -uroot test"
159
+ end
160
+ end
161
+ end
@@ -0,0 +1,62 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe Reflection::Rails do
4
+ before(:each) do
5
+ @config = OpenStruct.new({ :rails_root => '/rails_root/', :rails_environment => 'development' })
6
+ @rails = Reflection::Rails
7
+ end
8
+
9
+ describe 'validate_environment' do
10
+ it "should fail if the specified environment does't exist" do
11
+ Reflection::Support.should_receive(:exit_with_error)
12
+ File.stub!(:exist?).and_return(false)
13
+ @rails.validate_environment(@config)
14
+ end
15
+ end
16
+
17
+ describe 'stash' do
18
+ before(:each) do
19
+ @mock_target = mock('Reflection::Directory', :path => 'target')
20
+ @mock_database = mock('Reflection::Rails::Database')
21
+ Reflection::Rails::Database.stub!(:new).and_return(@mock_database)
22
+ end
23
+
24
+ it 'should should dump the database to the target directory' do
25
+ @mock_database.should_receive(:dump_to_directory).with('target')
26
+ @rails.stash(@config, @mock_target)
27
+ end
28
+ end
29
+
30
+ describe 'apply' do
31
+ before(:each) do
32
+ @mock_target = mock('Reflection::Directory', :path => 'target')
33
+ @mock_database = mock('Reflection::Rails::Database')
34
+ @mock_database.stub!(:recreate!)
35
+ @mock_database.stub!(:load_dump_from_file)
36
+ @mock_database.stub!(:clean_dump_file)
37
+ @mock_database.stub!(:migrate!)
38
+ Reflection::Rails::Database.stub!(:new).and_return(@mock_database)
39
+ end
40
+
41
+ it 'should recreate the database before apply a dump' do
42
+ @mock_database.should_receive(:recreate!)
43
+ @rails.apply(@config, @mock_target)
44
+ end
45
+
46
+ it 'should should load the dump from the target directory into the database' do
47
+ @mock_database.should_receive(:load_dump_from_file).with('target')
48
+ @rails.apply(@config, @mock_target)
49
+ end
50
+
51
+ it 'should should remove the dump file from target' do
52
+ @mock_database.should_receive(:clean_dump_file).with('target')
53
+ @rails.apply(@config, @mock_target)
54
+ end
55
+
56
+ it 'should should migrate the database after applying a dump' do
57
+ @mock_database.should_receive(:migrate!)
58
+ @rails.apply(@config, @mock_target)
59
+ end
60
+ end
61
+
62
+ end
@@ -0,0 +1,71 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe Reflection::Repository do
4
+ before(:all) do
5
+ @test_git_url = 'git.rubyphunk.com:test.git'
6
+ @test_identifier = 'f5c4e386bcf8339e4b6e5c15c22e5b97'
7
+ end
8
+
9
+ before(:each) do
10
+ @repository = Reflection::Repository.new(@test_git_url)
11
+ @mock_git_repo = mock('Git::Base')
12
+ @mock_git_repo.stub!(:remote).and_return(@mock_remote = mock('Git::Remote'))
13
+ end
14
+
15
+ describe 'new_from_path' do
16
+ it 'should create an instance by path' do
17
+ Git.stub!(:open).and_return(@mock_git_repo)
18
+ @mock_remote.stub!(:url).and_return('git@example.com:repo.git')
19
+ instance = Reflection::Repository.new_from_path('/test/repo/path')
20
+ instance.should be_instance_of(Reflection::Repository)
21
+ instance.url.should eql('git@example.com:repo.git')
22
+ end
23
+
24
+ it 'should raise an error if path is not a valid git repository' do
25
+ lambda do
26
+ Reflection::Repository.stub!(:exists?).and_return(false)
27
+ Reflection::Repository.new_from_path('/test/repo/path')
28
+ end.should raise_error(/not a valid/)
29
+ end
30
+ end
31
+
32
+ describe 'exists?' do
33
+ it 'should return true if a repository exists in path' do
34
+ Git.should_receive(:open).with('/test/path').and_return(@mock_git_repo)
35
+ @mock_remote.stub!(:url).and_return(@test_git_url)
36
+ Reflection::Repository.exists?('/test/path').should be_true
37
+ end
38
+
39
+ it 'should return false if the path is not a repository' do
40
+ Git.should_receive(:open).with('/test/path').and_raise(ArgumentError)
41
+ Reflection::Repository.exists?('/test/path').should be_false
42
+ end
43
+ end
44
+
45
+ describe '#identifier' do
46
+ it 'should return an md5 hash of the repository url' do
47
+ @repository.identifier.should eql(@test_identifier)
48
+ end
49
+ end
50
+
51
+ describe '#same_in_path?' do
52
+ it 'should return true if the path is a repository with the repositories url' do
53
+ Git.should_receive(:open).with('/test/path').and_return(@mock_git_repo)
54
+ @mock_remote.stub!(:url).and_return(@test_git_url)
55
+ @repository.same_in_path?('/test/path').should be_true
56
+ end
57
+
58
+ it 'should return false if the path is a repository but has no remote' do
59
+ Git.should_receive(:open).with('/test/path').and_return(@mock_git_repo)
60
+ @mock_git_repo.stub!(:remote).and_return(nil)
61
+ @repository.same_in_path?('/test/path').should be_false
62
+ end
63
+ end
64
+
65
+ describe '#clone' do
66
+ it 'should clone the reposity to a path' do
67
+ Git.should_receive(:clone).with(@test_git_url, '/test/path')
68
+ @repository.clone('/test/path')
69
+ end
70
+ end
71
+ end