Skip to content

Commit

Permalink
Merge pull request #2 from propertybase/fix_nil_error
Browse files Browse the repository at this point in the history
Fix undefined method `length' for nil:NilClass"
  • Loading branch information
leifg committed Jun 17, 2013
2 parents b126986 + 4ee1d59 commit fb89577
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 3 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
@@ -1,3 +1,9 @@
## 0.1.1 (June 17th, 2013)

BUG FIXES:

- Just return `nil` for nil input

## 0.1.0 (June 17th, 2013)

- initial release
4 changes: 2 additions & 2 deletions lib/comfan.rb
Expand Up @@ -4,7 +4,7 @@ module Comfan
extend self

def api_id input_id
return input_id if input_id.length >= 18
return input_id if input_id.nil? || input_id.length >= 18
suffix = ''

3.times do |i|
Expand All @@ -21,7 +21,7 @@ def api_id input_id
end

def ui_id input_id
return input_id if input_id.length <= 15
return input_id if input_id.nil? || input_id.length <= 15

input_id[0..-4]
end
Expand Down
2 changes: 1 addition & 1 deletion lib/comfan/version.rb
@@ -1,3 +1,3 @@
module Comfan
VERSION = '0.1.0'
VERSION = '0.1.1'
end
8 changes: 8 additions & 0 deletions spec/lib/comfan_spec.rb
Expand Up @@ -15,6 +15,10 @@
output = '752S00000000KtkIAE'
expect(subject.api_id(input)).to eq(output)
end

it 'returns nil for nil input' do
expect(subject.api_id(nil)).to be_nil
end
end

describe '.ui_id' do
Expand All @@ -28,5 +32,9 @@
output = '752S00000000Ktk'
expect(subject.ui_id(input)).to eq(output)
end

it 'returns nil for nil input' do
expect(subject.ui_id(nil)).to be_nil
end
end
end

0 comments on commit fb89577

Please sign in to comment.