Skip to content

Instantly share code, notes, and snippets.

@kylewelsby
Created October 18, 2012 18:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save kylewelsby/3913805 to your computer and use it in GitHub Desktop.
Save kylewelsby/3913805 to your computer and use it in GitHub Desktop.
Example for NWRUG visitor
require 'rspec'
class Risk
def code(user)
user_site = user.site[0..1]
if department
department_name = department.name[0..1]
end
[user_site,department_name,"001"].compact.join('-').upcase
end
# def department
# Department.new()
# sleep 10
# end
end
# class Department
# def initialize
# sleep 10
# end
# def name
# end
# end
describe Risk do
let(:current_user) {mock "User", :site => "Atherton"}
let(:department) {mock "Department", :name => "All Departments"}
describe ".code" do
context "with department" do
it "returns AT-AL-0001" do
subject.stub(:department).and_return(department)
subject.code(current_user).should eql "AT-AL-001"
end
end
context "without department" do
it "returns AT-001" do
subject.stub(:department)
subject.code(current_user).should eql "AT-001"
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment