gpt4 book ai didi

ruby-on-rails - 在 Redmine 中测试

转载 作者:数据小太阳 更新时间:2023-10-29 08:34:11 25 4
gpt4 key购买 nike

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

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

我正在测试的 Controller 在 init.rb 中设置了权限,并且需要授权才能执行某些操作。

虽然我以特权用户 (Admin) 身份打开 session ,但我无权在 Controller 中执行操作,不知何故它不会在测试开始时加载权限。

我已经在 roles.yml 中手动添加了权限,并确保用户具有适当的角色,但还是没有。该插件运行良好,我仅在测试时遇到这些问题。如果我在我的 Controller 中使用 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

关于ruby-on-rails - 在 Redmine 中测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6809555/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com