reflection 0.4.6 → 0.5.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.
@@ -1,4 +1,15 @@
1
1
  === current HEAD
2
+
3
+ * enhancements
4
+ * Move instead of copy to preserve even more cpu-io-wait
5
+ * Show the current version (--version)
6
+ * Rails: Recreate the database before applying a dump
7
+ * Rails: Run pending migrations after applying a dump
8
+
9
+ === 0.4.6 / 2009-11-19
10
+
11
+ * fixes
12
+ * Fixed a blocking command call
2
13
 
3
14
  === 0.4.5 / 2009-11-19
4
15
 
@@ -6,5 +17,5 @@
6
17
  * Added --force option to skip moments of user-interaction
7
18
  * Replaced FileUtils#methods with its native brothers to gain more speed (and to preserve your cpu)
8
19
 
9
- * fixed
20
+ * fixes
10
21
  * Fixed no-working repository-pull
@@ -14,13 +14,9 @@ It provides two main command modes:
14
14
 
15
15
  Reflection is a gem, hosted on Gemcutter:
16
16
 
17
-
18
- gem install gemcutter
19
- gem tumble
20
17
  gem install reflection
21
18
 
22
19
 
23
-
24
20
  == Stashing your production data
25
21
 
26
22
  ==== The simplest form:
@@ -102,9 +98,10 @@ If you have a <tt>reflection.yml</tt> config file in your current application-de
102
98
  --rails [RAILS_ROOT] Enable dumping/applying of a Rails managed MySQL database
103
99
  --rails-env [ENV] Rails environment to instrument
104
100
  --write [FILE] Create a configuration FILE from the current commandline options
105
- -v, --verbose Include debug information in output
106
101
  --force Hide tedious warnings
107
-
102
+ -v, --verbose Include debug information in output
103
+ --version Show version
104
+
108
105
 
109
106
  == Note on Patches/Pull Requests
110
107
 
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{reflection}
8
- s.version = "0.4.6"
8
+ s.version = "0.5.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Andreas Wolff"]
12
- s.date = %q{2009-11-19}
12
+ s.date = %q{2009-12-01}
13
13
  s.default_executable = %q{reflection}
