implement current_user
This commit is contained in:
@@ -5,7 +5,7 @@ RSpec.describe Post, type: :model do
|
||||
context 'when post have other post reference and a content' do
|
||||
it 'returns :quoted_post' do
|
||||
quoted_post = create(:post)
|
||||
post = create(:post, quoted_post: quoted_post)
|
||||
post = build(:post, quoted_post: quoted_post)
|
||||
|
||||
expect(post.kind).to eq(:quoted_post)
|
||||
end
|
||||
@@ -14,7 +14,7 @@ RSpec.describe Post, type: :model do
|
||||
context 'when post have other post reference and dont have a content' do
|
||||
it 'returns :repost' do
|
||||
quoted_post = create(:post)
|
||||
post = create(:post, quoted_post: quoted_post, content: nil)
|
||||
post = build(:post, quoted_post: quoted_post, content: nil)
|
||||
|
||||
expect(post.kind).to eq(:repost)
|
||||
end
|
||||
@@ -22,7 +22,7 @@ RSpec.describe Post, type: :model do
|
||||
|
||||
context 'when post dont have other post reference and have a content' do
|
||||
it 'returns :post' do
|
||||
post = create(:post)
|
||||
post = build(:post)
|
||||
|
||||
expect(post.kind).to eq(:post)
|
||||
end
|
||||
|
||||
@@ -13,18 +13,17 @@ require 'rails_helper'
|
||||
# sticking to rails and rspec-rails APIs to keep things simple and stable.
|
||||
|
||||
RSpec.describe "/posts", type: :request do
|
||||
let(:quoted_post) { create(:post) }
|
||||
let(:user) { create(:user) }
|
||||
|
||||
let(:valid_attributes) {
|
||||
{
|
||||
content: "Quo dolorem recusandae. Vero laborum deleniti. Qui ipsam illum.",
|
||||
user_id: create(:user).id,
|
||||
}
|
||||
}
|
||||
|
||||
let(:invalid_attributes) {
|
||||
{
|
||||
content: "Quo dolorem recusandae. Vero laborum deleniti. Qui ipsam illum."
|
||||
content: nil,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,12 +32,14 @@ RSpec.describe "/posts", type: :request do
|
||||
# PostsController, or in your router and rack
|
||||
# middleware. Be sure to keep this updated too.
|
||||
let(:valid_headers) {
|
||||
{}
|
||||
{
|
||||
Cookie: "user_id=#{user.id}"
|
||||
}
|
||||
}
|
||||
|
||||
describe "GET /index" do
|
||||
it "renders a successful response" do
|
||||
Post.create! valid_attributes
|
||||
create(:post)
|
||||
get posts_url, headers: valid_headers, as: :json
|
||||
expect(response).to be_successful
|
||||
end
|
||||
@@ -46,7 +47,7 @@ RSpec.describe "/posts", type: :request do
|
||||
|
||||
describe "GET /show" do
|
||||
it "renders a successful response" do
|
||||
post = Post.create! valid_attributes
|
||||
post = create(:post)
|
||||
get post_url(post), as: :json
|
||||
expect(response).to be_successful
|
||||
end
|
||||
|
||||
@@ -7,19 +7,19 @@ RSpec.describe "/user_follows", type: :request do
|
||||
let(:valid_attributes) {
|
||||
{
|
||||
followed_id: followed.id,
|
||||
follower_id: follower.id
|
||||
}
|
||||
}
|
||||
|
||||
let(:invalid_attributes) {
|
||||
{
|
||||
followed_id: followed.id,
|
||||
follower_id: 'follower.id'
|
||||
followed_id: 'invalid_id',
|
||||
}
|
||||
}
|
||||
|
||||
let(:valid_headers) {
|
||||
{}
|
||||
{
|
||||
Cookie: "user_id=#{follower.id}"
|
||||
}
|
||||
}
|
||||
|
||||
describe "POST /create" do
|
||||
@@ -58,7 +58,7 @@ RSpec.describe "/user_follows", type: :request do
|
||||
|
||||
describe "DELETE /destroy" do
|
||||
it "destroys the requested user_follow" do
|
||||
user_follow = UserFollow.create! valid_attributes
|
||||
user_follow = create(:user_follow, follower: follower, followed: followed)
|
||||
expect {
|
||||
delete user_follow_url(user_follow), headers: valid_headers, as: :json
|
||||
}.to change(UserFollow, :count).by(-1)
|
||||
|
||||
Reference in New Issue
Block a user