add user follow feature
This commit is contained in:
6
spec/factories/user_follows.rb
Normal file
6
spec/factories/user_follows.rb
Normal file
@@ -0,0 +1,6 @@
|
||||
FactoryBot.define do
|
||||
factory :user_follow do
|
||||
follower { nil }
|
||||
followed { nil }
|
||||
end
|
||||
end
|
||||
@@ -1,5 +1,5 @@
|
||||
FactoryBot.define do
|
||||
factory :user do
|
||||
username { "xpto" }
|
||||
username { Faker::Internet.username.gsub(/[^0-9a-z ]/i, '') }
|
||||
end
|
||||
end
|
||||
|
||||
67
spec/requests/user_follows_spec.rb
Normal file
67
spec/requests/user_follows_spec.rb
Normal file
@@ -0,0 +1,67 @@
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe "/user_follows", type: :request do
|
||||
let(:followed) { create(:user) }
|
||||
let(:follower) { create(:user) }
|
||||
|
||||
let(:valid_attributes) {
|
||||
{
|
||||
followed_id: followed.id,
|
||||
follower_id: follower.id
|
||||
}
|
||||
}
|
||||
|
||||
let(:invalid_attributes) {
|
||||
{
|
||||
followed_id: followed.id,
|
||||
follower_id: 'follower.id'
|
||||
}
|
||||
}
|
||||
|
||||
let(:valid_headers) {
|
||||
{}
|
||||
}
|
||||
|
||||
describe "POST /create" do
|
||||
context "with valid parameters" do
|
||||
it "creates a new UserFollow" do
|
||||
expect {
|
||||
post user_follows_url,
|
||||
params: { user_follow: valid_attributes }, headers: valid_headers, as: :json
|
||||
}.to change(UserFollow, :count).by(1)
|
||||
end
|
||||
|
||||
it "renders a JSON response with the new user_follow" do
|
||||
post user_follows_url,
|
||||
params: { user_follow: valid_attributes }, headers: valid_headers, as: :json
|
||||
expect(response).to have_http_status(:created)
|
||||
expect(response.content_type).to match(a_string_including("application/json"))
|
||||
end
|
||||
end
|
||||
|
||||
context "with invalid parameters" do
|
||||
it "does not create a new UserFollow" do
|
||||
expect {
|
||||
post user_follows_url,
|
||||
params: { user_follow: invalid_attributes }, as: :json
|
||||
}.to change(UserFollow, :count).by(0)
|
||||
end
|
||||
|
||||
it "renders a JSON response with errors for the new user_follow" do
|
||||
post user_follows_url,
|
||||
params: { user_follow: invalid_attributes }, headers: valid_headers, as: :json
|
||||
expect(response).to have_http_status(:unprocessable_entity)
|
||||
expect(response.content_type).to match(a_string_including("application/json"))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "DELETE /destroy" do
|
||||
it "destroys the requested user_follow" do
|
||||
user_follow = UserFollow.create! valid_attributes
|
||||
expect {
|
||||
delete user_follow_url(user_follow), headers: valid_headers, as: :json
|
||||
}.to change(UserFollow, :count).by(-1)
|
||||
end
|
||||
end
|
||||
end
|
||||
13
spec/routing/user_follows_routing_spec.rb
Normal file
13
spec/routing/user_follows_routing_spec.rb
Normal file
@@ -0,0 +1,13 @@
|
||||
require "rails_helper"
|
||||
|
||||
RSpec.describe UserFollowsController, type: :routing do
|
||||
describe "routing" do
|
||||
it "routes to #create" do
|
||||
expect(post: "/user_follows").to route_to("user_follows#create")
|
||||
end
|
||||
|
||||
it "routes to #destroy" do
|
||||
expect(delete: "/user_follows/1").to route_to("user_follows#destroy", id: "1")
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user