環境
rails 5.0.7
ruby 2.5.1
devise
Circleci 2
エラー
CircleCi
1) CommentsController POST #create log in count up comment Failure/Error: let(:user) { create(:user) } ActiveRecord::StatementInvalid: Mysql2::Error: Incorrect string value: '\xE6\xB1\xA0\xE7\x94\xB0' for column 'username' at row 1: INSERT INTO `users` (`email`, `encrypted_password`, `created_at`, `updated_at`, `username`) VALUES ('signe.strosin@yahoo.com', '$2a$04$JZLxPZ0ag.9HfZZ3nOVTGufAh8SShRjtwbv/X9JSUJITECSU4PXjm', '2020-03-05 15:13:26', '2020-03-05 15:13:26', '池田') # ./spec/controllers/comments_controller_spec.rb:6:in `block (2 levels) in <top (required)>' # ./spec/controllers/comments_controller_spec.rb:13:in `block (4 levels) in <top (required)>' # ------------------ # --- Caused by: --- # Mysql2::Error: # Incorrect string value: '\xE6\xB1\xA0\xE7\x94\xB0' for column 'username' at row 1 # ./spec/controllers/comments_controller_spec.rb:6:in `block (2 levels) in <top (required)>'
こちらはローカルでbundle exec rspecを実行した時は正常にパスするのですが、ci時にはテストに失敗しているという状況です。
同じエラーがusernameを使用しているところ全てに出ております。
コード
circleci/config.yml
version: 2 # use CircleCI 2.0 jobs: # a collection of steps build: # runs not using Workflows must have a `build` job as entry point parallelism: 3 # run three instances of this job in parallel docker: # run the steps with Docker - image: circleci/ruby:2.5.1-node-browsers # ...with this image as the primary container; this is where all `steps` will run environment: # environment variables for primary container BUNDLE_JOBS: 3 BUNDLE_RETRY: 3 BUNDLE_PATH: vendor/bundle RAILS_ENV: test - image: circleci/mysql:5.6 environment: MYSQL_ALLOW_EMPTY_PASSWORD: true MYSQL_ROOT_PASSWORD: '' MYSQL_DATABASE: circle_test MYSQL_HOST: 127.0.0.1 MYSQL_ROOT_HOST: '%' MYSQL_USER: root steps: # a collection of executable commands - checkout # special step to check out source code to working directory # Which version of bundler? - run: name: Which bundler? command: bundle -v # Restore bundle cache # Read about caching dependencies: https://circleci.com/docs/2.0/caching/ - restore_cache: keys: - rails-demo-bundle-v2-{{ checksum "Gemfile.lock" }} - rails-demo-bundle-v2- - run: # Install Ruby dependencies name: Bundle Install command: bundle check --path vendor/bundle || bundle install --deployment # Store bundle cache for Ruby dependencies - save_cache: key: rails-demo-bundle-v2-{{ checksum "Gemfile.lock" }} paths: - vendor/bundle - run: name: Yarn Install command: yarn install --cache-folder ~/.cache/yarn # Store yarn / webpacker cache - save_cache: key: rails-demo-yarn-{{ checksum "yarn.lock" }} paths: - ~/.cache/yarn - run: name: Wait for DB command: dockerize -wait tcp://127.0.0.1:3306 -timeout 120s - run: bundle exec rake db:create - run: bundle exec rake db:schema:load - run: name: Run rspec in parallel command: bundle exec rspec # Save test results for timing analysis - store_test_results: # Upload test results for display in Test Summary: https://circleci.com/docs/2.0/collect-test-data/ path: test_results # See https://circleci.com/docs/2.0/deployment-integrations/ for example deploy configs
database.yml
default: &default adapter: mysql2 encoding: utf8 pool: 5 username: root password: password socket: /tmp/mysql.sock development: <<: *default database: app_development host: db # Warning: The database defined as "test" will be erased and # re-generated from your development database when you run "rake". # Do not set this db to the same as development or production. test: adapter: mysql2 encoding: utf8 pool: 5 username: 'root' port: 3306 host: '127.0.0.1' database: app_test
spec/factories/users.rb
ruby
1FactoryBot.define do 2 factory :user do 3 password = Faker::Internet.password(min_length: 8) 4 username { Faker::Name.last_name } 5 password { password } 6 password_confirmation { password } 7 image { '' } 8 email { Faker::Internet.free_email } 9 end 10end
rspecのテストは全てusernameでエラーが起きているようです。
エラー自体は文字コードUTF8の設定で起きるというような記事がいくつもヒットしたのですが、私のようにci時にのみエラーが発生している状況というのが解決できない状態です。
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。