ruby on rails - `Assigns` isn't working in my integration test -
i'm trying write test following suggestion on https://stackoverflow.com/a/17002140/4499505.
my simplified test:
test "test"   log_in_as(@user)   users_path   assert_template 'users/index'   assigns[:users].each      assert_select 'a[href=?]', users_path(user)   end end the error result:
nomethoderror: undefined method `each' nil:nilclass the controller method:
  def index     @users_grid = initialize_grid(user.where(verified: true),       per_page:        15,       order:           'users.username',       order_direction: 'desc')   end apparantly assigns[:users] empty though there users in fixtures file. doing wrong? understand assigns[:users] should assign exact same users shown on users/index, want.
well, correct code :
test "test"   log_in_as(@user)   users_path   assert_template 'users/index'   # in controller have instance var    # @users_gird, not @users.   assigns[:users_grid].each      assert_select 'a[href=?]', users_path(@user)   end end assigns hash, accessible within rails tests, containing instance variables available view @ point. it’s accessor allows attribute symbol (since, historically, assigns hash’s keys strings). in other words, assigns(:contact) same assigns["contact"].
Comments
Post a Comment