stffn / declarative_authorization

An unmaintained authorization plugin for Rails. Please fork to support current versions of Rails
MIT License
1.24k stars 233 forks source link

authorization_rules inside spec/dummy not loaded during integration-tests #137

Closed masche842 closed 12 years ago

masche842 commented 12 years ago

While developing an engine using declerative_authorization I encountered problems with integration-tests (rspec + capybara).

When firing up a server in test-environment, spec/dummy/config/authorization_rules.rb is loaded as expected. But: With rspec spec it skips the custom rules and only loads config/authorization_rules.rb This makes testing of custom, app-dependent, functions difficult.

Though without_access_control does work, it leads to other problems such as current_user_session being nil.

Do someone has an idea, why this happens? Can I load the rules manually in my specs?

stffn commented 12 years ago

You should be able to use a custom authorization_engine in tests. Have a look at test/authorization.rb for how the decl_auth tests use custom rules.

masche842 commented 12 years ago

I see, that looks quite handy for unit tests.

Is there also a way to replace the 'default' authorization_engine? As my integration-tests are end-to-end, I need to have custom authorizations available without calling engine directly. As I mentioned above I would appreciate to use spec/dummy/config/authorization_rules.rb, as this is most end_to_end as possible. It doesn't work unfortunately.

stffn commented 12 years ago

Have you tried Authorization.instance(reader)? From looking at the code, it should set the default instance then.

masche842 commented 12 years ago

Well, this is working now:

def load_authorization_rules
  instance = Alchemy::AuthEngine.get_instance
  instance.load(File.join(File.dirname(__FILE__), '../dummy', 'config/authorization_rules.rb'))
  instance.load(File.join(File.dirname(__FILE__), '../..', 'config/authorization_rules.rb'))
end

I'm not sure why I have to load them explicitly (whereas they're loaded automatically in server/console), but as long as this works I'm fine. Actually this could even be some special behaviour of alchemy cms that has nothing to do with decl auth directly...

However: Thank you very much for your help, you put me in the right direction with this!!