pdf_tempura 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (80) hide show
  1. checksums.yaml +15 -0
  2. data/.gitignore +18 -0
  3. data/.rspec +2 -0
  4. data/.travis.yml +5 -0
  5. data/Gemfile +4 -0
  6. data/LICENSE.txt +22 -0
  7. data/README.md +342 -0
  8. data/Rakefile +1 -0
  9. data/example/my_pdf.rb +37 -0
  10. data/lib/pdf_tempura.rb +8 -0
  11. data/lib/pdf_tempura/document.rb +121 -0
  12. data/lib/pdf_tempura/document/boxed_characters.rb +70 -0
  13. data/lib/pdf_tempura/document/boxed_characters/groups.rb +53 -0
  14. data/lib/pdf_tempura/document/character_field.rb +37 -0
  15. data/lib/pdf_tempura/document/checkbox_field.rb +15 -0
  16. data/lib/pdf_tempura/document/default_commands.rb +40 -0
  17. data/lib/pdf_tempura/document/field/base.rb +55 -0
  18. data/lib/pdf_tempura/document/field_set.rb +51 -0
  19. data/lib/pdf_tempura/document/page.rb +33 -0
  20. data/lib/pdf_tempura/document/table.rb +95 -0
  21. data/lib/pdf_tempura/document/table/boxed_character_column.rb +20 -0
  22. data/lib/pdf_tempura/document/table/checkbox_column.rb +9 -0
  23. data/lib/pdf_tempura/document/table/column.rb +18 -0
  24. data/lib/pdf_tempura/document/table/spacer.rb +13 -0
  25. data/lib/pdf_tempura/document/table/text_column.rb +9 -0
  26. data/lib/pdf_tempura/document/text_field.rb +18 -0
  27. data/lib/pdf_tempura/document/validation.rb +79 -0
  28. data/lib/pdf_tempura/extensions/hash/stringify_keys.rb +35 -0
  29. data/lib/pdf_tempura/render.rb +18 -0
  30. data/lib/pdf_tempura/render/boxed_characters.rb +42 -0
  31. data/lib/pdf_tempura/render/character_field.rb +49 -0
  32. data/lib/pdf_tempura/render/checkbox_field.rb +35 -0
  33. data/lib/pdf_tempura/render/debug.rb +16 -0
  34. data/lib/pdf_tempura/render/debug/annotation/base.rb +83 -0
  35. data/lib/pdf_tempura/render/debug/character_field_annotation.rb +13 -0
  36. data/lib/pdf_tempura/render/debug/checkbox_field_annotation.rb +24 -0
  37. data/lib/pdf_tempura/render/debug/field_set_annotation.rb +23 -0
  38. data/lib/pdf_tempura/render/debug/grid.rb +59 -0
  39. data/lib/pdf_tempura/render/debug/outside_annotation.rb +42 -0
  40. data/lib/pdf_tempura/render/debug/table_annotation.rb +19 -0
  41. data/lib/pdf_tempura/render/debug/text_field_annotation.rb +42 -0
  42. data/lib/pdf_tempura/render/field.rb +40 -0
  43. data/lib/pdf_tempura/render/field_bounds.rb +26 -0
  44. data/lib/pdf_tempura/render/field_data_mapper.rb +15 -0
  45. data/lib/pdf_tempura/render/field_set.rb +31 -0
  46. data/lib/pdf_tempura/render/option_access.rb +21 -0
  47. data/lib/pdf_tempura/render/page.rb +23 -0
  48. data/lib/pdf_tempura/render/table.rb +35 -0
  49. data/lib/pdf_tempura/render/text_field.rb +13 -0
  50. data/lib/pdf_tempura/renderer.rb +39 -0
  51. data/lib/pdf_tempura/version.rb +3 -0
  52. data/pdf_tempura.gemspec +27 -0
  53. data/spec/assets/sample_pdf_form.odg +0 -0
  54. data/spec/assets/sample_pdf_form.pdf +0 -0
  55. data/spec/integration_spec.rb +88 -0
  56. data/spec/lib/pdf_tempura/document/boxed_characters_spec.rb +125 -0
  57. data/spec/lib/pdf_tempura/document/checkbox_field_spec.rb +54 -0
  58. data/spec/lib/pdf_tempura/document/field_common.rb +12 -0
  59. data/spec/lib/pdf_tempura/document/field_set_spec.rb +38 -0
  60. data/spec/lib/pdf_tempura/document/page_spec.rb +57 -0
  61. data/spec/lib/pdf_tempura/document/table_spec.rb +161 -0
  62. data/spec/lib/pdf_tempura/document/text_field_spec.rb +195 -0
  63. data/spec/lib/pdf_tempura/document_spec.rb +131 -0
  64. data/spec/lib/pdf_tempura/extensions/hash/stringify_keys_spec.rb +42 -0
  65. data/spec/lib/pdf_tempura/render/boxed_characters_spec.rb +68 -0
  66. data/spec/lib/pdf_tempura/render/checkbox_field_spec.rb +39 -0
  67. data/spec/lib/pdf_tempura/render/debug/annotation_renderer/base_spec.rb +45 -0
  68. data/spec/lib/pdf_tempura/render/debug/checkbox_field_annotation_spec.rb +45 -0
  69. data/spec/lib/pdf_tempura/render/debug/grid_spec.rb +15 -0
  70. data/spec/lib/pdf_tempura/render/debug/text_field_annotation_spec.rb +46 -0
  71. data/spec/lib/pdf_tempura/render/field_data_mapper_spec.rb +31 -0
  72. data/spec/lib/pdf_tempura/render/field_set_spec.rb +41 -0
  73. data/spec/lib/pdf_tempura/render/field_spec.rb +37 -0
  74. data/spec/lib/pdf_tempura/render/page_spec.rb +77 -0
  75. data/spec/lib/pdf_tempura/render/table_spec.rb +44 -0
  76. data/spec/lib/pdf_tempura/render/text_field_spec.rb +39 -0
  77. data/spec/lib/pdf_tempura/renderer_spec.rb +79 -0
  78. data/spec/spec_helper.rb +29 -0
  79. data/spec/support/shared_examples/field_examples.rb +265 -0
  80. metadata +219 -0
