前端开发中的呈现器与移动视图处理
1. 呈现器测试与使用
在前端开发中,测试标记时需要谨慎,避免编写脆弱的测试用例。例如,在测试 DesignersController 的 show() 动作时,我们应专注于验证重要信息,而非过度测试标记结构。以下是具体的测试代码:
# artflow/presenters/test/functional/designers_controller_test.rb
require 'test_helper'
class DesignersControllerTest < ActionController::TestCase
def setup
setup_designer
end
test "should render designer status presenter" do
get :show, id: @designer.id
assert_response :success
assert_select 'section.designer-status .active-projects', text: '3'
end
end
此测试验证了呈现器是否被渲染,并检查了设计师的活跃项目数量。
当需要展示多条记录时,可使用呈现器来处理表格。我们创建了一个通用的 SimpleTable 呈现器,其初始化方法接受模板、记录集合和列定义。以下是相关代码:
超级会员免费看
订阅专栏 解锁全文
9万+

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



