Skip to content

Commit

Permalink
refactor: update after second review
Browse files Browse the repository at this point in the history
  • Loading branch information
Stef-Rousset committed May 23, 2024
1 parent 09373ac commit 78b4edc
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,8 @@ def run_after_hooks

return if space.respond_to?("is_transparent") && space.is_transparent?

user = Decidim::User.find(resource.decidim_user_id)
ids = []
follows = Decidim::Follow.where(user:)
follows = Decidim::Follow.where(user: resource.decidim_user_id)
ids << find_space_follow_id(follows, resource, space)
ids << find_children_follows_ids(follows, space)
follows.where(id: ids.flatten).destroy_all if ids.present?
Expand All @@ -38,9 +37,11 @@ def find_space_follow_id(follows, resource, space)
end

def find_children_follows_ids(follows, space)
follows.select { |follow| find_object_followed(follow).respond_to?("decidim_component_id") }
.select { |follow| space.components.ids.include?(find_object_followed(follow).decidim_component_id) }
&.map(&:id)
follows.map do |follow|
object = find_object_followed(follow) || nil
next unless object.respond_to?("decidim_component_id")
return follow.id if space.components.ids.include?(object.decidim_component_id)
end
end

def find_object_followed(follow)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,9 @@ module Decidim::Admin

it "destroys the follow" do
expect(Decidim::Follow.where(user: normal_user).count).to eq(1)
subject.call
expect(Decidim::Follow.where(user: normal_user).count).to eq(0)
expect do
subject.call
end.to change(Decidim::Follow, :count).by(-1)
end

context "and user follows meeting belonging to assembly" do
Expand All @@ -61,8 +62,9 @@ module Decidim::Admin
component: meetings_component, author: user)
create(:follow, followable: meeting, user: normal_user)
expect(Decidim::Follow.where(user: normal_user).count).to eq(2)
subject.call
expect(Decidim::Follow.where(user: normal_user).count).to eq(0)
expect do
subject.call
end.to change(Decidim::Follow, :count).by(-2)
end
end
end
Expand Down

0 comments on commit 78b4edc

Please sign in to comment.