Reputation: 21
I'm following along with Michael Hartl's Ruby on Rails Tutorial. I've completed the tutorial, but now when I try to run the command
bundle exec rspec spec/
I get a whole bunch of Encoding::UndefinedConversionErrors. Here's an example:
101) Authentication AuthenticationPages signin with valid information followed by signout
Failure/Error: let(:user) { FactoryGirl.create(:user) }
ActiveRecord::StatementInvalid:
Encoding::UndefinedConversionError: "\xDC" from ASCII-8BIT to UTF-8: INSERT INTO "users" ("created_at", "email", "name", "password_digest", "remember_token", "updated_at") VALUES (?, ?, ?, ?, ?, ?)
# ./spec/requests/authentication_pages_spec.rb:33:in `block (5 levels) in <top (required)>'
# ./spec/requests/authentication_pages_spec.rb:34:in `block (5 levels) in <top (required)>'
I've searched similar problems on Stack Overflow, but the problems involved file I/O, so the solutions there didn't really apply to my problem. I've done some reading of the test.log file after running rspec, and I got a hint that it could have something to do with the way my data is being uploaded to the server, some kind of weird conversion error going on there.
Here is what I have in database.yml to define my test database:
test:
adapter: sqlite3
database: db/test.sqlite3
pool: 5
timeout: 5000
encoding: UTF8
I'm running Rails 4.0.0, Ruby 2.0.0 and using an sqlite3 database. The sqlite gem I have in my Gemfile is: gem 'sqlite3', '1.3.8'
. The gem in my Gemfile for rspec is the following: gem 'rspec-rails', '2.13.1'
.
Essentially, I'm trying to figure out why these errors are occurring and how to make them stop happening, and I'm not really sure about either.
EDIT: Here are the contents of my factories.rb file:
#encoding: utf-8
FactoryGirl.define do
factory :user do
sequence(:name) { |n| "Person #{n}" }
sequence(:email) { |n| "person_#{n}@example.com" }
password "foobar"
password_confirmation"foobar"
factory :admin do
admin true
end
end
factory :micropost do
content "Lorem ipsum"
user
end
end
I've also noticed that my development.sqlite3 and test.sqlite3 had some ASCII characters in it. Using Notepad++, I tried to re-encode the documents as UTF-8, but then I got an error that required I reset and re-migrate my database. After I did all that, the development and test SQLITE3 files were back to containing ASCII characters. I'm not sure if that could have something to do with it.
Upvotes: 2
Views: 1488
Reputation: 5154
You get this error because you're trying to put ASCII-8BIT character to UTF-8 encoded database. Did you change something in you user factory file? Any special characters eg. 'Ü' are there? Try to put on top of your factory file:
#encoding: utf-8
Upvotes: 1