wordpress-deploy 1.0.0.alpha2 → 1.0.0.rc1

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 (40) hide show
  1. data/.gitignore +7 -1
  2. data/Guardfile +1 -16
  3. data/README.md +56 -0
  4. data/lib/wordpress_deploy.rb +43 -9
  5. data/lib/wordpress_deploy/cli/helpers.rb +6 -3
  6. data/lib/wordpress_deploy/cli/utility.rb +56 -33
  7. data/lib/wordpress_deploy/config.rb +77 -0
  8. data/lib/wordpress_deploy/database/mysql.rb +281 -20
  9. data/lib/wordpress_deploy/environment.rb +85 -43
  10. data/lib/wordpress_deploy/environments.rb +89 -0
  11. data/lib/wordpress_deploy/logger.rb +3 -3
  12. data/lib/wordpress_deploy/{transfer_protocols → storage}/ftp.rb +52 -116
  13. data/lib/wordpress_deploy/storage/local.rb +12 -0
  14. data/lib/wordpress_deploy/version.rb +1 -1
  15. data/lib/wordpress_deploy/wordpress/salts.rb +68 -0
  16. data/spec/data/blue.rb +52 -0
  17. data/spec/data/development.rb +49 -0
  18. data/spec/data/green.rb +52 -0
  19. data/spec/data/production.rb +52 -0
  20. data/spec/data/red.rb +52 -0
  21. data/spec/data/wp-config.php +90 -0
  22. data/spec/spec_helper.rb +16 -5
  23. data/spec/wordpress_deploy/cli/utility_spec.rb +48 -0
  24. data/spec/{environment_spec.rb → wordpress_deploy/config_spec.rb} +9 -7
  25. data/spec/wordpress_deploy/database/mysql_spec.rb +147 -0
  26. data/spec/wordpress_deploy/environment_spec.rb +96 -0
  27. data/spec/wordpress_deploy/environments_spec.rb +65 -0
  28. data/spec/wordpress_deploy/storage/ftp_spec.rb +58 -0
  29. data/spec/wordpress_deploy/storage/local_spec.rb +0 -0
  30. data/spec/wordpress_deploy/wordpress/salts_spec.rb +70 -0
  31. data/{spec/data/wp-config-sample.php → templates/wp-config.erb} +17 -17
  32. data/wordpress_deploy.gemspec +7 -6
  33. metadata +64 -30
  34. data/Gemfile.lock +0 -83
  35. data/lib/wordpress_deploy/wordpress/configuration.rb +0 -196
  36. data/spec/data/ftp.yml +0 -4
  37. data/spec/data/wp-config.yml +0 -128
  38. data/spec/database/mysql_spec.rb +0 -93
  39. data/spec/transfer_protocols/ftp_spec.rb +0 -193
  40. data/spec/wordpress/configuration_spec.rb +0 -202
@@ -0,0 +1,48 @@
1
+ require 'spec_helper'
2
+
3
+ describe WordpressDeploy::Cli::Utility do
4
+ before(:each) do
5
+ # Make sure the logger is defined
6
+ WordpressDeploy::Logger.should_receive(:verbose=)
7
+
8
+ # Make sure the options are defined
9
+ WordpressDeploy::Config.should_receive(:set_options)
10
+
11
+ # Make sure the environments are loaded
12
+ WordpressDeploy::Environments.should_receive(:load)
13
+ end
14
+
15
+ it "should generate the wp-config.php file for a real environment" do
16
+ # Get the Environment instance
17
+ stub = double("Environment")
18
+ WordpressDeploy::Environments.should_receive(:find).with(:development).and_return(stub)
19
+
20
+ # Because the find method was stubbed just make sure the
21
+ # Environment#save_wp_config is called on the stubbed
22
+ # object
23
+ stub.should_receive(:save_wp_config)
24
+
25
+ # Execute the command
26
+ args = ["config", "development"]
27
+ arg, options = WordpressDeploy::Cli::Utility.start(args)
28
+ end
29
+
30
+ it "should deploy the configured environments" do
31
+ # Get the Environment instance
32
+ from = double("Environment")
33
+ to = double("Environment")
34
+ WordpressDeploy::Environments.should_receive(:find).once.with(:development).and_return(from)
35
+ WordpressDeploy::Environments.should_receive(:find).once.with(:production).and_return(to)
36
+
37
+ from.should_receive(:database)
38
+
39
+ to.should_receive(:save_wp_config)
40
+ to.should_receive(:transmit)
41
+ to.should_receive(:datbase)
42
+
43
+ # Execute the command
44
+ args = ["deploy", "development", "production"]
45
+ arg, options = WordpressDeploy::Cli::Utility.start(args)
46
+ end
47
+
48
+ end
@@ -1,35 +1,37 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe WordpressDeploy::Environment do
3
+ describe WordpressDeploy::Config do
4
4
 
