|
- 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: '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)
-
- expect(json).to have_key('posts')
- expect(json['posts']).to be_an(Array)
- expect(json['posts']).not_to be_empty
-
- tags = json['posts'][0]['tags']
- expect(tags).to be_an(Array)
- expect(tags).not_to be_empty
-
- expect(tags[0]).to have_key('name')
- expect(tags[0]['name']).to eq('spec_tag')
-
- expect(tags.map { |t| t['name'] }).to include('spec_tag')
- expect(tags[0]).to include('category')
- end
- end
- end
|