重构了测试, 去掉没有用的文件
This commit is contained in:
parent
4dfe7a4bdb
commit
dadc70e0f4
|
@ -2,67 +2,36 @@ require 'spec_helper'
|
||||||
|
|
||||||
describe BlogsController do
|
describe BlogsController do
|
||||||
|
|
||||||
it 'index should get by order desc' do
|
describe 'get INDEX' do
|
||||||
a = Post.new(title: 'a123', content: '123'*20, type: Post::TECH)
|
it 'index should get by order desc' do
|
||||||
a.save!
|
create_list(:post_list, 5)
|
||||||
|
|
||||||
b = Post.new(title: 'b1234', content: '123'*20,type: Post::TECH)
|
first = Post.first
|
||||||
b.save!
|
first.update(title: 'first')
|
||||||
|
|
||||||
c = Post.new(title: 'c1234', content: '123'*20,type: Post::TECH)
|
second = Post.desc(:created_at)[1]
|
||||||
c.save!
|
get :index
|
||||||
|
expect(assigns(:newest)).to eq(first)
|
||||||
d = Post.new(title: 'd1234', content: '123'*20,type: Post::TECH)
|
expect(assigns(:recent)[0]).to eq(second)
|
||||||
d.save!
|
end
|
||||||
|
|
||||||
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'
|
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "get SHOW" do
|
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
|
it "#prev, #next" do
|
||||||
posts = create_list(:post_list, 3)
|
posts = create_list(:post_list, 3)
|
||||||
posts = Post.order_by(created_at: 'asc')
|
posts = Post.order_by(created_at: 'asc')
|
||||||
|
@ -91,8 +60,6 @@ describe BlogsController do
|
||||||
get :show, id: selected.id
|
get :show, id: selected.id
|
||||||
expect(assigns(:prev)).to eq(posts[0])
|
expect(assigns(:prev)).to eq(posts[0])
|
||||||
expect(assigns(:next)).to eq(posts[2])
|
expect(assigns(:next)).to eq(posts[2])
|
||||||
|
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
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
|
FactoryGirl.define do
|
||||||
factory :comment do
|
factory :comment do
|
||||||
content 'content' * 10
|
content 'content' * 10
|
||||||
type Post::TECH
|
name 'commentor'
|
||||||
|
email 'tester@xx.com'
|
||||||
association :post
|
association :post
|
||||||
end
|
end
|
||||||
|
|
||||||
|
factory :comment_no_post, class: Comment do
|
||||||
|
content 'content' * 10
|
||||||
|
name 'commentor'
|
||||||
|
email 'tester@xx.com'
|
||||||
|
end
|
||||||
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