lita-kidoikoi 0.1.0
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.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/.travis.yml +8 -0
- data/Gemfile +7 -0
- data/LICENSE.md +21 -0
- data/README.md +38 -0
- data/Rakefile +6 -0
- data/lib/kidoikoi.rb +64 -0
- data/lib/lita-kidoikoi.rb +12 -0
- data/lib/lita/handlers/kidoikoi.rb +75 -0
- data/lita-kidoikoi.gemspec +30 -0
- data/locales/en.yml +4 -0
- data/spec/lita/handlers/kidoikoi_spec.rb +118 -0
- data/spec/lita/kidoikoi_spec.rb +129 -0
- data/spec/spec_helper.rb +18 -0
- data/templates/.gitkeep +0 -0
- metadata +181 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: b4830036785a65c0e4af2f2def89503219cb3a54
|
4
|
+
data.tar.gz: 7ccde7fec4039e54049112f97a2af85d83dec470
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 6da81fca23a6b265ed48b6f2dfd5097cc642ecb74965cb597c4a868c5109ad33283ec302eb739d77e86142fad52dc21ab831086ab128eb629d5b3a18eae1f7ca
|
7
|
+
data.tar.gz: 9f1b72e7643e84ecdf4797b4593f47f45d047fc3245cd2832a7b0c98bf038ada3b539c81ddf93957937539e41c753e4b9ab47f352ebeb2da3635e37082437815
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.md
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 Loïc Delmaire Sacha Al Himdani
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
# lita-kidoikoi
|
2
|
+
|
3
|
+
[](https://travis-ci.org/blackbirdco/lita-kidoikoi)
|
4
|
+
[](https://coveralls.io/r/blackbirdco/lita-kidoikoi)
|
5
|
+
|
6
|
+
A plugin for splitting bills between coworkers.
|
7
|
+
|
8
|
+
"Kidoikoi" is for "qui doit quoi", which means in french "who owes what".
|
9
|
+
|
10
|
+
## Installation
|
11
|
+
|
12
|
+
Add lita-kidoikoi to your Lita instance's Gemfile:
|
13
|
+
|
14
|
+
``` ruby
|
15
|
+
gem "lita-kidoikoi"
|
16
|
+
```
|
17
|
+
|
18
|
+
## Usage
|
19
|
+
|
20
|
+
###Commands:
|
21
|
+
|
22
|
+
####split\_bill:
|
23
|
+
|
24
|
+
`split bill @DEBTOR1... VALUE @CREDITOR`
|
25
|
+
|
26
|
+
Split a bill of the specified value between one ore more debtors and one creditor.
|
27
|
+
|
28
|
+
####clear\_debt\_between:
|
29
|
+
|
30
|
+
`clear debt between @USER1 @USER2`
|
31
|
+
|
32
|
+
Clear mutual debt of two users.
|
33
|
+
|
34
|
+
####resume\_debt\_of:
|
35
|
+
|
36
|
+
`resume debt of @USER`
|
37
|
+
|
38
|
+
Resume debt of one user.
|
data/Rakefile
ADDED
data/lib/kidoikoi.rb
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
class Kidoikoi
|
2
|
+
attr_reader :database
|
3
|
+
|
4
|
+
def initialize(database)
|
5
|
+
@database = database
|
6
|
+
end
|
7
|
+
|
8
|
+
def split_bill_between(debtors, total_value, creditor)
|
9
|
+
remove_all_duplicate_in(debtors, creditor)
|
10
|
+
|
11
|
+
total_people = debtors.length + 1
|
12
|
+
amount = calcul_amount(total_value, total_people)
|
13
|
+
|
14
|
+
debtors.each do |debtor|
|
15
|
+
add_amount_to_debt_between(debtor, creditor, amount)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def clear_debt_between(user1, user2)
|
20
|
+
delete_debt(user_from: user1, user_to: user2)
|
21
|
+
delete_debt(user_from: user2, user_to: user1)
|
22
|
+
end
|
23
|
+
|
24
|
+
def debts_of(user)
|
25
|
+
debts = database.get(user) || {}
|
26
|
+
debts = eval(debts) if debts.is_a? String
|
27
|
+
debts
|
28
|
+
end
|
29
|
+
|
30
|
+
alias_method :resume_debt, :debts_of
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def remove_all_duplicate_in(debtors, creditor)
|
35
|
+
debtors.uniq!
|
36
|
+
debtors.delete(creditor)
|
37
|
+
end
|
38
|
+
|
39
|
+
def calcul_amount(total_value, total_people)
|
40
|
+
(total_value / total_people).round(2)
|
41
|
+
end
|
42
|
+
|
43
|
+
def add_amount_to_debt_between(debtor, creditor, amount)
|
44
|
+
add_debt(-amount, user_from: debtor, user_to: creditor)
|
45
|
+
add_debt(amount, user_from: creditor, user_to: debtor)
|
46
|
+
end
|
47
|
+
|
48
|
+
def add_debt(amount, user_from: nil, user_to: nil)
|
49
|
+
user_debts = debts_of(user_from)
|
50
|
+
user_debts[user_to] = calcul_debt_value(user_debts[user_to], amount)
|
51
|
+
database.set(user_from, user_debts)
|
52
|
+
end
|
53
|
+
|
54
|
+
def calcul_debt_value(debt_value, amount)
|
55
|
+
debt_value ||= 0
|
56
|
+
debt_value += amount
|
57
|
+
end
|
58
|
+
|
59
|
+
def delete_debt(user_from: nil, user_to: nil)
|
60
|
+
user_debts = debts_of(user_from)
|
61
|
+
user_debts.delete(user_to)
|
62
|
+
database.set(user_from, user_debts)
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require "lita"
|
2
|
+
|
3
|
+
Lita.load_locales Dir[File.expand_path(
|
4
|
+
File.join("..", "..", "locales", "*.yml"), __FILE__
|
5
|
+
)]
|
6
|
+
|
7
|
+
require "lita/handlers/kidoikoi"
|
8
|
+
|
9
|
+
Lita::Handlers::Kidoikoi.template_root File.expand_path(
|
10
|
+
File.join("..", "..", "templates"),
|
11
|
+
__FILE__
|
12
|
+
)
|
@@ -0,0 +1,75 @@
|
|
1
|
+
require 'kidoikoi'
|
2
|
+
|
3
|
+
module Lita
|
4
|
+
module Handlers
|
5
|
+
class Kidoikoi < Handler
|
6
|
+
|
7
|
+
# http://rubular.com/r/4KljBTwuXK
|
8
|
+
route(/^split\s+bill(\s+@\S+)+\s+\d+[.€]?\d{0,2}\s+@\S+$/,
|
9
|
+
:split_bill, command: true,
|
10
|
+
help: {
|
11
|
+
"split bill @DEBTOR1 @DEBTOR2 12 @CREDITOR" =>
|
12
|
+
"Split a 12 euros bill : @DEBTOR1 and @DEBTOR2 owe now 3 euros to @CREDITOR, in addition of their previous debt"
|
13
|
+
}
|
14
|
+
)
|
15
|
+
|
16
|
+
def split_bill(response)
|
17
|
+
kidoikoi = ::Kidoikoi.new(redis)
|
18
|
+
|
19
|
+
creditor = response.args.last
|
20
|
+
value = response.args[-2].to_f
|
21
|
+
debtors = response.args[1..-3]
|
22
|
+
|
23
|
+
kidoikoi.split_bill_between(debtors, value, creditor)
|
24
|
+
|
25
|
+
response.reply("A %.2f euros bill has been successfully split" % value)
|
26
|
+
end
|
27
|
+
|
28
|
+
# http://rubular.com/r/BhwCm7D7Ny
|
29
|
+
route(/^clear\s+debt\s+between\s+@\S+\s+\@\S+$/,
|
30
|
+
:clear_debt, command: true,
|
31
|
+
help: {"clear debt between @USER1 @USER2" => "Clear mutual debt between @USER1 and @USER2."}
|
32
|
+
)
|
33
|
+
|
34
|
+
def clear_debt(response)
|
35
|
+
kidoikoi = ::Kidoikoi.new(redis)
|
36
|
+
|
37
|
+
kidoikoi.clear_debt_between(response.args[-2], response.args.last)
|
38
|
+
|
39
|
+
response.reply "Debt between #{response.args[-2]} and #{response.args.last} has been successfully clear"
|
40
|
+
end
|
41
|
+
|
42
|
+
# http://rubular.com/r/QqJ5mihDz0
|
43
|
+
route(/^resume\s+debt\s+of\s+@\S+$/,
|
44
|
+
:resume_debt, command: true,
|
45
|
+
help: { "resume debt of @USER" => "Resume debt of @USER." }
|
46
|
+
)
|
47
|
+
|
48
|
+
def resume_debt(response)
|
49
|
+
kidoikoi = ::Kidoikoi.new(redis)
|
50
|
+
|
51
|
+
user = response.args.last
|
52
|
+
user_debts = kidoikoi.resume_debt(user)
|
53
|
+
|
54
|
+
response.reply formated_debt(user, user_debts)
|
55
|
+
end
|
56
|
+
|
57
|
+
private
|
58
|
+
|
59
|
+
def formated_debt(user, user_debts)
|
60
|
+
if user_debts.empty?
|
61
|
+
"#{user} do not have any debt"
|
62
|
+
else
|
63
|
+
reply = "#{user} credit:\n"
|
64
|
+
|
65
|
+
user_debts.each do |to_whom, debt|
|
66
|
+
reply += "%s: %.2f euros\n" % [to_whom, debt]
|
67
|
+
end
|
68
|
+
reply.chop
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
Lita.register_handler(Kidoikoi)
|
74
|
+
end
|
75
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
Gem::Specification.new do |spec|
|
2
|
+
spec.name = "lita-kidoikoi"
|
3
|
+
spec.version = "0.1.0"
|
4
|
+
spec.authors = ["Loic Delmaire", "Sacha Al Himdani"]
|
5
|
+
spec.email = ["loic.delmaire@gmail.com", "sal-himd@students.42.fr"]
|
6
|
+
spec.description = "A plugin for splitting bills between coworkers.
|
7
|
+
\"Kidoikoi\" is for \"qui doit quoi\", which means in french \"who owes what\"."
|
8
|
+
spec.summary = "Commands:\n
|
9
|
+
*split bill* _@debtor1_ _..._ _value_ _@creditor_\n
|
10
|
+
*clear debt between* _@user1_ _@user2_ \n
|
11
|
+
*resume debt of* _@user1_"
|
12
|
+
spec.homepage = "https://github.com/sal-himd/lita-kidoikoi"
|
13
|
+
spec.license = "Licence MIT"
|
14
|
+
spec.metadata = { "lita_plugin_type" => "handler" }
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_runtime_dependency "lita", ">= 4.5"
|
22
|
+
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
24
|
+
spec.add_development_dependency "pry-byebug"
|
25
|
+
spec.add_development_dependency "rake"
|
26
|
+
spec.add_development_dependency "rack-test"
|
27
|
+
spec.add_development_dependency "rspec", ">= 3.0.0"
|
28
|
+
spec.add_development_dependency "simplecov"
|
29
|
+
spec.add_development_dependency "coveralls"
|
30
|
+
end
|
data/locales/en.yml
ADDED
@@ -0,0 +1,118 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Lita::Handlers::Kidoikoi, lita_handler: true do
|
4
|
+
|
5
|
+
let(:botname) { "Lita" }
|
6
|
+
|
7
|
+
describe "command : split bill" do
|
8
|
+
it { is_expected.to route("#{botname} split bill @debtor 152 @creditor") }
|
9
|
+
it { is_expected.to route("#{botname} split bill @debtor1 @debtor2 @debtor3 1234567.89 @creditor") }
|
10
|
+
it { is_expected.to route("#{botname} split bill @debtor @debtor 0 @debtor") }
|
11
|
+
|
12
|
+
it { is_expected.not_to route("#{botname} split bill") }
|
13
|
+
it { is_expected.not_to route("#{botname} split bill @debtor -10 @creditor") }
|
14
|
+
it { is_expected.not_to route("#{botname} split bill debtor 10 creditor") }
|
15
|
+
it { is_expected.not_to route("#{botname} split bill @debtor 10") }
|
16
|
+
it { is_expected.not_to route("#{botname} split bill @debtor 10 @creditor1 @creditor2") }
|
17
|
+
|
18
|
+
describe "when we want to split a 10 euros bill between one debtor and one creditor" do
|
19
|
+
let(:message) { "#{botname} split bill @debtor 10 @creditor" }
|
20
|
+
|
21
|
+
it "sends [@debtor], 10 and @creditor to kidoikoi#split_bill_between" do
|
22
|
+
expect_any_instance_of(Kidoikoi).to receive(:split_bill_between).with(["@debtor"], 10, "@creditor")
|
23
|
+
send_message(message)
|
24
|
+
end
|
25
|
+
|
26
|
+
it "responds a success message" do
|
27
|
+
send_message(message)
|
28
|
+
|
29
|
+
expect(replies.last).to eq("A 10.00 euros bill has been successfully split")
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
describe "when we want to split a 5.99 euros bill between two debtors and one creditor" do
|
34
|
+
let(:message) { "#{botname} split bill @debtor1 @debtor2 5.99 @creditor" }
|
35
|
+
|
36
|
+
it "sends [@debtor1, @debtor2], 5.99, @creditor to kidoikoi#split_bill_between" do
|
37
|
+
expect_any_instance_of(Kidoikoi).to receive(:split_bill_between).with(["@debtor1", "@debtor2"], 5.99, "@creditor")
|
38
|
+
send_message(message)
|
39
|
+
end
|
40
|
+
|
41
|
+
it "responds a success message" do
|
42
|
+
send_message(message)
|
43
|
+
|
44
|
+
expect(replies.last).to eq("A 5.99 euros bill has been successfully split")
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
describe "command : resume_debt" do
|
50
|
+
it { is_expected.to route( "#{botname} resume debt of @user" ) }
|
51
|
+
|
52
|
+
it { is_expected.not_to route("#{botname} resume debt of") }
|
53
|
+
it { is_expected.not_to route("#{botname} resume debt of user") }
|
54
|
+
it { is_expected.not_to route("#{botname} resume debt of @user1 @user2") }
|
55
|
+
|
56
|
+
context "when @user have no debt" do
|
57
|
+
context "when we want the debts resume of this user" do
|
58
|
+
before do
|
59
|
+
allow_any_instance_of(Kidoikoi).to receive(:resume_debt).with("@user").and_return({})
|
60
|
+
end
|
61
|
+
|
62
|
+
let(:message) { "#{botname} resume debt of @user" }
|
63
|
+
|
64
|
+
it "sends @user to kidoikoi#resume_debt" do
|
65
|
+
expect_any_instance_of(Kidoikoi).to receive(:resume_debt).with("@user")
|
66
|
+
|
67
|
+
send_message(message)
|
68
|
+
end
|
69
|
+
|
70
|
+
it "display a message saying that this user do not have debts" do
|
71
|
+
send_message(message)
|
72
|
+
|
73
|
+
expect(replies.last).to eq( "@user do not have any debt" )
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
context "when @user have debts" do
|
78
|
+
before do
|
79
|
+
allow_any_instance_of(Kidoikoi).to receive(:resume_debt).with("@user").and_return({"@user1" => 10.00, "@user2" => -20.00 })
|
80
|
+
end
|
81
|
+
|
82
|
+
context "when we want the debts resume of this user" do
|
83
|
+
let(:message) { "#{botname} resume debt of @user" }
|
84
|
+
|
85
|
+
it "displays debts of this user" do
|
86
|
+
send_message(message)
|
87
|
+
|
88
|
+
expect(replies.last).to eq("@user credit:\n@user1: 10.00 euros\n@user2: -20.00 euros")
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
describe "command : clear_debt" do
|
95
|
+
it { is_expected.to route("#{botname} clear debt between @user1 @user2") }
|
96
|
+
|
97
|
+
it { is_expected.not_to route("#{botname} clear debt between") }
|
98
|
+
it { is_expected.not_to route("#{botname} clear debt between @user") }
|
99
|
+
it { is_expected.not_to route("#{botname} clear debt between user1 user2") }
|
100
|
+
it { is_expected.not_to route("#{botname} clear debt between @user1 @user2 @user3") }
|
101
|
+
|
102
|
+
context "when we want to clear debt between @user1 and @user2" do
|
103
|
+
let(:message) {"#{botname} clear debt between @user1 @user2" }
|
104
|
+
|
105
|
+
it "sends @user1 @user2 to kidoikoi#clear_debt_between" do
|
106
|
+
expect_any_instance_of(Kidoikoi).to receive(:clear_debt_between).with("@user1", "@user2")
|
107
|
+
|
108
|
+
send_message(message)
|
109
|
+
end
|
110
|
+
|
111
|
+
it "responds a success message" do
|
112
|
+
send_message(message)
|
113
|
+
|
114
|
+
expect(replies.last).to eq("Debt between @user1 and @user2 has been successfully clear")
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
@@ -0,0 +1,129 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Kidoikoi do
|
4
|
+
let(:database) { double("database") }
|
5
|
+
let(:kidoikoi) { Kidoikoi.new(database) }
|
6
|
+
|
7
|
+
before do
|
8
|
+
allow(database).to receive(:set)
|
9
|
+
allow(database).to receive(:get)
|
10
|
+
end
|
11
|
+
|
12
|
+
describe "#split_bill_between" do
|
13
|
+
subject { kidoikoi.split_bill_between(debtors, amount, creditor) }
|
14
|
+
|
15
|
+
let(:debtors) { ["Sacha", "PG"] }
|
16
|
+
let(:amount) { 9 }
|
17
|
+
let(:creditor) { "Loic" }
|
18
|
+
|
19
|
+
context "when there is no debt relation between users" do
|
20
|
+
before do
|
21
|
+
allow(database).to receive(:get).with("Loic").and_return(nil, "{\"Sacha\" => 3}")
|
22
|
+
end
|
23
|
+
|
24
|
+
context "when Sacha and Pg split a 9 euros bill with Loic" do
|
25
|
+
it "sets Sacha's and Pg's debt to Loic at 3 euros" do
|
26
|
+
subject
|
27
|
+
expect(database).to have_received(:set).with("Sacha", {"Loic" => -3})
|
28
|
+
expect(database).to have_received(:set).with("PG", {"Loic" => -3})
|
29
|
+
expect(database).to have_received(:set).with("Loic", {"Sacha" => 3, "PG" => 3})
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
context "when Sacha is a debitor twice" do
|
34
|
+
let(:debtors) { ["Sacha", "Sacha", "PG"] }
|
35
|
+
|
36
|
+
it "counts Sacha as a debitor just once" do
|
37
|
+
subject
|
38
|
+
expect(database).to have_received(:set).with("Sacha", {"Loic" => -3})
|
39
|
+
expect(database).to have_received(:set).with("PG", {"Loic" => -3})
|
40
|
+
expect(database).to have_received(:set).with("Loic", {"Sacha" => 3, "PG" => 3})
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
context "when Loic is the creditor and one debtor" do
|
45
|
+
let(:debtors) { ["Sacha", "PG", "Loic"] }
|
46
|
+
|
47
|
+
it "does not count Loic as a debtor" do
|
48
|
+
subject
|
49
|
+
expect(database).to have_received(:set).with("Sacha", {"Loic" => -3})
|
50
|
+
expect(database).to have_received(:set).with("PG", {"Loic" => -3})
|
51
|
+
expect(database).to have_received(:set).with("Loic", {"Sacha" => 3, "PG" => 3})
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
context "when a debt relation between users is already set" do
|
57
|
+
before do
|
58
|
+
allow(database).to receive(:get).with("Sacha").and_return("{\"Loic\" => -50, \"PG\" => 5}")
|
59
|
+
allow(database).to receive(:get).with("Loic").and_return("{\"Sacha\" => 50}", "{\"Sacha\" => 57.83}" )
|
60
|
+
allow(database).to receive(:get).with("PG").and_return("{\"Sacha\" => -5}")
|
61
|
+
end
|
62
|
+
|
63
|
+
context "when Sacha and Pg split a 23.50 euros bill with Loic" do
|
64
|
+
let(:amount) { 23.50 }
|
65
|
+
|
66
|
+
it "adds 7.83 to Sacha's and Pg's debt to Loic" do
|
67
|
+
subject
|
68
|
+
expect(database).to have_received(:set).with("Sacha", {"Loic" => -57.83, "PG" => 5}).at_least(1).times
|
69
|
+
expect(database).to have_received(:set).with("PG", {"Loic" => -7.83, "Sacha" => -5})
|
70
|
+
expect(database).to have_received(:set).with("Loic", {"Sacha" => 57.83, "PG" => 7.83}).at_least(1).times
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
describe "#resume_debt" do
|
77
|
+
context "when there is no debt relation between users" do
|
78
|
+
it "returns an empty hash" do
|
79
|
+
expect(kidoikoi.resume_debt("Loic")).to be_empty
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
context "when a debt relation between users is already set" do
|
84
|
+
before do
|
85
|
+
allow(database).to receive(:get).with("Sacha").and_return("{\"Loic\" => -50, \"PG\" => 5}")
|
86
|
+
allow(database).to receive(:get).with("Loic").and_return("{\"Sacha\" => 50}")
|
87
|
+
allow(database).to receive(:get).with("PG").and_return("{\"Sacha\" => -5}")
|
88
|
+
end
|
89
|
+
|
90
|
+
it "returns a hash that resume debt relation of an user" do
|
91
|
+
expect(kidoikoi.resume_debt("Loic")).to eq({"Sacha" => 50})
|
92
|
+
expect(kidoikoi.resume_debt("Sacha")).to eq({"Loic" => -50, "PG" => 5})
|
93
|
+
expect(kidoikoi.resume_debt("PG")).to eq({"Sacha" => -5})
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
describe "#clear_debt_between" do
|
99
|
+
subject { kidoikoi.clear_debt_between(user1, user2) }
|
100
|
+
|
101
|
+
let(:user1) { "Sacha" }
|
102
|
+
let(:user2) { "Loic" }
|
103
|
+
|
104
|
+
context "when there is no debt relation between users" do
|
105
|
+
before do
|
106
|
+
allow(database).to receive(:get).with("Sacha").and_return("{\"PG\" => 50}")
|
107
|
+
allow(database).to receive(:get).with("Loic").and_return("{\"PG\"=> -50}")
|
108
|
+
end
|
109
|
+
|
110
|
+
it "does not set users debts" do
|
111
|
+
subject
|
112
|
+
expect(database).not_to have_received(:set).with("Sacha")
|
113
|
+
expect(database).not_to have_received(:set).with("Loic")
|
114
|
+
expect(database).not_to have_received(:set).with("PG")
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
before do
|
119
|
+
allow(database).to receive(:get).with("Sacha").and_return("{\"Loic\" => 50}")
|
120
|
+
allow(database).to receive(:get).with("Loic").and_return("{\"Sacha\" => -50, \"PG\"=> -50}")
|
121
|
+
end
|
122
|
+
|
123
|
+
it "sets debt to zero between users" do
|
124
|
+
subject
|
125
|
+
expect(database).to have_received(:set).with("Sacha", {})
|
126
|
+
expect(database).to have_received(:set).with("Loic", {"PG" => -50})
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require "simplecov"
|
2
|
+
require "coveralls"
|
3
|
+
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
|
4
|
+
SimpleCov::Formatter::HTMLFormatter,
|
5
|
+
Coveralls::SimpleCov::Formatter
|
6
|
+
]
|
7
|
+
SimpleCov.start { add_filter "/spec/" }
|
8
|
+
|
9
|
+
require "fakeredis"
|
10
|
+
|
11
|
+
require "lita-kidoikoi"
|
12
|
+
require "lita/rspec"
|
13
|
+
|
14
|
+
require "kidoikoi.rb"
|
15
|
+
|
16
|
+
# A compatibility mode is provided for older plugins upgrading from Lita 3. Since this plugin
|
17
|
+
# was generated with Lita 4, the compatibility mode should be left disabled.
|
18
|
+
Lita.version_3_compatibility_mode = false
|
data/templates/.gitkeep
ADDED
File without changes
|
metadata
ADDED
@@ -0,0 +1,181 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: lita-kidoikoi
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Loic Delmaire
|
8
|
+
- Sacha Al Himdani
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2015-09-10 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: lita
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - ">="
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '4.5'
|
21
|
+
type: :runtime
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '4.5'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: bundler
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - "~>"
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '1.3'
|
35
|
+
type: :development
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - "~>"
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '1.3'
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: pry-byebug
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - ">="
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '0'
|
49
|
+
type: :development
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: rake
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
63
|
+
type: :development
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
- !ruby/object:Gem::Dependency
|
71
|
+
name: rack-test
|
72
|
+
requirement: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - ">="
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
type: :development
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - ">="
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '0'
|
84
|
+
- !ruby/object:Gem::Dependency
|
85
|
+
name: rspec
|
86
|
+
requirement: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: 3.0.0
|
91
|
+
type: :development
|
92
|
+
prerelease: false
|
93
|
+
version_requirements: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - ">="
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: 3.0.0
|
98
|
+
- !ruby/object:Gem::Dependency
|
99
|
+
name: simplecov
|
100
|
+
requirement: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - ">="
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '0'
|
105
|
+
type: :development
|
106
|
+
prerelease: false
|
107
|
+
version_requirements: !ruby/object:Gem::Requirement
|
108
|
+
requirements:
|
109
|
+
- - ">="
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
version: '0'
|
112
|
+
- !ruby/object:Gem::Dependency
|
113
|
+
name: coveralls
|
114
|
+
requirement: !ruby/object:Gem::Requirement
|
115
|
+
requirements:
|
116
|
+
- - ">="
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
version: '0'
|
119
|
+
type: :development
|
120
|
+
prerelease: false
|
121
|
+
version_requirements: !ruby/object:Gem::Requirement
|
122
|
+
requirements:
|
123
|
+
- - ">="
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '0'
|
126
|
+
description: |-
|
127
|
+
A plugin for splitting bills between coworkers.
|
128
|
+
"Kidoikoi" is for "qui doit quoi", which means in french "who owes what".
|
129
|
+
email:
|
130
|
+
- loic.delmaire@gmail.com
|
131
|
+
- sal-himd@students.42.fr
|
132
|
+
executables: []
|
133
|
+
extensions: []
|
134
|
+
extra_rdoc_files: []
|
135
|
+
files:
|
136
|
+
- ".gitignore"
|
137
|
+
- ".travis.yml"
|
138
|
+
- Gemfile
|
139
|
+
- LICENSE.md
|
140
|
+
- README.md
|
141
|
+
- Rakefile
|
142
|
+
- lib/kidoikoi.rb
|
143
|
+
- lib/lita-kidoikoi.rb
|
144
|
+
- lib/lita/handlers/kidoikoi.rb
|
145
|
+
- lita-kidoikoi.gemspec
|
146
|
+
- locales/en.yml
|
147
|
+
- spec/lita/handlers/kidoikoi_spec.rb
|
148
|
+
- spec/lita/kidoikoi_spec.rb
|
149
|
+
- spec/spec_helper.rb
|
150
|
+
- templates/.gitkeep
|
151
|
+
homepage: https://github.com/sal-himd/lita-kidoikoi
|
152
|
+
licenses:
|
153
|
+
- Licence MIT
|
154
|
+
metadata:
|
155
|
+
lita_plugin_type: handler
|
156
|
+
post_install_message:
|
157
|
+
rdoc_options: []
|
158
|
+
require_paths:
|
159
|
+
- lib
|
160
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
161
|
+
requirements:
|
162
|
+
- - ">="
|
163
|
+
- !ruby/object:Gem::Version
|
164
|
+
version: '0'
|
165
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
166
|
+
requirements:
|
167
|
+
- - ">="
|
168
|
+
- !ruby/object:Gem::Version
|
169
|
+
version: '0'
|
170
|
+
requirements: []
|
171
|
+
rubyforge_project:
|
172
|
+
rubygems_version: 2.2.2
|
173
|
+
signing_key:
|
174
|
+
specification_version: 4
|
175
|
+
summary: 'Commands: *split bill* _@debtor1_ _..._ _value_ _@creditor_ *clear debt
|
176
|
+
between* _@user1_ _@user2_ *resume debt of* _@user1_'
|
177
|
+
test_files:
|
178
|
+
- spec/lita/handlers/kidoikoi_spec.rb
|
179
|
+
- spec/lita/kidoikoi_spec.rb
|
180
|
+
- spec/spec_helper.rb
|
181
|
+
has_rdoc:
|