引擎开发与Rack应用实践
1. 引擎功能完善与测试
1.1 用户认证与帖子创建
在开发过程中,为了实现用户认证并将认证后的用户与帖子关联,我们进行了如下操作:
params[:post].merge!(:user => current_user)
@post = @topic.posts.create(params[:post])
将代码分开写是为了提高可读性。运行 bin/rspec spec/integration/posts_spec.rb 测试,结果显示所有测试通过:
2 examples, 0 failures
这表明用户在创建新帖子前会进行认证,认证通过后会被关联到帖子上。接着运行 bin/rspec spec 确保所有功能正常:
7 examples, 0 failures
测试通过后,进行提交:
git add .
git commit -m "Authenticate users and link them to posts"
1.2 显示最后一篇帖子信息
当前 app/views/topics/i
超级会员免费看
订阅专栏 解锁全文
1622

被折叠的 条评论
为什么被折叠?



