Skip to content

Commit

Permalink
CV2-4869 investigate empty clusters (#1962)
Browse files Browse the repository at this point in the history
* CV2-4896: add null constrain to Cluster

* CV2-4869: skip update cluster with null center

* CV2-4869: fix tests

* CV2-4869: fix tests
  • Loading branch information
melsawy authored Jul 22, 2024
1 parent 795080b commit 00add5d
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 12 deletions.
5 changes: 5 additions & 0 deletions db/migrate/20240719183518_add_null_constraints_to_cluster.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddNullConstraintsToCluster < ActiveRecord::Migration[6.1]
def change
change_column_null(:clusters, :project_media_id, false)
end
end
4 changes: 2 additions & 2 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 2024_04_20_104318) do
ActiveRecord::Schema.define(version: 2024_07_19_183518) do

# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
Expand Down Expand Up @@ -233,7 +233,7 @@
end

create_table "clusters", force: :cascade do |t|
t.integer "project_media_id"
t.integer "project_media_id", null: false
t.datetime "first_item_at"
t.datetime "last_item_at"
t.datetime "created_at", null: false
Expand Down
1 change: 1 addition & 0 deletions lib/sample_data.rb
Original file line number Diff line number Diff line change
Expand Up @@ -874,6 +874,7 @@ def create_tipline_request(options = {})
end

def create_cluster(options = {})
options[:project_media] = create_project_media if options[:project_media].blank?
team = options[:project_media]&.team || create_team
options[:feed] = options[:feed] || create_feed({ team: team })
c = Cluster.new
Expand Down
6 changes: 5 additions & 1 deletion lib/tasks/check_khousheh.rake
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,11 @@ namespace :check do
cluster_title = cluster_center == pm.id ? pm.title : cluster.title
updated_cluster_attributes[:title] = cluster_title
# Update cluster
cluster_items[cluster.id] = updated_cluster_attributes
if updated_cluster_attributes[:project_media_id].blank?
error_logs << {Cluster: "Failed to update Cluster with id #{cluster.id}"}
else
cluster_items[cluster.id] = updated_cluster_attributes
end
end
end
# Bulk-update Cluster
Expand Down
6 changes: 2 additions & 4 deletions test/controllers/graphql_controller_12_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -345,8 +345,7 @@ def teardown
pm2 = create_project_media team: t
f = create_feed team: @t
f.teams << t
c = create_cluster feed: f, team_ids: [t.id], project_media_id: pm1.id
create_cluster_project_media cluster: c, project_media: pm1
c = create_cluster feed: f, team_ids: [t.id], project_media: pm1
create_cluster_project_media cluster: c, project_media: pm2
assert_equal 0, @t.project_medias.count

Expand All @@ -365,8 +364,7 @@ def teardown
pm2 = create_project_media team: t
f = create_feed team: @t
f.teams << t
c = create_cluster feed: f, team_ids: [t.id], project_media_id: pm1.id
create_cluster_project_media cluster: c, project_media: pm1
c = create_cluster feed: f, team_ids: [t.id], project_media: pm1
create_cluster_project_media cluster: c, project_media: pm2
assert_equal 1, @t.project_medias.count

Expand Down
4 changes: 3 additions & 1 deletion test/models/cluster_project_media_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ def setup
end

test "should create cluster project media" do
c = create_cluster
pm = create_project_media
assert_difference 'ClusterProjectMedia.count' do
create_cluster_project_media
create_cluster_project_media cluster: c, project_media: pm
end
end

Expand Down
9 changes: 5 additions & 4 deletions test/models/cluster_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@ def setup
end

test "should have items" do
c = create_cluster
pm = create_project_media
c = create_cluster project_media: pm
pm1 = create_project_media cluster: c
pm2 = create_project_media cluster: c
assert_equal [pm1, pm2].sort, c.reload.items.sort
assert_equal [pm, pm1, pm2].sort, c.reload.items.sort
end

test "should access cluster" do
Expand Down Expand Up @@ -69,8 +70,8 @@ def setup

test "should return size" do
c = create_cluster
assert_equal 0, c.size
c.project_medias << create_project_media
assert_equal 1, c.size
c.project_medias << create_project_media
assert_equal 2, c.size
end
end

0 comments on commit 00add5d

Please sign in to comment.