cc_manager 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +4 -0
- data/.rspec +1 -0
- data/Gemfile +4 -0
- data/README.md +3 -0
- data/Rakefile +1 -0
- data/bin/ccmgr +11 -0
- data/cc_manager.gemspec +59 -0
- data/features/invalid_file.feature +21 -0
- data/features/process.feature +74 -0
- data/features/support/env.rb +18 -0
- data/features/version.feature +12 -0
- data/lib/cc_manager/account.rb +75 -0
- data/lib/cc_manager/cli.rb +99 -0
- data/lib/cc_manager/version.rb +3 -0
- data/lib/cc_manager.rb +9 -0
- data/spec/add_spec.rb +60 -0
- data/spec/charge_spec.rb +77 -0
- data/spec/credit_spec.rb +77 -0
- data/spec/spec_helper.rb +2 -0
- metadata +157 -0
data/.gitignore
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/Gemfile
ADDED
data/README.md
ADDED
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'bundler/gem_tasks'
|
data/bin/ccmgr
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
ENV['BUNDLE_GEMFILE'] = File.expand_path('../../Gemfile', __FILE__)
|
4
|
+
require 'rubygems' unless defined?(Gem)
|
5
|
+
require 'bundler/setup'
|
6
|
+
|
7
|
+
lib = File.expand_path(File.dirname(__FILE__) + '/../lib')
|
8
|
+
$LOAD_PATH.unshift(lib) if File.directory?(lib) && !$LOAD_PATH.include?(lib)
|
9
|
+
|
10
|
+
require 'cc_manager/cli'
|
11
|
+
CcManager::CLI.start
|
data/cc_manager.gemspec
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "cc_manager/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "cc_manager"
|
7
|
+
s.version = CcManager::VERSION
|
8
|
+
s.authors = ["Manish Lal Das"]
|
9
|
+
s.email = ["manishlaldas.md@gmail.com"]
|
10
|
+
s.homepage = "http://manishdas.github.com/cc_manager"
|
11
|
+
s.summary = %q{Credit card processing}
|
12
|
+
s.description = %q{Managing Credit card processing with ease via command line app with file input}
|
13
|
+
|
14
|
+
s.rubyforge_project = "cc_manager"
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
+
s.executables = ["ccmgr"]
|
19
|
+
s.require_paths = ["lib"]
|
20
|
+
|
21
|
+
|
22
|
+
s.post_install_message =<<EOF
|
23
|
+
|
24
|
+
********************************************************************************
|
25
|
+
|
26
|
+
Process credit card information with ease
|
27
|
+
using CLI and file as input
|
28
|
+
|
29
|
+
# cc_details.txt
|
30
|
+
Add Tom 4111111111111111 $1000
|
31
|
+
Add Lisa 5454545454545454 $3000
|
32
|
+
Add Quincy 1234567890123456 $2000
|
33
|
+
Charge Tom $500
|
34
|
+
Charge Tom $800
|
35
|
+
Charge Lisa $7
|
36
|
+
Credit Lisa $100
|
37
|
+
Credit Quincy $200
|
38
|
+
|
39
|
+
> ccmgr cc_details.txt
|
40
|
+
|
41
|
+
Output:
|
42
|
+
|
43
|
+
Lisa: $-93
|
44
|
+
Quincy: error
|
45
|
+
Tom: $500
|
46
|
+
|
47
|
+
********************************************************************************
|
48
|
+
|
49
|
+
EOF
|
50
|
+
|
51
|
+
s.add_dependency "thor", "~> 0.14"
|
52
|
+
s.add_dependency "terminal-table", "~> 1.4"
|
53
|
+
|
54
|
+
s.add_development_dependency "aruba"
|
55
|
+
s.add_development_dependency "rspec", '~>2.6.0'
|
56
|
+
s.add_development_dependency "bundler", "~> 1.0.0"
|
57
|
+
s.add_development_dependency "pry"
|
58
|
+
s.add_development_dependency "pry-doc"
|
59
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
Feature: CLI Process
|
2
|
+
In order to process all the credit card actions
|
3
|
+
As a CLI user
|
4
|
+
I want to get final output with error message for Invalid File Location in CLI
|
5
|
+
|
6
|
+
|
7
|
+
@announce, @moderate_slow_process
|
8
|
+
Scenario: Invalid file Location
|
9
|
+
Given a file named "billings.txt" with:
|
10
|
+
"""
|
11
|
+
Add Tom 4111111111111111 $1000 Chicago
|
12
|
+
Add Lisa 5454545454545454 $3000
|
13
|
+
Charge Tom $500
|
14
|
+
Charge Lisa $7
|
15
|
+
Credit Lisa $100
|
16
|
+
"""
|
17
|
+
When I run `ccmgr -f billings_invalid.txt`
|
18
|
+
Then the output should contain:
|
19
|
+
"""
|
20
|
+
Invalid File location. Please Enter Valid path of File!!!
|
21
|
+
"""
|
@@ -0,0 +1,74 @@
|
|
1
|
+
Feature: CLI Process
|
2
|
+
In order to process all the credit card actions
|
3
|
+
As a CLI user
|
4
|
+
I want to get final output with error messages in CLI
|
5
|
+
|
6
|
+
@announce, @moderate_slow_process
|
7
|
+
Scenario: file with given actions
|
8
|
+
Given a file named "billings.txt" with:
|
9
|
+
"""
|
10
|
+
Add Tom 4111111111111111 $1000
|
11
|
+
Add Lisa 5454545454545454 $3000
|
12
|
+
Add Quincy 1234567890123456 $2000
|
13
|
+
Charge Tom $500
|
14
|
+
Charge Tom $800
|
15
|
+
Charge Lisa $7
|
16
|
+
Credit Lisa $100
|
17
|
+
Credit Quincy $200
|
18
|
+
"""
|
19
|
+
When I run `ccmgr -f billings.txt`
|
20
|
+
Then the output should match:
|
21
|
+
"""
|
22
|
+
Tom: $500
|
23
|
+
Lisa: $-93
|
24
|
+
Quincy: Error
|
25
|
+
|
26
|
+
List of Errors:
|
27
|
+
+------------------+------------------------------------------------------------+
|
28
|
+
| File Line Number | Error Message |
|
29
|
+
+------------------+------------------------------------------------------------+
|
30
|
+
| Line Number: 3 | Cannot Add Credit because Invalid Account!!! |
|
31
|
+
| Line Number: 5 | Cannot Charge because Charged Amount exceeded the limit!!! |
|
32
|
+
| Line Number: 8 | Cannot Add Credit because Invalid Account!!! |
|
33
|
+
+------------------+------------------------------------------------------------+
|
34
|
+
"""
|
35
|
+
|
36
|
+
@announce, @moderate_slow_process
|
37
|
+
Scenario: file with given actions and without errors
|
38
|
+
Given a file named "billings.txt" with:
|
39
|
+
"""
|
40
|
+
Add Tom 4111111111111111 $1000
|
41
|
+
Add Lisa 5454545454545454 $3000
|
42
|
+
Charge Tom $500
|
43
|
+
Charge Lisa $7
|
44
|
+
Credit Lisa $100
|
45
|
+
"""
|
46
|
+
When I run `ccmgr -f billings.txt`
|
47
|
+
Then the output should contain:
|
48
|
+
"""
|
49
|
+
Tom: $500
|
50
|
+
Lisa: $-93
|
51
|
+
"""
|
52
|
+
|
53
|
+
@announce, @moderate_slow_process
|
54
|
+
Scenario: file with given actions but with invalid arguments
|
55
|
+
Given a file named "billings.txt" with:
|
56
|
+
"""
|
57
|
+
Add Tom 4111111111111111 $1000 Chicago
|
58
|
+
Add Lisa 5454545454545454 $3000
|
59
|
+
Charge Tom $500
|
60
|
+
Charge Lisa $7
|
61
|
+
Credit Lisa $100
|
62
|
+
"""
|
63
|
+
When I run `ccmgr -f billings.txt`
|
64
|
+
Then the output should contain:
|
65
|
+
"""
|
66
|
+
Lisa: $-93
|
67
|
+
|
68
|
+
List of Errors:
|
69
|
+
+------------------+-----------------------+
|
70
|
+
| File Line Number | Error Message |
|
71
|
+
+------------------+-----------------------+
|
72
|
+
| Line Number: 1 | Invalid Input Line!!! |
|
73
|
+
+------------------+-----------------------+
|
74
|
+
"""
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'aruba/cucumber'
|
2
|
+
require 'cc_manager'
|
3
|
+
ENV['PATH'] = "#{File.expand_path(File.dirname(__FILE__) + '/../../bin')}#{File::PATH_SEPARATOR}#{ENV['PATH']}"
|
4
|
+
|
5
|
+
Before('@slow_process') do
|
6
|
+
@aruba_io_wait_seconds = 5
|
7
|
+
@aruba_timeout_seconds = 5
|
8
|
+
end
|
9
|
+
|
10
|
+
Before('@moderate_slow_process') do
|
11
|
+
@aruba_io_wait_seconds = 2
|
12
|
+
@aruba_timeout_seconds = 2
|
13
|
+
end
|
14
|
+
|
15
|
+
Before('@too_slow_process') do
|
16
|
+
@aruba_io_wait_seconds = 4
|
17
|
+
@aruba_timeout_seconds = 50
|
18
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
Feature: CLI Process
|
2
|
+
In order to see the version of the gem
|
3
|
+
As a CLI user
|
4
|
+
I want to get version in CLI
|
5
|
+
|
6
|
+
@announce, @moderate_slow_process
|
7
|
+
Scenario: execute version method in CLI
|
8
|
+
When I run `ccmgr -v`
|
9
|
+
Then the output should match:
|
10
|
+
"""
|
11
|
+
Version: 0.0.1
|
12
|
+
"""
|
@@ -0,0 +1,75 @@
|
|
1
|
+
module CcManager
|
2
|
+
class Account
|
3
|
+
# Contains Error message if any
|
4
|
+
attr_accessor :name, :cc_number, :limit, :balance, :errors, :valid_account
|
5
|
+
|
6
|
+
def initialize(name, cc_number, limit)
|
7
|
+
@errors = []
|
8
|
+
@valid_account = false
|
9
|
+
@name = name
|
10
|
+
@balance = "$0"
|
11
|
+
valid_amount?(limit) ? @limit = limit : @errors << "Invalid Amount specified for limit!!!"
|
12
|
+
valid_card?(cc_number) ? @cc_number = cc_number : @errors << "#{name}'s account could not be added because Credit Card is invalid!!!"
|
13
|
+
@valid_account = true if @errors.count == 0
|
14
|
+
end
|
15
|
+
|
16
|
+
def charge(charged_amount)
|
17
|
+
if valid_account?
|
18
|
+
if valid_amount?(charged_amount)
|
19
|
+
limit_val = get_amount_in_integer(self.limit)
|
20
|
+
charged_amount_val = get_amount_in_integer(charged_amount)
|
21
|
+
balance = get_amount_in_integer(self.balance)
|
22
|
+
if charged_amount_val+balance < limit_val
|
23
|
+
self.balance = get_amount_in_string(balance + charged_amount_val)
|
24
|
+
else
|
25
|
+
@errors << "Cannot Charge because Charged Amount exceeded the limit!!!"
|
26
|
+
end
|
27
|
+
else
|
28
|
+
@errors << "Cannot Charge because Invalid Amount!!!"
|
29
|
+
end
|
30
|
+
else
|
31
|
+
@errors << "Cannot Charge because Invalid Account!!!"
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def credit(credited_amount)
|
36
|
+
if valid_account?
|
37
|
+
if valid_amount?(credited_amount)
|
38
|
+
balance = get_amount_in_integer(self.balance)
|
39
|
+
credited_amount_val = get_amount_in_integer(credited_amount)
|
40
|
+
self.balance = get_amount_in_string(balance - credited_amount_val)
|
41
|
+
else
|
42
|
+
@errors << "Cannot Add Credit because Invalid Amount!!!"
|
43
|
+
end
|
44
|
+
else
|
45
|
+
@errors << "Cannot Add Credit because Invalid Account!!!"
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
private
|
50
|
+
def valid_account?
|
51
|
+
@valid_account
|
52
|
+
end
|
53
|
+
|
54
|
+
def valid_amount?(amount)
|
55
|
+
amount =~ /\A\$\d+\z/
|
56
|
+
end
|
57
|
+
|
58
|
+
def get_amount_in_integer(string_val)
|
59
|
+
string_val.split("$").last.to_i
|
60
|
+
end
|
61
|
+
|
62
|
+
def get_amount_in_string(integer_val)
|
63
|
+
"$" + integer_val.to_s
|
64
|
+
end
|
65
|
+
|
66
|
+
def valid_card?(number)
|
67
|
+
digits = ''
|
68
|
+
number.split('').reverse.each_with_index do |d,i|
|
69
|
+
digits += d if i%2 == 0
|
70
|
+
digits += (d.to_i*2).to_s if i%2 == 1
|
71
|
+
end
|
72
|
+
digits.split('').inject(0){|sum,d| sum+d.to_i}%10 == 0
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
@@ -0,0 +1,99 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
require 'thor'
|
3
|
+
require 'terminal-table/import'
|
4
|
+
|
5
|
+
require File.expand_path('../../cc_manager', __FILE__) #=> requiring the gem
|
6
|
+
|
7
|
+
module CcManager # :nodoc: all
|
8
|
+
class CLI < Thor # :nodoc: all
|
9
|
+
include Thor::Actions
|
10
|
+
|
11
|
+
default_task :process
|
12
|
+
|
13
|
+
map "-v" => :version
|
14
|
+
|
15
|
+
desc "version", "Shows the current version of cloudfactory gem"
|
16
|
+
def version
|
17
|
+
say("Version: #{CcManager::VERSION}", :green)
|
18
|
+
end
|
19
|
+
|
20
|
+
desc "process", "heart of this gem"
|
21
|
+
method_option :file, :required => true, :aliases => '-f', :type => :string
|
22
|
+
def process
|
23
|
+
file = options['file']
|
24
|
+
accounts = []
|
25
|
+
errors = []
|
26
|
+
counter = 1
|
27
|
+
if File.exist?(file)
|
28
|
+
File.open(file, "r") do |infile|
|
29
|
+
while (line = infile.gets)
|
30
|
+
args = line.split(" ")
|
31
|
+
action = args.first
|
32
|
+
case(action)
|
33
|
+
when "Add"
|
34
|
+
if args.count == 4
|
35
|
+
name = args[1]
|
36
|
+
card_number = args[2]
|
37
|
+
limit_amount = args[3]
|
38
|
+
account = CcManager::Account.new(name, card_number, limit_amount)
|
39
|
+
accounts << account
|
40
|
+
errors << {:line_number => counter, :message => account.errors} if account.errors.count > 0
|
41
|
+
else
|
42
|
+
errors << {:line_number => counter, :message => ["Invalid Input Line!!!"]}
|
43
|
+
end
|
44
|
+
when "Charge"
|
45
|
+
if args.count == 3
|
46
|
+
if accounts.count > 0
|
47
|
+
name_to_charge = args[1]
|
48
|
+
amount_to_charge = args[2]
|
49
|
+
accounts.each do |account|
|
50
|
+
if account.name == name_to_charge
|
51
|
+
charge = account.charge(amount_to_charge)
|
52
|
+
errors << {:line_number => counter, :message => charge} if charge.class == Array
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
when "Credit"
|
58
|
+
if args.count == 3
|
59
|
+
if accounts.count > 0
|
60
|
+
name_for_credit = args[1]
|
61
|
+
amount_for_credit = args[2]
|
62
|
+
accounts.each do |account|
|
63
|
+
if account.name == name_for_credit
|
64
|
+
credit = account.credit(amount_for_credit)
|
65
|
+
errors << {:line_number => counter, :message => credit} if credit.class == Array
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
counter = counter + 1
|
72
|
+
end
|
73
|
+
end
|
74
|
+
else
|
75
|
+
say("Invalid File location. Please Enter Valid path of File!!!", :red)
|
76
|
+
end
|
77
|
+
|
78
|
+
accounts.each do |a|
|
79
|
+
if a.cc_number.nil?
|
80
|
+
say("#{a.name}: Error", :red)
|
81
|
+
else
|
82
|
+
say("#{a.name}: #{a.balance}", :green)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
if errors.count > 0
|
87
|
+
say("\nList of Errors:", :yellow)
|
88
|
+
require 'terminal-table'
|
89
|
+
error_table = table do |t|
|
90
|
+
t.headings = ["File Line Number", 'Error Message']
|
91
|
+
errors.each do |error|
|
92
|
+
t << ["Line Number: #{error[:line_number]}", error[:message].last]
|
93
|
+
end
|
94
|
+
end
|
95
|
+
say(error_table, :red)
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
data/lib/cc_manager.rb
ADDED
data/spec/add_spec.rb
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe CcManager::Account do
|
4
|
+
context "Add new account without any errors, " do
|
5
|
+
it "having valid credit card number" do
|
6
|
+
account = CcManager::Account.new("Tom", "4111111111111111", "$1000")
|
7
|
+
account.name.should eql("Tom")
|
8
|
+
account.cc_number.should eql("4111111111111111")
|
9
|
+
account.limit.should eql("$1000")
|
10
|
+
account.balance.should eql("$0")
|
11
|
+
account.errors.should be_empty
|
12
|
+
account.valid_account.should be_true
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
context "Add new account containing errors, " do
|
17
|
+
it "with invalid credit card number" do
|
18
|
+
account = CcManager::Account.new("Quincy", "1234567890123456", "$1000")
|
19
|
+
account.name.should eql("Quincy")
|
20
|
+
account.limit.should eql("$1000")
|
21
|
+
account.cc_number.should_not eql("1234567890123456")
|
22
|
+
account.balance.should eql("$0")
|
23
|
+
account.errors.should include("Quincy's account could not be added because Credit Card is invalid!!!")
|
24
|
+
account.valid_account.should_not be_true
|
25
|
+
end
|
26
|
+
|
27
|
+
it "with invalid credit card i.e. having alpha-numeric values" do
|
28
|
+
account = CcManager::Account.new("Tom", "123d56h890t23456", "$1000")
|
29
|
+
account.name.should eql("Tom")
|
30
|
+
account.balance.should eql("$0")
|
31
|
+
account.limit.should eql("$1000")
|
32
|
+
account.cc_number.should_not eql("123d56h890t23456")
|
33
|
+
account.cc_number.should be_nil
|
34
|
+
account.errors.should include("Tom's account could not be added because Credit Card is invalid!!!")
|
35
|
+
account.valid_account.should_not be_true
|
36
|
+
end
|
37
|
+
|
38
|
+
it "with invalid limit value" do
|
39
|
+
account = CcManager::Account.new("Tom", "1234567890123456", "1000")
|
40
|
+
account.name.should eql("Tom")
|
41
|
+
account.balance.should eql("$0")
|
42
|
+
account.limit.should be_nil
|
43
|
+
account.cc_number.should_not eql("1234567890123456")
|
44
|
+
account.cc_number.should be_nil
|
45
|
+
account.errors.should include("Invalid Amount specified for limit!!!")
|
46
|
+
account.valid_account.should_not be_true
|
47
|
+
end
|
48
|
+
|
49
|
+
it "with limit value in decimal" do
|
50
|
+
account = CcManager::Account.new("Tom", "1234567890123456", "$1000.25")
|
51
|
+
account.name.should eql("Tom")
|
52
|
+
account.balance.should eql("$0")
|
53
|
+
account.limit.should be_nil
|
54
|
+
account.cc_number.should_not eql("1234567890123456")
|
55
|
+
account.cc_number.should be_nil
|
56
|
+
account.errors.should include("Invalid Amount specified for limit!!!")
|
57
|
+
account.valid_account.should_not be_true
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
data/spec/charge_spec.rb
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe CcManager::Account do
|
4
|
+
context "Charging for valid account without any errors, " do
|
5
|
+
it "having valid credit card number and charging amount is less than the limit of the account" do
|
6
|
+
account = CcManager::Account.new("Tom", "4111111111111111", "$1000")
|
7
|
+
account.name.should eql("Tom")
|
8
|
+
account.cc_number.should eql("4111111111111111")
|
9
|
+
account.limit.should eql("$1000")
|
10
|
+
account.balance.should eql("$0")
|
11
|
+
account.errors.should eql([])
|
12
|
+
account.valid_account.should eql(true)
|
13
|
+
|
14
|
+
account.charge("$500")
|
15
|
+
account.balance.should eql("$500")
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
context "Charging account with Erroneous conditions, " do
|
20
|
+
it "with invalid account" do
|
21
|
+
account = CcManager::Account.new("Tom", "4111r111u1111111", "$1000")
|
22
|
+
account.name.should eql("Tom")
|
23
|
+
account.limit.should eql("$1000")
|
24
|
+
account.balance.should eql("$0")
|
25
|
+
account.errors.should include("Tom's account could not be added because Credit Card is invalid!!!")
|
26
|
+
account.valid_account.should eql(false)
|
27
|
+
|
28
|
+
account.charge("$500")
|
29
|
+
account.balance.should eql("$0")
|
30
|
+
account.errors.should include("Cannot Charge because Invalid Account!!!")
|
31
|
+
end
|
32
|
+
|
33
|
+
it "with invalid charged amount i.e. containing decimal value" do
|
34
|
+
account = CcManager::Account.new("Tom", "4111111111111111", "$1000")
|
35
|
+
account.name.should eql("Tom")
|
36
|
+
account.limit.should eql("$1000")
|
37
|
+
account.balance.should eql("$0")
|
38
|
+
account.cc_number.should eql("4111111111111111")
|
39
|
+
account.errors.should eql([])
|
40
|
+
account.valid_account.should eql(true)
|
41
|
+
|
42
|
+
account.charge("$500.0")
|
43
|
+
account.balance.should eql("$0")
|
44
|
+
account.errors.should include("Cannot Charge because Invalid Amount!!!")
|
45
|
+
end
|
46
|
+
|
47
|
+
it "with invalid charged amount i.e. not starting with $ in the amount" do
|
48
|
+
account = CcManager::Account.new("Tom", "4111111111111111", "$1000")
|
49
|
+
account.name.should eql("Tom")
|
50
|
+
account.limit.should eql("$1000")
|
51
|
+
account.balance.should eql("$0")
|
52
|
+
account.cc_number.should eql("4111111111111111")
|
53
|
+
account.errors.should eql([])
|
54
|
+
account.valid_account.should eql(true)
|
55
|
+
|
56
|
+
account.charge("%500")
|
57
|
+
account.balance.should eql("$0")
|
58
|
+
account.errors.should include("Cannot Charge because Invalid Amount!!!")
|
59
|
+
end
|
60
|
+
|
61
|
+
it "with charged amount greater than the limit of Account" do
|
62
|
+
account = CcManager::Account.new("Tom", "4111111111111111", "$1000")
|
63
|
+
account.name.should eql("Tom")
|
64
|
+
account.limit.should eql("$1000")
|
65
|
+
account.balance.should eql("$0")
|
66
|
+
account.cc_number.should eql("4111111111111111")
|
67
|
+
account.errors.should eql([])
|
68
|
+
account.valid_account.should eql(true)
|
69
|
+
|
70
|
+
account.charge("$500")
|
71
|
+
account.balance.should eql("$500")
|
72
|
+
account.charge("$800")
|
73
|
+
account.balance.should eql("$500")
|
74
|
+
account.errors.should include("Cannot Charge because Charged Amount exceeded the limit!!!")
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
data/spec/credit_spec.rb
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe CcManager::Account do
|
4
|
+
context "Adding Credits for valid account without any errors, " do
|
5
|
+
it "having valid credit card number" do
|
6
|
+
account = CcManager::Account.new("Tom", "4111111111111111", "$1000")
|
7
|
+
account.name.should eql("Tom")
|
8
|
+
account.cc_number.should eql("4111111111111111")
|
9
|
+
account.limit.should eql("$1000")
|
10
|
+
account.balance.should eql("$0")
|
11
|
+
account.errors.should eql([])
|
12
|
+
account.valid_account.should eql(true)
|
13
|
+
|
14
|
+
account.credit("$200")
|
15
|
+
account.balance.should eql("$-200")
|
16
|
+
end
|
17
|
+
|
18
|
+
it "having valid credit card number and already charged account" do
|
19
|
+
account = CcManager::Account.new("Tom", "4111111111111111", "$1000")
|
20
|
+
account.name.should eql("Tom")
|
21
|
+
account.cc_number.should eql("4111111111111111")
|
22
|
+
account.limit.should eql("$1000")
|
23
|
+
account.balance.should eql("$0")
|
24
|
+
account.errors.should eql([])
|
25
|
+
account.valid_account.should eql(true)
|
26
|
+
|
27
|
+
account.charge("$800")
|
28
|
+
account.balance.should eql("$800")
|
29
|
+
|
30
|
+
account.credit("$200")
|
31
|
+
account.balance.should eql("$600")
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
context "Adding Credit to account with Erronous conditions, " do
|
36
|
+
it "with invalid account" do
|
37
|
+
account = CcManager::Account.new("Tom", "4111r111u1111111", "$1000")
|
38
|
+
account.name.should eql("Tom")
|
39
|
+
account.limit.should eql("$1000")
|
40
|
+
account.balance.should eql("$0")
|
41
|
+
account.errors.should include("Tom's account could not be added because Credit Card is invalid!!!")
|
42
|
+
account.valid_account.should eql(false)
|
43
|
+
|
44
|
+
account.credit("$500")
|
45
|
+
account.balance.should eql("$0")
|
46
|
+
account.errors.should include("Cannot Add Credit because Invalid Account!!!")
|
47
|
+
end
|
48
|
+
|
49
|
+
it "with invalid credited amount i.e. containing decimal value" do
|
50
|
+
account = CcManager::Account.new("Tom", "4111111111111111", "$1000")
|
51
|
+
account.name.should eql("Tom")
|
52
|
+
account.limit.should eql("$1000")
|
53
|
+
account.balance.should eql("$0")
|
54
|
+
account.cc_number.should eql("4111111111111111")
|
55
|
+
account.errors.should eql([])
|
56
|
+
account.valid_account.should eql(true)
|
57
|
+
|
58
|
+
account.credit("$500.0")
|
59
|
+
account.balance.should eql("$0")
|
60
|
+
account.errors.should include("Cannot Add Credit because Invalid Amount!!!")
|
61
|
+
end
|
62
|
+
|
63
|
+
it "with invalid credited amount i.e. not starting with $ in the amount" do
|
64
|
+
account = CcManager::Account.new("Tom", "4111111111111111", "$1000")
|
65
|
+
account.name.should eql("Tom")
|
66
|
+
account.limit.should eql("$1000")
|
67
|
+
account.balance.should eql("$0")
|
68
|
+
account.cc_number.should eql("4111111111111111")
|
69
|
+
account.errors.should eql([])
|
70
|
+
account.valid_account.should eql(true)
|
71
|
+
|
72
|
+
account.credit("%500")
|
73
|
+
account.balance.should eql("$0")
|
74
|
+
account.errors.should include("Cannot Add Credit because Invalid Amount!!!")
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,157 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: cc_manager
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Manish Lal Das
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2011-09-05 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: thor
|
16
|
+
requirement: &2159307460 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0.14'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *2159307460
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: terminal-table
|
27
|
+
requirement: &2159306640 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ~>
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '1.4'
|
33
|
+
type: :runtime
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *2159306640
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: aruba
|
38
|
+
requirement: &2159306000 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
44
|
+
type: :development
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *2159306000
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: rspec
|
49
|
+
requirement: &2159304920 !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 2.6.0
|
55
|
+
type: :development
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: *2159304920
|
58
|
+
- !ruby/object:Gem::Dependency
|
59
|
+
name: bundler
|
60
|
+
requirement: &2159295040 !ruby/object:Gem::Requirement
|
61
|
+
none: false
|
62
|
+
requirements:
|
63
|
+
- - ~>
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: 1.0.0
|
66
|
+
type: :development
|
67
|
+
prerelease: false
|
68
|
+
version_requirements: *2159295040
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: pry
|
71
|
+
requirement: &2159294420 !ruby/object:Gem::Requirement
|
72
|
+
none: false
|
73
|
+
requirements:
|
74
|
+
- - ! '>='
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
type: :development
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: *2159294420
|
80
|
+
- !ruby/object:Gem::Dependency
|
81
|
+
name: pry-doc
|
82
|
+
requirement: &2159293940 !ruby/object:Gem::Requirement
|
83
|
+
none: false
|
84
|
+
requirements:
|
85
|
+
- - ! '>='
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '0'
|
88
|
+
type: :development
|
89
|
+
prerelease: false
|
90
|
+
version_requirements: *2159293940
|
91
|
+
description: Managing Credit card processing with ease via command line app with file
|
92
|
+
input
|
93
|
+
email:
|
94
|
+
- manishlaldas.md@gmail.com
|
95
|
+
executables:
|
96
|
+
- ccmgr
|
97
|
+
extensions: []
|
98
|
+
extra_rdoc_files: []
|
99
|
+
files:
|
100
|
+
- .gitignore
|
101
|
+
- .rspec
|
102
|
+
- Gemfile
|
103
|
+
- README.md
|
104
|
+
- Rakefile
|
105
|
+
- cc_manager.gemspec
|
106
|
+
- features/invalid_file.feature
|
107
|
+
- features/process.feature
|
108
|
+
- features/support/env.rb
|
109
|
+
- features/version.feature
|
110
|
+
- lib/cc_manager.rb
|
111
|
+
- lib/cc_manager/account.rb
|
112
|
+
- lib/cc_manager/cli.rb
|
113
|
+
- lib/cc_manager/version.rb
|
114
|
+
- spec/add_spec.rb
|
115
|
+
- spec/charge_spec.rb
|
116
|
+
- spec/credit_spec.rb
|
117
|
+
- spec/spec_helper.rb
|
118
|
+
- bin/ccmgr
|
119
|
+
homepage: http://manishdas.github.com/cc_manager
|
120
|
+
licenses: []
|
121
|
+
post_install_message: ! " \n ********************************************************************************\n
|
122
|
+
\ \n Process credit card information with ease\n using CLI and file as input\n
|
123
|
+
\ \n # cc_details.txt\n Add Tom 4111111111111111 $1000\n Add
|
124
|
+
Lisa 5454545454545454 $3000\n Add Quincy 1234567890123456 $2000\n Charge
|
125
|
+
Tom $500\n Charge Tom $800\n Charge Lisa $7\n Credit Lisa $100\n
|
126
|
+
\ Credit Quincy $200\n\n > ccmgr cc_details.txt\n \n Output:\n\n
|
127
|
+
\ Lisa: $-93\n Quincy: error\n Tom: $500\n \n ********************************************************************************\n\n"
|
128
|
+
rdoc_options: []
|
129
|
+
require_paths:
|
130
|
+
- lib
|
131
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
132
|
+
none: false
|
133
|
+
requirements:
|
134
|
+
- - ! '>='
|
135
|
+
- !ruby/object:Gem::Version
|
136
|
+
version: '0'
|
137
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
138
|
+
none: false
|
139
|
+
requirements:
|
140
|
+
- - ! '>='
|
141
|
+
- !ruby/object:Gem::Version
|
142
|
+
version: '0'
|
143
|
+
requirements: []
|
144
|
+
rubyforge_project: cc_manager
|
145
|
+
rubygems_version: 1.8.10
|
146
|
+
signing_key:
|
147
|
+
specification_version: 3
|
148
|
+
summary: Credit card processing
|
149
|
+
test_files:
|
150
|
+
- features/invalid_file.feature
|
151
|
+
- features/process.feature
|
152
|
+
- features/support/env.rb
|
153
|
+
- features/version.feature
|
154
|
+
- spec/add_spec.rb
|
155
|
+
- spec/charge_spec.rb
|
156
|
+
- spec/credit_spec.rb
|
157
|
+
- spec/spec_helper.rb
|