ぼざクリタグ広場 https://hub.nizika.monster
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

33 lines
895 B

  1. require 'rails_helper'
  2. RSpec.describe 'Posts API', type: :request do
  3. describe 'GET /posts' do
  4. it 'returns tags with name in JSON' do
  5. tn = TagName.create!(name: 'spec_tag')
  6. tag = Tag.create!(tag_name: tn, category: 'general')
  7. post = Post.create!(title: 'spec post', url: 'https://example.com/spec')
  8. PostTag.create!(post: post, tag: tag)
  9. get '/posts'
  10. expect(response).to have_http_status(:ok)
  11. expect(json).to have_key('posts')
  12. expect(json['posts']).to be_an(Array)
  13. expect(json['posts']).not_to be_empty
  14. tags = json['posts'][0]['tags']
  15. expect(tags).to be_an(Array)
  16. expect(tags).not_to be_empty
  17. expect(tags[0]).to have_key('name')
  18. expect(tags[0]['name']).to eq('spec_tag')
  19. expect(tags.map { |t| t['name'] }).to include('spec_tag')
  20. expect(tags[0]).to include('category')
  21. end
  22. end
  23. end