# Rails -- NoMethodError undefined method unpack1 for nil NilClass

DevFeed: [Rails -- NoMethodError undefined method unpack1 for nil NilClass](<https://devfeed.tech/articles/rails-nomethoderror-undefined-method-unpack1-for-nil-nilclass-28257.md>)

Original publisher: [Read original article](<http://fuzzyblog.io/blog/rails/2020/01/26/rails-nomethoderror-undefined-method-unpack1-for-nil-nilclass.html>)

Author: Fuzzygroup

Published: 2020-01-26T00:00:00Z

Content type: tutorial

Language: en

Sources: [Scott Johnson](<https://devfeed.tech/sources/scott-johnson.md>)

Topics: [Rails](<https://devfeed.tech/topics/rails.md>), [test](<https://devfeed.tech/topics/test.md>), [Encryption](<https://devfeed.tech/topics/encryption.md>)

Tags: [blog](<https://devfeed.tech/tags/blog.md>), [encryption](<https://devfeed.tech/tags/encryption.md>), [environment](<https://devfeed.tech/tags/environment.md>), [errors](<https://devfeed.tech/tags/errors.md>), [process](<https://devfeed.tech/tags/process.md>), [rails](<https://devfeed.tech/tags/rails.md>), [test](<https://devfeed.tech/tags/test.md>), [tests](<https://devfeed.tech/tags/tests.md>)

## AI overview

A Rails test run fails with NoMethodError because Base64.decode64 receives nil from Rails.application.credentials.access_token_encryption_key. The article explains that the test environment credentials file must be created with EDITOR=vi rails credentials:edit --environment test.

## Source excerpt

I recently started a new application and tried running the generated tests and got this: rails test test/models/user_test.rb Running via Spring preloader in process 27379 Run options: --seed 14413 # Running: E Error: UserTest#test_can_delete_user_with_teams: NoMethodError: undefined method `unpack1' for nil:NilClass app/models/user/connected_account.rb:37:in `<class:ConnectedAccount>' app/models/user/connected_account.rb:31:in `<main>' rails test test/models/user_test.rb:57 E Error: UserTest#test_user_has_a_personal_team: NoMethodError: undefined method `unpack1' for nil:NilClass app/models/user/connected_account.rb:37:in `<class:ConnectedAccount>' app/models/user/connected_account.rb:31:in `<main>' rails test test/models/user_test.rb:52 E Error: UserTest#test_user_has_many_teams: NoMethodError: undefined method `unpack1' for nil:NilClass app/models/user/connected_account.rb:37:in `<class:ConnectedAccount>' app/models/user/connected_account.rb:31:in `<main>' rails test test/models/user_test.rb:46 Finished in 0.060465s, 49.6155 runs/s, 0.0000 assertions/s. 3 runs, 0 assertions, 0 failures, 3 errors, 0 skips Now this is the the first time I've used test (as opposed to RSpec) in more than a decade and I was more than a bit taken aback. A quick Stack Overflow led me to: The error happens if you call Base64.decode64(nil). The method however is strictly expecting a String object here. Now the line of code in question is: attr_encrypted :access_token, key: Base64.decode64(Rails.application.credentials.access_token_encryption_key) So the implication is that: Rails.application.credentials.access_token_encryption_key is returning nil. The solution is actually pretty simple - create the credentials file using: EDITOR=vi rails credentials:edit --environment test See this blog post for why you have to use EDITOR=vi.