This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#spec/requests/the_service/ping_spec.rb | |
require 'spec_helper' | |
describe 'ping request' do | |
include_context 'the_service_black_box' | |
it 'returns response back' do | |
params[:type] = 'ping' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#spec/support/shared_contexts/the_service_black_box.rb | |
shared_context 'the_service_black_box' do | |
let(:params) do | |
{ | |
type: 'save', | |
data: 1 | |
} | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#/spec/support/the_service.rb | |
class TheServiceControl | |
#.... | |
def stop | |
return if @pid.nil? | |
print "Stopping TheService (PID: #{@pid}). " | |
Process.kill("KILL", -Process.getpgid(@pid)) | |
res = Process.wait | |
@pid = nil |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#/spec/support/the_service_config.yml | |
server: | |
addr: 127.0.0.1:8082 | |
db: | |
dsn: dbname=project_test sslmode=disable user=postgres password=secret | |
redis: | |
url: redis://127.0.0.1:6379/1 | |
rails: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#/spec/support/the_service.rb | |
class TheServiceControl | |
#.... | |
def start | |
return unless @pid.nil? | |
puts "TheService starting. " | |
env = config['rails']['env'] | |
cmd = "go run #{config['rails']['main_go']} --config.file=#{config_path}" | |
puts cmd #useful for debug when need run project manually |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#/spec/support/the_service.rb | |
#ensure that after all specs TheService will be stopped | |
RSpec.configure do |config| | |
config.after :suite do | |
TheServiceControl.stop | |
end | |
end | |
class TheServiceControl |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#https://en.wikipedia.org/wiki/Luhn_algorithm | |
# v1 | |
def self.check_digit_for(number) | |
digits = number.to_s.reverse.split(//) | |
sum = 0 | |
digits.each_with_index do |digit, index| | |
digit = digit.to_i | |
digit *= 2 if index.even? | |
digit -= 9 if digit > 9 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#для работы этого кода нужно установить гем 'savon' | |
#для этого выполните: gem install savon | |
#или пропишите в Gemfile: gem 'savon' | |
class TurboSMS | |
LOGIN = '...' # не забудьте активировать SOAP шлюз в личном кабинете и создать логин/пароль | |
PASSWORD = '...' | |
SENDER = 'MySite' #не забудьте добавить эту подпись в личном кабинете | |
def get_balance |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class SftpUploader | |
def upload!(local_filename, remote_filename) | |
raise "#{local_filename} not readable" unless File.exist?(local_filename) | |
connect do |sftp| | |
dirs = File.dirname(remote_filename).split('/') | |
dir_to_create = credentials.path | |
dirs.each do |dir| | |
dir_to_create = File.join(dir_to_create, dir) | |
sftp.mkdir(dir_to_create) | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//protected/config/main.php | |
return array( | |
//.. | |
'components'=>array( | |
//... | |
"clientScript"=>array( | |
"class"=>"myClientScript", | |
), | |
//.. |
NewerOlder