2014-03-30 23:10:26 +08:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe LikesController do
|
|
|
|
|
|
|
|
it "get index" do
|
|
|
|
a = Post.create!(title: 'one', content: '1'*31, type: Post::TECH )
|
|
|
|
get 'index', blog_id: a.id
|
2014-11-25 01:05:00 +08:00
|
|
|
expect(JSON.parse(response.body)['count']).to eq(0)
|
2014-03-30 23:10:26 +08:00
|
|
|
a.likes << Like.new
|
|
|
|
a.save!
|
|
|
|
get 'index', blog_id: a.id
|
2014-11-25 01:05:00 +08:00
|
|
|
expect(JSON.parse(response.body)['count']).to eq(1)
|
2014-03-30 23:10:26 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
it "post create" do
|
|
|
|
a = Post.create!(title: 'one', content: '1'*31, type: Post::TECH )
|
|
|
|
post 'create', blog_id: a.id
|
2014-11-25 01:05:00 +08:00
|
|
|
expect(a.likes.size).to eq(1)
|
2014-03-30 23:10:26 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
it "DELETE destroy" do
|
|
|
|
a = Post.create!(title: 'one', content: '1'*31, type: Post::TECH )
|
|
|
|
like = Like.new
|
|
|
|
a.likes << like
|
|
|
|
a.save!
|
|
|
|
delete 'destroy', blog_id: a.id, id: like.id
|
2014-11-25 01:05:00 +08:00
|
|
|
expect(a.reload.likes.size).to eq(0)
|
2014-03-30 23:10:26 +08:00
|
|
|
end
|
|
|
|
end
|