REFACTOR: admin emojis controller specs to requests (#5974)

This commit is contained in:
OsamaSayegh 2018-06-11 07:39:31 +03:00 committed by Guo Xiang Tan
parent 12b1687e1f
commit d22b552c9b
2 changed files with 14 additions and 34 deletions

View File

@ -1,34 +0,0 @@
require "rails_helper"
describe Admin::EmojisController do
let(:custom_emoji) do
Emoji.new("/path/to/hello").tap do |e|
e.name = "hello"
e.url = "/url/to/hello.png"
end
end
let(:custom_emoji2) do
Emoji.new("/path/to/hello2").tap do |e|
e.name = "hello2"
e.url = "/url/to/hello2.png"
end
end
context "when logged in" do
let!(:user) { log_in(:admin) }
context ".index" do
it "returns a list of custom emojis" do
Emoji.expects(:custom).returns([custom_emoji])
get :index, format: :json
expect(response.status).to eq(200)
json = ::JSON.parse(response.body)
expect(json[0]["name"]).to eq(custom_emoji.name)
expect(json[0]["url"]).to eq(custom_emoji.url)
end
end
end
end

View File

@ -8,6 +8,20 @@ RSpec.describe Admin::EmojisController do
sign_in(admin)
end
describe '#index' do
it "returns a list of custom emojis" do
CustomEmoji.create!(name: 'osama-test-emoji', upload: upload)
Emoji.clear_cache
get "/admin/customize/emojis.json"
expect(response.status).to eq(200)
json = ::JSON.parse(response.body)
expect(json[0]["name"]).to eq("osama-test-emoji")
expect(json[0]["url"]).to eq(upload.url)
end
end
describe "#create" do
describe 'when upload is invalid' do
it 'should publish the right error' do