Skip to content

Commit

Permalink
Merge pull request #194 from identity-research-lab/hotfix-codes-being…
Browse files Browse the repository at this point in the history
…-cloned-and-purged-2

HOTFIX revisit issue with categories leaking codes
  • Loading branch information
CoralineAda authored Dec 3, 2024
2 parents 48833a2 + 06488ea commit a528bb3
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion app/models/code.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class Code
validates_uniqueness_of :name, scope: :context

has_many :in, :personas, rel_class: :Experiences
has_many :in, :categories, rel_class: :CategorizedAs, dependent: :delete_orphans
has_many :in, :categories, rel_class: :CategorizedAs

# Given a context, generates a hash with each unique Codes as a key and the counts of its uses as a value.
def self.histogram(context)
Expand Down
6 changes: 3 additions & 3 deletions app/models/persona.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ class Persona
validates :name, presence: true
validates :case_id, presence: true

has_many :out, :codes, rel_class: :Experiences, dependent: :delete_orphans
has_many :out, :identities, rel_class: :IdentifiesWith, dependent: :delete_orphans
has_many :out, :keywords, rel_class: :ReflectsOn, dependent: :delete_orphans
has_many :out, :codes, rel_class: :Experiences
has_many :out, :identities, rel_class: :IdentifiesWith
has_many :out, :keywords, rel_class: :ReflectsOn

# Traverses the codes-[]-categories relationship to return a list of unique Categories.
def categories
Expand Down
4 changes: 2 additions & 2 deletions app/models/response.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def populate_codes
self.raw_codes.compact.uniq.each do |name|
if code = Code.find_or_create_by(name: name, context: context_name)
next unless code.valid?
Experiences.create(from_node: persona, to_node: code)
persona.codes << code
end
end

Expand All @@ -58,7 +58,7 @@ def populate_identities
self.raw_codes.compact.uniq.each do |name|
if identity = Identity.find_or_create_by(name: name.strip, context: context_name)
next unless identity.valid?
IdentifiesWith.create(from_node: persona, to_node: identity)
persona.identities << identity
end
end

Expand Down
4 changes: 2 additions & 2 deletions spec/models/response_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

allow(Persona).to receive(:find_or_create_by).and_return(persona)
allow(Persona).to receive(:find_or_initialize_by).and_return(persona)
allow(persona).to receive(:codes).and_return([])
allow(persona).to receive(:identities).and_return([])

allow(Identity).to receive(:find_or_create_by).and_return(identity)
allow(Identity).to receive(:reap_orphans)
Expand Down Expand Up @@ -43,14 +45,12 @@
it "creates identities" do
allow(Response).to receive(:find).and_return(response_1)
expect(Identity).to receive(:find_or_create_by).with(name: "not okay", context: "age").and_return(identity)
expect(IdentifiesWith).to receive(:create)
response_1.sync_to_graph
end

it "creates codes" do
allow(Response).to receive(:find).and_return(response_2)
expect(Code).to receive(:find_or_create_by).with(name: "just okay", context: "age"). and_return(code)
expect(Experiences).to receive(:create)
response_2.sync_to_graph
end

Expand Down

0 comments on commit a528bb3

Please sign in to comment.