require File.expand_path(File.join(File.dirname(__FILE__),'..', 'spec_helper')) class ApiApiClientProxyTest include Trigga::ParamFu include Trigga::AdminApiClient::Proxies::Api end describe Trigga::AdminApiClient::Proxies::Api do before do ApiApiClientProxyTest.stub!(:require_one_of).and_return(true) ApiApiClientProxyTest.stub!(:require_param).and_return(true) Trigga::AdminApiClient.stub!(:make_call).and_return(true) @opts = {:abc => 123, :api_key => "blah"} end describe "common_params" do ApiApiClientProxyTest.new.send("common_params").should == [:page, :per_page, :max_tags, :site_key, :api_key] end describe "make_api_call" do before do end it "should require a site or site_id" do ApiApiClientProxyTest.should_receive(:require_one_of).with(@opts, :site_key, :site_id) ApiApiClientProxyTest.new.send("make_api_call","endpoint",@opts) end it "should call make_call filtering out bad params" do Trigga::AdminApiClient.should_receive(:make_call).with("api","endpoint",{:api_key => "blah"}) ApiApiClientProxyTest.new.send("make_api_call","endpoint",@opts) end end describe "get_channels" do it "should call make_api_call" do ApiApiClientProxyTest.should_receive(:make_api_call).with("channels",@opts) ApiApiClientProxyTest.get_channels @opts end end describe "get_channel_items" do before do @opts = @opts.merge(:channel_id => 42) end it "should require the channel_id" do ApiApiClientProxyTest.should_receive(:require_param).with(@opts, :channel_id) ApiApiClientProxyTest.get_channel_items @opts end it "should call make_api_call" do ApiApiClientProxyTest.should_receive(:make_api_call).with("channels/42",@opts) ApiApiClientProxyTest.get_channel_items @opts end end describe "get_sources" do it "should call make_api_call" do ApiApiClientProxyTest.should_receive(:make_api_call).with("sources",@opts) ApiApiClientProxyTest.get_sources @opts end end describe "get_item_tags" do it "should call make_api_call" do ApiApiClientProxyTest.should_receive(:make_api_call).with("item_tags",@opts) ApiApiClientProxyTest.get_item_tags @opts end end describe "get_latest_items" do it "should call make_api_call" do ApiApiClientProxyTest.should_receive(:make_api_call).with("items",@opts) ApiApiClientProxyTest.get_latest_items @opts end end describe "get_item_details" do before do @opts = @opts.merge(:item_id => 42) end it "should require the channel_id" do ApiApiClientProxyTest.should_receive(:require_param).with(@opts, :item_id) ApiApiClientProxyTest.get_item_details @opts end it "should call make_api_call" do ApiApiClientProxyTest.should_receive(:make_api_call).with("items/42",@opts) ApiApiClientProxyTest.get_item_details @opts end end end