2016-08-07 00:44:11 +08:00
|
|
|
require 'rails_helper'
|
2014-03-30 23:10:26 +08:00
|
|
|
|
2016-08-07 00:44:11 +08:00
|
|
|
RSpec.describe LikesController, type: :controller do
|
2014-03-30 23:10:26 +08:00
|
|
|
|
|
|
|
it "get index" do
|
2016-04-25 12:27:32 +08:00
|
|
|
a = Post.create!(title: 'one', content: '1'*31)
|
2016-08-07 00:44:11 +08:00
|
|
|
get 'index', params: { 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!
|
2016-08-07 00:44:11 +08:00
|
|
|
get 'index', params: { 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
|
2016-04-25 12:27:32 +08:00
|
|
|
a = Post.create!(title: 'one', content: '1'*31)
|
2016-08-07 00:44:11 +08:00
|
|
|
post 'create', params: { 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
|
2016-04-25 12:27:32 +08:00
|
|
|
a = Post.create!(title: 'one', content: '1'*31)
|
2014-03-30 23:10:26 +08:00
|
|
|
like = Like.new
|
|
|
|
a.likes << like
|
|
|
|
a.save!
|
2016-08-07 00:44:11 +08:00
|
|
|
delete 'destroy', params: { 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
|