This file contains 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 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 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 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 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 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 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' |
OlderNewer