14
14
  s.description = %q{
15
15
  Reflection is designed to keep your development system in sync with your production system's files and database (by dumping).
@@ -20,7 +20,8 @@ Gem::Specification.new do |s|
20
20
  s.executables = ["reflection"]
21
21
  s.extra_rdoc_files = [
22
22
  "LICENSE",
23
- "README.rdoc"
23
+ "README.rdoc",
24
+ "TODO"
24
25
  ]
25
26
  s.files = [
26
27
  ".document",
@@ -75,6 +76,7 @@ Gem::Specification.new do |s|
75
76
  "lib/reflection/directory/base.rb",
76
77
  "lib/reflection/directory/stash.rb",
77
78
  "lib/reflection/rails.rb",
79
+ "lib/reflection/rails/database.rb",
78
80
  "lib/reflection/repository.rb",
79
81
  "lib/reflection/support.rb",
80
82
  "lib/reflection/support/home.rb",
@@ -85,6 +87,7 @@ Gem::Specification.new do |s|
85
87
  "spec/reflection/config_spec.rb",
86
88
  "spec/reflection/directory/base_spec.rb",
87
89
  "spec/reflection/directory/stash_spec.rb",
90
+ "spec/reflection/rails/database_spec.rb",
88
91
  "spec/reflection/rails_spec.rb",
89
92
  "spec/reflection/repository_spec.rb",
90
93
  "spec/reflection/support/home_spec.rb",
@@ -104,6 +107,7 @@ Gem::Specification.new do |s|
104
107
  "spec/reflection/config_spec.rb",
105
108
  "spec/reflection/directory/base_spec.rb",
106
109
  "spec/reflection/directory/stash_spec.rb",
110
+ "spec/reflection/rails/database_spec.rb",
107
111
  "spec/reflection/rails_spec.rb",
108
112
  "spec/reflection/repository_spec.rb",
109
113
  "spec/reflection/support/home_spec.rb",
data/TODO CHANGED
@@ -1,9 +1,10 @@
1
+ + Allow for relative paths (enables one config for different machines)
1
2
  + Remove stash directory if its empty (on reinit)
2
3
  + Add Logger (Reflection::Support.log)
3
4
  + After command callbacks: Apphunk
5
+ + Add cli option "use tmp-apply" --> (removes ~/.reflection/apply-dir after command)
6
+ + Allow collection of assets from Akamai and/or CloudFront (hm.. does that make sense?)
4
7
  + List existing reflections in client side
5
8
  + Allow to apply any (git) version, not just the latest
6
- + Add cli option use tmp-apply (removes ~/.reflection/apply-dir after command)
7
- + Allow collection of assets from Akamai and/or CloudFront (hm.. does that make sense?)
8
- + Add option to output --version
9
+
9
10
  - Remove ruby-git dependency
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4.6
1
+ 0.5.0
@@ -23,5 +23,10 @@ module Reflection
23
23
  Reflection::CLI.run!(args)
24
24
  end
25
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
26
31
  end
27
32
  end
@@ -4,9 +4,14 @@ module Reflection
4
4
 
5
5
  def run!(args = nil)
6
6
  config = Reflection::Config.parse(args)
7
-
7
+
8
+ if config.command == :show_version
9
+ puts "Version: #{Reflection.version}"
10
+ exit
11
+ end
12
+
8
13
  if verify_config(config) == false
9
- Reflection::Support.exit_with_error("Ahh ja, missing arguments. Please read 'reflection --help' to get a feeling of how it works.")
14
+ Reflection::Support.exit_with_error("Missing arguments. Please read 'reflection --help' to get a feeling of how it works.")
10
15
  else
11
16
  case config.command
12
17
  when :apply
@@ -35,7 +35,7 @@ module Reflection
35
35
  else
36
36
  stash_directory.clone_repository
37
37
  stash_directory.move_content_to(target_directory.path)
38
- stash_directory.get_git_index_from(target_directory.path)
38
+ # stash_directory.get_git_index_from(target_directory.path)
39
39
  end
40
40
 
41
41
  Reflection::Rails.apply(config, target_directory)
@@ -35,18 +35,18 @@ module Reflection
35
35
  end
36
36
 
37
37
  def stash_directory_into_repository(stash_directory, target_directory)
38
- copy_stash_repository_git_index_to_target(stash_directory.git_index, target_directory.path)
38
+ move_stash_repository_git_index_to_target(stash_directory.git_index, target_directory.path)
39
39
  Reflection::Rails.stash(config, target_directory) if config.rails_root
40
40
  commit_and_push_files(target_directory.path, target_directory.name)
41
41
  move_stash_repository_git_index_back(target_directory.git_index, stash_directory.path)
42
- Reflection::Rails.clean_target(target_directory) if config.rails_root
42
+ Reflection::Rails.clean_target(config, target_directory) if config.rails_root
43
43
  end
44
44
 
45
45
 
46
46
  private
47
47
 
48
- def copy_stash_repository_git_index_to_target(source, target)
49
- %x(cp -R #{source} #{target})
48
+ def move_stash_repository_git_index_to_target(source, target)
49
+ %x(mv #{source} #{target})
50
50
  end
51
51
 
52
52
  def commit_and_push_files(repository_path, target)
@@ -56,7 +56,6 @@ module Reflection
56
56
  end
57
57
 
58
58
  def move_stash_repository_git_index_back(source, target)
59
- %x(rm -rf #{File.join(target, "/.git")})
60
59
  %x(mv #{source} #{target})
61
60
  end
62
61
 
@@ -118,13 +118,17 @@ module Reflection
118
118
  self.store_configuration_path = config_file_path if config_file_path
119
119
  end
120
120
 
121
+ opts.on("--force", "Hide tedious warnings") do
122
+ self.force = true
123
+ end
124
+
121
125
  opts.on("-v", "--verbose", "Include debug information in output") do
122
126
  self.verbose = true
123
127
  Reflection.verbose = true
124
128
  end
125
129
 
126
- opts.on("--force", "Hide tedious warnings") do
127
- self.force = true
130
+ opts.on("--version", "Show version") do
131
+ self.command = :show_version
128
132
  end
129
133
  end
130
134
 
@@ -48,8 +48,9 @@ module Reflection
48
48
 
49
49
  def move_content_to(target_path)
50
50
  Reflection.log.debug "Moving content to '#{target_path}'.."
51
- %x(cp -R #{File.join(self.path, '/.')} #{target_path})
52
- %x(rm -rf #{self.path})
51
+ %x(mv #{File.join(self.path, '/*')} #{File.join(target_path, '/')})
52
+ # %x(cp -R #{File.join(self.path, '/.')} #{target_path})
53
+ # %x(rm -rf #{self.path})
53
54
  end
54
55
 
55
56
  end
@@ -1,5 +1,8 @@
1
1
  module Reflection
2
2
  module Rails
3
+
4
+ autoload :Database, 'reflection/rails/database'
5
+
3
6
  class << self
4
7
 
5
8
  def validate_environment(config)
@@ -9,52 +12,27 @@ module Reflection
9
12
  end
10
13
  end
11
14
 
12
- def clean_target(target_directory)
13
- target_file_path = File.join(target_directory.path, '_rails_database_dump.sql')
14
- if File.exist?(target_file_path)
15
- %x(rm #{target_file_path})
16
- end
17
- end
18
-
19
- def database_command_line_options(database_config)
20
- options = []
21
- options << "-h #{database_config['host']}"
22
- options << "-u#{database_config['username']}"
23
- options << "-p#{database_config['password']}" if database_config['password'] && !database_config['password'].empty?
24
- options << "#{database_config['database']}"
25
- options.join(' ')
26
- end
27
-
28
- def read_database_configuration(config)
29
- begin
30
- database_path = File.join(config.rails_root, "config/database.yml")
31
- if db_config = YAML.load_file(database_path)[config.rails_environment]
32
- return db_config
33
- else
34
- Reflection.log.error("Rails database configuration for '#{config.rails_environment}' isn't available in #{database_path}")
35
- return false
36
- end
37
- rescue => e
38
- Reflection.log.error("Error while parsing Rails database configuration: #{e}")
39
- return false
40
- end
15
+ # TODO:
16
+ # Method is obsolete and has moved to Rails::Database
17
+ # Cannot be removed atm because Command::Stash depends on it
18
+ def clean_target(config, target_directory)
19
+ database = Database.new(config.rails_root, config.rails_environment)
20
+ database.clean_dump_file(target_directory.path)
41
21
  end
42
22
 
43
23
  def stash(config, target_directory)
44
24
  Reflection.log.debug "Stashing database dump.."
45
- return unless database_config = read_database_configuration(config)
46
- options = database_command_line_options(database_config)
47
- target_file_path = File.join(target_directory.path, '_rails_database_dump.sql')
48
- %x(mysqldump #{options} --add-drop-table > #{target_file_path})
25
+ database = Database.new(config.rails_root, config.rails_environment)
26
+ database.dump_to_directory(target_directory.path)
49
27
  end
50
28
 
51
29
  def apply(config, target_directory)
52
30
  Reflection.log.debug "Applying database dump.."
53
- return unless database_config = read_database_configuration(config)
54
- options = database_command_line_options(database_config)
55
- target_file_path = File.join(target_directory.path, '_rails_database_dump.sql')
56
- %x(mysql #{options} < #{target_file_path})
57
- clean_target(target_directory)
31
+ database = Database.new(config.rails_root, config.rails_environment)
32
+ database.recreate!
33
+ database.load_dump_from_file(target_directory.path)
34
+ database.clean_dump_file(target_directory.path)
35
+ database.migrate!
58
36
  end
59
37
 
60
38
  end
@@ -0,0 +1,95 @@
1
+ module Reflection
2
+ module Rails
3
+ class Database
4
+
5
+ attr_accessor :configuration
6
+ attr_accessor :environment
7
+ attr_accessor :rails_root
8
+
9
+ def initialize(new_rails_root, new_environment)
10
+ self.rails_root = new_rails_root
11
+ self.environment = new_environment
12
+ self.configuration = read_configuration_yml
13
+ end
14
+
15
+ def dump_to_directory(target_directory)
16
+ run("mysqldump #{command_line_options} > #{dump_file_path(target_directory)}")
17
+ end
18
+
19
+ def load_dump_from_file(target_directory)
20
+ Reflection.log.debug "Loading dump.."
21
+ run("mysql #{command_line_options(:no_rehash => true)} < #{dump_file_path(target_directory)}")
22
+ end
23
+
24
+ def clean_dump_file(target_directory)
25
+ dump_file = dump_file_path(target_directory)
26
+ if File.exist?(dump_file)
27
+ run "rm #{dump_file}"
28
+ end
29
+ end
30
+
31
+ def recreate!
32
+ Reflection.log.debug "Recreating database.."
33
+ drop
34
+ create
35
+ end
36
+
37
+ def create
38
+ run("echo \"CREATE DATABASE #{self.configuration['database']};\" | mysql #{command_line_options(:skip => :database)}")
39
+ end
40
+
41
+ def drop
42
+ run("echo \"DROP DATABASE #{self.configuration['database']};\" | mysql #{command_line_options(:skip => :database)}")
43
+ end
44
+
45
+ def migrate!
46
+ Reflection.log.debug "Migrating database.."
47
+ run("(cd #{self.rails_root} && RAILS_ENV=#{self.environment} rake db:migrate)")
48
+ end
49
+
50
+ def read_configuration_yml
51
+ begin
52
+ if configuration = YAML.load_file(database_config_file_path)[self.environment]
53
+ return configuration
54
+ else
55
+ return Support.exit_with_error("Rails database configuration for '#{self.environment}' isn't available in #{database_config_file_path}")
56
+ end
57
+ rescue => e
58
+ return Support.exit_with_error("Error while parsing Rails database configuration: #{e}")
59
+ end
60
+ end
61
+
62
+ def command_line_options(opts = {})
63
+ options = []
64
+ options << "-A" if opts[:no_rehash] && opts[:no_rehash] == true
65
+ options << "-h #{configuration['host']}"
66
+ options << "-u#{configuration['username']}"
67
+ options << "-p#{configuration['password']}" if configuration['password'] && !configuration['password'].empty?
68
+ options << "#{configuration['database']}" unless opts[:skip] && opts[:skip] == :database
69
+ options.join(' ')
70
+ end
71
+
72
+ def run(command)
73
+ # Reflection.log.debug "-- #{command}"
74
+ %x(#{command})
75
+ end
76
+
77
+
78
+ private
79
+
80
+ def log_error_and_return_false(message)
81
+ Reflection.log.error(message)
82
+ return false
83
+ end
84
+
85
+ def database_config_file_path
86
+ @database_config_file_path ||= File.join(self.rails_root, "config/database.yml")
87
+ end
88
+
89
+ def dump_file_path(directory)
90
+ File.join(directory, "_rails_database_dump.sql")
91
+ end
92
+
93
+ end
94
+ end
95
+ end
@@ -73,18 +73,19 @@ describe Reflection::Command::Stash do
73
73
  @mock_stash_repository.stub!(:repository).and_return(@mock_stash_repository)
74
74
  @mock_target_directory = mock('Directory::Base', :name => 'assets', :path => '/home/tmp/assets', :git_index => '/home/tmp/assets/.git')
75
75
 
76
- @subject.stub!(:copy_stash_repository_git_index_to_target)
76
+ @subject.stub!(:move_stash_repository_git_index_to_target)
77
77
  @subject.stub!(:commit_and_push_files)
78
78
  @subject.stub!(:move_stash_repository_git_index_back)
79
79
  end
80
80
 
81
81
  it "should move the stash-repository-directory (.git) one level above the asset directory path" do
82
- @subject.should_receive(:copy_stash_repository_git_index_to_target).with("/home/stash/path/.git", "/home/tmp/assets")
82
+ @subject.should_receive(:move_stash_repository_git_index_to_target).with("/home/stash/path/.git", "/home/tmp/assets")
83
83
  @subject.stash_directory_into_repository(@mock_stash_directory, @mock_target_directory)
84
84
  end
85
85
 
86
86
  it 'should call the stash command on the database dumper if enabled' do
87
87
  @config.rails_root = "/rails/root"
88
+ Reflection::Rails.stub!(:clean_target)
88
89
  Reflection::Rails.should_receive(:stash).with(@config, @mock_target_directory)
89
90
  @subject.stash_directory_into_repository(@mock_stash_directory, @mock_target_directory)
90
91
  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
@@ -14,42 +14,49 @@ describe Reflection::Rails do
14
14
  end
15
15
  end
16
16
 
17
- describe 'read_database_configuration' do
18
- it 'should read the configuration for the specified environment' do
19
- db_config = { "host" => "localhost", "username" => "root" }
20
- YAML.should_receive(:load_file).with('/rails_root/config/database.yml').and_return({ "production" => {}, "development" => db_config })
21
- db_config = @rails.read_database_configuration(@config)
22
- db_config.should == db_config
23
- end
24
-
25
- it "should log an error and return false if the environment isn't configured" do
26
- Reflection.log.should_receive(:error).with(/available/)
27
- YAML.stub!(:load_file).and_return({ "production" => {} })
28
- @rails.read_database_configuration(@config).should be_false
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)
29
22
  end
30
23
 
31
- it "should log an error and return false if the database.yml cannot be found" do
32
- Reflection.log.should_receive(:error).with(/Error/)
33
- YAML.stub!(:load_file).and_raise(StandardError)
34
- @rails.read_database_configuration(@config).should be_false
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)
35
27
  end
36
28
  end
37
29
 
38
- describe 'database_command_line_options' do
30
+ describe 'apply' do
39
31
  before(:each) do
40
- @db_config = { "host" => "localhost", "database" => "test", "username" => "root", "password" => "secret" }
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)
41
39
  end
42
40
 
43
- it 'should create options for the mysql command' do
44
- @rails.database_command_line_options(@db_config).should == "-h localhost -uroot -psecret test"
41
+ it 'should recreate the database before apply a dump' do
42
+ @mock_database.should_receive(:recreate!)
43
+ @rails.apply(@config, @mock_target)
45
44
  end
46
45
 
47
- it 'should ignore the password option if its not available' do
48
- @db_config['password'] = ""
49
- @rails.database_command_line_options(@db_config).should == "-h localhost -uroot test"
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
50
 
51
- @db_config['password'] = nil
52
- @rails.database_command_line_options(@db_config).should == "-h localhost -uroot test"
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)
53
59
  end
54
60
  end
61
+
55
62
  end
@@ -9,6 +9,7 @@ Spec::Runner.configure do |config|
9
9
  @global_mock_log = mock('Log')
10
10
  @global_mock_log.stub!(:debug)
11
11
  @global_mock_log.stub!(:info)
12
+ @global_mock_log.stub!(:error)
12
13
  Reflection.stub!(:log).and_return(@global_mock_log)
13
14
  end
14
15
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: reflection
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.6
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andreas Wolff
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-11-19 00:00:00 +01:00
12
+ date: 2009-12-01 00:00:00 +01:00
13
13
  default_executable: reflection
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -41,6 +41,7 @@ extensions: []
41
41
  extra_rdoc_files:
42
42
  - LICENSE
43
43
  - README.rdoc
44
+ - TODO
44
45
  files:
45
46
  - .document
46
47
  - .gitignore
@@ -94,6 +95,7 @@ files:
94
95
  - lib/reflection/directory/base.rb
95
96
  - lib/reflection/directory/stash.rb
96
97
  - lib/reflection/rails.rb
98
+ - lib/reflection/rails/database.rb
97
99
  - lib/reflection/repository.rb
98
100
  - lib/reflection/support.rb
99
101
  - lib/reflection/support/home.rb
@@ -104,6 +106,7 @@ files:
104
106
  - spec/reflection/config_spec.rb
105
107
  - spec/reflection/directory/base_spec.rb
106
108
  - spec/reflection/directory/stash_spec.rb
109
+ - spec/reflection/rails/database_spec.rb
107
110
  - spec/reflection/rails_spec.rb
108
111
  - spec/reflection/repository_spec.rb
109
112
  - spec/reflection/support/home_spec.rb
@@ -145,6 +148,7 @@ test_files:
145
148
  - spec/reflection/config_spec.rb
146
149
  - spec/reflection/directory/base_spec.rb
147
150
  - spec/reflection/directory/stash_spec.rb
151
+ - spec/reflection/rails/database_spec.rb
148
152
  - spec/reflection/rails_spec.rb
149
153
  - spec/reflection/repository_spec.rb
150
154
  - spec/reflection/support/home_spec.rb