fix tests and allow SE onebox to onebox Meta cause I need that for an post I am writing

This commit is contained in:
Sam 2013-06-12 12:23:24 +10:00
parent 74041be23b
commit 54d8c963d0
3 changed files with 25 additions and 4 deletions

View file

@ -12,7 +12,7 @@ module Oneboxer
# http://rubular.com/r/V3T0I1VTPn
REGEX =
/^http:\/\/(?:(?<subdomain>\w*)\.)?(?<domain>#{DOMAINS.join('|')})\.com\/(?:questions|q)\/(?<question>\d*)/
/^http:\/\/(?:(?:(?<subsubdomain>\w*)\.)?(?<subdomain>\w*)\.)?(?<domain>#{DOMAINS.join('|')})\.com\/(?:questions|q)\/(?<question>\d*)/
matcher REGEX
favicon 'stackexchange.png'
@ -20,9 +20,9 @@ module Oneboxer
def translate_url
@url.match(REGEX) do |match|
site = if match[:domain] == 'stackexchange'
match[:subdomain]
[match[:subsubdomain],match[:subdomain]].compact.join('.')
else
match[:domain]
[match[:subdomain],match[:domain]].compact.join('.')
end
["http://api.stackexchange.com/2.1/",

View file

@ -36,6 +36,27 @@ describe Oneboxer::StackExchangeOnebox do
end
end
context 'when the question is from Meta Stack Overflow' do
let(:site) { 'meta.stackoverflow' }
it 'returns the correct api url' do
onebox = described_class.new("http://meta.stackoverflow.com/q/#{question}")
expect(onebox.translate_url).to eq api_url
end
end
context 'when the question is from a Meta Stack Exchange subdomain' do
let(:site) { 'meta.gamedev' }
it 'returns the correct api url' do
onebox = described_class.new("http://meta.gamedev.stackexchange.com/q/#{question}")
expect(onebox.translate_url).to eq api_url
end
end
context 'when the question is from a Stack Exchange subdomain' do
let(:site) { 'gamedev' }

View file

@ -20,7 +20,7 @@ describe UserActionsController do
action = actions[0]
action["acting_name"].should == post.user.name
action["email"].should be_nil
action["post_number"].should == "1"
action["post_number"].should == 1
end
end
end