Skip to content

Commit

Permalink
Ticket CV2-5653 [WIP]: Fixing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
caiosba committed Nov 23, 2024
1 parent b5d9370 commit 5da8e26
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
3 changes: 2 additions & 1 deletion app/models/relationship.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ class Relationship < ApplicationRecord
validate :cant_be_related_to_itself
validates :relationship_type, uniqueness: { scope: [:source_id, :target_id], message: :already_exists }, on: :create

before_create :point_targets_to_new_source
before_create :destroy_same_suggested_item, if: proc { |r| r.is_confirmed? }
after_create :move_to_same_project_as_main, prepend: true
after_create :point_targets_to_new_source, :update_counters, prepend: true
after_create :update_counters, prepend: true
after_update :reset_counters, prepend: true
after_update :propagate_inversion
after_save :turn_off_unmatched_field, if: proc { |r| r.is_confirmed? || r.is_suggested? }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ def up
$$ LANGUAGE plpgsql;
SQL

# Attach the trigger to the table
# Attach the trigger to the table (only on INSERT - we shouldn't have it for UPDATE since we need to support reverting a relationship
execute <<~SQL
CREATE TRIGGER enforce_relationships
BEFORE INSERT OR UPDATE ON relationships
BEFORE INSERT ON relationships
FOR EACH ROW
EXECUTE FUNCTION validate_relationships();
SQL
Expand Down
4 changes: 2 additions & 2 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@
t.jsonb "value_json", default: "{}"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index "dynamic_annotation_fields_value(field_name, value)", name: "dynamic_annotation_fields_value", where: "((field_name)::text = ANY (ARRAY[('external_id'::character varying)::text, ('smooch_user_id'::character varying)::text, ('verification_status_status'::character varying)::text]))"
t.index "dynamic_annotation_fields_value(field_name, value)", name: "dynamic_annotation_fields_value", where: "((field_name)::text = ANY ((ARRAY['external_id'::character varying, 'smooch_user_id'::character varying, 'verification_status_status'::character varying])::text[]))"
t.index ["annotation_id", "field_name"], name: "index_dynamic_annotation_fields_on_annotation_id_and_field_name"
t.index ["annotation_id"], name: "index_dynamic_annotation_fields_on_annotation_id"
t.index ["annotation_type"], name: "index_dynamic_annotation_fields_on_annotation_type"
Expand Down Expand Up @@ -984,6 +984,6 @@
add_foreign_key "requests", "feeds"

create_trigger :enforce_relationships, sql_definition: <<-SQL
CREATE TRIGGER enforce_relationships BEFORE INSERT OR UPDATE ON public.relationships FOR EACH ROW EXECUTE PROCEDURE validate_relationships()
CREATE TRIGGER enforce_relationships BEFORE INSERT ON public.relationships FOR EACH ROW EXECUTE PROCEDURE validate_relationships()
SQL
end

0 comments on commit 5da8e26

Please sign in to comment.