进行 Rails 2.3 重构并将其移植到 Rails 3 的好方法是什么?
我必须重构一个巨大的写得不好(大控制器方法)、未经测试和未记录的 Rails 2.3-Webapp 并将其移植到 Rails 3。
我不能简单地将所有内容移动到 Rails 3,因为该应用程序的某些部分是自制插件,其中嵌套了控制器控制器(据我所知)在 Rails 3 中是不可能的,因为所使用的插件不兼容。
有什么提示我应该如何开始吗?或者一个小路线图? 我应该首先尝试编写文档吗? 然后测试?
此致
--------------------------------------------------------------------------------
Language files blank comment code
--------------------------------------------------------------------------------
Javascript 231 9679 6538 42954
Ruby 601 5540 3032 28417
HTML 68 1172 266 13179
CSS 80 1796 805 7677
XML 17 69 63 1299
YAML 36 114 216 1212
Bourne Shell 12 77 226 343
MXML 1 7 0 52
PHP 2 29 28 26
Bourne Again Shell 1 9 29 17
--------------------------------------------------------------------------------
SUM: 1049 18492 11203 95176
--------------------------------------------------------------------------------
I have to refactor a huge badly written (big controller methods), untested and undocumented Rails 2.3-Webapp and port it to Rails 3.
I can't simply move everything to rails 3 because parts of the app are selfmade plugins which nest controllers in controllers which is (as i was told) not possible in rails 3 because the used plugin for that isn't compatible.
Any hints how i should start? Or a little roadmap?
Should I first try to write a documentation?
Then tests?
Best regards
--------------------------------------------------------------------------------
Language files blank comment code
--------------------------------------------------------------------------------
Javascript 231 9679 6538 42954
Ruby 601 5540 3032 28417
HTML 68 1172 266 13179
CSS 80 1796 805 7677
XML 17 69 63 1299
YAML 36 114 216 1212
Bourne Shell 12 77 226 343
MXML 1 7 0 52
PHP 2 29 28 26
Bourne Again Shell 1 9 29 17
--------------------------------------------------------------------------------
SUM: 1049 18492 11203 95176
--------------------------------------------------------------------------------
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我这样做的方式:
添加大量测试,因为您想要“保存”应用程序的工作方式,并确保即使在迁移到 Rails 3 后它也能正常工作
将旧插件移植到 Rails 3 兼容版本或放弃它们以获得更好的版本
添加更多测试
升级到最新版本的 Rails 2,这样您就更接近 Rails 3,获得所有弃用通知等等。
更多测试
升级到Rails 3并修复损坏的测试
The way I'd do it:
Add tons of tests because you want to "save" how your application works and be sure it works even after the migration to rails 3
Port old plugins to a rails 3 compatible version or drop them for better ones
Add even more tests
Upgrade to the latest version of Rails 2 so you get closer to rails 3, get all the deprecation notices and so on.
More tests
Upgrade to Rails 3 and fix tests that broke
听起来您可能继承了代码库。我建议除了“添加测试”之外的另一个步骤是深入查看该项目的所有表格(希望有生产数据或其图册)并查找任何 WTF。追踪使用这些 WTF 的代码通常很有启发性。 :)
It sounds like you may have inherited the codebase. Another step on top of “Add Tests” I would suggest is take a deep look at all the tables for the project (hopefully with production data or a fascimile thereof) and look for any WTFs. it is often illuminating to track down the code that uses those WTFs. :)
我对非常糟糕的 Rails 应用程序进行了一些重构,编写测试始终是向前迈出的一大步。在此之后,您将对代码库有更好的了解,您将发现一些小(也可能是大)错误,并且在将其更新到 Rails 3 时对代码进行更改会感觉更好,因为不太可能你破坏了任何重要的东西。您还不需要测试每个细节,但需要测试所有主要功能。此外,这还为您提供了一组不错的固定装置(如果还不存在)
I have done some refactoring of very bad Rails apps and writing tests was always a big step forward. After this you will have a far better knowledge of the code base, you'll have found several small (and maybe large) bugs and you can feel far better about making changes to the code while updating it to Rails 3 since it's less likely that you break anything important. You don't need to test every details yet, but all the main functionality. In addition this gives you a nice set of fixtures (if that doesn't exist yet)