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.

115 lines
3.2 KiB

  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. describe 'PUT #update' do
  42. let(:custom_emoji) { Fabricate(:custom_emoji, shortcode: 'test') }
  43. let(:image) { fixture_file_upload(Rails.root.join('spec', 'fixtures', 'files', 'emojo.png'), 'image/png') }
  44. before do
  45. put :update, params: { id: custom_emoji.id, custom_emoji: params }
  46. end
  47. context 'when parameter is valid' do
  48. let(:params) { { shortcode: 'updated', image: image } }
  49. it 'succeeds in updating custom emoji' do
  50. expect(flash[:notice]).to eq I18n.t('admin.custom_emojis.updated_msg')
  51. expect(custom_emoji.reload).to have_attributes(shortcode: 'updated')
  52. end
  53. end
  54. context 'when parameter is invalid' do
  55. let(:params) { { shortcode: 'u', image: image } }
  56. it 'fails to update custom emoji' do
  57. expect(flash[:alert]).to eq I18n.t('admin.custom_emojis.update_failed_msg')
  58. expect(custom_emoji.reload).to have_attributes(shortcode: 'test')
  59. end
  60. end
  61. end
  62. describe 'POST #copy' do
  63. subject { post :copy, params: { id: custom_emoji.id } }
  64. let(:custom_emoji) { Fabricate(:custom_emoji, shortcode: 'test') }
  65. it 'copies custom emoji' do
  66. expect { subject }.to change { CustomEmoji.where(shortcode: 'test').count }.by(1)
  67. expect(flash[:notice]).to eq I18n.t('admin.custom_emojis.copied_msg')
  68. end
  69. end
  70. describe 'POST #enable' do
  71. let(:custom_emoji) { Fabricate(:custom_emoji, shortcode: 'test', disabled: true) }
  72. before { post :enable, params: { id: custom_emoji.id } }
  73. it 'enables custom emoji' do
  74. expect(response).to redirect_to admin_custom_emojis_path
  75. expect(custom_emoji.reload).to have_attributes(disabled: false)
  76. end
  77. end
  78. describe 'POST #disable' do
  79. let(:custom_emoji) { Fabricate(:custom_emoji, shortcode: 'test', disabled: false) }
  80. before { post :disable, params: { id: custom_emoji.id } }
  81. it 'enables custom emoji' do
  82. expect(response).to redirect_to admin_custom_emojis_path
  83. expect(custom_emoji.reload).to have_attributes(disabled: true)
  84. end
  85. end
  86. end