class PrestaShopAutomation::PrestaShop

Public Class Methods

new(options) click to toggle source
Calls superclass method
# File lib/prestashop-automation.rb, line 52
    def initialize options

            @front_office_url = options[:front_office_url]
            @back_office_url  = options[:back_office_url]
@installer_url = options[:installer_url]
            @admin_email = options[:admin_email] || 'pub@prestashop.com'
            @admin_password = options[:admin_password] || '123456789'
            @default_customer_email = options[:default_customer_email] || 'pub@prestashop.com'
            @default_customer_password = options[:default_customer_password] || '123456789'
            @database_user = options[:database_user] || 'root'
            @database_password = options[:database_password] || ''
            @database_name = options[:database_name]
            @database_prefix = options[:database_prefix] || 'ps_'
            @database_port = options[:database_port] || '3306'
            @database_host = options[:database_host] || 'localhost'
@filesystem_path = options[:filesystem_path]
            @version = options[:version]

            @dumps = []

            super :selenium_with_long_timeout
    end

Public Instance Methods

all(*args) click to toggle source

Rspec defines this method, but we want the one from Capybara::Session

# File lib/prestashop-automation.rb, line 48
def all *args
        Capybara::Session.instance_method(:all).bind(self).call *args
end
clear_cookies() click to toggle source
# File lib/prestashop-automation.rb, line 113
def clear_cookies
        reset!
end
dump_database(target) click to toggle source
# File lib/prestashop-automation.rb, line 79
def dump_database target
        if database_exists
                cmd = "mysqldump -uroot "
                if @database_password.to_s.strip != ''
                        cmd += "-p#{Shellwords.shellescape @database_password} "
                end
                cmd += "-h#{Shellwords.shellescape @database_host} "
                cmd += "-P#{@database_port} "
                cmd += "#{Shellwords.shellescape @database_name} "
                cmd += "> #{Shellwords.shellescape target}"
                `#{cmd}`
                if !$?.success?
                        throw "Could not dump database!"
                end
                return true
        else
                return false
        end
end
load_database(src) click to toggle source
# File lib/prestashop-automation.rb, line 99
def load_database src
        prepare_database
        cmd = "mysql -uroot "
        if @database_password.to_s.strip != ''
                cmd += "-p#{Shellwords.shellescape @database_password} "
        end
        cmd += "-h#{Shellwords.shellescape @database_host} "
        cmd += "-P#{@database_port} "
        cmd += "#{Shellwords.shellescape @database_name} "
        cmd += "< #{Shellwords.shellescape src}"
        `#{cmd}`
        return $?.success?
end
quit() click to toggle source
# File lib/prestashop-automation.rb, line 75
def quit
    driver.browser.quit
end
restore(dump=nil) click to toggle source
# File lib/prestashop-automation.rb, line 133
def restore dump=nil
        unless dump
                dump = @dumps.pop
        end

        if dump[:database]
                load_database dump[:database].path
        end
end
save() click to toggle source
# File lib/prestashop-automation.rb, line 117
def save
        out = {
                :database => nil,
                :files => nil
        }

        if database_exists
                out[:database] = Tempfile.new 'prestashop-db'
                dump_database out[:database].path
        end

        @dumps << out

        return out
end