2

我为 Redmine 创建了一个插件,现在很难为它编写测试用例。我没有为此使用任何像 rspec 这样的框架,只是使用 rails 提供的默认断言。

我首先通过 ruby​​ 解释器运行文件来运行我的测试。这没有加载固定装置,所以我找到了一个替代方案:我将固定装置文件复制到 ${redmine_root}/test/fixtures,从 ${redmine_root}/vendor/plugins/my_plugin/test/fixtures,运行 rake db:fixtures:加载,现在它加载它们。

我正在测试的控制器在 init.rb 中设置了权限,并且需要对某些操作进行授权。

虽然我以特权用户(管理员)的身份打开会话,但我无权在控制器中执行操作,不知何故它在测试开始时没有加载权限。

我已经在 roles.yml 中手动添加了权限,并确保用户具有适当的角色,但又没有。该插件运行良好,我仅在测试时遇到这些问题。如果我在控制器中使用 before_filter :authorize 注释该行,则测试通过。

我错过了什么吗?init.rb 的权限是否存储在不同的位置,或者在测试阶段以不同的方式加载?

4

1 回答 1

5

尝试使用 Redmine 提供的 rake 任务来运行您的测试套件。他们应该正确设置一切。您可以使用 搜索它们rake -T search-patternrake -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
于 2011-07-25T12:28:15.953 回答