pdf-toolkit 0.5.0 → 1.0.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,84 +0,0 @@
1
- require 'test/unit'
2
- require 'pdf/toolkit'
3
- require 'tempfile'
4
- # require 'active_record'
5
- # require 'active_record/validations'
6
- # require 'active_record/callbacks'
7
- # require 'active_record/timestamp'
8
-
9
- class PDF::Toolkit
10
- end
11
-
12
- class MyPDF < PDF::Toolkit
13
- loot_active_record
14
- self.record_timestamps = true
15
- validates_presence_of :author
16
- before_save do |object|
17
- object.producer = "PDF::Toolkit Test"
18
- end
19
- self.default_permissions = %w(Printing ModifyAnnotations)
20
- end
21
-
22
- class PDFToolkitActiveRecordTest < Test::Unit::TestCase
23
- DATA = File.open(File.join(File.dirname(__FILE__),"pdfs","blank.pdf")).read
24
-
25
- def setup
26
- @tempfiles = []
27
- @pdf = new_pdf
28
- @pdftk = MyPDF.new(@pdf)
29
- end
30
-
31
- def teardown
32
- (@tempfiles || []).each do |tempfile|
33
- tempfile.close
34
- tempfile.unlink
35
- end
36
- @tempfiles = nil
37
- end
38
-
39
- def new_pdf
40
- tempfile = Tempfile.open("pdftktest")
41
- tempfile.write(DATA)
42
- tempfile.close
43
- @tempfiles << tempfile if @tempfiles
44
- return tempfile
45
- end
46
-
47
- def new_tempfile
48
- tempfile = Tempfile.open("pdftktest")
49
- tempfile.close
50
- @tempfiles << tempfile if @tempfiles
51
- return tempfile.path
52
- end
53
-
54
- def test_invalid
55
- PDF::Toolkit.loot_active_record # Ensure a double loot is harmless
56
- assert_nil @pdftk.author
57
- assert_equal false, @pdftk.valid?
58
- assert_nil @pdftk.save_as(new_tempfile)
59
- end
60
-
61
- def test_save
62
- @pdftk.author = "John Smith"
63
- assert_equal true, @pdftk.valid?
64
- assert @pdftk.save
65
- end
66
-
67
- def test_callback
68
- @pdftk.author = "Andy Hunt"
69
- assert @pdftk.save
70
- @pdftk.reload
71
- assert_match /PDF::Toolkit/, @pdftk.producer
72
- end
73
-
74
- def test_timestamp
75
- before = Time.now
76
- @pdftk.author = "Dave Thomas"
77
- assert @pdftk.save
78
- @pdftk.reload
79
- after = Time.now
80
- assert @pdftk.updated_at >= before-1 && @pdftk.updated_at <= after,
81
- "Timestamp (#{@pdftk.updated_at}) out of range"
82
- end
83
-
84
- end
@@ -1,84 +0,0 @@
1
- require 'test/unit'
2
- require 'pdf/toolkit'
3
- require 'tempfile'
4
- # require 'active_record'
5
- require 'active_record/validations'
6
- # require 'active_record/callbacks'
7
- # require 'active_record/timestamp'
8
-
9
- class PDF::Toolkit
10
- end
11
-
12
- class MyPDF < PDF::Toolkit
13
- loot_active_record
14
- self.record_timestamps = true
15
- validates_presence_of :author
16
- before_save do |object|
17
- object.producer = "PDF::Toolkit Test"
18
- end
19
- self.default_permissions = %w(Printing ModifyAnnotations)
20
- end
21
-
22
- class PDFToolkitActiveRecordTest < Test::Unit::TestCase
23
- DATA = File.open(File.join(File.dirname(__FILE__),"pdfs","blank.pdf")).read
24
-
25
- def setup
26
- @tempfiles = []
27
- @pdf = new_pdf
28
- @pdftk = MyPDF.new(@pdf)
29
- end
30
-
31
- def teardown
32
- (@tempfiles || []).each do |tempfile|
33
- tempfile.close
34
- tempfile.unlink
35
- end
36
- @tempfiles = nil
37
- end
38
-
39
- def new_pdf
40
- tempfile = Tempfile.open("pdftktest")
41
- tempfile.write(DATA)
42
- tempfile.close
43
- @tempfiles << tempfile if @tempfiles
44
- return tempfile
45
- end
46
-
47
- def new_tempfile
48
- tempfile = Tempfile.open("pdftktest")
49
- tempfile.close
50
- @tempfiles << tempfile if @tempfiles
51
- return tempfile.path
52
- end
53
-
54
- def test_invalid
55
- PDF::Toolkit.loot_active_record # Ensure a double loot is harmless
56
- assert_nil @pdftk.author
57
- assert_equal false, @pdftk.valid?
58
- assert_nil @pdftk.save_as(new_tempfile)
59
- end
60
-
61
- def test_save
62
- @pdftk.author = "John Smith"
63
- assert_equal true, @pdftk.valid?
64
- assert @pdftk.save
65
- end
66
-
67
- def test_callback
68
- @pdftk.author = "Andy Hunt"
69
- assert @pdftk.save
70
- @pdftk.reload
71
- assert_match /PDF::Toolkit/, @pdftk.producer
72
- end
73
-
74
- def test_timestamp
75
- before = Time.now
76
- @pdftk.author = "Dave Thomas"
77
- assert @pdftk.save
78
- @pdftk.reload
79
- after = Time.now
80
- assert @pdftk.updated_at >= before-1 && @pdftk.updated_at <= after,
81
- "Timestamp (#{@pdftk.updated_at}) out of range"
82
- end
83
-
84
- end