death_and_taxes 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +73 -50
- data/README.rdoc +74 -4
- data/config/ca.yml +12 -8
- data/death_and_taxes.gemspec +1 -0
- data/lib/death_and_taxes/country.rb +4 -4
- data/lib/death_and_taxes/state.rb +7 -6
- data/lib/death_and_taxes/tax_info.rb +4 -5
- data/lib/death_and_taxes/tax_version.rb +5 -7
- data/lib/death_and_taxes/version.rb +1 -1
- data/lib/death_and_taxes.rb +6 -4
- data/spec/helper.rb +54 -0
- data/spec/test_death_and_taxes.rb +99 -0
- metadata +22 -14
- data/lib/death_and_taxes/railtie.rb +0 -11
- data/test/helper.rb +0 -18
- data/test/test_death_and_taxes.rb +0 -7
data/Gemfile.lock
CHANGED
@@ -1,74 +1,96 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
death_and_taxes (0.0.
|
4
|
+
death_and_taxes (0.0.3)
|
5
5
|
rails
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: http://rubygems.org/
|
9
9
|
specs:
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
rack (~> 1.2
|
21
|
-
rack-mount (~> 0.
|
22
|
-
rack-test (~> 0.
|
23
|
-
|
24
|
-
activemodel (3.0.
|
25
|
-
activesupport (= 3.0.
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
10
|
+
actionmailer (3.1.0.rc5)
|
11
|
+
actionpack (= 3.1.0.rc5)
|
12
|
+
mail (~> 2.3.0)
|
13
|
+
actionpack (3.1.0.rc5)
|
14
|
+
activemodel (= 3.1.0.rc5)
|
15
|
+
activesupport (= 3.1.0.rc5)
|
16
|
+
builder (~> 3.0.0)
|
17
|
+
erubis (~> 2.7.0)
|
18
|
+
i18n (~> 0.6)
|
19
|
+
rack (~> 1.3.1)
|
20
|
+
rack-cache (~> 1.0.2)
|
21
|
+
rack-mount (~> 0.8.1)
|
22
|
+
rack-test (~> 0.6.0)
|
23
|
+
sprockets (~> 2.0.0.beta.12)
|
24
|
+
activemodel (3.1.0.rc5)
|
25
|
+
activesupport (= 3.1.0.rc5)
|
26
|
+
bcrypt-ruby (~> 2.1.4)
|
27
|
+
builder (~> 3.0.0)
|
28
|
+
i18n (~> 0.6)
|
29
|
+
activerecord (3.1.0.rc5)
|
30
|
+
activemodel (= 3.1.0.rc5)
|
31
|
+
activesupport (= 3.1.0.rc5)
|
32
|
+
arel (~> 2.1.4)
|
33
|
+
tzinfo (~> 0.3.29)
|
34
|
+
activeresource (3.1.0.rc5)
|
35
|
+
activemodel (= 3.1.0.rc5)
|
36
|
+
activesupport (= 3.1.0.rc5)
|
37
|
+
activesupport (3.1.0.rc5)
|
38
|
+
multi_json (~> 1.0)
|
39
|
+
arel (2.1.4)
|
40
|
+
bcrypt-ruby (2.1.4)
|
41
|
+
builder (3.0.0)
|
42
|
+
diff-lcs (1.1.3)
|
43
|
+
erubis (2.7.0)
|
44
|
+
hike (1.2.0)
|
45
|
+
i18n (0.6.0)
|
46
|
+
mail (2.3.0)
|
44
47
|
i18n (>= 0.4.0)
|
45
48
|
mime-types (~> 1.16)
|
46
49
|
treetop (~> 1.4.8)
|
47
50
|
mime-types (1.16)
|
51
|
+
multi_json (1.0.3)
|
48
52
|
polyglot (0.3.2)
|
49
|
-
rack (1.2
|
50
|
-
rack-
|
53
|
+
rack (1.3.2)
|
54
|
+
rack-cache (1.0.2)
|
55
|
+
rack (>= 0.4)
|
56
|
+
rack-mount (0.8.2)
|
51
57
|
rack (>= 1.0.0)
|
52
|
-
rack-
|
58
|
+
rack-ssl (1.3.2)
|
59
|
+
rack
|
60
|
+
rack-test (0.6.1)
|
53
61
|
rack (>= 1.0)
|
54
|
-
rails (3.0.
|
55
|
-
actionmailer (= 3.0.
|
56
|
-
actionpack (= 3.0.
|
57
|
-
activerecord (= 3.0.
|
58
|
-
activeresource (= 3.0.
|
59
|
-
activesupport (= 3.0.
|
62
|
+
rails (3.1.0.rc5)
|
63
|
+
actionmailer (= 3.1.0.rc5)
|
64
|
+
actionpack (= 3.1.0.rc5)
|
65
|
+
activerecord (= 3.1.0.rc5)
|
66
|
+
activeresource (= 3.1.0.rc5)
|
67
|
+
activesupport (= 3.1.0.rc5)
|
60
68
|
bundler (~> 1.0)
|
61
|
-
railties (= 3.0.
|
62
|
-
railties (3.0.
|
63
|
-
actionpack (= 3.0.
|
64
|
-
activesupport (= 3.0.
|
69
|
+
railties (= 3.1.0.rc5)
|
70
|
+
railties (3.1.0.rc5)
|
71
|
+
actionpack (= 3.1.0.rc5)
|
72
|
+
activesupport (= 3.1.0.rc5)
|
73
|
+
rack-ssl (~> 1.3.2)
|
65
74
|
rake (>= 0.8.7)
|
66
75
|
rdoc (~> 3.4)
|
67
|
-
thor (~> 0.14.
|
76
|
+
thor (~> 0.14.6)
|
68
77
|
rake (0.9.2)
|
69
|
-
rdoc (3.9.
|
78
|
+
rdoc (3.9.2)
|
79
|
+
rspec (2.7.0)
|
80
|
+
rspec-core (~> 2.7.0)
|
81
|
+
rspec-expectations (~> 2.7.0)
|
82
|
+
rspec-mocks (~> 2.7.0)
|
83
|
+
rspec-core (2.7.1)
|
84
|
+
rspec-expectations (2.7.0)
|
85
|
+
diff-lcs (~> 1.1.2)
|
86
|
+
rspec-mocks (2.7.0)
|
87
|
+
sprockets (2.0.0.beta.13)
|
88
|
+
hike (~> 1.2)
|
89
|
+
rack (~> 1.0)
|
90
|
+
tilt (!= 1.3.0, ~> 1.1)
|
70
91
|
sqlite3 (1.3.4)
|
71
92
|
thor (0.14.6)
|
93
|
+
tilt (1.3.2)
|
72
94
|
treetop (1.4.10)
|
73
95
|
polyglot
|
74
96
|
polyglot (>= 0.3.1)
|
@@ -79,4 +101,5 @@ PLATFORMS
|
|
79
101
|
|
80
102
|
DEPENDENCIES
|
81
103
|
death_and_taxes!
|
104
|
+
rspec
|
82
105
|
sqlite3
|
data/README.rdoc
CHANGED
@@ -1,8 +1,77 @@
|
|
1
|
-
|
1
|
+
Death And Taxes
|
2
|
+
===============
|
2
3
|
|
3
|
-
|
4
|
+
> "In this world nothing can be said to be certain,
|
5
|
+
> except death and taxes." - Benjamin Franklin
|
4
6
|
|
5
|
-
|
7
|
+
|
8
|
+
Death And Taxes is a gem for ActiveRecord that makes it easier to handle Tax handling.
|
9
|
+
|
10
|
+
|
11
|
+
DeathAndTaxes
|
12
|
+
-------------
|
13
|
+
|
14
|
+
If you want to se the taxes that are in the config file, you can use DeathAndTaxes.applicable_taxes
|
15
|
+
|
16
|
+
DeathAndTaxes.applicable_taxes({:country => "ca", :state => "qc"}, {:country => "ca", :state => "qc"}, Date.today)
|
17
|
+
#=> ["GST", "QST"]
|
18
|
+
|
19
|
+
To obtain the tax itself you can user DeathAndTaxes.build
|
20
|
+
|
21
|
+
DeathAndTaxes.build "QST", Date.today
|
22
|
+
#=> #<DeathAndTaxes::Tax percentage: 8.5, name: "QST" ...>
|
23
|
+
|
24
|
+
|
25
|
+
Tax
|
26
|
+
---
|
27
|
+
|
28
|
+
The tax model should have a name and a percentage. You configure them in the config/#{country}.yml file if you wish to use the _DeathAndTaxes::applicable\_taxes_ method.
|
29
|
+
|
30
|
+
Taxes can be applied on another tax (like in Quebec before 2012) by having a tax itself.
|
31
|
+
|
32
|
+
You can obtain the effective rate of a tax (after being compounded) by using
|
33
|
+
|
34
|
+
tax.multiplier
|
35
|
+
|
36
|
+
Taxable
|
37
|
+
-------
|
38
|
+
|
39
|
+
You can make ActiveRecord models taxable. The taxable models must respond to 'amount'
|
40
|
+
|
41
|
+
|
42
|
+
class Product < ActiveRecord::Base
|
43
|
+
acts_as_taxable
|
44
|
+
end
|
45
|
+
|
46
|
+
|
47
|
+
Taxable models have a method apply_taxes which applies the correct taxes as taxations.
|
48
|
+
|
49
|
+
product = Product.create :name => "Toto", :amount => 100
|
50
|
+
product.apply_taxes [DeathAndTaxes::Tax.new(:name => "GST", :percentage => 7)]
|
51
|
+
product.taxations
|
52
|
+
#=> [#<DeathAndTaxes::Taxation amount: 7, percentage: 7.0, name: "GST" ...>]
|
53
|
+
|
54
|
+
|
55
|
+
Taxer
|
56
|
+
-----
|
57
|
+
|
58
|
+
Taxer model can have taxes associated.
|
59
|
+
|
60
|
+
class Organization < ActiveRecord::Base
|
61
|
+
acts_as_taxer
|
62
|
+
end
|
63
|
+
|
64
|
+
organization.taxes << DeathAndTaxes::Tax.new(:name => "GST", :percentage => 7)
|
65
|
+
|
66
|
+
|
67
|
+
Testing
|
68
|
+
-------
|
69
|
+
|
70
|
+
rspec spec/test_death_and_taxes.rb
|
71
|
+
|
72
|
+
|
73
|
+
Contributing to death_and_taxes
|
74
|
+
===============================
|
6
75
|
|
7
76
|
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
|
8
77
|
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
|
@@ -12,7 +81,8 @@ Description goes here.
|
|
12
81
|
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
13
82
|
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
14
83
|
|
15
|
-
|
84
|
+
Copyright
|
85
|
+
=========
|
16
86
|
|
17
87
|
Copyright (c) 2011 Guillaume Malette. See LICENSE.txt for
|
18
88
|
further details.
|
data/config/ca.yml
CHANGED
@@ -2,32 +2,36 @@ taxes:
|
|
2
2
|
GST:
|
3
3
|
versions:
|
4
4
|
- starts: 2011-01-01
|
5
|
-
ends:
|
5
|
+
ends: 2013-12-31
|
6
6
|
percentage: 5
|
7
7
|
|
8
8
|
states:
|
9
9
|
qc:
|
10
10
|
rules:
|
11
|
-
|
12
|
-
|
11
|
+
- starts: 0001-01-01
|
12
|
+
ends: 2020-12-31
|
13
|
+
same_state: [GST, QST]
|
14
|
+
same_country: GST
|
13
15
|
taxes:
|
14
16
|
QST:
|
15
|
-
apply_on: GST
|
16
17
|
versions:
|
17
18
|
- starts: 2011-01-01
|
18
19
|
ends: 2011-12-31
|
19
20
|
percentage: 8.5
|
20
|
-
|
21
|
+
apply_on: GST
|
22
|
+
|
21
23
|
- starts: 2012-01-01
|
22
24
|
ends: 2012-12-31
|
23
25
|
percentage: 9.5
|
24
26
|
|
25
|
-
on:
|
27
|
+
"on":
|
26
28
|
rules:
|
27
|
-
|
29
|
+
- starts: 0001-01-01
|
30
|
+
ends: 2020-12-31
|
31
|
+
same_country: HST
|
28
32
|
taxes:
|
29
33
|
HST:
|
30
34
|
versions:
|
31
35
|
- starts: 2011-01-01
|
32
36
|
ends: 2012-12-31
|
33
|
-
percentage:
|
37
|
+
percentage: 13
|
data/death_and_taxes.gemspec
CHANGED
@@ -18,9 +18,9 @@ module DeathAndTaxes
|
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
21
|
-
def applicable_taxes
|
22
|
-
if
|
23
|
-
@states[
|
21
|
+
def applicable_taxes seller, buyer, date
|
22
|
+
if seller[:country] == buyer[:country] && seller[:country] == @code
|
23
|
+
@states[seller[:state]].applicable_taxes buyer[:state], date
|
24
24
|
else
|
25
25
|
[]
|
26
26
|
end
|
@@ -31,7 +31,7 @@ module DeathAndTaxes
|
|
31
31
|
end
|
32
32
|
|
33
33
|
def build_tax tax, date
|
34
|
-
@taxes[tax].try(:build, date) || @states.
|
34
|
+
@taxes[tax].try(:build, date) || @states.detect{|t, s| s.try(:build_tax, tax, date)}.try(:last).try(:build_tax, tax, date)
|
35
35
|
end
|
36
36
|
end
|
37
37
|
end
|
@@ -13,15 +13,16 @@ module DeathAndTaxes
|
|
13
13
|
yml['taxes'].each do |tax_name, infos|
|
14
14
|
@taxes[tax_name] = TaxInfo.new(tax_name, infos)
|
15
15
|
end
|
16
|
-
|
16
|
+
|
17
17
|
@rules = yml['rules']
|
18
18
|
end
|
19
19
|
|
20
20
|
def applicable_taxes to_state, date
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
21
|
+
rule = @rules.select{|d| (d['starts']..d['ends']).cover? date}.first
|
22
|
+
taxes = if to_state == @code && rule['same_state']
|
23
|
+
rule['same_state']
|
24
|
+
elsif rule['same_country']
|
25
|
+
rule['same_country']
|
25
26
|
else
|
26
27
|
[]
|
27
28
|
end
|
@@ -29,7 +30,7 @@ module DeathAndTaxes
|
|
29
30
|
end
|
30
31
|
|
31
32
|
def build_tax tax, date
|
32
|
-
if i = @taxes[tax] && i.cover?(date)
|
33
|
+
if (i = @taxes[tax]) && i.cover?(date)
|
33
34
|
i.build(date)
|
34
35
|
end
|
35
36
|
end
|
@@ -6,20 +6,19 @@ module DeathAndTaxes
|
|
6
6
|
end
|
7
7
|
|
8
8
|
def parse yml
|
9
|
-
@apply_on = yml['apply_on']
|
10
9
|
@versions = yml['versions'].collect do |version|
|
11
10
|
TaxVersion.new(version)
|
12
11
|
end
|
13
12
|
end
|
14
13
|
|
15
14
|
def cover? date
|
16
|
-
@versions.any?{ |
|
15
|
+
@versions.any?{ |v| v.cover? date }
|
17
16
|
end
|
18
17
|
|
19
18
|
def build date
|
20
|
-
if v = @versions.detect{ |
|
21
|
-
t = Tax.new :name => @name, :percentage => v
|
22
|
-
t.tax = DeathAndTaxes.
|
19
|
+
if v = @versions.detect{ |version| version.cover?(date) }
|
20
|
+
t = Tax.new :name => @name, :percentage => v.percentage
|
21
|
+
t.tax = DeathAndTaxes.build(v.apply_on, date) if v.apply_on
|
23
22
|
t
|
24
23
|
end
|
25
24
|
end
|
@@ -1,17 +1,15 @@
|
|
1
1
|
module DeathAndTaxes
|
2
2
|
class TaxVersion
|
3
|
+
attr_reader :starts, :ends, :percentage, :apply_on
|
3
4
|
def initialize yml
|
4
|
-
@
|
5
|
-
@
|
5
|
+
@starts = yml['starts']
|
6
|
+
@ends = yml['ends']
|
6
7
|
@percentage = yml['percentage']
|
8
|
+
@apply_on = yml['apply_on']
|
7
9
|
end
|
8
10
|
|
9
11
|
def cover? date
|
10
|
-
(@
|
11
|
-
end
|
12
|
-
|
13
|
-
def build
|
14
|
-
|
12
|
+
(@starts..@ends).cover? date
|
15
13
|
end
|
16
14
|
end
|
17
15
|
end
|
data/lib/death_and_taxes.rb
CHANGED
@@ -3,11 +3,10 @@ require 'active_record/version'
|
|
3
3
|
|
4
4
|
require 'active_support/core_ext'
|
5
5
|
|
6
|
-
require File.join(File.dirname(__FILE__), 'death_and_taxes', 'railtie')
|
7
6
|
|
8
7
|
module DeathAndTaxes
|
9
8
|
%w( Country State Tax Taxable Taxation Taxer TaxInfo TaxVersion ).each do |class_name|
|
10
|
-
|
9
|
+
require File.join(File.dirname(__FILE__), "death_and_taxes/#{class_name.underscore}")
|
11
10
|
end
|
12
11
|
|
13
12
|
Dir[File.join(File.dirname(__FILE__), '..', 'config', '*.yml')].each do |filename|
|
@@ -22,6 +21,9 @@ module DeathAndTaxes
|
|
22
21
|
end
|
23
22
|
|
24
23
|
def self.build tax, date
|
25
|
-
@countries.detect {|code, country| country.build_tax(tax, date)}
|
24
|
+
@countries.detect {|code, country| country.build_tax(tax, date)}.try(:last).try(:build_tax, tax, date)
|
26
25
|
end
|
27
|
-
end
|
26
|
+
end
|
27
|
+
|
28
|
+
ActiveRecord::Base.send(:include, DeathAndTaxes::Taxable)
|
29
|
+
ActiveRecord::Base.send(:include, DeathAndTaxes::Taxer)
|
data/spec/helper.rb
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
require 'active_record'
|
4
|
+
require 'active_support'
|
5
|
+
require 'rake'
|
6
|
+
require 'sqlite3'
|
7
|
+
|
8
|
+
|
9
|
+
begin
|
10
|
+
Bundler.setup(:default, :development)
|
11
|
+
rescue Bundler::BundlerError => e
|
12
|
+
$stderr.puts e.message
|
13
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
14
|
+
exit e.status_code
|
15
|
+
end
|
16
|
+
require 'rspec'
|
17
|
+
|
18
|
+
|
19
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
20
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
21
|
+
require 'death_and_taxes'
|
22
|
+
require 'generators/death_and_taxes/migration/templates/active_record/migration'
|
23
|
+
|
24
|
+
db_file = File.join(File.dirname(__FILE__), "death_and_taxes.sqlite3")
|
25
|
+
|
26
|
+
File.delete db_file if File.exists? db_file
|
27
|
+
|
28
|
+
ActiveRecord::Base.establish_connection(
|
29
|
+
:adapter => "sqlite3",
|
30
|
+
:database => db_file
|
31
|
+
)
|
32
|
+
|
33
|
+
|
34
|
+
RSpec.configure do |config|
|
35
|
+
end
|
36
|
+
|
37
|
+
ActiveRecord::Base.connection.execute("DROP TABLE IF EXISTS 'products'")
|
38
|
+
ActiveRecord::Base.connection.create_table(:products) do |t|
|
39
|
+
t.string :name
|
40
|
+
t.integer :amount
|
41
|
+
end
|
42
|
+
|
43
|
+
DeathAndTaxesMigration.up
|
44
|
+
|
45
|
+
class Product < ActiveRecord::Base
|
46
|
+
acts_as_taxable
|
47
|
+
end
|
48
|
+
|
49
|
+
def applicable_taxes from, to, date = nil
|
50
|
+
defaults = {:country => "ca", :state => "qc"}
|
51
|
+
from = defaults.merge from
|
52
|
+
to = defaults.merge to
|
53
|
+
DeathAndTaxes.applicable_taxes from, to, date
|
54
|
+
end
|
@@ -0,0 +1,99 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
describe 'DeathAndTaxes' do
|
4
|
+
describe 'should find the correct taxes' do
|
5
|
+
it 'within Quebec, in 2011' do
|
6
|
+
applicable_taxes({:state => "qc"}, {:state => "qc"},
|
7
|
+
Date.new(2011,01,01)).should == ["GST", "QST"]
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'within Quebec, in 2012' do
|
11
|
+
applicable_taxes({:state => "qc"}, {:state => "qc"},
|
12
|
+
Date.new(2012,01,01)).should == ["GST", "QST"]
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'within Ontario, in 2011' do
|
16
|
+
applicable_taxes({:state => "on"}, {:state => "on"},
|
17
|
+
Date.new(2011,01,01)).should == ["HST"]
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'from Ontario to Quebec, in 2011' do
|
21
|
+
applicable_taxes({:state => "on"}, {:state => "qc"},
|
22
|
+
Date.new(2011,01,01)).should == ["HST"]
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe 'should build the correct taxes' do
|
27
|
+
describe 'within Quebec' do
|
28
|
+
{2011 => 8.5, 2012 => 9.5}.each do |year, percentage|
|
29
|
+
it "in #{year}" do
|
30
|
+
date = Date.new(year,01,01)
|
31
|
+
taxes = applicable_taxes({:state => "qc"}, {:state => "qc"},
|
32
|
+
date).map{|name| DeathAndTaxes::build name, date}
|
33
|
+
|
34
|
+
taxes.first.name.should == "GST"
|
35
|
+
taxes.first.percentage.should == 5.0
|
36
|
+
|
37
|
+
taxes.last.name.should == "QST"
|
38
|
+
taxes.last.percentage.should == percentage
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'from Quebec to Ontario, in 2011' do
|
44
|
+
date = Date.new(2011,01,01)
|
45
|
+
taxes = applicable_taxes({:state => "qc"}, {:state => "on"},
|
46
|
+
date).map{|name| DeathAndTaxes::build name, date}
|
47
|
+
|
48
|
+
taxes.length.should == 1
|
49
|
+
|
50
|
+
taxes.first.name.should == "GST"
|
51
|
+
taxes.first.percentage.should == 5.0
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'from Ontario to Quebec, in 2011' do
|
55
|
+
date = Date.new(2011,01,01)
|
56
|
+
taxes = applicable_taxes({:state => "on"}, {:state => "qc"},
|
57
|
+
date).map{|name| DeathAndTaxes::build name, date}
|
58
|
+
|
59
|
+
taxes.length.should == 1
|
60
|
+
taxes.first.name.should == "HST"
|
61
|
+
taxes.first.percentage.should == 13
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
describe 'applicable_taxes' do
|
66
|
+
it 'should get the correct taxes to apply' do
|
67
|
+
taxes = DeathAndTaxes.applicable_taxes({:country => "ca", :state => "qc"}, {:country => "ca", :state => "qc"}, Date.new(2011, 1, 1))
|
68
|
+
taxes.should == ["GST", "QST"]
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
describe 'building taxes' do
|
73
|
+
it 'should build the correct taxes' do
|
74
|
+
tax = DeathAndTaxes.build "GST", Date.new(2011, 1, 1)
|
75
|
+
tax.name.should == "GST"
|
76
|
+
tax.percentage.should == 5
|
77
|
+
|
78
|
+
tax = DeathAndTaxes.build "QST", Date.new(2011, 1, 1)
|
79
|
+
tax.name.should == "QST"
|
80
|
+
tax.percentage.should == 8.5
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
describe 'applying taxes' do
|
85
|
+
it 'should create the correct taxations' do
|
86
|
+
product = Product.create(:amount => 100_000)
|
87
|
+
taxes = ["GST", "QST"].map{|name| DeathAndTaxes.build name, Date.new(2011, 1, 1)}
|
88
|
+
product.apply_taxes taxes
|
89
|
+
taxations = product.taxations
|
90
|
+
|
91
|
+
taxations.first.name.should == "GST"
|
92
|
+
taxations.first.amount.should == 5000
|
93
|
+
|
94
|
+
taxations.last.name.should == "QST"
|
95
|
+
taxations.last.amount.should == 8925
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: death_and_taxes
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,12 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-08-09 00:00:00.
|
13
|
-
default_executable:
|
12
|
+
date: 2011-08-09 00:00:00.000000000Z
|
14
13
|
dependencies:
|
15
14
|
- !ruby/object:Gem::Dependency
|
16
15
|
name: rails
|
17
|
-
requirement: &
|
16
|
+
requirement: &2164795680 !ruby/object:Gem::Requirement
|
18
17
|
none: false
|
19
18
|
requirements:
|
20
19
|
- - ! '>='
|
@@ -22,10 +21,10 @@ dependencies:
|
|
22
21
|
version: '0'
|
23
22
|
type: :runtime
|
24
23
|
prerelease: false
|
25
|
-
version_requirements: *
|
24
|
+
version_requirements: *2164795680
|
26
25
|
- !ruby/object:Gem::Dependency
|
27
26
|
name: sqlite3
|
28
|
-
requirement: &
|
27
|
+
requirement: &2164795260 !ruby/object:Gem::Requirement
|
29
28
|
none: false
|
30
29
|
requirements:
|
31
30
|
- - ! '>='
|
@@ -33,7 +32,18 @@ dependencies:
|
|
33
32
|
version: '0'
|
34
33
|
type: :development
|
35
34
|
prerelease: false
|
36
|
-
version_requirements: *
|
35
|
+
version_requirements: *2164795260
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: rspec
|
38
|
+
requirement: &2164794840 !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: *2164794840
|
37
47
|
description: Death and Taxes allows to 'easily' calculate taxes on a model
|
38
48
|
email: gmalette@gmail.com
|
39
49
|
executables: []
|
@@ -51,7 +61,6 @@ files:
|
|
51
61
|
- death_and_taxes.gemspec
|
52
62
|
- lib/death_and_taxes.rb
|
53
63
|
- lib/death_and_taxes/country.rb
|
54
|
-
- lib/death_and_taxes/railtie.rb
|
55
64
|
- lib/death_and_taxes/state.rb
|
56
65
|
- lib/death_and_taxes/tax.rb
|
57
66
|
- lib/death_and_taxes/tax_info.rb
|
@@ -62,9 +71,8 @@ files:
|
|
62
71
|
- lib/death_and_taxes/version.rb
|
63
72
|
- lib/generators/death_and_taxes/migration/migration_generator.rb
|
64
73
|
- lib/generators/death_and_taxes/migration/templates/active_record/migration.rb
|
65
|
-
-
|
66
|
-
-
|
67
|
-
has_rdoc: true
|
74
|
+
- spec/helper.rb
|
75
|
+
- spec/test_death_and_taxes.rb
|
68
76
|
homepage: ''
|
69
77
|
licenses: []
|
70
78
|
post_install_message:
|
@@ -85,10 +93,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
85
93
|
version: '0'
|
86
94
|
requirements: []
|
87
95
|
rubyforge_project:
|
88
|
-
rubygems_version: 1.6
|
96
|
+
rubygems_version: 1.8.6
|
89
97
|
signing_key:
|
90
98
|
specification_version: 3
|
91
99
|
summary: Tax calculations
|
92
100
|
test_files:
|
93
|
-
-
|
94
|
-
-
|
101
|
+
- spec/helper.rb
|
102
|
+
- spec/test_death_and_taxes.rb
|
@@ -1,11 +0,0 @@
|
|
1
|
-
require 'rails'
|
2
|
-
require 'death_and_taxes'
|
3
|
-
|
4
|
-
module DeathAndTaxes
|
5
|
-
class Railtie < Rails::Railtie
|
6
|
-
config.to_prepare do
|
7
|
-
ActiveRecord::Base.send(:include, DeathAndTaxes::Taxable)
|
8
|
-
ActiveRecord::Base.send(:include, DeathAndTaxes::Taxer)
|
9
|
-
end
|
10
|
-
end
|
11
|
-
end
|
data/test/helper.rb
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
require 'bundler'
|
3
|
-
begin
|
4
|
-
Bundler.setup(:default, :development)
|
5
|
-
rescue Bundler::BundlerError => e
|
6
|
-
$stderr.puts e.message
|
7
|
-
$stderr.puts "Run `bundle install` to install missing gems"
|
8
|
-
exit e.status_code
|
9
|
-
end
|
10
|
-
require 'test/unit'
|
11
|
-
require 'shoulda'
|
12
|
-
|
13
|
-
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
14
|
-
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
15
|
-
require 'death_and_taxes'
|
16
|
-
|
17
|
-
class Test::Unit::TestCase
|
18
|
-
end
|