Add likes model, controller and tests

This commit is contained in:
riggraz
2019-09-27 12:32:30 +02:00
parent e1d8dbc281
commit 970cd6934c
13 changed files with 118 additions and 2 deletions

6
spec/factories/likes.rb Normal file
View File

@@ -0,0 +1,6 @@
FactoryBot.define do
factory :like do
user
post
end
end

19
spec/models/like_spec.rb Normal file
View File

@@ -0,0 +1,19 @@
require 'rails_helper'
RSpec.describe Like, type: :model do
let(:like) { FactoryBot.build(:like) }
it 'is valid' do
expect(like).to be_valid
end
it 'must have a user_id' do
like.user = nil
expect(like).to be_invalid
end
it 'must have a post_id' do
like.post = nil
expect(like).to be_invalid
end
end

View File

@@ -0,0 +1,18 @@
require 'rails_helper'
RSpec.describe 'likes routing', :aggregate_failures, type: :routing do
it 'routes likes' do
expect(post: '/posts/1/likes').to route_to(
controller: 'likes', action: 'create', post_id: "1"
)
expect(delete: '/posts/1/likes').to route_to(
controller: 'likes', action: 'destroy', post_id: "1"
)
expect(get: '/posts/1/likes').not_to be_routable
expect(get: '/posts/1/likes/1').not_to be_routable
expect(get: '/posts/1/likes/new').not_to be_routable
expect(get: '/posts/1/likes/1/edit').not_to be_routable
expect(patch: '/posts/1/likes/1').not_to be_routable
end
end