2017-07-20 03:08:54 +08:00
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
describe InlineOneboxController do
|
|
|
|
|
|
|
|
it "requires the user to be logged in" do
|
2018-01-12 11:15:10 +08:00
|
|
|
get :show, params: { urls: [] }, format: :json
|
|
|
|
expect(response.status).to eq(403)
|
2017-07-20 03:08:54 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
context "logged in" do
|
|
|
|
let!(:user) { log_in(:user) }
|
|
|
|
|
|
|
|
it "returns empty JSON for empty input" do
|
2017-08-31 12:06:56 +08:00
|
|
|
get :show, params: { urls: [] }, format: :json
|
2018-06-05 15:29:17 +08:00
|
|
|
expect(response).to be_successful
|
2017-07-20 03:08:54 +08:00
|
|
|
json = JSON.parse(response.body)
|
|
|
|
expect(json['inline-oneboxes']).to eq([])
|
|
|
|
end
|
|
|
|
|
|
|
|
context "topic link" do
|
|
|
|
let(:topic) { Fabricate(:topic) }
|
|
|
|
|
|
|
|
it "returns information for a valid link" do
|
2017-08-31 12:06:56 +08:00
|
|
|
get :show, params: { urls: [ topic.url ] }, format: :json
|
2018-06-05 15:29:17 +08:00
|
|
|
expect(response).to be_successful
|
2017-07-20 03:08:54 +08:00
|
|
|
json = JSON.parse(response.body)
|
|
|
|
onebox = json['inline-oneboxes'][0]
|
|
|
|
|
|
|
|
expect(onebox).to be_present
|
|
|
|
expect(onebox['url']).to eq(topic.url)
|
|
|
|
expect(onebox['title']).to eq(topic.title)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|