-
-
Notifications
You must be signed in to change notification settings - Fork 265
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
An error occurred while Rails/UniqueValidationWithoutIndex cop #226
Comments
|
I believe this should be all you need https://pastebin.com/gSdGA2a2 |
Thank you for showing db/schema.rb.
% cat Gemfile
# frozen_string_literal: true
source "https://rubygems.org"
git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
gem "rubocop-rails"
% cat app/models/user.rb
# User of the app
class User < ApplicationRecord
attr_writer :login # Used for devise authentication by username
devise :invitable, :database_authenticatable,
:recoverable, :rememberable, :trackable, :validatable,
:confirmable, :lockable, :timeoutable, timeout_in: 2.days
belongs_to :legacy_user, foreign_key: :id, inverse_of: :user
validates :username, presence: true, uniqueness: { case_sensitive: false }
validates :username, format: { with: /^[a-zA-Z0-9_\.]*$/, multiline: true }
def login
@login || username
end
def self.find_first_by_auth_conditions(warden_conditions)
conditions = warden_conditions.dup
login = conditions.delete(:login)
if login.present?
where(conditions).find_by(["lower(username) = :value ", { value: login.downcase }])
elsif conditions[:username].nil?
find_by(conditions)
else
find_by(username: conditions[:username])
end
end
end
% cat db/schema.rb
# This file is auto-generated from the current state of the database. Instead
# of editing this file, please use the migrations feature of Active Record to
# incrementally modify your database, and then regenerate this schema definition.
#
# This file is the source Rails uses to define your schema when running `rails
# db:schema:load`. When creating a new database, `rails db:schema:load` tends to
# be faster and is potentially less error prone than running all of your
# migrations from scratch. Old migrations may fail to apply correctly if those
# migrations use external dependencies or application code.
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 2020_03_25_143346) do
create_table "users", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t|
t.string "email", default: "", null: false
t.string "username"
t.string "encrypted_password", default: "", null: false
t.string "reset_password_token"
t.datetime "reset_password_sent_at"
t.datetime "remember_created_at"
t.integer "sign_in_count", default: 0, null: false
t.datetime "current_sign_in_at"
t.datetime "last_sign_in_at"
t.string "current_sign_in_ip"
t.string "last_sign_in_ip"
t.string "confirmation_token"
t.datetime "confirmed_at"
t.datetime "confirmation_sent_at"
t.string "unconfirmed_email"
t.integer "failed_attempts", default: 0, null: false
t.string "unlock_token"
t.datetime "locked_at"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "invitation_token"
t.datetime "invitation_created_at"
t.datetime "invitation_sent_at"
t.datetime "invitation_accepted_at"
t.integer "invitation_limit"
t.string "invited_by_type"
t.bigint "invited_by_id"
t.integer "invitations_count", default: 0
t.index ["confirmation_token"], name: "index_users_on_confirmation_token", unique: true
t.index ["email"], name: "index_users_on_email"
t.index ["invitation_token"], name: "index_users_on_invitation_token", unique: true
t.index ["invitations_count"], name: "index_users_on_invitations_count"
t.index ["invited_by_id"], name: "index_users_on_invited_by_id"
t.index ["invited_by_type", "invited_by_id"], name: "index_users_on_invited_by_type_and_invited_by_id"
t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true
t.index ["unlock_token"], name: "index_users_on_unlock_token", unique: true
t.index ["username"], name: "index_users_on_username", unique: true
end
end
% bundle exec rubocop --require rubocop-rails --only Rails/ApplicationRecord
Inspecting 3 files
...
3 files inspected, no offenses detected
Also I tried replacing db/schema.rb with this full db/schema.rb, but no error occurred. |
Thank you for taking the time to fix it. It sadly isn't reproduceable on my development computer.
Did you try in the docker image (Ruby 2.6.3 docker image) ? This is where it happens, actually in BitBucket Pipeline: https://pastebin.com/g5M5F2Nq |
Just letting you know that 2.5.2 update resolved the issue ! Thank you ! :) |
@jamesst20 Yeah, I'm relieved to hear the issue is solved. Thank you too! |
Hrm I have a dependabot upgrade to rubcop-rails 2.5.2 in process and I'm getting this same error for 12 of my models.
Running with This may be a valid failure of a
Also:
|
@rylanb Can you open a new issue with an example schema.rb that reproduces the error? |
Add RSpec/StubbedMock cop
Information
Same as #216 that was closed by wrong assumption.
Error is still present:
rubocop-rails 2.5.1
Mention the following information in the issue report:
0.81.0 (using Parser 2.7.0.5, running on ruby 2.6.3 x86_64-linux)
Error
The file in error
Extra information
I am not able to replicate the issue on my PC (Mac OS Catalina). I'm guessing cloning the docker image would be enough to replicate the issue, it probably isn't BitBucket-Pipeline related.
Error happens under BitBucket-Pipeline in Ruby 2.6.3 docker image
Thank you
The text was updated successfully, but these errors were encountered: