Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
j_api_agent / spec / agent_spec.rb
Size: Mime:
require "spec_helper"

describe JApiAgent::Agent do

	context "ClassMethods" do
		before(:each) do
			@test_class = Class.new
			@test_class.send :include, JApiAgent::Agent
			@test_class.job_queue(:test)
		end

		describe "#job_queue" do
			it "should set queue" do
				@test_class.job_queue(:test)
				@test_class.instance_eval { @queue }.should == :test
			end
		end

		describe "#bulk_limit" do
			it "should set bulk_limit" do
				@test_class.bulk_limit(100)
				@test_class.instance_eval { @bulk_limit }.should == 100
			end
		end

		describe "#after_delayed_block" do
			it "should not do anything if block is not specified" do
				@test_class.stub(:web_call).and_return(true)
				@test_class.instance_eval { @after_delayed_block }.should_receive(:call)
				@test_class.instance_eval { @after_delayed_block }.should_not be_nil
				@test_class.perform(:params)
			end

			it "should call the block if specified" do
				p = Proc.new {|data| data}
				@test_class.after_delayed(&p)

				@test_class.stub(:web_call).and_return(true)
				@test_class.instance_eval { @after_delayed_block }.should_receive(:call)
				@test_class.instance_eval { @after_delayed_block }.should == p
				@test_class.perform(:params)
			end
		end

		describe "#delayed_batch" do
			before do
    		ResqueSpec.reset!
  		end

			it "should enqueue multiple bulk web api calls with the bulk_limit" do
				bulk_param_name = :screen_name
				bulk_list = ['test1','test2','test3']
				bulk_other_param = {:page => 3}
				@test_class.bulk_limit 2
				@test_class.batch(:delayed, :screen_name, bulk_list,bulk_other_param)

 				@test_class.should have_queued({:page=>3, :screen_name => 'test1,test2'})
 				@test_class.should have_queued({:page=>3, :screen_name => 'test3'})
 				@test_class.should have_queue_size_of(2)
			end
		end
	end
end