payday 1.1.0 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ # CHANGELOG
2
+
3
+ ## 1.1.1
4
+
5
+ * Added support for zh-CN locale (thanks [Martin91](https://github.com/Martin91)!
data/Gemfile CHANGED
@@ -2,3 +2,4 @@ source "http://rubygems.org"
2
2
 
3
3
  gemspec
4
4
  gem "rake"
5
+ gem "rspec", "~> 2.11.0"
@@ -0,0 +1,21 @@
1
+ zh-CN:
2
+ payday:
3
+ status:
4
+ paid: 付款成功
5
+ overdue: 已过期
6
+ invoice:
7
+ bill_to: 账单地址
8
+ ship_to: 送货地址
9
+ invoice_no: "单号 #:"
10
+ due_date: "过期日期:"
11
+ paid_date: "支付日期:"
12
+ subtotal: "小计:"
13
+ shipping: "邮费:"
14
+ tax: "税费:"
15
+ total: "总计:"
16
+ notes: "备注"
17
+ line_item:
18
+ description: 描述
19
+ unit_price: 单价
20
+ quantity: 数量
21
+ amount: 合计
@@ -2,5 +2,5 @@
2
2
  module Payday
3
3
 
4
4
  # Current Version
5
- VERSION = "1.1.0"
5
+ VERSION = "1.1.1"
6
6
  end
@@ -0,0 +1,177 @@
1
+ require 'spec_helper'
2
+
3
+ module Payday
4
+ describe Invoice do
5
+
6
+ it "should be able to be initalized with a hash of options" do
7
+ i = Invoice.new(:invoice_number => 20, :bill_to => "Here", :ship_to => "There",
8
+ :notes => "These are some notes.",
9
+ :line_items => [LineItem.new(:price => 10, :quantity => 3, :description => "Shirts")],
10
+ :shipping_rate => 15.00, :shipping_description => "USPS Priority Mail:",
11
+ :tax_rate => 0.125, :tax_description => "Local Sales Tax, 12.5%")
12
+
13
+ expect(i.invoice_number).to eq(20)
14
+ expect(i.bill_to).to eq("Here")
15
+ expect(i.ship_to).to eq("There")
16
+ expect(i.notes).to eq("These are some notes.")
17
+ expect(i.line_items[0].description).to eq("Shirts")
18
+ expect(i.shipping_rate).to eq(BigDecimal.new("15.00"))
19
+ expect(i.shipping_description).to eq("USPS Priority Mail:")
20
+ expect(i.tax_rate).to eq(BigDecimal.new("0.125"))
21
+ expect(i.tax_description).to eq("Local Sales Tax, 12.5%")
22
+ end
23
+
24
+ it "should total all of the line items into a subtotal correctly" do
25
+ i = Invoice.new
26
+
27
+ # $100 in Pants
28
+ i.line_items << LineItem.new(:price => 20, :quantity => 5, :description => "Pants")
29
+
30
+ # $30 in Shirts
31
+ i.line_items << LineItem.new(:price => 10, :quantity => 3, :description => "Shirts")
32
+
33
+ # $1000 in Hats
34
+ i.line_items << LineItem.new(:price => 5, :quantity => 200, :description => "Hats")
35
+
36
+ expect(i.subtotal).to eq(BigDecimal.new("1130"))
37
+ end
38
+
39
+ it "should calculate the correct tax amount, rounded to two decimal places" do
40
+ i = Invoice.new(:tax_rate => 0.1)
41
+ i.line_items << LineItem.new(:price => 20, :quantity => 5, :description => "Pants")
42
+
43
+ expect(i.tax).to eq(BigDecimal.new("10"))
44
+ end
45
+
46
+ it "shouldn't apply taxes to invoices with a subtotal of 0 or a negative amount" do
47
+ i = Invoice.new(:tax_rate => 0.1)
48
+ i.line_items << LineItem.new(:price => -1, :quantity => 100, :description => "Negative Priced Pants")
49
+
50
+ expect(i.tax).to eq(BigDecimal.new("0"))
51
+ end
52
+
53
+ it "should calculate the total for an invoice correctly" do
54
+ i = Invoice.new(:tax_rate => 0.1)
55
+
56
+ # $100 in Pants
57
+ i.line_items << LineItem.new(:price => 20, :quantity => 5, :description => "Pants")
58
+
59
+ # $30 in Shirts
60
+ i.line_items << LineItem.new(:price => 10, :quantity => 3, :description => "Shirts")
61
+
62
+ # $1000 in Hats
63
+ i.line_items << LineItem.new(:price => 5, :quantity => 200, :description => "Hats")
64
+
65
+ expect(i.total).to eq(BigDecimal.new("1234"))
66
+ end
67
+
68
+ it "is overdue when it's past date and unpaid" do
69
+ i = Invoice.new(:due_at => Date.today - 1)
70
+ expect(i.overdue?).to eq(true)
71
+ end
72
+
73
+ it "isn't overdue when past due date and paid" do
74
+ i = Invoice.new(:due_at => Date.today - 1, :paid_at => Date.today)
75
+ expect(i.overdue?).not_to eq(true)
76
+ end
77
+
78
+ it "is overdue when due date is a time before the current date" do
79
+ i = Invoice.new(:due_at => Time.parse("Jan 1 14:33:20 GMT 2011"))
80
+ expect(i.overdue?).to eq(true)
81
+ end
82
+
83
+ it "shouldn't be paid when not marked paid" do
84
+ i = Invoice.new
85
+ expect(i.paid?).not_to eq(true)
86
+ end
87
+
88
+ it "should be paid when marked as paid" do
89
+ i = Invoice.new(:paid_at => Date.today)
90
+ expect(i.paid?).to eq(true)
91
+ end
92
+
93
+ it "should be able to iterate over details" do
94
+ i = Invoice.new(:invoice_details => [["Test", "Yes"], ["Awesome", "Absolutely"]])
95
+ details = []
96
+ i.each_detail do |key, value|
97
+ details << [key, value]
98
+ end
99
+
100
+ expect(details.length).to eq(2)
101
+ expect(details).to include(["Test", "Yes"])
102
+ expect(details).to include(["Awesome", "Absolutely"])
103
+ end
104
+
105
+ it "should be able to iterate through invoice_details as a hash" do
106
+ i = Invoice.new(:invoice_details => {"Test" => "Yes", "Awesome" => "Absolutely"})
107
+ details = []
108
+ i.each_detail do |key, value|
109
+ details << [key, value]
110
+ end
111
+
112
+ expect(details.length).to eq(2)
113
+ expect(details).to include(["Test", "Yes"])
114
+ expect(details).to include(["Awesome", "Absolutely"])
115
+ end
116
+
117
+ describe "rendering" do
118
+ before do
119
+ Dir.mkdir("tmp") unless File.exists?("tmp")
120
+ Config.default.reset
121
+ end
122
+
123
+ it "should be able to render to a file" do
124
+ File.unlink("tmp/testing.pdf") if File.exists?("tmp/testing.pdf")
125
+
126
+ i = Invoice.new(:tax_rate => 0.1, :notes => "These are some crazy awesome notes!", :invoice_number => 12,
127
+ :due_at => Date.civil(2011, 1, 22), #:paid_at => Date.civil(2012, 2, 22),
128
+ :bill_to => "Alan Johnson\n101 This Way\nSomewhere, SC 22222",
129
+ :ship_to => "Frank Johnson\n101 That Way\nOther, SC 22229",
130
+ :invoice_details => {"Ordered By:" => "Alan Johnson", "Paid By:" => "Dude McDude"})
131
+
132
+ Payday::Config.default.company_details = "10 This Way\nManhattan, NY 10001\n800-111-2222\nawesome@awesomecorp.com"
133
+
134
+ 30.times do
135
+ i.line_items << LineItem.new(:price => 20, :quantity => 5, :description => "Pants")
136
+ i.line_items << LineItem.new(:price => 10, :quantity => 3, :description => "Shirts")
137
+ i.line_items << LineItem.new(:price => 5, :quantity => 200, :description => "Hats")
138
+ end
139
+
140
+ i.render_pdf_to_file("tmp/testing.pdf")
141
+
142
+ expect(File.exists?("tmp/testing.pdf")).to eq(true)
143
+ end
144
+
145
+ it "should be able to render to a string" do
146
+ i = Invoice.new(:tax_rate => 0.1, :notes => "These are some crazy awesome notes!", :invoice_number => 12,
147
+ :due_at => Date.civil(2011, 1, 22), :paid_at => Date.civil(2012, 2, 22),
148
+ :bill_to => "Alan Johnson\n101 This Way\nSomewhere, SC 22222", :ship_to => "Frank Johnson\n101 That Way\nOther, SC 22229")
149
+
150
+ 3.times do
151
+ i.line_items << LineItem.new(:price => 20, :quantity => 5, :description => "Pants")
152
+ i.line_items << LineItem.new(:price => 10, :quantity => 3, :description => "Shirts")
153
+ i.line_items << LineItem.new(:price => 5, :quantity => 200.0, :description => "Hats")
154
+ end
155
+
156
+ expect(i.render_pdf).not_to eq(nil)
157
+ end
158
+
159
+ it "should be able to render with an svg logo" do
160
+ Payday::Config.default.invoice_logo = { :filename => "assets/tiger.svg", :size => "100x100" }
161
+ i = Invoice.new(:tax_rate => 0.1, :notes => "These are some crazy awesome notes!", :invoice_number => 12,
162
+ :due_at => Date.civil(2011, 1, 22), :paid_at => Date.civil(2012, 2, 22),
163
+ :bill_to => "Alan Johnson\n101 This Way\nSomewhere, SC 22222", :ship_to => "Frank Johnson\n101 That Way\nOther, SC 22229")
164
+
165
+ 3.times do
166
+ i.line_items << LineItem.new(:price => 20, :quantity => 5, :description => "Pants")
167
+ i.line_items << LineItem.new(:price => 10, :quantity => 3, :description => "Shirts")
168
+ i.line_items << LineItem.new(:price => 5, :quantity => 200.0, :description => "Hats")
169
+ end
170
+
171
+ i.render_pdf_to_file("tmp/svg.pdf")
172
+
173
+ expect(i.render_pdf).not_to eq(nil)
174
+ end
175
+ end
176
+ end
177
+ end
@@ -0,0 +1,26 @@
1
+ require 'spec_helper'
2
+
3
+ module Payday
4
+ describe LineItem do
5
+ it "should be able to be initilized with a price" do
6
+ li = LineItem.new(:price => BigDecimal.new("20"))
7
+ expect(li.price).to eq(BigDecimal.new("20"))
8
+ end
9
+
10
+ it "should be able to be initialized with a quantity" do
11
+ li = LineItem.new(:quantity => 30)
12
+ expect(li.quantity).to eq(BigDecimal.new("30"))
13
+ end
14
+
15
+ it "should be able to be initlialized with a description" do
16
+ li = LineItem.new(:description => "12 Pairs of Pants")
17
+ expect(li.description).to eq("12 Pairs of Pants")
18
+ end
19
+
20
+ it "should return the correct amount" do
21
+ li = LineItem.new(:price => 10, :quantity => 12)
22
+ expect(li.amount).to eq(BigDecimal.new("120"))
23
+ end
24
+ end
25
+ end
26
+
@@ -0,0 +1,10 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+
4
+ require 'payday'
5
+ require 'date'
6
+ require 'time'
7
+
8
+ RSpec.configure do |config|
9
+ # some (optional) config here
10
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: payday
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-09-24 00:00:00.000000000 Z
12
+ date: 2013-07-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: prawn
16
- requirement: &70306223004560 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,15 @@ dependencies:
21
21
  version: 0.12.0
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70306223004560
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: 0.12.0
25
30
  - !ruby/object:Gem::Dependency
26
31
  name: money
27
- requirement: &70306223004060 !ruby/object:Gem::Requirement
32
+ requirement: !ruby/object:Gem::Requirement
28
33
  none: false
29
34
  requirements:
30
35
  - - ~>
@@ -32,10 +37,15 @@ dependencies:
32
37
  version: 3.6.1
33
38
  type: :runtime
34
39
  prerelease: false
35
- version_requirements: *70306223004060
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: 3.6.1
36
46
  - !ruby/object:Gem::Dependency
37
47
  name: prawn-svg
38
- requirement: &70306223003580 !ruby/object:Gem::Requirement
48
+ requirement: !ruby/object:Gem::Requirement
39
49
  none: false
40
50
  requirements:
41
51
  - - ~>
@@ -43,10 +53,15 @@ dependencies:
43
53
  version: 0.9.1
44
54
  type: :runtime
45
55
  prerelease: false
46
- version_requirements: *70306223003580
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 0.9.1
47
62
  - !ruby/object:Gem::Dependency
48
63
  name: i18n
49
- requirement: &70306223026900 !ruby/object:Gem::Requirement
64
+ requirement: !ruby/object:Gem::Requirement
50
65
  none: false
51
66
  requirements:
52
67
  - - ! '>='
@@ -54,10 +69,15 @@ dependencies:
54
69
  version: 0.5.0
55
70
  type: :runtime
56
71
  prerelease: false
57
- version_requirements: *70306223026900
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: 0.5.0
58
78
  - !ruby/object:Gem::Dependency
59
79
  name: minitest
60
- requirement: &70306223026520 !ruby/object:Gem::Requirement
80
+ requirement: !ruby/object:Gem::Requirement
61
81
  none: false
62
82
  requirements:
63
83
  - - ! '>='
@@ -65,7 +85,12 @@ dependencies:
65
85
  version: '0'
66
86
  type: :development
67
87
  prerelease: false
68
- version_requirements: *70306223026520
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
69
94
  description: Payday is a library for rendering invoices. At present it supports rendering
70
95
  invoices to pdfs, but we're planning on adding support for other formats in the
71
96
  near future.
@@ -76,6 +101,7 @@ extensions: []
76
101
  extra_rdoc_files: []
77
102
  files:
78
103
  - .gitignore
104
+ - CHANGELOG.md
79
105
  - Gemfile
80
106
  - README.md
81
107
  - Rakefile
@@ -97,12 +123,13 @@ files:
97
123
  - lib/payday/locale/en.yml
98
124
  - lib/payday/locale/es.yml
99
125
  - lib/payday/locale/fr.yml
126
+ - lib/payday/locale/zh-CN.yml
100
127
  - lib/payday/pdf_renderer.rb
101
128
  - lib/payday/version.rb
102
129
  - payday.gemspec
103
- - test/invoice_test.rb
104
- - test/line_item_test.rb
105
- - test/test_helper.rb
130
+ - spec/invoice_spec.rb
131
+ - spec/line_item_spec.rb
132
+ - spec/spec_helper.rb
106
133
  homepage: ''
107
134
  licenses: []
108
135
  post_install_message:
@@ -115,20 +142,25 @@ required_ruby_version: !ruby/object:Gem::Requirement
115
142
  - - ! '>='
116
143
  - !ruby/object:Gem::Version
117
144
  version: '0'
145
+ segments:
146
+ - 0
147
+ hash: 2492971967055799217
118
148
  required_rubygems_version: !ruby/object:Gem::Requirement
119
149
  none: false
120
150
  requirements:
121
151
  - - ! '>='
122
152
  - !ruby/object:Gem::Version
123
153
  version: '0'
154
+ segments:
155
+ - 0
156
+ hash: 2492971967055799217
124
157
  requirements: []
125
158
  rubyforge_project:
126
- rubygems_version: 1.8.11
159
+ rubygems_version: 1.8.23
127
160
  signing_key:
128
161
  specification_version: 3
129
162
  summary: git remote add origin git@github.com:commondream/payday.git
130
163
  test_files:
131
- - test/invoice_test.rb
132
- - test/line_item_test.rb
133
- - test/test_helper.rb
134
- has_rdoc:
164
+ - spec/invoice_spec.rb
165
+ - spec/line_item_spec.rb
166
+ - spec/spec_helper.rb
data/test/invoice_test.rb DELETED
@@ -1,175 +0,0 @@
1
- require File.expand_path("test/test_helper")
2
-
3
- module Payday
4
- class InvoiceTest < MiniTest::Unit::TestCase
5
- def setup
6
- Dir.mkdir("tmp") unless File.exists?("tmp")
7
- Config.default.reset
8
- end
9
-
10
- test "that setting values through the options hash on initialization works" do
11
- i = Invoice.new(:invoice_number => 20, :bill_to => "Here", :ship_to => "There",
12
- :notes => "These are some notes.",
13
- :line_items => [LineItem.new(:price => 10, :quantity => 3, :description => "Shirts")],
14
- :shipping_rate => 15.00, :shipping_description => "USPS Priority Mail:",
15
- :tax_rate => 0.125, :tax_description => "Local Sales Tax, 12.5%")
16
-
17
- assert_equal 20, i.invoice_number
18
- assert_equal "Here", i.bill_to
19
- assert_equal "There", i.ship_to
20
- assert_equal "These are some notes.", i.notes
21
- assert_equal "Shirts", i.line_items[0].description
22
- assert_equal BigDecimal.new("15.00"), i.shipping_rate
23
- assert_equal "USPS Priority Mail:", i.shipping_description
24
- assert_equal BigDecimal.new("0.125"), i.tax_rate
25
- assert_equal "Local Sales Tax, 12.5%", i.tax_description
26
- end
27
-
28
- test "that subtotal totals up all of the line items in an invoice correctly" do
29
- i = Invoice.new
30
-
31
- # $100 in Pants
32
- i.line_items << LineItem.new(:price => 20, :quantity => 5, :description => "Pants")
33
-
34
- # $30 in Shirts
35
- i.line_items << LineItem.new(:price => 10, :quantity => 3, :description => "Shirts")
36
-
37
- # $1000 in Hats
38
- i.line_items << LineItem.new(:price => 5, :quantity => 200, :description => "Hats")
39
-
40
- assert_equal BigDecimal.new("1130"), i.subtotal
41
- end
42
-
43
- test "that tax returns the correct tax amount, rounded to two decimal places" do
44
- i = Invoice.new(:tax_rate => 0.1)
45
- i.line_items << LineItem.new(:price => 20, :quantity => 5, :description => "Pants")
46
-
47
- assert_equal(BigDecimal.new("10"), i.tax)
48
- end
49
-
50
- test "that taxes aren't applied to invoices with a subtotal of 0 or a negative amount" do
51
- i = Invoice.new(:tax_rate => 0.1)
52
- i.line_items << LineItem.new(:price => -1, :quantity => 100, :description => "Negative Priced Pants")
53
-
54
- assert_equal(BigDecimal.new("0"), i.tax)
55
- end
56
-
57
- test "that the total for this invoice calculates correctly" do
58
- i = Invoice.new(:tax_rate => 0.1)
59
-
60
- # $100 in Pants
61
- i.line_items << LineItem.new(:price => 20, :quantity => 5, :description => "Pants")
62
-
63
- # $30 in Shirts
64
- i.line_items << LineItem.new(:price => 10, :quantity => 3, :description => "Shirts")
65
-
66
- # $1000 in Hats
67
- i.line_items << LineItem.new(:price => 5, :quantity => 200, :description => "Hats")
68
-
69
- assert_equal BigDecimal.new("1243"), i.total
70
- end
71
-
72
- test "overdue? is false when past date and unpaid" do
73
- i = Invoice.new(:due_at => Date.today - 1)
74
- assert i.overdue?
75
- end
76
-
77
- test "overdue? is true when past date but paid" do
78
- i = Invoice.new(:due_at => Date.today - 1, :paid_at => Date.today)
79
- assert !i.overdue?
80
- end
81
-
82
- test "overdue? when due_at is a time" do
83
- i = Invoice.new(:due_at => Time.parse("Jan 1 14:33:20 GMT 2011"))
84
- assert i.overdue?
85
- end
86
-
87
- test "paid is false when not paid" do
88
- i = Invoice.new
89
- assert !i.paid?
90
- end
91
-
92
- test "paid is true when paid" do
93
- i = Invoice.new(:paid_at => Date.today)
94
- assert i.paid?
95
- end
96
-
97
- test "iterating through invoice_details as two element arrays" do
98
- i = Invoice.new(:invoice_details => [["Test", "Yes"], ["Awesome", "Absolutely"]])
99
- details = []
100
- i.each_detail do |key, value|
101
- details << [key, value]
102
- end
103
-
104
- assert_equal 2, details.length
105
- assert details.include?(["Test", "Yes"])
106
- assert details.include?(["Awesome", "Absolutely"])
107
- end
108
-
109
- test "iterating through invoice_details as a hash" do
110
- i = Invoice.new(:invoice_details => {"Test" => "Yes", "Awesome" => "Absolutely"})
111
- details = []
112
- i.each_detail do |key, value|
113
- details << [key, value]
114
- end
115
-
116
- assert_equal 2, details.length
117
- assert details.include?(["Test", "Yes"])
118
- assert details.include?(["Awesome", "Absolutely"])
119
- end
120
-
121
- test "rendering to file" do
122
- File.unlink("tmp/testing.pdf") if File.exists?("tmp/testing.pdf")
123
- assert !File.exists?("tmp/testing.pdf")
124
-
125
- i = Invoice.new(:tax_rate => 0.1, :notes => "These are some crazy awesome notes!", :invoice_number => 12,
126
- :due_at => Date.civil(2011, 1, 22), #:paid_at => Date.civil(2012, 2, 22),
127
- :bill_to => "Alan Johnson\n101 This Way\nSomewhere, SC 22222",
128
- :ship_to => "Frank Johnson\n101 That Way\nOther, SC 22229",
129
- :invoice_details => {"Ordered By:" => "Alan Johnson", "Paid By:" => "Dude McDude"})
130
-
131
- Payday::Config.default.company_details = "10 This Way\nManhattan, NY 10001\n800-111-2222\nawesome@awesomecorp.com"
132
-
133
- 30.times do
134
- i.line_items << LineItem.new(:price => 20, :quantity => 5, :description => "Pants")
135
- i.line_items << LineItem.new(:price => 10, :quantity => 3, :description => "Shirts")
136
- i.line_items << LineItem.new(:price => 5, :quantity => 200, :description => "Hats")
137
- end
138
-
139
- i.render_pdf_to_file("tmp/testing.pdf")
140
-
141
- assert File.exists?("tmp/testing.pdf")
142
- end
143
-
144
- test "rendering to string" do
145
- i = Invoice.new(:tax_rate => 0.1, :notes => "These are some crazy awesome notes!", :invoice_number => 12,
146
- :due_at => Date.civil(2011, 1, 22), :paid_at => Date.civil(2012, 2, 22),
147
- :bill_to => "Alan Johnson\n101 This Way\nSomewhere, SC 22222", :ship_to => "Frank Johnson\n101 That Way\nOther, SC 22229")
148
-
149
- 3.times do
150
- i.line_items << LineItem.new(:price => 20, :quantity => 5, :description => "Pants")
151
- i.line_items << LineItem.new(:price => 10, :quantity => 3, :description => "Shirts")
152
- i.line_items << LineItem.new(:price => 5, :quantity => 200.0, :description => "Hats")
153
- end
154
-
155
- refute_nil i.render_pdf
156
- end
157
-
158
- test "rendering with an svg logo" do
159
- Payday::Config.default.invoice_logo = { :filename => "assets/tiger.svg", :size => "100x100" }
160
- i = Invoice.new(:tax_rate => 0.1, :notes => "These are some crazy awesome notes!", :invoice_number => 12,
161
- :due_at => Date.civil(2011, 1, 22), :paid_at => Date.civil(2012, 2, 22),
162
- :bill_to => "Alan Johnson\n101 This Way\nSomewhere, SC 22222", :ship_to => "Frank Johnson\n101 That Way\nOther, SC 22229")
163
-
164
- 3.times do
165
- i.line_items << LineItem.new(:price => 20, :quantity => 5, :description => "Pants")
166
- i.line_items << LineItem.new(:price => 10, :quantity => 3, :description => "Shirts")
167
- i.line_items << LineItem.new(:price => 5, :quantity => 200.0, :description => "Hats")
168
- end
169
-
170
- i.render_pdf_to_file("tmp/svg.pdf")
171
-
172
- refute_nil i.render_pdf
173
- end
174
- end
175
- end
@@ -1,25 +0,0 @@
1
- require File.expand_path("test/test_helper")
2
-
3
- module Payday
4
- class LineItemTest < MiniTest::Unit::TestCase
5
- test "initializing with a price" do
6
- li = LineItem.new(:price => BigDecimal.new("20"))
7
- assert_equal BigDecimal.new("20"), li.price
8
- end
9
-
10
- test "initializing with a quantity" do
11
- li = LineItem.new(:quantity => 30)
12
- assert_equal BigDecimal.new("30"), li.quantity
13
- end
14
-
15
- test "initializing with a description" do
16
- li = LineItem.new(:description => "12 Pairs of Pants")
17
- assert_equal "12 Pairs of Pants", li.description
18
- end
19
-
20
- test "that amount returns the correct amount" do
21
- li = LineItem.new(:price => 10, :quantity => 12)
22
- assert_equal BigDecimal.new("120"), li.amount
23
- end
24
- end
25
- end
data/test/test_helper.rb DELETED
@@ -1,32 +0,0 @@
1
- require File.expand_path('lib/payday')
2
-
3
- require 'minitest/autorun'
4
- require 'date'
5
- require 'time'
6
-
7
- # Shamelessly ripped from jm's context library: https://github.com/jm/context/blob/master/lib/context/test.rb
8
- class MiniTest::Unit::TestCase
9
- class << self
10
- # Create a test method. +name+ is a native-language string to describe the test
11
- # (e.g., no more +test_this_crazy_thing_with_underscores+).
12
- #
13
- # test "A user should not be able to delete another user" do
14
- # assert_false @user.can?(:delete, @other_user)
15
- # end
16
- #
17
- def test(name, opts={}, &block)
18
- test_name = ["test:", name].reject { |n| n == "" }.join(' ')
19
- # puts "running test #{test_name}"
20
- defined = instance_method(test_name) rescue false
21
- raise "#{test_name} is already defined in #{self}" if defined
22
-
23
- if block_given?
24
- define_method(test_name, &block)
25
- else
26
- define_method(test_name) do
27
- flunk "No implementation provided for #{name}"
28
- end
29
- end
30
- end
31
- end
32
- end