dbmanager 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -58,11 +58,7 @@ module Dbmanager
58
58
  end
59
59
 
60
60
  def import_command
61
- unless target.protected?
62
- "mysql #{params(target)} < #{tmp_file}"
63
- else
64
- raise EnvironmentProtectedError
65
- end
61
+ "mysql #{params(target)} < #{tmp_file}"
66
62
  end
67
63
 
68
64
  def remove_tmp_file
@@ -5,6 +5,7 @@
5
5
  #
6
6
  # The dump process happens in the #run method, and is eventually delegated to
7
7
  # the specific database adapter which must implement the #run method.
8
+
8
9
  module Dbmanager
9
10
  module Dumpable
10
11
  def self.extended(base)
@@ -1,4 +1,3 @@
1
- require 'ostruct'
2
1
  # An +Environment+ object is created for each environment listed in the
3
2
  # database.yml file.
4
3
  #
@@ -13,6 +12,9 @@ require 'ostruct'
13
12
  # If on the other hand you want to be free to overwrite the production db
14
13
  # you need to explicitly set +protected: false+ to that environment in the
15
14
  # database.yml file.
15
+
16
+ require 'ostruct'
17
+
16
18
  module Dbmanager
17
19
  class Environment < OpenStruct
18
20
 
@@ -8,6 +8,7 @@
8
8
  # The source and target environment must use the same adapter, ie you cannot
9
9
  # import a mysql database on a sqlite3 database. For that purpose you can use
10
10
  # the taps gem.
11
+
11
12
  module Dbmanager
12
13
  module Importable
13
14
  def self.extended(base)
@@ -16,8 +17,12 @@ module Dbmanager
16
17
 
17
18
  def run
18
19
  @target = get_env('target')
19
- execute_import
20
- output.puts 'Database Import completed.'
20
+ if target.protected?
21
+ raise EnvironmentProtectedError
22
+ else
23
+ execute_import
24
+ output.puts 'Database Import completed.'
25
+ end
21
26
  end
22
27
 
23
28
  def execute_import
@@ -7,6 +7,7 @@
7
7
  #
8
8
  # Extension modules must define the #run method which contains the specific
9
9
  # behaviour they provide.
10
+
10
11
  module Dbmanager
11
12
  class Runner
12
13
  attr_reader :input, :output, :environments, :source
@@ -1,3 +1,3 @@
1
1
  module Dbmanager
2
- VERSION = '0.1.1'
2
+ VERSION = '0.1.2'
3
3
  end
@@ -58,17 +58,8 @@ module Dbmanager
58
58
  end
59
59
 
60
60
  describe '#import_command' do
61
- context 'when environment is not protected' do
62
- it 'returns expected command' do
63
- subject.import_command.should == 'mysql -ubeta_user < /some/arbitrary/path'
64
- end
65
- end
66
-
67
- context 'when environment is protected' do
68
- it 'raises EnvironmentProtectedError' do
69
- target.stub! :protected? => true
70
- expect { subject.import_command }.to raise_error(EnvironmentProtectedError)
71
- end
61
+ it 'returns expected command' do
62
+ subject.import_command.should == 'mysql -ubeta_user < /some/arbitrary/path'
72
63
  end
73
64
  end
74
65
 
@@ -20,7 +20,7 @@ module Dbmanager
20
20
  before do
21
21
  subject.stub(
22
22
  :source => mock(:adapter => 'mysql2'),
23
- :target => mock(:adapter => 'mysql2')
23
+ :target => mock(:adapter => 'mysql2', :protected? => false)
24
24
  )
25
25
  end
26
26
 
@@ -49,11 +49,23 @@ module Dbmanager
49
49
  end
50
50
 
51
51
  describe '#run' do
52
- it 'outputs expected messages' do
53
- subject.stub(:execute_import => nil)
54
- subject.run
55
- message = 'Database Import completed.'
56
- subject.output.content.should include(message)
52
+ context 'when target is protected' do
53
+ before { subject.stub :target => mock(:protected? => true) }
54
+
55
+ it 'raises EnvironmentProtectedError' do
56
+ expect { subject.run }.to raise_error(EnvironmentProtectedError)
57
+ end
58
+ end
59
+
60
+ context 'when target is not protected' do
61
+ before { subject.stub :target => mock(:protected? => false) }
62
+
63
+ it 'outputs expected messages' do
64
+ subject.stub(:execute_import => nil)
65
+ subject.run
66
+ message = 'Database Import completed.'
67
+ subject.output.content.should include(message)
68
+ end
57
69
  end
58
70
  end
59
71
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dbmanager
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
4
+ hash: 31
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 1
10
- version: 0.1.1
9
+ - 2
10
+ version: 0.1.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - andrea longhi
@@ -15,11 +15,12 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-06-27 00:00:00 Z
18
+ date: 2012-07-04 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: activesupport
22
- version_requirements: &id001 !ruby/object:Gem::Requirement
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
23
24
  none: false
24
25
  requirements:
25
26
  - - ">="
@@ -29,11 +30,11 @@ dependencies:
29
30
  - 0
30
31
  version: "0"
31
32
  type: :runtime
32
- requirement: *id001
33
- prerelease: false
33
+ version_requirements: *id001
34
34
  - !ruby/object:Gem::Dependency
35
35
  name: rspec
36
- version_requirements: &id002 !ruby/object:Gem::Requirement
36
+ prerelease: false
37
+ requirement: &id002 !ruby/object:Gem::Requirement
37
38
  none: false
38
39
  requirements:
39
40
  - - ">="
@@ -43,11 +44,11 @@ dependencies:
43
44
  - 0
44
45
  version: "0"
45
46
  type: :development
46
- requirement: *id002
47
- prerelease: false
47
+ version_requirements: *id002
48
48
  - !ruby/object:Gem::Dependency
49
49
  name: rake
50
- version_requirements: &id003 !ruby/object:Gem::Requirement
50
+ prerelease: false
51
+ requirement: &id003 !ruby/object:Gem::Requirement
51
52
  none: false
52
53
  requirements:
53
54
  - - ">="
@@ -57,8 +58,7 @@ dependencies:
57
58
  - 0
58
59
  version: "0"
59
60
  type: :development
60
- requirement: *id003
61
- prerelease: false
61
+ version_requirements: *id003
62
62
  description: helps manage db dumps and imports via rake tasks
63
63
  email:
64
64
  - andrea.longhi@mikamai.com
@@ -146,3 +146,4 @@ test_files:
146
146
  - spec/lib/yml_parser_spec.rb
147
147
  - spec/spec_helper.rb
148
148
  - spec/support/std_stub.rb
149
+ has_rdoc: