tags_controller_spec.rb 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. RSpec.describe Admin::TagsController do
  4. render_views
  5. before do
  6. sign_in Fabricate(:user, role: UserRole.find_by(name: 'Admin'))
  7. end
  8. describe 'GET #show' do
  9. let!(:tag) { Fabricate(:tag) }
  10. before do
  11. get :show, params: { id: tag.id }
  12. end
  13. it 'returns status 200' do
  14. expect(response).to have_http_status(200)
  15. end
  16. end
  17. describe 'PUT #update' do
  18. let!(:tag) { Fabricate(:tag, listable: false) }
  19. context 'with valid params' do
  20. it 'updates the tag' do
  21. put :update, params: { id: tag.id, tag: { listable: '1' } }
  22. expect(response).to redirect_to(admin_tag_path(tag.id))
  23. expect(tag.reload).to be_listable
  24. end
  25. end
  26. context 'with invalid params' do
  27. it 'does not update the tag' do
  28. put :update, params: { id: tag.id, tag: { name: 'cant-change-name' } }
  29. expect(response).to have_http_status(200)
  30. expect(response).to render_template(:show)
  31. end
  32. end
  33. end
  34. end