Skip to content

Instantly share code, notes, and snippets.

@Heavyblade
Created January 29, 2013 15:19
Show Gist options
  • Select an option

  • Save Heavyblade/4665023 to your computer and use it in GitHub Desktop.

Select an option

Save Heavyblade/4665023 to your computer and use it in GitHub Desktop.
current_dir = File.dirname __FILE__
require File.join(current_dir, '..', 'unit_spec_helper.rb')
require 'ostruct'
require 'clutch/model_performable'
class PerformableTestClass
include ::MongoMapper::Document
include ::Clutch::Model::Performable
def initialize
configure_perform_options
end
def authorization
::OpenStruct.new(:valid? => true)
end
end
describe Clutch::Model::Performable do
let!(:perform) {PerformableTestClass.new}
it "should include its methods on other clases" do
Clutch::Model::Performable::InstanceMethods.instance_methods.each do |method|
perform.methods.include?(method).should == true
end
end
it "should check for authentication credentials and take record if aren't valid" do
perform.stub!(:authorization => ::OpenStruct.new(:valid? => false, :errors => {:timeout => mock(:empty? => true)}))
perform.valid_auth?.should == false
perform.perform_options.valid_auth.should == true
perform.perform_options.failed_count.should == 1
end
it "should disable the perform in the case of a time out" do
perform.stub!(:authorization => ::OpenStruct.new(:valid? => false, :errors => {:timeout => mock(:empty? => true)}))
10.times do
perform.valid_auth?
end
perform.perform_options.valid_auth.should == false
perform.perform_options.failed_count.should == 0
end
it "should indicate if the base class can peform" do
perform.stub!(:authorization => ::OpenStruct.new(:valid? => true, :errors => {:timeout => mock(:empty? => true)}))
perform.can_perform?.should == true
end
it "should indicate if the base class can't peform" do
perform.stub!(:authorization => ::OpenStruct.new(:valid? => false, :errors => {:timeout => mock(:empty? => true)}))
perform.can_perform?.should == false
end
it "should be able to tell me if credentials are valid" do
perform.valid_credentials?.should == true
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment