require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper') class MockRuleDefinition < RulesEngine::Rule::Definition end describe "RulesEngine::Rule::Definition" do it "should add a class method rule_class_name" do MockRuleDefinition.methods.should include("rule_class_name") end it "should return the rule_class_name as the rule class" do MockRuleDefinition.rule_class_name.should == "MockRuleDefinition" end it "should be able to set the attribute 'data'" do RulesEngine::Rule::Definition.new.methods.should include("data=") end describe "title" do it "should be nil by default" do RulesEngine::Rule::Definition.new.title.should be_nil end end describe "summary" do it "should be nil by default" do RulesEngine::Rule::Definition.new.summary.should be_nil end end describe "data" do it "should be nil by default" do RulesEngine::Rule::Definition.new.data.should be_nil end end describe "expected_outcomes" do it "should be set the default as NEXT" do RulesEngine::Rule::Definition.new.expected_outcomes.should be_instance_of(Array) RulesEngine::Rule::Definition.new.expected_outcomes[0][:outcome].should == RulesEngine::Rule::Outcome::NEXT RulesEngine::Rule::Definition.new.expected_outcomes[0][:workflow_code].should be_nil end end describe "valid?" do it "should be valid by default" do MockRuleDefinition.new.valid?.should be_true end end describe "errors" do it "should be a hash" do RulesEngine::Rule::Definition.new.errors.should be_instance_of(Hash) rule = RulesEngine::Rule::Definition.new end end it "should have the helper function 'before_create'" do RulesEngine::Rule::Definition.new.methods.should include("before_create") end it "should have the helper function 'before_update'" do RulesEngine::Rule::Definition.new.methods.should include("before_update") end it "should have the helper function 'before_destroy'" do RulesEngine::Rule::Definition.new.methods.should include("before_destroy") end describe "processing a rule" do it "should return a rule_outcome" do MockRuleDefinition.new.process(101, {}, {}).should be_instance_of(RulesEngine::Rule::Outcome) end it "should set the outcome to NEXT by default" do MockRuleDefinition.new.process(101, {}, {}).outcome.should == RulesEngine::Rule::Outcome::NEXT end end end