|
- require 'rails_helper'
-
-
- RSpec.describe 'Posts API', type: :request do
- describe 'GET /posts' do
- it 'returns tags with name in JSON' do
- tn = TagName.create!(name: 'gen:spec_tag')
- tag = Tag.create!(tag_name: tn, category: 'general')
-
- post = Post.create!(title: 'spec post', url: 'https://example.com/spec')
- PostTag.create!(post: post, tag: tag)
-
- get '/posts'
-
- expect(response).to have_http_status(:ok)
-
- json = JSON.parse(response.body)
- expect(json).to have_key('posts')
- expect(json['posts']).to be_a(Array)
- expect(json['posts']).not_to be_empty
-
- tags = json['posts'][0]['tags']
- expect(tags).to be_a(Array)
- expect(tags).not_to be_empty
-
- expect(tags[0]).to have_key('name')
- expect(tags[0]['name']).to eq('gen:spec_tag')
- end
- end
- end
|