2017-07-19 14:08:54 -05:00
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
describe InlineOneboxController do
|
|
|
|
|
|
|
|
it "requires the user to be logged in" do
|
2018-06-06 04:10:59 -05:00
|
|
|
get "/inline-onebox.json", params: { urls: [] }
|
2018-01-11 21:15:10 -06:00
|
|
|
expect(response.status).to eq(403)
|
2017-07-19 14:08:54 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
context "logged in" do
|
2018-06-06 04:10:59 -05:00
|
|
|
let!(:user) { sign_in(Fabricate(:user)) }
|
2017-07-19 14:08:54 -05:00
|
|
|
|
|
|
|
it "returns empty JSON for empty input" do
|
2018-06-06 04:10:59 -05:00
|
|
|
get "/inline-onebox.json", params: { urls: [] }
|
|
|
|
expect(response.status).to eq(200)
|
2017-07-19 14:08:54 -05: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
|
2018-06-06 04:10:59 -05:00
|
|
|
get "/inline-onebox.json", params: { urls: [ topic.url ] }
|
|
|
|
expect(response.status).to eq(200)
|
2017-07-19 14:08:54 -05: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
|