I've created a plugin for Redmine, and now am having difficulties writing the test cases for it. I am not using any framework like rspec for this, just the default asserts provided by rails.
I first ran my test by running the file trough the ruby interpreter. This did not load the fixtures , so I found an alternative : I copied the fixtures file to ${redmine_root}/test/fixtures, from ${redmine_root}/vendor/plugins/my_plugin/test/fixtures, ran rake db:fixtures:load and now it loads them.
The controller that I'm testing has permissions set in init.rb, and requires authorization for some actions.
Although I open a session as a privileged user (Admin), I am not authorized to take th开发者_如何学Pythone actions in the controller, somehow it does not load the permissions at the beginning of the test.
I have added the permissions manually in roles.yml, and ensured that the user has the appropriate role, but again nothing. The plugin works well, I am experiencing these problems only when testing. If I comment the line with before_filter :authorize in my controller, the test passes.
Am I missing something? Are the permissions from init.rb stored in a different place, or are loaded differently during the test phase?
Try using the rake tasks provided by Redmine to run your test suite. They should set everything up properly. You can search for them by using rake -T search-pattern
. rake -T test:plugins
will list the following ones:
rake test:plugins # Run tests for pluginsenvironment / Run the plugin tests in vendor/plugins/*/**/test (or specify with PLUGIN=name)
rake test:plugins:all # Run the plugin tests in vendor/plugins/**/test (or specify with PLUGIN=name)
rake test:plugins:functionals # Run tests for functionalssetup_plugin_fixtures
rake test:plugins:integration # Run tests for integrationsetup_plugin_fixtures
rake test:plugins:setup_plugin_fixtures # Mirrors plugin fixtures into a single location to help plugin tests
rake test:plugins:units # Run tests for unitssetup_plugin_fixtures
精彩评论