prestashop-automation 0.5 → 0.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -89,6 +89,8 @@ module PrestaShopAutomation
89
89
  sleep 4 #this wait seems necessary, strange
90
90
  click 'a.buttonFinish'
91
91
  standard_success_check
92
+
93
+ return options[:name]
92
94
  end
93
95
  end
94
96
  end
@@ -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
- results = client.query("SHOW DATABASES LIKE '#{client.escape @database_name}'")
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}%'")
@@ -60,7 +60,7 @@ module PrestaShopAutomation
60
60
 
61
61
  if options[:get_invoice_json]
62
62
  visit pdf_url+'&debug=1'
63
- return JSON.parse(page.find('body').text)
63
+ return JSON.parse(find('body').text)
64
64
  end
65
65
  end
66
66
  end
@@ -12,7 +12,7 @@ module PrestaShopAutomation
12
12
  standard_success_check
13
13
  end
14
14
 
15
- def set_gift_wrapping_option on, options
15
+ def set_gift_wrapping_option on, options={}
16
16
  goto_admin_tab 'AdminOrderPreferences'
17
17
  if on
18
18
  click_label_for 'PS_GIFT_WRAPPING_on'
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
@@ -53,11 +53,13 @@ module PrestaShopAutomation
53
53
  end
54
54
 
55
55
  def visit base, rest=nil
56
- if rest == nil
57
- super base
56
+ url = if rest == nil
57
+ base
58
58
  else
59
- super base.sub(/\/\s*/, '') + rest.sub(/^\s*\//, '')
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: prestashop-automation
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.5'
4
+ version: '0.6'
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: