Skip to content

Instantly share code, notes, and snippets.

@brandoncordell
Created November 21, 2011 20:08
Show Gist options
  • Save brandoncordell/1383767 to your computer and use it in GitHub Desktop.
Save brandoncordell/1383767 to your computer and use it in GitHub Desktop.
to_param not working in model
# user.rb
class User
include Mongoid::Document
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
field :username
.
.
.
def to_param
username
end
end
# users.rb
FactoryGirl.define do
factory :user do
username 'jim_halpert'
email '[email protected]'
end
end
# user_spec.rb
require 'spec_helper'
describe User do
setup do
@user = Factory(:user)
end
it "should use the username as the identifier" do
@user.to_param.should == "jim_halpert"
end
end
# RESULT
#Failures:
# 1) User should use the username as the identifier
# Failure/Error: @user.to_param.should == "jim_halpert"
# expected: "jim_halpert"
# got: nil (using ==)
# # ./spec/models/user_spec.rb:9:in `block (2 levels) in <top (required)>'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment