diff --git a/lib/oneboxer/stack_exchange_onebox.rb b/lib/oneboxer/stack_exchange_onebox.rb index 0a1f42f7213..028bc717006 100644 --- a/lib/oneboxer/stack_exchange_onebox.rb +++ b/lib/oneboxer/stack_exchange_onebox.rb @@ -12,7 +12,7 @@ module Oneboxer # http://rubular.com/r/V3T0I1VTPn REGEX = - /^http:\/\/(?:(?\w*)\.)?(?#{DOMAINS.join('|')})\.com\/(?:questions|q)\/(?\d*)/ + /^http:\/\/(?:(?:(?\w*)\.)?(?\w*)\.)?(?#{DOMAINS.join('|')})\.com\/(?:questions|q)\/(?\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/", diff --git a/spec/components/oneboxer/stack_exchange_onebox_spec.rb b/spec/components/oneboxer/stack_exchange_onebox_spec.rb index 3a4dbd9a74c..edf182d4a43 100644 --- a/spec/components/oneboxer/stack_exchange_onebox_spec.rb +++ b/spec/components/oneboxer/stack_exchange_onebox_spec.rb @@ -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' } diff --git a/spec/controllers/user_actions_controller_spec.rb b/spec/controllers/user_actions_controller_spec.rb index 25d4a1b9b46..0ab1528a87a 100644 --- a/spec/controllers/user_actions_controller_spec.rb +++ b/spec/controllers/user_actions_controller_spec.rb @@ -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