diff --git a/spec/controllers/blogs_controller_spec.rb b/spec/controllers/blogs_controller_spec.rb index b03d2c6..462ff8c 100644 --- a/spec/controllers/blogs_controller_spec.rb +++ b/spec/controllers/blogs_controller_spec.rb @@ -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 diff --git a/spec/controllers/comments_controller_spec.rb b/spec/controllers/comments_controller_spec.rb deleted file mode 100644 index 562bf1a..0000000 --- a/spec/controllers/comments_controller_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'spec_helper' - -describe CommentsController do - -end diff --git a/spec/controllers/photos_controller_spec.rb b/spec/controllers/photos_controller_spec.rb deleted file mode 100644 index 5f2c12a..0000000 --- a/spec/controllers/photos_controller_spec.rb +++ /dev/null @@ -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 diff --git a/spec/factories/comments.rb b/spec/factories/comments.rb index 58a5ae2..6b373a2 100644 --- a/spec/factories/comments.rb +++ b/spec/factories/comments.rb @@ -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 diff --git a/spec/models/comment_spec.rb b/spec/models/comment_spec.rb deleted file mode 100644 index b504a0a..0000000 --- a/spec/models/comment_spec.rb +++ /dev/null @@ -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 diff --git a/spec/models/label_spec.rb b/spec/models/label_spec.rb deleted file mode 100644 index 45b9dde..0000000 --- a/spec/models/label_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'spec_helper' - -describe Label do - -end diff --git a/spec/models/photo_spec.rb b/spec/models/photo_spec.rb deleted file mode 100644 index d64d07f..0000000 --- a/spec/models/photo_spec.rb +++ /dev/null @@ -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 diff --git a/spec/models/subscribe_spec.rb b/spec/models/subscribe_spec.rb deleted file mode 100644 index 0df4fbb..0000000 --- a/spec/models/subscribe_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'spec_helper' - -describe Subscribe do - pending "add some examples to (or delete) #{__FILE__}" -end