Skip to content

Instantly share code, notes, and snippets.

@nikonoid
Created July 31, 2008 05:22
Show Gist options
  • Save nikonoid/3412 to your computer and use it in GitHub Desktop.
Save nikonoid/3412 to your computer and use it in GitHub Desktop.
require File.dirname(__FILE__) + '/../spec_helper'
require File.dirname(__FILE__) + '/../../app/models/notifications'
class Notifications
def self.spec_new(method_name,*parameters)
n = self.allocate
n.__send__ :initialize_defaults, method_name
n.__send__(method_name, *parameters)
return n
end
def iv(name)
instance_variable_get("@#{name}")
end
end
describe ::Notifications do
describe "recruitment model" do
before(:each) do
#require 'ruby-debug'
@valid_param_hash =
{
'firstname' => "fakeous",
'preferredname' => "fake",
'surname' => "user",
"recruitment" => "some BS stuff"
}
@from = 'hr@rsp.com.au'
end
it "should have valid attributes after induction_memo call" do
#TODO mock out Notifications lookup from the below n.should_receive(:lookup)...
@n = Notifications.spec_new(:induction_memo,@valid_param_hash)
@n.iv(:body)["recruitment"].should == @valid_param_hash
@n.iv(:recipients).should == @n.lookup('induction memo recipients')
@n.iv(:from).should == @from
end
it "should have valid attributes after notification_for_resourcing call" do
#TODO mock out Notifications lookup from the below n.should_receive(:lookup)...
@n = Notifications.spec_new(:notification_for_resourcing,@valid_param_hash)
@n.iv(:body)["recruitment"].should == @valid_param_hash
@n.iv(:recipients).should == @n.lookup('resourcing recipients')
@n.iv(:from).should == @from
end
it "should have valid attributes after notification_for_resourcing call" do
#TODO mock out Notifications lookup from the below n.should_receive(:lookup)...
@n = Notifications.spec_new(:notification_for_resourcing,@valid_param_hash)
@n.iv(:body)["recruitment"].should == @valid_param_hash
@n.iv(:recipients).should == @n.lookup('resourcing recipients')
@n.iv(:from).should == @from
end
end
describe "purchase model" do
before(:each) do
#require 'ruby-debug'
@valid_param_hash =
{
'supplier' => "supplier X",
'price' => '10'
}
Notifications.stub!(:render_message).and_return(true)
end
it "should have a mail subject that contains supplier and price" do
@n = Notifications.spec_new(:purchase,@valid_param_hash)
@n.iv(:subject).should == /@valid_param_hash['supplier']/
@n.iv(:subject).should == /@valid_param_hash['price']/
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment