Adds Label#persisted? method
Cássio Marques
committed Jan 08, 2014
commit 71333c247ef524621b68f97019509fad6baef4ae
Showing 2
changed files with
24 additions
and 1 deletions
zebra/epl/label.rb b/lib/zebra/epl/label.rb
+6
-1
| @@ | @@ -7,7 +7,7 @@ module Zebra |
| class InvalidPrintDensityError < StandardError; end | |
| class PrintSpeedNotInformedError < StandardError; end | |
| - | attr_reader :elements |
| + | attr_reader :elements, :tempfile |
| attr_accessor :width, :length, :gap, :print_speed, :print_density | |
| def initialize(options = {}) | |
| @@ | @@ -63,9 +63,14 @@ module Zebra |
| tempfile = Tempfile.new "zebra_label" | |
| dump_contents tempfile | |
| tempfile.rewind | |
| + | @tempfile = tempfile |
| tempfile | |
| end | |
| + | def persisted? |
| + | !!self.tempfile |
| + | end |
| + | |
| private | |
| def check_required_configurations | |
spec/zebra/epl/label_spec.rb
+18
-0
| @@ | @@ -111,5 +111,23 @@ describe Zebra::Epl::Label do |
| tempfile.should_receive(:rewind) | |
| label.persist | |
| end | |
| + | |
| + | it "sets the `tempfile` attribute" do |
| + | label.persist |
| + | label.tempfile.should == tempfile |
| + | end |
| + | end |
| + | |
| + | describe "#persisted?" do |
| + | it "returns false if the `tempfile` attribute is nil" do |
| + | label = described_class.new :print_speed => 2 |
| + | label.should_not be_persisted |
| + | end |
| + | |
| + | it "returns true if the `tempfile` attribute is not nil" do |
| + | label = described_class.new :print_speed => 2 |
| + | label.instance_variable_set(:@tempfile, stub) |
| + | label.should be_persisted |
| + | end |
| end | |
| end | |