5
5
  it { should respond_to :set_options }
6
6
 
7
7
  let(:new_options) do
8
- Hash["root_dir", "/some/new/dir", "wp_dir", "./dir2"]
8
+ Hash["root_dir", "/some/new/dir", "wp_dir", "./dir2", "sql_dir", "./sql"]
9
9
  end
10
10
 
11
11
  it "should allow mass assignment of options" do
12
12
  subject.set_options new_options
13
13
  subject.root_dir.should eq "/some/new/dir"
14
14
  subject.wp_dir.should eq "/some/new/dir/dir2"
15
+ subject.sql_dir.should eq "/some/new/dir/sql"
15
16
  subject.log_file.should =~ /\/some\/new\/dir/
16
17
  end
17
18
 
18
19
  its(:root_dir) { should eq data_dir }
19
20
  its(:wp_dir) { should eq data_dir }
21
+ its(:sql_dir) { should eq data_dir }
20
22
  its(:log_file) { should =~ /#{data_dir}.*.log/ }
21
23
 
22
24
  context "logs" do
23
- before(:all) { @log_before = WordpressDeploy::Environment.logging? }
25
+ before(:all) { @log_before = WordpressDeploy::Config.logging? }
24
26
  it "should default to logging off unless explicitly set to true" do
25
- WordpressDeploy::Environment.logging = true
27
+ WordpressDeploy::Config.logging = true
26
28
  [:true, "true", 1, 0, false, :false, "Cool"].each do |val|
27
- WordpressDeploy::Environment.logging = val
28
- WordpressDeploy::Environment.logging?.should be_false
29
+ WordpressDeploy::Config.logging = val
30
+ WordpressDeploy::Config.logging?.should be_false
29
31
  end
30
32
  end
31
33
  its(:logging?) { should be_false }
32
- after(:all) { WordpressDeploy::Environment.logging = @log_before }
34
+ after(:all) { WordpressDeploy::Config.logging = @log_before }
33
35
  end
34
36
  end
35
37
 
@@ -0,0 +1,147 @@
1
+ require 'spec_helper'
2
+
3
+ include WordpressDeploy::Database
4
+ include WordpressDeploy::Wordpress
5
+
6
+ describe MySql do
7
+
8
+ let(:mysql) { "/path/to/mysql" }
9
+ let(:mysqldump) { "/path/to/mysqldump" }
10
+
11
+ it { should respond_to :run }
12
+ it { should respond_to :utility }
13
+ it { should respond_to :command_name }
14
+ it { should respond_to :file }
15
+ it { should respond_to :save! }
16
+ it { should respond_to :send! }
17
+ it { should respond_to :migrate! }
18
+
19
+ shared_examples "the environment is" do |env_name|
20
+ before(:all) { WordpressDeploy::Environments.load }
21
+ subject { WordpressDeploy::Environments.find(env_name).database }
22
+ context "#{env_name}" do
23
+ its(:name) { should eq expected_name }
24
+ its(:user) { should eq expected_user }
25
+ its(:password) { should eq expected_password }
26
+ its(:host) { should eq expected_host }
27
+ its(:wp_host) { should eq expected_wp_host }
28
+ its(:charset) { should eq expected_charset }
29
+ its(:collate) { should eq expected_collate }
30
+ its(:port) { should eq expected_port }
31
+ its(:socket) { should eq expected_socket }
32
+ its(:port?) { should eq has_port }
33
+ its(:socket?) { should eq has_socket }
34
+ its(:file) { should =~ /#{expected_name}.sql$/ }
35
+ end
36
+ end
37
+
38
+ it_should_behave_like "the environment is", :development do
39
+ let(:expected_name) { "developer_database_name" }
40
+ let(:expected_user) { "root" }
41
+ let(:expected_password) { "q9&hu6Re_*dReWr_GAba_2wr89#2Ra8$" }
42
+ let(:expected_host) { "localhost" }
43
+ let(:expected_wp_host) { "localhost" }
44
+ let(:expected_charset) { "utf8" }
45
+ let(:expected_collate) { "" }
46
+ let(:expected_port) { 3306 }
47
+ let(:expected_socket) { "" }
48
+ let(:has_port) { false }
49
+ let(:has_socket) { false }
50
+
51
+ let(:expected_args) { "-P \"3306\" -h \"localhost\" -u \"root\" -p\"q9&hu6Re_*dReWr_GAba_2wr89#2Ra8$\" -B \"developer_database_name\"" }
52
+ end
53
+
54
+ it_should_behave_like "the environment is", :production do
55
+ let(:expected_name) { "production_database_name" }
56
+ let(:expected_user) { "some_user" }
57
+ let(:expected_password) { "trecuwawraJaZe6P@kucraDrachustUq" }
58
+ let(:expected_host) { "abbott.biz" }
59
+ let(:expected_wp_host) { "abbott.biz:6654" }
60
+ let(:expected_charset) { "utf8" }
61
+ let(:expected_collate) { "" }
62
+ let(:expected_port) { 6654 }
63
+ let(:expected_socket) { "" }
64
+ let(:has_port) { true }
65
+ let(:has_socket) { false }
66
+
67
+ let(:expected_args) { "-P \"6654\" -h \"abbott.biz\" -u \"some_user\" -p\"trecuwawraJaZe6P@kucraDrachustUq\" -B \"production_database_name\"" }
68
+ end
69
+
70
+ it_should_behave_like "the environment is", :red do
71
+ let(:expected_name) { "red" }
72
+ let(:expected_user) { "red_user" }
73
+ let(:expected_password) { "Bun__huPEMeBreM6tebRAp@eguzuQExe" }
74
+ let(:expected_host) { "hanerutherford.biz" }
75
+ let(:expected_wp_host) { "hanerutherford.biz" }
76
+ let(:expected_charset) { "utf8" }
77
+ let(:expected_collate) { "" }
78
+ let(:expected_port) { 3306 }
79
+ let(:expected_socket) { "" }
80
+ let(:has_port) { false }
81
+ let(:has_socket) { false }
82
+
83
+ let(:expected_args) { "-P \"3306\" -h \"hanerutherford.biz\" -u \"red_user\" -p\"Bun__huPEMeBreM6tebRAp@eguzuQExe\" -B \"red\"" }
84
+ end
85
+
86
+ it_should_behave_like "the environment is", :green do
87
+ let(:expected_name) { "green" }
88
+ let(:expected_user) { "domenick.dare" }
89
+ let(:expected_password) { "Daw&HEWuzaz6sa&epHech_spAKucHaTH" }
90
+ let(:expected_host) { "yundt.org" }
91
+ let(:expected_wp_host) { "yundt.org" }
92
+ let(:expected_charset) { "utf8" }
93
+ let(:expected_collate) { "" }
94
+ let(:expected_port) { 3306 }
95
+ let(:expected_socket) { "" }
96
+ let(:has_port) { false }
97
+ let(:has_socket) { false }
98
+
99
+ let(:expected_args) { "-P \"3306\" -h \"yundt.org\" -u \"domenick.dare\" -p\"Daw&HEWuzaz6sa&epHech_spAKucHaTH\" -B \"green\"" }
100
+ end
101
+
102
+ it_should_behave_like "the environment is", :blue do
103
+ let(:expected_name) { "blue" }
104
+ let(:expected_user) { "harrison" }
105
+ let(:expected_password) { "w5@reba?9?pepuk7w9a#H86ustaGawE!" }
106
+ let(:expected_host) { "torphagenes.com" }
107
+ let(:expected_wp_host) { "torphagenes.com:/tmp/mysql5.sock" }
108
+ let(:expected_charset) { "utf8" }
109
+ let(:expected_collate) { "" }
110
+ let(:expected_port) { 3306 }
111
+ let(:expected_socket) { "/tmp/mysql5.sock" }
112
+ let(:has_port) { false }
113
+ let(:has_socket) { true }
114
+
115
+ let(:expected_args) { "-P \"3306\" -h \"torphagenes.com\" -u \"harrison\" -p\"w5@reba?9?pepuk7w9a#H86ustaGawE!\" -B \"blue\"" }
116
+ end
117
+
118
+ context "dump the configuration's database to the local filesystem" do
119
+ let(:mysql_cmd) { "#{mysqldump} -P \"6654\" -h \"abbott.biz\" -u \"some_user\" -p\"trecuwawraJaZe6P@kucraDrachustUq\" -B \"production_database_name\"" }
120
+
121
+ before(:each) do
122
+ @mysql = WordpressDeploy::Environments.production.database
123
+ @mysql.should_receive(:utility).with("mysqldump").and_return(mysqldump)
124
+ @mysql.should_receive(:run).with(mysql_cmd).and_return("STDOUT from run")
125
+ end
126
+
127
+ it "should call the mysqldump command with the correct arguments" do
128
+ @mysql.save!
129
+ end
130
+
131
+ it "should then save the output from STDOUT to a file" do
132
+ # Stub file behavior;
133
+ # expect to receive a call to new, write, and close
134
+ file = double("file")
135
+ File.should_receive(:new).with(/production_database_name.sql$/, 'w').and_return(file)
136
+ file.should_receive(:write).with("STDOUT from run")
137
+ file.should_receive(:close)
138
+
139
+ @mysql.save!
140
+ end
141
+ end
142
+
143
+ context "send a dumped configuration's database to a remote database" do
144
+
145
+ end
146
+
147
+ end
@@ -0,0 +1,96 @@
1
+ require 'spec_helper'
2
+ require 'tempfile'
3
+
4
+ describe WordpressDeploy::Environment do
5
+ let(:tmp_file) do
6
+ tmp = Tempfile.new ["wp-config", ".php"]
7
+ path = tmp.path
8
+ tmp.unlink
9
+ path
10
+ end
11
+
12
+ let(:wp_config_out) { File.read(File.join(data_dir, "wp-config.php")) }
13
+
14
+ let(:sample_configuration) do
15
+ WordpressDeploy::Environment.new(:sample, false) do
16
+
17
+ wplang "de_DE"
18
+ wpdebug true
19
+
20
+ database do
21
+ name "production_database_name"
22
+ user "some_user"
23
+ password "trecuwawraJaZe6P@kucraDrachustUq"
24
+ host "abbott.biz:6654"
25
+ charset "utf8"
26
+ collate "ryan-collate"
27
+ table_prefix "ryan_";
28
+ end
29
+
30
+ salts do
31
+ auth_key '<r-*;SgTbz7&}VlyE.[H,F~4GB+s>)MRm9Y8KuUw{c15!Q3i/vIqtA^|jOPa6feW'
32
+ secure_auth_key 'a%*bxGH)us+mQOPh7[I2$U{;Eijk.r#w!T>NZz&S?<V:AWY~vyC]3odLe}q9D56t'
33
+ logged_in_key 'k#>.*)5W,V|OJSHRF?;dvmb/{LGg8hNB2ZQK]s$0+-1Itw7ux^YElr@9fn6i<P4j'
34
+ nonce_key 'hCOW{xmyPG*z;oYJtgRvMFrnI.k0%&1KL,ewUT^2!>up=E:QD/)+d[|6$#?qSs]<'
35
+ auth_salt '~qC3]YB&ou/ry6<z{-WhPNR|I.mL2)XdHS+1p}?Ql^MKEiGA(>:f=#tc%;84Tkx7'
36
+ secure_auth_salt 'RF,ZU<H^$Cgq}8S&[Y4zE65OBW(+.:0LDMGlr/ujk#JT{-?;29iyP*d~)nVp1cbe'
37
+ logged_in_salt 'aT6q#EXyj3s*=Qf%0doLFc$?@O4i:S)I[GZRH/PWJw{^mY8(N,.xpMVD91etnv}&'
38
+ nonce_salt 'FSOjHgapy-3b>&B^c@Pzw49ALqZ!<M7uvGJUnV;t#.C/kxoX:5*}{21=hsRT?l8,'
39
+ end
40
+
41
+ end
42
+ end
43
+
44
+ context "sample working configuration" do
45
+ subject { sample_configuration }
46
+
47
+ it { should respond_to :name }
48
+ it { should respond_to :database }
49
+ it { should respond_to :transfer }
50
+
51
+ its(:name) { should eq :sample }
52
+ its(:wplang) { should eq "de_DE" }
53
+ its(:wpdebug) { should eq "true" }
54
+
55
+ context "database configuration" do
56
+ subject { sample_configuration.database }
57
+ its(:name) { should eq "production_database_name" }
58
+ its(:user) { should eq "some_user" }
59
+ its(:password) { should eq "trecuwawraJaZe6P@kucraDrachustUq" }
60
+ its(:host) { should eq "abbott.biz" }
61
+ its(:charset) { should eq "utf8" }
62
+ its(:collate) { should eq "ryan-collate" }
63
+ its(:table_prefix) { should eq "ryan_" }
64
+ end
65
+
66
+ context "save wp-config.php" do
67
+ before(:each) do
68
+ WordpressDeploy::Environment.stub(:output_file).and_return(tmp_file)
69
+ end
70
+ it "should save the wp-config.php file" do
71
+ # Remove the file from the filesystem (if it exists)
72
+ FileUtils.rm(tmp_file) if File.exists?(tmp_file)
73
+
74
+ # Try saving it
75
+ subject.save_wp_config
76
+
77
+ # Check that it now exists
78
+ File.exists?(tmp_file).should be_true
79
+
80
+ # Remove the file from the filesystem (if it exists)
81
+ FileUtils.rm(tmp_file) if File.exists?(tmp_file)
82
+ end
83
+
84
+ it "should have all of the correct values" do
85
+ file = mock('file')
86
+ file.should_receive(:write).with(wp_config_out)
87
+ File.should_receive(:open).with(tmp_file, 'w').and_yield(file)
88
+
89
+ # Try saving the file
90
+ subject.save_wp_config
91
+ end
92
+ end
93
+
94
+ end
95
+
96
+ end
@@ -0,0 +1,65 @@
1
+ require 'spec_helper'
2
+
3
+ describe WordpressDeploy::Environments do
4
+ it { should respond_to :load }
5
+ it { should respond_to :<< }
6
+ it { should respond_to :available_names }
7
+ it { should respond_to :names }
8
+ it { should respond_to :name? }
9
+ it { should respond_to :find }
10
+
11
+ context "loading and accessing configuration files" do
12
+ its(:names) { should have(5).symbols }
13
+ its(:names) { should include :development }
14
+ its(:names) { should include :production }
15
+ its(:names) { should include :red }
16
+ its(:names) { should include :green }
17
+ its(:names) { should include :blue }
18
+ its(:available_names) { should have(5).symbols }
19
+ its(:available_names) { should include :development }
20
+ its(:available_names) { should include :production }
21
+ its(:available_names) { should include :red }
22
+ its(:available_names) { should include :green }
23
+ its(:available_names) { should include :blue }
24
+
25
+ it { should respond_to :development }
26
+ it { should respond_to :production }
27
+ it { should respond_to :red }
28
+ it { should respond_to :green }
29
+ it { should respond_to :blue }
30
+
31
+ its(:development) { should be_instance_of WordpressDeploy::Environment }
32
+ its(:production) { should be_instance_of WordpressDeploy::Environment }
33
+ its(:red) { should be_instance_of WordpressDeploy::Environment }
34
+ its(:green) { should be_instance_of WordpressDeploy::Environment }
35
+ its(:blue) { should be_instance_of WordpressDeploy::Environment }
36
+ end
37
+
38
+ context "check for valid names" do
39
+ it "should validate :development" do
40
+ subject.name?(:development).should be_true
41
+ end
42
+ it "should validate :production" do
43
+ subject.name?(:production).should be_true
44
+ end
45
+ it "should validate :red" do
46
+ subject.name?(:red).should be_true
47
+ end
48
+ it "should validate :green" do
49
+ subject.name?(:green).should be_true
50
+ end
51
+ it "should validate :blue" do
52
+ subject.name?(:blue).should be_true
53
+ end
54
+ it "should not validate :cool" do
55
+ subject.name?(:cool).should be_false
56
+ end
57
+ end
58
+
59
+ context "allow method to find a name" do
60
+ it "should not validate :cool" do
61
+ expect { subject.find(:cool) }.to raise_error(Exception)
62
+ end
63
+ end
64
+
65
+ end
@@ -0,0 +1,58 @@
1
+ require 'spec_helper'
2
+
3
+ include WordpressDeploy
4
+
5
+ describe WordpressDeploy::Storage::Ftp do
6
+ before(:each) do
7
+ # None of the methods that follow are testing
8
+ # the Net::FTP object actions; therefore they
9
+ # can be stubbed out
10
+ @ftp = double("ftp")
11
+ [:connect, :login, :passive=].each do |methods|
12
+ @ftp.stub(methods).with(any_args)
13
+ end
14
+ Net::FTP.stub(:new).and_return(@ftp)
15
+ end
16
+
17
+ it "has methods that allow for interactive overwrite" do
18
+ expect { subject.transmit }.to raise_error(NotImplementedError)
19
+ expect { subject.receive }.to raise_error(NotImplementedError)
20
+ end
21
+
22
+ it { should respond_to :transmit! }
23
+ it { should respond_to :receive! }
24
+
25
+ context "FTP connection" do
26
+ before(:each) do
27
+ @ftp = double("ftp")
28
+ @ftp.should_receive(:connect).with("ftp.hanerutherford.biz", 77)
29
+ @ftp.should_receive(:login).with("red_user", "Bun__huPEMeBreM6tebRAp@eguzuQExe")
30
+ @ftp.should_receive(:passive=).with(true)
31
+ @ftp.stub(:pwd)
32
+ @ftp.stub(:closed?).and_return(false)
33
+ @ftp.stub(:close)
34
+ @ftp.stub(:chdir)
35
+ @ftp.stub(:putbinaryfile)
36
+ Net::FTP.stub(:new).and_return(@ftp)
37
+ WordpressDeploy::Storage::Ftp.any_instance.stub(:ftp).and_return(@ftp)
38
+ end
39
+
40
+ it "should send files" do
41
+ files = Dir.glob(File.join(data_dir, "**/*"))
42
+
43
+ Dir.should_receive(:glob).with("#{data_dir}/**/*").and_return(files)
44
+
45
+ ftp = WordpressDeploy::Storage::Ftp.new do
46
+ host "ftp.hanerutherford.biz:77"
47
+ user "red_user"
48
+ password "Bun__huPEMeBreM6tebRAp@eguzuQExe"
49
+ destination "/html"
50
+ end
51
+
52
+ ftp.should_receive(:put_file).exactly(files.count).times
53
+
54
+ ftp.transmit!
55
+ end
56
+ end
57
+
58
+ end