@@ -0,0 +1,41 @@
1
+ require 'spec_helper'
2
+
3
+ describe PdfTempura::Render::FieldSet do
4
+
5
+ let(:group) {
6
+ PdfTempura::Document::FieldSet.new("group") do
7
+ text_field :a, [0,0], [10,10]
8
+ text_field :b, [10,0], [10,10]
9
+ end
10
+ }
11
+ let(:data) { {"a" => "1","b" => "2"} }
12
+ let(:pdf) { Prawn::Document.new }
13
+ let(:options) { {} }
14
+
15
+ describe "init" do
16
+ example do
17
+ expect {
18
+ described_class.new(group,data)
19
+ }.not_to raise_exception
20
+ end
21
+ end
22
+
23
+ describe "render" do
24
+
25
+ let(:text_field_1){double(:text_field_1)}
26
+ let(:text_field_2){double(:text_field_2)}
27
+
28
+ it "renders each field with the appropriate data" do
29
+ PdfTempura::Render::Field.tap do |it|
30
+ it.should_receive(:generate).with(kind_of(PdfTempura::Document::TextField),"1",{}).and_return(text_field_1)
31
+ it.should_receive(:generate).with(kind_of(PdfTempura::Document::TextField),"2",{}).and_return(text_field_2)
32
+ end
33
+ text_field_1.should_receive(:render).with(pdf)
34
+ text_field_2.should_receive(:render).with(pdf)
35
+ described_class.new(group,data).render(pdf)
36
+ end
37
+ end
38
+
39
+ end
40
+
41
+
@@ -0,0 +1,37 @@
1
+ require 'spec_helper'
2
+
3
+ describe PdfTempura::Render::Field do
4
+
5
+ describe ".generate" do
6
+ let(:options) { {} }
7
+
8
+ context "when passing a text field" do
9
+ let(:field) { PdfTempura::Document::TextField.new("foo", [0,0], [0,0]) }
10
+
11
+ it "returns a TextField object" do
12
+ object = described_class.generate(field, "foo", options)
13
+ object.should be_kind_of(PdfTempura::Render::TextField)
14
+ end
15
+ end
16
+
17
+ context "when passing a table field" do
18
+ let(:field) { PdfTempura::Document::Table.new("foo", [0,0], height: 100, number_of_rows: 10) }
19
+
20
+ it "returns a Table object" do
21
+ object = described_class.generate(field,[], options)
22
+ object.should be_kind_of(PdfTempura::Render::Table)
23
+ end
24
+ end
25
+
26
+ context "when passing a different field" do
27
+ let(:field) { double(:different_field, type: "different")}
28
+
29
+ it "raises an ArgumentError" do
30
+ expect {
31
+ described_class.generate(field, "foo", options)
32
+ }.to raise_exception(ArgumentError)
33
+ end
34
+ end
35
+ end
36
+
37
+ end
@@ -0,0 +1,77 @@
1
+ require 'spec_helper'
2
+
3
+ describe PdfTempura::Render::Page do
4
+
5
+ let(:page) { PdfTempura::Document::Page.new(1) }
6
+ let(:data) { { } }
7
+ let(:pdf) { Prawn::Document.new }
8
+ let(:options) { {} }
9
+
10
+ before do
11
+ page.data = data
12
+
13
+ pdf.stub(:bounding_box) do |&block|
14
+ block.call
15
+ end
16
+ end
17
+
18
+ describe "init" do
19
+ example do
20
+ expect {
21
+ described_class.new(page, options)
22
+ }.not_to raise_exception
23
+ end
24
+ end
25
+
26
+ describe "render" do
27
+
28
+ subject do
29
+ described_class.new(page, options)
30
+ end
31
+
32
+ let(:page) do
33
+ page = PdfTempura::Document::Page.new(1)
34
+ page.text_field "one", [0,0], [0,0]
35
+ page.text_field "two", [0,0], [0,0]
36
+ page
37
+ end
38
+
39
+ let(:data) do
40
+ {
41
+ "one" => "foo",
42
+ "two" => "bar",
43
+ }
44
+ end
45
+
46
+ let(:text_field_1) { double(:text_field_1) }
47
+ let(:text_field_2) { double(:text_field_2) }
48
+
49
+ it "calls renders each field" do
50
+ PdfTempura::Render::TextField.tap do |it|
51
+ it.should_receive(:new).with(page.fields[0], "foo", options).and_return(text_field_1)
52
+ it.should_receive(:new).with(page.fields[1], "bar", options).and_return(text_field_2)
53
+ end
54
+ text_field_1.should_receive(:render).with(pdf)
55
+ text_field_2.should_receive(:render).with(pdf)
56
+ subject.render(pdf)
57
+ end
58
+
59
+ describe "calling the grid drawing code when enabled" do
60
+ let(:options) do
61
+ {
62
+ :debug => [:grid]
63
+ }
64
+ end
65
+
66
+ let(:grid_renderer) { double(:grid_renderer) }
67
+
68
+ example do
69
+ PdfTempura::Render::Debug::Grid.should_receive(:new).and_return(grid_renderer)
70
+ grid_renderer.should_receive(:render).with(pdf)
71
+ subject.render(pdf)
72
+ end
73
+ end
74
+
75
+ end
76
+
77
+ end
@@ -0,0 +1,44 @@
1
+ require 'spec_helper'
2
+
3
+ describe PdfTempura::Render::Table do
4
+
5
+ let(:doc_table) {
6
+ PdfTempura::Document::Table.new(:table,[0,100],:number_of_rows => 10, :height => 100) do
7
+ text_column :a, 10
8
+ space 10
9
+ text_column :b, 10
10
+ space 5
11
+ boxed_character_column :c,box_width: 10,box_spacing: 1 do
12
+ characters 3;space 2;characters 3
13
+ end
14
+ end
15
+ }
16
+ let(:data) { [{:a => "1",:b => "2",c: "333333"},{:a => "3",:b => "4",c: "555555"}] }
17
+ let(:pdf) { Prawn::Document.new }
18
+ let(:options) { {} }
19
+
20
+ describe "init" do
21
+ example do
22
+ expect {
23
+ described_class.new(doc_table, data, options)
24
+ }.not_to raise_exception
25
+ end
26
+ end
27
+
28
+ describe "render" do
29
+
30
+ let(:expected_options) {{"number_of_rows"=>10, "height"=>100}}
31
+
32
+ it "renders each field with the appropriate data" do
33
+ PdfTempura::Document::TextField.tap do |it|
34
+ it.should_receive(:new).with(:a, [0,100],[10,10], expected_options).and_call_original
35
+ it.should_receive(:new).with(:b, [20,100],[10,10], expected_options).and_call_original
36
+ it.should_receive(:new).with(:a, [0,90],[10,10], expected_options).and_call_original
37
+ it.should_receive(:new).with(:b, [20,90],[10,10], expected_options).and_call_original
38
+ end
39
+ described_class.new(doc_table,data,options).render(pdf)
40
+ end
41
+ end
42
+
43
+ end
44
+
@@ -0,0 +1,39 @@
1
+ require 'spec_helper'
2
+
3
+ describe PdfTempura::Render::TextField do
4
+
5
+ let(:field) { PdfTempura::Document::TextField.new("foo", [0,0], [100,100]) }
6
+ let(:options) { {} }
7
+ let(:pdf) { Prawn::Document.new }
8
+
9
+ describe "initialize" do
10
+ example do
11
+ expect {
12
+ described_class.new(field, "foo", options)
13
+ }.not_to raise_exception
14
+ end
15
+ end
16
+
17
+ describe "#render" do
18
+
19
+ subject { described_class.new(field, "foo", options) }
20
+
21
+ describe "calling the annotation drawing code when enabled" do
22
+ let(:options) do
23
+ {
24
+ :debug => [:outlines]
25
+ }
26
+ end
27
+
28
+ let(:annotation_renderer) { double(:annotation_renderer) }
29
+
30
+ example do
31
+ PdfTempura::Render::Debug::TextFieldAnnotation.should_receive(:new).with(field).and_return(annotation_renderer)
32
+ annotation_renderer.should_receive(:render).with(pdf)
33
+ subject.render(pdf)
34
+ end
35
+ end
36
+
37
+ end
38
+
39
+ end
@@ -0,0 +1,79 @@
1
+ require 'spec_helper'
2
+
3
+ describe PdfTempura::Renderer do
4
+
5
+ let(:page_1){ PdfTempura::Document::Page.new(1) }
6
+ let(:pages){ [ page_1 ] }
7
+ let(:options) { { debug: [] } }
8
+
9
+ describe "initialize" do
10
+ example do
11
+ expect {
12
+ described_class.new(sample_pdf_path, pages, options)
13
+ }.not_to raise_exception
14
+ end
15
+ end
16
+
17
+ describe "#render_into" do
18
+ subject do
19
+ described_class.new(sample_pdf_path, pages, options)
20
+ end
21
+ let(:pdf) {
22
+ Prawn::Document.new(skip_page_creation: true, margin: 0)
23
+ }
24
+
25
+ it "renders into the pdf" do
26
+ expect {
27
+ subject.render_into(pdf)
28
+ }.not_to raise_exception
29
+ end
30
+ end
31
+
32
+ describe "#render" do
33
+ subject do
34
+ described_class.new(sample_pdf_path, pages, options)
35
+ end
36
+
37
+ it "yields" do
38
+ expect { |x|
39
+ subject.render(&x)
40
+ }.to yield_control
41
+ end
42
+
43
+ it "yields an object that responds to read" do
44
+ subject.render do |file|
45
+ expect(file).to respond_to(:read)
46
+ end
47
+ end
48
+
49
+ it "yields a file with a pdf in it" do
50
+ subject.render do |file|
51
+ tempfile = Tempfile.new("spec")
52
+ begin
53
+ tempfile.write file.read
54
+ tempfile.flush
55
+ expect(`file -b --mime-type #{tempfile.path.inspect}`.strip).to eq("application/pdf")
56
+ ensure
57
+ tempfile.unlink
58
+ end
59
+ end
60
+ end
61
+
62
+ describe do
63
+ let(:page_2){ PdfTempura::Document::Page.new(2) }
64
+ let(:pages){ [ page_1, page_2 ] }
65
+ let(:render_page_1) { double(:render_page_1) }
66
+ let(:render_page_2) { double(:render_page_2) }
67
+
68
+ # bit of an implementation test, but can't see a better way to do it right now
69
+ it "calls render on each page" do
70
+ PdfTempura::Render::Page.should_receive(:new).with(pages[0], options).and_return(render_page_1)
71
+ PdfTempura::Render::Page.should_receive(:new).with(pages[1], options).and_return(render_page_2)
72
+ render_page_1.should_receive(:render)
73
+ render_page_2.should_receive(:render)
74
+ subject.render{ |file|; }
75
+ end
76
+ end
77
+ end
78
+
79
+ end
@@ -0,0 +1,29 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # Require this file using `require "spec_helper"` to ensure that it is only
4
+ # loaded once.
5
+ #
6
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
7
+
8
+ require 'rubygems'
9
+ require 'bundler/setup'
10
+
11
+ Dir["./spec/support/**/*.rb"].each {|f| require f}
12
+
13
+ RSpec.configure do |config|
14
+ config.treat_symbols_as_metadata_keys_with_true_values = true
15
+ config.run_all_when_everything_filtered = true
16
+ config.filter_run :focus
17
+
18
+ # Run specs in random order to surface order dependencies. If you find an
19
+ # order dependency and want to debug it, you can fix the order by providing
20
+ # the seed, which is printed after each run.
21
+ # --seed 1234
22
+ config.order = 'random'
23
+ end
24
+
25
+ def sample_pdf_path
26
+ "spec/assets/sample_pdf_form.pdf"
27
+ end
28
+
29
+ require 'pdf_tempura'
@@ -0,0 +1,265 @@
1
+ require 'spec_helper'
2
+
3
+ shared_examples_for "a document field" do
4
+ let(:name){ :name }
5
+ let(:coordinates){ [10, 20] }
6
+ let(:dimensions){ [200, 100] }
7
+
8
+ its(:name){ should == "name" }
9
+ its(:coordinates){ should == [10, 20] }
10
+ its(:dimensions){ should == [200, 100] }
11
+ its(:x){ should == 10 }
12
+ its(:y){ should == 20 }
13
+ its(:width){ should == 200 }
14
+ its(:height){ should == 100 }
15
+
16
+ end
17
+
18
+
19
+ shared_examples_for "a document field with a standard constructor" do
20
+ let(:name){ :name }
21
+ let(:coordinates){ [10, 20] }
22
+ let(:dimensions){ [200, 100] }
23
+
24
+ describe "validation" do
25
+ context "when passed valid attributes" do
26
+ it "returns a field object" do
27
+ described_class.new(name, coordinates, dimensions, options).should be_a(described_class)
28
+ end
29
+ end
30
+
31
+ context "when passed an invalid name" do
32
+ let(:name){ [] }
33
+
34
+ it "throws an error" do
35
+ expect{
36
+ described_class.new(name, coordinates, dimensions, options)
37
+ }.to raise_error ArgumentError, "Name must be of type String."
38
+ end
39
+ end
40
+
41
+ context "when passed invalid coordinates" do
42
+ context "as an object other than Array" do
43
+ let(:coordinates){ "1x1" }
44
+
45
+ it "throws an error" do
46
+ expect{
47
+ described_class.new(name, coordinates, dimensions, options)
48
+ }.to raise_error ArgumentError, "Coordinates must be of type Array."
49
+ end
50
+ end
51
+
52
+ context "by passing an invalid x or y coordinate" do
53
+ let(:coordinates){ ["a", "b" ] }
54
+
55
+ it "throws an error" do
56
+ expect{
57
+ described_class.new(name, coordinates, dimensions, options)
58
+ }.to raise_error ArgumentError, "Coordinates must contain only Numeric values."
59
+ end
60
+ end
61
+
62
+ context "by passing not enough coordinates" do
63
+ let(:coordinates){ [1] }
64
+
65
+ it "throws an error" do
66
+ expect{
67
+ described_class.new(name, coordinates, dimensions, options)
68
+ }.to raise_error ArgumentError, "Coordinates must contain 2 values."
69
+ end
70
+ end
71
+
72
+ context "by passing too many coordinates" do
73
+ let(:coordinates){ [1, 2, 3] }
74
+
75
+ it "throws an error" do
76
+ expect{
77
+ described_class.new(name, coordinates, dimensions, options)
78
+ }.to raise_error ArgumentError, "Coordinates must contain 2 values."
79
+ end
80
+ end
81
+ end
82
+
83
+ context "when passed invalid dimensions" do
84
+ context "as an object other than Array" do
85
+ let(:dimensions){ "width200 height100" }
86
+
87
+ it "throws an error" do
88
+ expect{
89
+ described_class.new(name, coordinates, dimensions, options)
90
+ }.to raise_error ArgumentError, "Dimensions must be of type Array."
91
+ end
92
+ end
93
+
94
+ context "by passing an invalid width or height" do
95
+ let(:dimensions){ ["one hundred", "two_hundred" ]}
96
+
97
+ it "throws an error" do
98
+ expect{
99
+ described_class.new(name, coordinates, dimensions, options)
100
+ }.to raise_error ArgumentError, "Dimensions must contain only Numeric values."
101
+ end
102
+ end
103
+
104
+ context "by passing not enough dimensions" do
105
+ let(:dimensions){ [1] }
106
+
107
+ it "throws an error" do
108
+ expect{
109
+ described_class.new(name, coordinates, dimensions, options)
110
+ }.to raise_error ArgumentError, "Dimensions must contain 2 values."
111
+ end
112
+ end
113
+
114
+ context "by passing too many dimensions" do
115
+ let(:dimensions){ [1, 2, 3] }
116
+
117
+ it "throws an error" do
118
+ expect{
119
+ described_class.new(name, coordinates, dimensions, options)
120
+ }.to raise_error ArgumentError, "Dimensions must contain 2 values."
121
+ end
122
+ end
123
+
124
+ end
125
+
126
+ context "when passed invalid options" do
127
+ context "as an object other than a hash" do
128
+ let(:options){ "these are bogus options" }
129
+
130
+ it "throws an error" do
131
+ expect{
132
+ described_class.new(name, coordinates, dimensions, options)
133
+ }.to raise_error ArgumentError, "Options must be a hash."
134
+ end
135
+ end
136
+ end
137
+ end
138
+
139
+ end
140
+
141
+ shared_examples "a field that accepts default commands" do
142
+ describe ".table" do
143
+
144
+ it "adds a table field to the field list" do
145
+ subject.fields.should == []
146
+ subject.table(:foo, [0,0], height: 100, number_of_rows: 10) { }
147
+ subject.fields.first.should be_a(PdfTempura::Document::Table)
148
+ end
149
+
150
+ it "yields" do
151
+ expect { |b|
152
+ subject.table(:foo, [0,0], height: 100, number_of_rows: 10, &b)
153
+ }.to yield_control
154
+ end
155
+
156
+ end
157
+
158
+ describe ".with_default_options" do
159
+ it "yields a block that changes the default options" do
160
+ subject.with_default_options :alignment => "center" do
161
+ text_field :one, [0,0], [50,50]
162
+ end
163
+ subject.text_field :two, [100,100], [50,50]
164
+ subject.fields.first.alignment.should == "center"
165
+ subject.fields[1].alignment.should_not == "center"
166
+ end
167
+
168
+ it "cascades to field_set" do
169
+ subject.with_default_options :alignment => "center" do
170
+ text_field :one, [0,0], [50,50]
171
+ field_set "three" do
172
+ text_field :four, [0,0], [60,60]
173
+ end
174
+ end
175
+ subject.text_field :two, [100,100], [50,50]
176
+ subject.fields.first.alignment.should == "center"
177
+ subject.fields[1].fields.first.alignment.should == "center"
178
+ end
179
+
180
+ it "cascades to table" do
181
+ subject.with_default_options :alignment => "center" do
182
+ table :two,[5,5],:number_of_rows => 20,:row_height => 10 do
183
+ text_column :three, 60
184
+ end
185
+ end
186
+
187
+ subject.fields.first.columns.first.options["alignment"].should == "center"
188
+ end
189
+ end
190
+
191
+ describe ".text_field" do
192
+ let(:name){ :text_field }
193
+ let(:coordinates){ [10, 20] }
194
+ let(:dimensions){ [200, 100] }
195
+
196
+ context "when not passed a type" do
197
+ it "adds a field object given valid attributes" do
198
+ expect{
199
+ subject.text_field(name, coordinates, dimensions)
200
+ }.to change(subject.fields, :count).by (1)
201
+ end
202
+
203
+ it "creates the correct field object" do
204
+ subject.text_field(name, coordinates, dimensions)
205
+ field = subject.fields.first
206
+ field.should be_a(PdfTempura::Document::TextField)
207
+ field.name.should == "text_field"
208
+ field.coordinates.should == [10, 20]
209
+ field.dimensions.should == [200, 100]
210
+ end
211
+ end
212
+ end
213
+
214
+ describe ".boxed_characters" do
215
+ let(:name){ :pin_code}
216
+ let(:height) {20}
217
+ let(:coordinates) {[50,20]}
218
+ let(:options) {{box_spacing: 1, box_width: 10}}
219
+
220
+ context "when passed appropriate parameters" do
221
+ it "adds a field to the subject" do
222
+ expect{
223
+ subject.boxed_characters(name, coordinates, height, options) do
224
+ characters 4
225
+ end
226
+ }.to change(subject.fields, :count).by (1)
227
+ end
228
+ end
229
+ end
230
+
231
+ describe ".field_set" do
232
+ let(:name) { :group }
233
+
234
+ context "when called" do
235
+ it "adds a field" do
236
+ expect {
237
+ subject.field_set "group"
238
+ }.to change(subject.fields,:count).by (1)
239
+ end
240
+ end
241
+ end
242
+
243
+ describe ".checkbox_field" do
244
+ let(:name){ :checkbox_field}
245
+ let(:coordinates){ [10, 20] }
246
+ let(:dimensions){ [20, 20] }
247
+
248
+ context "when not passed a type" do
249
+ it "adds a field object given valid attributes" do
250
+ expect{
251
+ subject.checkbox_field(name, coordinates, dimensions)
252
+ }.to change(subject.fields, :count).by (1)
253
+ end
254
+
255
+ it "creates the correct field object" do
256
+ subject.checkbox_field(name, coordinates, dimensions)
257
+ field = subject.fields.first
258
+ field.should be_a(PdfTempura::Document::CheckboxField)
259
+ field.name.should == "checkbox_field"
260
+ field.coordinates.should == [10, 20]
261
+ field.dimensions.should == [20, 20]
262
+ end
263
+ end
264
+ end
265
+ end