现在的位置: 首页 > 综合 > 正文

rails笔记: 工具

2012年09月19日 ⁄ 综合 ⁄ 共 1113字 ⁄ 字号 评论关闭
文章目录

工具

script

script/server -e development | test | production 切换运行环境 script/generate 支持 Admin::Book 这样的语法, 方便创建子空间 script/console 提供一个包含了当前工程环境的irb(注意运行环境,dev,test,prod)

(以下两个目前在win32下面有bug,不能运行)

script/profiler "some invokcation" # 分析某操作的性能,自动导入rails环境, 然后执行语句, 打印分析结果 script/benchmark 10 "invoke1" "invoke2" 可以通过执行多次,比较两个操作的性能,

调试

有一个debug方法可以在rhtml中打印对象(html方式)

断点支持 : 在需要断点的地方调用breakpoint()方法,然后使用 ruby script/breakpointer 连接, 当遇到breakpoint以后会自动连接然后出现irb的环境, 退出irb以后程序会自动运行

配置

database.yml支持_alias_的比如

development: development_sqlite
development_mysql:
adapter: mysql
database: depot_development
host: localhost
username:
password:
development_sqlite:
adapter: sqlite
dbfile: my_db

还比如这样, _typo用到的语法_

login: &login
  adapter: mysql
  host: localhost
  username: root
  password: 

development:
  database: typo_dev
  

rake

rake clone_structure_to_test #copy dev的数据库结构到test

rake test_units #所有的unit

rake test_functional #所有的functional

rake #所有的测试

ruby xxxxx.rb -n name # 测试某方法

ruby xxxxx.rb -n /regex/ # 正则匹配测试方法

持续集成,因为不熟悉, 暂时不写

rake stats # 统计测试

ruby -rcoverage test/functional/xxx_controller_test.rb #统计覆盖率

convention

表对应关系: Person -> people table -> person_id join table: tablenamea_tablenameb 为table名(按照字母顺序排列)

字段 xxx_on xxx_at 自动维护date 和 datetime

抱歉!评论已关闭.