prestashop-automation 0.5 → 0.6
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/actions/carriers.rb +2 -0
- data/lib/actions/installer.rb +7 -3
- data/lib/actions/orders.rb +1 -1
- data/lib/actions/settings.rb +1 -1
- data/lib/actions/taxes.rb +1 -1
- data/lib/helpers/general.rb +5 -3
- data/lib/prestashop-automation.rb +68 -0
- metadata +1 -1
data/lib/actions/carriers.rb
CHANGED
data/lib/actions/installer.rb
CHANGED
@@ -66,10 +66,14 @@ module PrestaShopAutomation
|
|
66
66
|
client.query("DROP DATABASE IF EXISTS #{safe_database_name}")
|
67
67
|
end
|
68
68
|
|
69
|
+
def database_exists
|
70
|
+
count = client.query("SHOW DATABASES LIKE '#{client.escape @database_name}'").count
|
71
|
+
expect(count).to be <= 1
|
72
|
+
count == 1
|
73
|
+
end
|
74
|
+
|
69
75
|
def prepare_database
|
70
|
-
|
71
|
-
expect(results.count).to be <= 1
|
72
|
-
if results.count == 0
|
76
|
+
if !database_exists
|
73
77
|
client.query "CREATE DATABASE #{safe_database_name}"
|
74
78
|
else
|
75
79
|
tables = client.query("SHOW TABLES IN #{safe_database_name} LIKE '#{client.escape @database_prefix}%'")
|
data/lib/actions/orders.rb
CHANGED
data/lib/actions/settings.rb
CHANGED
data/lib/actions/taxes.rb
CHANGED
@@ -33,7 +33,7 @@ module PrestaShopAutomation
|
|
33
33
|
end
|
34
34
|
|
35
35
|
def create_tax_group_from_rate rate
|
36
|
-
if /^(?:\d+(?:.\d+)?)$/ =~ rate
|
36
|
+
if /^(?:\d+(?:.\d+)?)$/ =~ rate.to_s
|
37
37
|
tax_id = create_tax :name => "#{rate}% Tax (Rate)", :rate => rate
|
38
38
|
create_tax_group :name => "#{rate}% Tax (Group)", :taxes => [{:tax_id => tax_id}]
|
39
39
|
elsif /(?:\d+(?:.\d+)?)(?:\s*(?:\+|\*)\s*(?:\d+(?:.\d+)?))+/ =~ rate
|
data/lib/helpers/general.rb
CHANGED
@@ -53,11 +53,13 @@ module PrestaShopAutomation
|
|
53
53
|
end
|
54
54
|
|
55
55
|
def visit base, rest=nil
|
56
|
-
if rest == nil
|
57
|
-
|
56
|
+
url = if rest == nil
|
57
|
+
base
|
58
58
|
else
|
59
|
-
|
59
|
+
base.sub(/\/\s*/, '') + rest.sub(/^\s*\//, '')
|
60
60
|
end
|
61
|
+
|
62
|
+
super url
|
61
63
|
end
|
62
64
|
|
63
65
|
def wait_until options = {}, &block
|
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'rspec-expectations'
|
2
2
|
require 'capybara'
|
3
|
+
require 'shellwords'
|
3
4
|
|
4
5
|
require_relative 'actions/general.rb'
|
5
6
|
require_relative 'actions/settings.rb'
|
@@ -13,6 +14,7 @@ require_relative 'actions/installer.rb'
|
|
13
14
|
require_relative 'helpers/general.rb'
|
14
15
|
|
15
16
|
module PrestaShopAutomation
|
17
|
+
|
16
18
|
class PrestaShop < Capybara::Session
|
17
19
|
|
18
20
|
include RSpec::Expectations
|
@@ -48,6 +50,8 @@ module PrestaShopAutomation
|
|
48
50
|
@filesystem_path = options[:filesystem_path]
|
49
51
|
@version = options[:version]
|
50
52
|
|
53
|
+
@dumps = []
|
54
|
+
|
51
55
|
super :selenium
|
52
56
|
end
|
53
57
|
|
@@ -55,5 +59,69 @@ module PrestaShopAutomation
|
|
55
59
|
driver.browser.quit
|
56
60
|
end
|
57
61
|
|
62
|
+
def dump_database target
|
63
|
+
if database_exists
|
64
|
+
cmd = "mysqldump -uroot "
|
65
|
+
if @database_password.to_s.strip != ''
|
66
|
+
cmd += "-p#{Shellwords.shellescape @database_password} "
|
67
|
+
end
|
68
|
+
cmd += "-h#{Shellwords.shellescape @database_host} "
|
69
|
+
cmd += "-P#{@database_port} "
|
70
|
+
cmd += "#{Shellwords.shellescape @database_name} "
|
71
|
+
cmd += "> #{Shellwords.shellescape target}"
|
72
|
+
`#{cmd}`
|
73
|
+
if !$?.success?
|
74
|
+
throw "Could not dump database!"
|
75
|
+
end
|
76
|
+
return true
|
77
|
+
else
|
78
|
+
return false
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
def load_database src
|
83
|
+
prepare_database
|
84
|
+
cmd = "mysql -uroot "
|
85
|
+
if @database_password.to_s.strip != ''
|
86
|
+
cmd += "-p#{Shellwords.shellescape @database_password} "
|
87
|
+
end
|
88
|
+
cmd += "-h#{Shellwords.shellescape @database_host} "
|
89
|
+
cmd += "-P#{@database_port} "
|
90
|
+
cmd += "#{Shellwords.shellescape @database_name} "
|
91
|
+
cmd += "< #{Shellwords.shellescape src}"
|
92
|
+
`#{cmd}`
|
93
|
+
return $?.success?
|
94
|
+
end
|
95
|
+
|
96
|
+
def clear_cookies
|
97
|
+
reset!
|
98
|
+
end
|
99
|
+
|
100
|
+
def save
|
101
|
+
out = {
|
102
|
+
:database => nil,
|
103
|
+
:files => nil
|
104
|
+
}
|
105
|
+
|
106
|
+
if database_exists
|
107
|
+
out[:database] = Tempfile.new 'prestashop-db'
|
108
|
+
dump_database out[:database].path
|
109
|
+
end
|
110
|
+
|
111
|
+
@dumps << out
|
112
|
+
|
113
|
+
return out
|
114
|
+
end
|
115
|
+
|
116
|
+
def restore dump=nil
|
117
|
+
unless dump
|
118
|
+
dump = @dumps.pop
|
119
|
+
end
|
120
|
+
|
121
|
+
if dump[:database]
|
122
|
+
load_database dump[:database].path
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
58
126
|
end
|
59
127
|
end
|