重构了测试, 去掉没有用的文件
This commit is contained in:
parent
4dfe7a4bdb
commit
dadc70e0f4
|
@ -2,67 +2,36 @@ require 'spec_helper'
|
|||
|
||||
describe BlogsController do
|
||||
|
||||
it 'index should get by order desc' do
|
||||
a = Post.new(title: 'a123', content: '123'*20, type: Post::TECH)
|
||||
a.save!
|
||||
describe 'get INDEX' do
|
||||
it 'index should get by order desc' do
|
||||
create_list(:post_list, 5)
|
||||
|
||||
b = Post.new(title: 'b1234', content: '123'*20,type: Post::TECH)
|
||||
b.save!
|
||||
first = Post.first
|
||||
first.update(title: 'first')
|
||||
|
||||
c = Post.new(title: 'c1234', content: '123'*20,type: Post::TECH)
|
||||
c.save!
|
||||
|
||||
d = Post.new(title: 'd1234', content: '123'*20,type: Post::TECH)
|
||||
d.save!
|
||||
|
||||
a.update(title: 'aaa')
|
||||
get :index
|
||||
assigns[:newest].title.should == d.title
|
||||
assigns[:recent][0].title.should == c.title
|
||||
assigns[:recent][1].title.should == b.title
|
||||
|
||||
end
|
||||
|
||||
it 'test show method' do
|
||||
post = Post.new(title: 'a123', content: '123'*20, type: Post::TECH)
|
||||
post.save!
|
||||
a = Comment.new(name: '1',content: '2432423',email: '22@.com')
|
||||
a.post = post
|
||||
a.save!
|
||||
b = Comment.new(name: '2',content: 'iloveyou',email: 'liuzhen@.com')
|
||||
b.post = post
|
||||
b.save!
|
||||
get :show, id: post.id
|
||||
assigns[:comments][0].name.should == '1'
|
||||
assigns[:comments][0].content.should == '2432423'
|
||||
assigns[:comments][0].email.should == '22@.com'
|
||||
assigns[:comments][1].name.should == '2'
|
||||
assigns[:comments][1].content.should == 'iloveyou'
|
||||
assigns[:comments][1].email.should == 'liuzhen@.com'
|
||||
end
|
||||
|
||||
it 'test show method' do
|
||||
post = Post.new(title: 'a123', content: '123'*20, type: Post::TECH)
|
||||
post.save!
|
||||
a = Comment.new(name: '1',content: '2432423',email: '22@.com')
|
||||
a.post = post
|
||||
a.save!
|
||||
b = Comment.new(name: '2',content: 'iloveyou',email: 'liuzhen@.com')
|
||||
b.post = post
|
||||
b.save!
|
||||
label = Label.new(name: '生活')
|
||||
post.labels << label
|
||||
post.save!
|
||||
get :show, id: post.id
|
||||
assigns[:comments][0].name.should == '1'
|
||||
assigns[:comments][0].content.should == '2432423'
|
||||
assigns[:comments][0].email.should == '22@.com'
|
||||
assigns[:comments][1].name.should == '2'
|
||||
assigns[:comments][1].content.should == 'iloveyou'
|
||||
assigns[:comments][1].email.should == 'liuzhen@.com'
|
||||
second = Post.desc(:created_at)[1]
|
||||
get :index
|
||||
expect(assigns(:newest)).to eq(first)
|
||||
expect(assigns(:recent)[0]).to eq(second)
|
||||
end
|
||||
end
|
||||
|
||||
describe "get SHOW" do
|
||||
|
||||
it 'get POST' do
|
||||
post = create(:post)
|
||||
comment1 = build(:comment_no_post)
|
||||
comment1.post = post
|
||||
comment1.save!
|
||||
comment2 = build(:comment_no_post)
|
||||
comment2.post = post
|
||||
comment2.save!
|
||||
|
||||
get :show, id: post.id
|
||||
expect(assigns(:comments)[0]).to eq(comment1)
|
||||
expect(assigns(:comments)[1]).to eq(comment2)
|
||||
end
|
||||
|
||||
it "#prev, #next" do
|
||||
posts = create_list(:post_list, 3)
|
||||
posts = Post.order_by(created_at: 'asc')
|
||||
|
@ -91,8 +60,6 @@ describe BlogsController do
|
|||
get :show, id: selected.id
|
||||
expect(assigns(:prev)).to eq(posts[0])
|
||||
expect(assigns(:next)).to eq(posts[2])
|
||||
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,5 +0,0 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe CommentsController do
|
||||
|
||||
end
|
|
@ -1,12 +0,0 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe PhotosController do
|
||||
|
||||
describe "GET 'create'" do
|
||||
it "returns http success" do
|
||||
get 'create'
|
||||
response.should be_success
|
||||
end
|
||||
end
|
||||
|
||||
end
|
|
@ -1,7 +1,14 @@
|
|||
FactoryGirl.define do
|
||||
factory :comment do
|
||||
content 'content' * 10
|
||||
type Post::TECH
|
||||
name 'commentor'
|
||||
email 'tester@xx.com'
|
||||
association :post
|
||||
end
|
||||
|
||||
factory :comment_no_post, class: Comment do
|
||||
content 'content' * 10
|
||||
name 'commentor'
|
||||
email 'tester@xx.com'
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,14 +0,0 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe Comment do
|
||||
it 'test comment' do
|
||||
a = Comment.new(name: '1',content: '2432423',email: '22@.com', post_id: 1)
|
||||
a.save.should == true
|
||||
b = Comment.new(content: '2432ddd423',email: '22@.com', post_id: 1)
|
||||
b.save.should == false
|
||||
b = Comment.new(name: '2', email: '22@.com', post_id: 1)
|
||||
b.save.should == false
|
||||
b = Comment.new(name: '2', content: '2432ddd423',email: '22.com', post_id: 1)
|
||||
b.save.should == false
|
||||
end
|
||||
end
|
|
@ -1,5 +0,0 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe Label do
|
||||
|
||||
end
|
|
@ -1,8 +0,0 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe Photo do
|
||||
it "photo with picture will be ok" do
|
||||
a = Photo.new
|
||||
a.save
|
||||
end
|
||||
end
|
|
@ -1,5 +0,0 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe Subscribe do
|
||||
pending "add some examples to (or delete) #{__FILE__}"
|
||||
end
|
Loading…
Reference in New Issue