use*_*689 2 ruby ruby-on-rails redmine redmine-plugins ruby-on-rails-3
我为Redmine创建了一个插件,现在很难为它编写测试用例.我没有使用像rspec这样的任何框架,只是rails提供的默认断言.
我首先通过ruby解释器运行文件来运行我的测试.这没有加载灯具,所以我找到了另一种选择:我将灯具文件复制到$ {redmine_root}/test/fixtures,来自$ {redmine_root}/vendor/plugins/my_plugin/test/fixtures,运行rake db:fixtures:加载,现在加载它们.
我正在测试的控制器具有在init.rb中设置的权限,并且需要对某些操作进行授权.
虽然我以特权用户(Admin)的身份打开会话,但我无权在控制器中执行操作,不知何故它在测试开始时没有加载权限.
我已经在roles.yml中手动添加了权限,并确保用户具有相应的角色,但同样没有.该插件运行良好,我只在测试时遇到这些问题.如果我在我的控制器中使用before_filter:authorize注释该行,则测试通过.
我错过了什么吗?init.rb的权限是存储在不同的位置,还是在测试阶段以不同方式加载?
尝试使用Redmine提供的rake任务来运行测试套件.他们应该正确地设置一切.您可以使用搜索它们rake -T search-pattern.rake -T test:plugins将列出以下内容:
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
Run Code Online (Sandbox Code Playgroud)