Created
September 19, 2012 14:29
-
-
Save olgen/3749983 to your computer and use it in GitHub Desktop.
pinoccio style stub'bing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def process | |
identify_site | |
return if !validate_bidder | |
identify_rtb_version | |
return if !validate_rtb_version | |
parse_bid_request | |
return if !validate_bid_request | |
extract_bid_request_params | |
load_ip_information | |
identify_country | |
return if !identify_and_validate_currency | |
return if !validate_ua | |
identify_device | |
return if !validate_device | |
identify_banner_type | |
return if !validate_banner_type | |
# TODO: change channel handling, this one is wrong! | |
channel_ids = identify_channels | |
get_channel_bitmask!(channel_ids) | |
identify_or_create_unique_user if !@user | |
get_ad | |
return no_bid(:no_ad) if !@ad | |
calculate_bid_price | |
generate_bid_lookup | |
generate_bid_response | |
if @result | |
log :bid, bid_token: @bid_token, ad: @ad.id, price: @price, currency: @currency | |
else | |
log :no_bid, reason: :failed_to_generate_response | |
no_content(:no_bid) | |
end | |
end | |
context 'process' do | |
before(:each) do | |
setup_request | |
end | |
it 'returns no content if rtb version invalid' do | |
@handler.should_not_receive :identify_bidder | |
@handler.stub!(:validate_rtb_version).and_return false | |
@handler.process | |
@handler.finish.should == Ed::NO_CONTENT | |
end | |
it 'returns not found if token not valid' do | |
@handler.should_receive :identify_site | |
@handler.stub!(:validate_rtb_version).and_return true | |
@handler.process | |
@handler.finish.should == Ed::NOT_FOUND | |
end | |
it 'returns bid request invalid if parse request failed' do | |
@handler.should_not_receive :identify_and_validate_currency | |
@handler.stub!(:validate_rtb_version).and_return true | |
@handler.stub!(:validate_bidder).and_return true | |
@handler.stub!(:parse_bid_request).and_return false | |
@handler.process | |
@handler.finish.should == Ed::NO_CONTENT | |
end | |
it 'returns no content if currency cannot be identified' do | |
@handler.should_not_receive :identify_banner_type | |
@handler.stub!(:validate_rtb_version).and_return true | |
@handler.stub!(:validate_bidder).and_return true | |
@handler.stub!(:parse_bid_request).and_return true | |
@handler.stub!(:identify_ip) | |
@handler.stub!(:identify_origin) | |
@handler.stub!(:identify_and_validate_currency).and_return false | |
@handler.process | |
@handler.finish.should == Ed::NO_CONTENT | |
end | |
it 'returns no content if banner size not identifiable' do | |
@handler.should_receive :identify_banner_type | |
@handler.stub!(:validate_rtb_version).and_return true | |
@handler.stub!(:validate_bidder).and_return true | |
@handler.stub!(:parse_bid_request).and_return true | |
@handler.stub!(:validate_bid_request).and_return true | |
@handler.stub!(:identify_and_validate_currency).and_return true | |
@handler.banner_type = nil | |
@handler.process | |
@handler.finish.should == Ed::NO_CONTENT | |
end | |
it 'returns no content if no ua in bid request' do | |
@handler.should_not_receive :identify_device | |
@handler.stub!(:validate_rtb_version).and_return true | |
@handler.stub!(:validate_bidder).and_return true | |
@handler.stub!(:parse_bid_request).and_return true | |
@handler.stub!(:identify_ip) | |
@handler.stub!(:identify_origin) | |
@handler.stub!(:identify_and_validate_currency).and_return true | |
@handler.stub!(:identify_banner_type).and_return true | |
@handler.banner_type = true | |
@handler.ua = nil | |
@handler.process | |
@handler.finish.should == Ed::NO_CONTENT | |
end | |
it 'returns no content if device cannot be identified' do | |
@handler.should_receive :identify_device | |
@handler.should_not_receive :identify_or_create_unique_user | |
@handler.should_not_receive :get_ad | |
@handler.stub!(:validate_rtb_version).and_return true | |
@handler.stub!(:validate_bidder).and_return true | |
@handler.stub!(:parse_bid_request).and_return true | |
@handler.stub!(:identify_ip) | |
@handler.stub!(:identify_origin) | |
@handler.stub!(:identify_and_validate_currency).and_return true | |
@handler.stub!(:identify_banner_type).and_return true | |
@handler.banner_type = true | |
@handler.ua = true | |
@handler.device = nil | |
@handler.process | |
@handler.finish.should == Ed::NO_CONTENT | |
end | |
it 'returns no content if no ad found' do | |
@handler.should_receive :identify_or_create_unique_user | |
@handler.should_receive :get_ad | |
@handler.stub!(:validate_rtb_version).and_return true | |
@handler.stub!(:validate_bidder).and_return true | |
@handler.stub!(:parse_bid_request).and_return true | |
@handler.stub!(:identify_and_validate_currency).and_return true | |
@handler.stub!(:identify_banner_type).and_return true | |
@handler.stub!(:identify_ip) | |
@handler.stub!(:identify_device).and_return true | |
@handler.stub!(:identify_origin) | |
@handler.stub!(:identify_channels) | |
@handler.stub!(:get_channel_bitmask!) | |
@handler.stub!(:get_ad).and_return true | |
@handler.banner_type = true | |
@handler.ua = true | |
@handler.device = true | |
@handler.user = nil | |
@handler.ad = nil | |
@handler.process | |
@handler.finish.should == Ed::NO_CONTENT | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment