From 6c5f73b241d3b31123fbbc61cc4acf76adae8d5e Mon Sep 17 00:00:00 2001 From: Miquel Sabaté Solà Date: Mon, 18 Mar 2024 22:20:23 +0100 Subject: thing: removed unique index on title MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Miquel Sabaté Solà --- app/models/thing.rb | 2 +- ...20240318211829_remove_uniqueness_index_on_title_things.rb | 5 +++++ db/schema.rb | 3 +-- test/models/thing_test.rb | 8 +------- test/system/things_test.rb | 12 ++++++------ 5 files changed, 14 insertions(+), 16 deletions(-) create mode 100644 db/migrate/20240318211829_remove_uniqueness_index_on_title_things.rb diff --git a/app/models/thing.rb b/app/models/thing.rb index a67d38e..01f59e9 100644 --- a/app/models/thing.rb +++ b/app/models/thing.rb @@ -1,8 +1,8 @@ # frozen_string_literal: true class Thing < ApplicationRecord - validates :title, presence: true, uniqueness: true validates :target, presence: true, uniqueness: true + validates :title, presence: true validates :authors, presence: true validates :rate, numericality: { in: 0..10 } diff --git a/db/migrate/20240318211829_remove_uniqueness_index_on_title_things.rb b/db/migrate/20240318211829_remove_uniqueness_index_on_title_things.rb new file mode 100644 index 0000000..96b5be6 --- /dev/null +++ b/db/migrate/20240318211829_remove_uniqueness_index_on_title_things.rb @@ -0,0 +1,5 @@ +class RemoveUniquenessIndexOnTitleThings < ActiveRecord::Migration[7.1] + def change + remove_index :things, :title + end +end diff --git a/db/schema.rb b/db/schema.rb index 8726291..50fae4d 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.1].define(version: 2024_03_14_211609) do +ActiveRecord::Schema[7.1].define(version: 2024_03_18_211829) do create_table "action_text_rich_texts", force: :cascade do |t| t.string "name", null: false t.text "body" @@ -108,7 +108,6 @@ ActiveRecord::Schema[7.1].define(version: 2024_03_14_211609) do t.boolean "editors", default: false t.string "where_is_it" t.index ["target"], name: "index_things_on_target", unique: true - t.index ["title"], name: "index_things_on_title", unique: true t.index ["user_id"], name: "index_things_on_user_id" end diff --git a/test/models/thing_test.rb b/test/models/thing_test.rb index 766a5e2..ef2a1e2 100644 --- a/test/models/thing_test.rb +++ b/test/models/thing_test.rb @@ -60,18 +60,12 @@ class ThingTest < ActiveSupport::TestCase thing.save! end - test 'title and target must be unique' do + test 'target must be unique' do thing = things(:thing1).dup - thing.title = 'another' assert_raise(ActiveRecord::RecordInvalid) { thing.save! } thing.target = 'also another' - thing.title = things(:thing1).title - assert_raise(ActiveRecord::RecordInvalid) { thing.save! } - - thing.target = 'also another' - thing.title = 'now for real' assert_difference('Thing.count') { thing.save! } end diff --git a/test/system/things_test.rb b/test/system/things_test.rb index 792c07f..8b25913 100644 --- a/test/system/things_test.rb +++ b/test/system/things_test.rb @@ -56,15 +56,15 @@ class ThingsTest < ApplicationSystemTestCase test 'you get feedback from wrong values for a new thing' do visit new_thing_url - fill_in I18n.t('activerecord.attributes.thing.title'), with: things(:thing1).title + fill_in I18n.t('activerecord.attributes.thing.title'), with: 'whatever title' fill_in I18n.t('activerecord.attributes.thing.authors'), with: 'author' - fill_in I18n.t('activerecord.attributes.thing.target'), with: 'identifier' + fill_in I18n.t('activerecord.attributes.thing.target'), with: things(:thing1).target fill_in I18n.t('activerecord.attributes.thing.rate'), with: 5 find("#thing_tag_ids_#{tags(:tag1).id}").click click_on I18n.t('helpers.submit.create') - assert_text "#{I18n.t('activerecord.attributes.thing.title')} " \ + assert_text "#{I18n.t('activerecord.attributes.thing.target')} " \ "#{I18n.t('errors.messages.taken')}" end @@ -87,13 +87,13 @@ class ThingsTest < ApplicationSystemTestCase assert_equal tags.map(&:id), [tags(:tag2).id] end - test 'you get feedback from wrong values for a thing' do + test 'you get feedback from wrong values when updating a thing' do visit edit_thing_url(things(:thing1)) - fill_in I18n.t('activerecord.attributes.thing.title'), with: things(:thing2).title + fill_in I18n.t('activerecord.attributes.thing.target'), with: things(:thing2).target click_on I18n.t('helpers.submit.update') - assert_text "#{I18n.t('activerecord.attributes.thing.title')} " \ + assert_text "#{I18n.t('activerecord.attributes.thing.target')} " \ "#{I18n.t('errors.messages.taken')}" end -- cgit v1.2.3