makandra/consul — pull request #16 by martin-straub (2014-09-19 15:33:40+00:00)
Title: fix default_power_ids for nil powers

In my project I defined a power like

```
power :clients do
Client.active unless guest?
end
```

and get this error
```
undefined method `collect_ids' for nil:NilClass (ActionView::Template::Error)
.../ruby-1.8.7-p374/gems/consul-0.12.0/lib/consul/power.rb:47:in `default_power_ids'
```

This would fix it:
```
def default_power_ids(power_name, *args)
scope = send(power_name, *args)
database_touched
if scope
scope.collect_ids
else
[]
end
end
```

But I don't know yet, why the following tests don't break
```
context 'nil powers' do

describe 'query methods' do

context 'when no record is given' do

it 'should return false' do
@user.role = 'guest'
@user.power.clients.should be_nil
@user.power.clients?.should == false
end

end

context 'with a given record' do

it 'should return false' do
client = Client.create!
@user.role = 'guest'
@user.power.clients.should be_nil
@user.power.client?(client).should == false
end

end

end
```

and I don't want to release this patch without a reliable test!