微博展示与操作全解析
1. 展示微博
虽然还没有实现通过网页创建微博的功能,但这并不妨碍我们展示微博并对展示效果进行测试。我们计划效仿 Twitter,将用户的微博直接显示在用户展示页面上,而不是单独的微博索引页面。
1.1 增强用户展示页面
首先,我们要为展示用户的微博编写测试。在用户请求规范中创建几个与用户关联的工厂微博,然后验证展示页面是否包含每条微博的内容,同时验证是否显示了微博的总数。
# spec/requests/user_pages_spec.rb
require 'spec_helper'
describe "User pages" do
describe "profile page" do
let(:user) { FactoryGirl.create(:user) }
let!(:m1) { FactoryGirl.create(:micropost, user: user, content: "Foo") }
let!(:m2) { FactoryGirl.create(:micropost, user: user, content: "Bar") }
before { visit user_path(user) }
it { should have_selector('h1', text: user.name) }
it { should have_selector('title', text: user.name) }
describe "microposts" do
it { should have
超级会员免费看
订阅专栏 解锁全文
62

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



