ruby on rails 3 - Test "should get index" throughs Undefined Method error -


all, have following models defined:

class role < activerecord::base   attr_accessible :name    has_many :users    validates :name, presence: true   validates :name, uniqueness: true  end 

and

class user < activerecord::base   attr_accessible :abv, :first_name, :full_name, :last_name, :role_id    has_many :defects   belongs_to :role    validates :first_name, :last_name, :full_name, :abv, :role_id, presence: true   validates :full_name, :abv, uniqueness: true  end 

i changed view users 'index' display user.role_id field user.role.name make view more friendly! worked great! when running rake test users_controller_test through following error:

1) error: test_should_get_index(userscontrollertest): actionview::template::error: undefined method `name' nil:nilclass

after searching blog found references erasing , recreating test database worked 1 individual, , changing "should index" test in controller from

get :index 

to :index, :user.role_id => 1 #forced known value

but nothing have done has corrected test failure. missing here, issue how data in test fixtures defined, or missing core rails concept?

as always, in advance,

richard

if working associations, can fix defining reference node between 2 different fixtures.


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -