custom_emojis_controller_spec.rb 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. require 'rails_helper'
  2. describe Admin::CustomEmojisController do
  3. render_views
  4. let(:user) { Fabricate(:user, admin: true) }
  5. before do
  6. sign_in user, scope: :user
  7. end
  8. describe 'GET #index' do
  9. subject { get :index }
  10. before do
  11. Fabricate(:custom_emoji)
  12. end
  13. it 'renders index page' do
  14. expect(subject).to have_http_status 200
  15. expect(subject).to render_template :index
  16. end
  17. end
  18. describe 'GET #new' do
  19. subject { get :new }
  20. it 'renders new page' do
  21. expect(subject).to have_http_status 200
  22. expect(subject).to render_template :new
  23. end
  24. end
  25. describe 'POST #create' do
  26. subject { post :create, params: { custom_emoji: params } }
  27. let(:image) { fixture_file_upload(Rails.root.join('spec', 'fixtures', 'files', 'emojo.png'), 'image/png') }
  28. context 'when parameter is valid' do
  29. let(:params) { { shortcode: 'test', image: image } }
  30. it 'creates custom emoji' do
  31. expect { subject }.to change { CustomEmoji.count }.by(1)
  32. end
  33. end
  34. context 'when parameter is invalid' do
  35. let(:params) { { shortcode: 't', image: image } }
  36. it 'renders new' do
  37. expect(subject).to render_template :new
  38. end
  39. end
  40. end
  41. end