Created
November 21, 2011 20:08
-
-
Save brandoncordell/1383767 to your computer and use it in GitHub Desktop.
to_param not working in model
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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