ぼざクリタグ広場 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.
 
 
 
 
 
 

31 lines
830 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: 'gen: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. json = JSON.parse(response.body)
  12. expect(json).to have_key('posts')
  13. expect(json['posts']).to be_a(Array)
  14. expect(json['posts']).not_to be_empty
  15. tags = json['posts'][0]['tags']
  16. expect(tags).to be_a(Array)
  17. expect(tags).not_to be_empty
  18. expect(tags[0]).to have_key('name')
  19. expect(tags[0]['name']).to eq('gen:spec_tag')
  20. end
  21. end
  22. end