Skip to content
This repository has been archived by the owner on Jan 3, 2023. It is now read-only.

Commit

Permalink
Strip quotes from all queue attributes values - Fixes #29
Browse files Browse the repository at this point in the history
  • Loading branch information
leoarnold committed Jan 16, 2018
1 parent e181452 commit 4e94f5e
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 17 deletions.
2 changes: 1 addition & 1 deletion lib/puppet/provider/cups_queue/cups.rb
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ def query_native_option(option)
value = 'none' if value.empty?
end

value.gsub(/\A"|"\Z/, '')
value
end

# @private
Expand Down
10 changes: 7 additions & 3 deletions lib/puppet_x/cups/queue.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,20 @@ def initialize(queue, name)
@name = name
end

# Encodes the queue name and returns the resource to query
# Executes the query and returns the attribute value
# without surrounding quotes, or an empty string
# if the query did not return a value
#
# @author Leo Arnold
# @since 2.0.0
#
# @return [String] The resource to query
# @return [String] The attribute value (if any) without surrounding quotes, or an empty string
def value
query = PuppetX::Cups::Ipp.query(resource, request)

query.results.empty? ? '' : query.results.first
answer = query.results.empty? ? '' : query.results.first

answer.gsub(/\A"|"\Z/, '')
end

private
Expand Down
8 changes: 0 additions & 8 deletions spec/unit/puppet/provider/cups_queue/cups_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -629,14 +629,6 @@
end
end

context "'job-sheets-default'" do
it 'strips leading and trailing quotes' do
allow(@provider).to receive(:query).with('job-sheets-default').and_return('"none,none"')

expect(@provider.send(:query_native_option, 'job-sheets-default')).to eq('none,none')
end
end

context 'using any other option' do
it 'returns nonempty query results unmodified' do
allow(@provider).to receive(:query).with('printer-error-policy').and_return('abort-job')
Expand Down
10 changes: 5 additions & 5 deletions spec/unit/puppet_x/cups/queue_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

RSpec.describe PuppetX::Cups::Queue::Attribute do
describe '#value' do
context 'when the query result is an array' do
context 'when the query result is an empty array' do
it 'returns an empty string' do
attribute = described_class.new('Office', 'auth-info-required')

Expand All @@ -24,14 +24,14 @@
end

context 'when the query result is a non-empty array' do
it 'returns the first entry' do
attribute = described_class.new('Office', 'device-uri')
it 'returns the first entry and strips surrounding quotes' do
attribute = described_class.new('Office', 'printer-make-and-model')

mock_query = double(PuppetX::Cups::Ipp::QueryC, results: %w[lpd://192.168.2.105/binary_p1])
mock_query = double(PuppetX::Cups::Ipp::QueryC, results: ['"HP Color LaserJet 4730mfp pcl3, hpcups 3.14.3"'])

allow(PuppetX::Cups::Ipp).to receive(:query).and_return(mock_query)

expect(attribute.value).to eq 'lpd://192.168.2.105/binary_p1'
expect(attribute.value).to eq 'HP Color LaserJet 4730mfp pcl3, hpcups 3.14.3'
end
end
end
Expand Down

0 comments on commit 4e94f5e

Please sign in to comment.