Skip to content

Commit

Permalink
Remove obsolete rake task
Browse files Browse the repository at this point in the history
After removing the community_id columns, migrating old data isn't
possible anymore.
  • Loading branch information
javierm committed Aug 7, 2018
1 parent ef1e951 commit 191a608
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 100 deletions.
24 changes: 0 additions & 24 deletions lib/tasks/communities.rake
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,4 @@ namespace :communities do
end
end
end

desc "Migrate communitable data to communitable columns"
task migrate_communitable: :environment do
(Proposal.all + Budget::Investment.all).each do |communitable|
if communitable.community_id.present?
community = Community.where(id: communitable.community_id).first

if community
community.update(
communitable_id: communitable.id,
communitable_type: communitable.class.name
)
else
warn "WARNING: The community associated to #{communitable.class.name} "\
"with ID #{communitable.id} no longer exists. "\
"Consider running `rake communities: associate_community`"
end
else
warn "WARNING: #{communitable.class.name} with ID #{communitable.id} "\
"should have an associated community. "\
"Consider running `rake communities: associate_community`"
end
end
end
end
76 changes: 0 additions & 76 deletions spec/lib/tasks/communities_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,80 +44,4 @@
end

end

describe "#migrate_communitable" do
let :run_rake_task do
Rake::Task["communities:migrate_communitable"].reenable
Rake.application.invoke_task "communities:migrate_communitable"
end

context "Associate community to Proposal" do
let(:proposal) { create(:proposal) }
let(:community) { proposal.community }

context "Community has no communitable_id" do
before { community.update(communitable_id: nil, communitable_type: nil) }

it "assigns the communitable_id" do
run_rake_task
community.reload
expect(community.communitable_id).to eq proposal.id
expect(community.communitable_type).to eq "Proposal"
end
end

context "Proposal has no community_id" do
before { proposal.update_column(:community_id, nil) }

it "writes a warning with the proposal id" do
warning = /Proposal(.+)#{proposal.id}(.+)should have an associated/
expect { run_rake_task }.to output(warning).to_stderr
end
end

context "The proposal community doesn't exist anymore" do
before { community.destroy }

it "writes a warning with the proposal id" do
warning = /community(.+)Proposal(.+)#{proposal.id}(.+)no longer exists/
expect { run_rake_task }.to output(warning).to_stderr
end
end
end

context "Associate community to Budget Investment" do
let(:investment) { create(:budget_investment) }
let(:community) { investment.community }

context "Community has no communitable_id" do
before { community.update(communitable_id: nil, communitable_type: nil) }

it "assigns the communitable_id" do
run_rake_task
community.reload
expect(community.communitable_id).to eq investment.id
expect(community.communitable_type).to eq "Budget::Investment"
end
end

context "Investment has no community_id" do
before { investment.update_column(:community_id, nil) }

it "writes a warning with the investment id" do
warning = /Investment(.+)#{investment.id}(.+)should have an associated/
expect { run_rake_task }.to output(warning).to_stderr
end
end

context "The investment community doesn't exist anymore" do
before { community.destroy }

it "writes a warning with the investment id" do
warning = /community(.+)Investment(.+)#{investment.id}(.+)no longer exists/
expect { run_rake_task }.to output(warning).to_stderr
end
end
end

end
end

0 comments on commit 191a608

Please sign in to comment.