We will first write a method lower_case
that will down case the name and then write its unit test.
Create a method lower_case
in the model employee.rb
. This method will down case the name of the employee:
class Employee include Rhom::PropertyBag belongs_to :company_id, 'Company' # Uncomment the following line to enable sync with Employee. enable :sync def lower_name self.name.downcase end end
Now, we will write a unit test case for the method lower_name
:
describe "Employee" do before :each do Employee.delete_all Employee.create "name" => "John", "company"=>"1" ,"age" => "23","gender" => "male", "salary"=>"20000" end it "should lower case name" do Employee.find(:all)[0].name.should == "John" Employee.find(:all)[0].lower_name.should == "john" end end
The Rhodes application interacts with the database and, as a result, your tests will need a database to interact with as well. So...