前提・実現したいこと
テストのエラーを、なくしたいです。
RailsTutorialの特性上、テストが全てエラーのままであると非常に厄介であるので、解決したいと思っています。
RailsTutorialを学習中の初心者です。
現在、7章の
7.4.3 実際のユーザー登録
という所まで来ています。そこで
rails db:migrate:reset
というコマンドを実行しました。
そして実行後、実際にユーザも登録できました。
User.first User Load (0.2ms) SELECT "users".* FROM "users" ORDER BY "users"."id" ASC LIMIT ? [["LIMIT", 1]] => #<User id: 1, name: "Rails Tutorial", email: "example@railstutorial.org", created_at: "2018-08-02 14:56:26", updated_at: "2018-08-02 14:56:26", password_digest: "$2a$10$5QA/jI9yjcjDFuRXoWVadeOxt5UzJzcdU9qJQKWrI.l...">
View上のエラーも確認できません。
しかし、テストが、
「全て」
エラーになります。
rails db:migrate:reset
これを実行するまでは、全てのテストがGREENでした。
発生している問題・エラーメッセージ
テストが全てエラーになります。
#※全てのテストにおいて、同様のエラーメッセージが表示されています。 ActiveRecord::RecordNotUnique: #ActiveRecord::~が2つ表示されていますが、コピペミスではないです。 ActiveRecord::RecordNotUnique: SQLite3::ConstraintException: column email is not unique: INSERT INTO "users" ("name", "email", "created_at", "updated_at", "id") VALUES ('MyString', 'MyString', '2018-08-03 14:51:53.610280', '2018-08-03 14:51:53.610280', 298486374)
該当のソースコード
test "password should be present (nonblank)" do @user.password = @user.password_confirmation = " " * 6 assert_not @user.valid? end test "password should have a minimum length" do @user.password = @user.password_confirmation = "a" * 5 assert_not @user.valid? end
などのテストと
class User < ApplicationRecord before_save { self.email = email.downcase } validates :name, presence: true, length: { maximum: 50 } validates :email, presence: true, length: { maximum: 255 }, format: { with: /\A[\w+\-.]+@[a-z\d\-.]+.[a-z]+\z/i }, uniqueness: { case_sensitive: false } validates :password, presence: true, length: { minimum: 6 } has_secure_password end
試したこと
user.rbのemaiのvalidateを書き換えたりしましたが何も変わっていません
補足情報(FW/ツールのバージョンなど)
Cloud9
Rails 5.2.0
Ruby 2.4.1p111
よろしくお願いします。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/08/04 04:50
2018/08/04 07:26