diff --git a/db/migrate/20210825152739_remove_link_from_dashboard_actions.rb b/db/migrate/20210825152739_remove_link_from_dashboard_actions.rb new file mode 100644 index 000000000..650414b24 --- /dev/null +++ b/db/migrate/20210825152739_remove_link_from_dashboard_actions.rb @@ -0,0 +1,5 @@ +class RemoveLinkFromDashboardActions < ActiveRecord::Migration[5.2] + def change + remove_column :dashboard_actions, :link, :string + end +end diff --git a/db/schema.rb b/db/schema.rb index 0537d3c8f..755e3b417 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2021_08_11_195800) do +ActiveRecord::Schema.define(version: 2021_08_25_152739) do # These are extensions that must be enabled in order to support this database enable_extension "pg_trgm" @@ -466,7 +466,6 @@ ActiveRecord::Schema.define(version: 2021_08_11_195800) do create_table "dashboard_actions", id: :serial, force: :cascade do |t| t.string "title", limit: 80 t.text "description" - t.string "link" t.boolean "request_to_administrators", default: false t.integer "day_offset", default: 0 t.integer "required_supports", default: 0 diff --git a/lib/tasks/proposal_actions.rake b/lib/tasks/proposal_actions.rake deleted file mode 100644 index 9eb2818db..000000000 --- a/lib/tasks/proposal_actions.rake +++ /dev/null @@ -1,431 +0,0 @@ -namespace :proposal_actions do - desc "Move link attribute to links collection" - task migrate_links: :environment do - ProposalDashboardAction.where.not(link: nil).each do |action| - next if action.link.blank? - - Link.create!(label: action.title, url: action.link, linkable: action) - end - end - - desc "Simulate successful proposal" - task create_successful_proposal: :environment do - expected_supports = [ - 1049, - 596, - 273, - 208, - 97, - 74, - 148, - 116, - 83, - 62, - 42, - 20, - 36, - 40, - 44, - 38, - 45, - 17, - 15, - 15, - 10, - 28, - 22, - 32, - 26, - 15, - 16, - 21, - 26, - 25, - 14, - 12, - 11, - 18, - 27, - 27, - 22, - 119, - 103, - 65, - 79, - 140, - 96, - 102, - 96, - 65, - 42, - 39, - 108, - 380, - 424, - 302, - 233, - 98, - 88, - 78, - 149, - 202, - 137, - 135, - 48, - 52, - 90, - 47, - 120, - 83, - 55, - 29, - 38, - 51, - 64, - 105, - 27, - 17, - 8, - 13, - 16, - 118, - 105, - 69, - 136, - 85, - 50, - 32, - 32, - 34, - 38, - 24, - 23, - 34, - 16, - 41, - 22, - 13, - 17, - 44, - 98, - 52, - 42, - 38, - 12, - 7, - 14, - 14, - 25, - 20, - 21, - 10, - 10, - 11, - 22, - 44, - 28, - 9, - 35, - 30, - 24, - 22, - 91, - 41, - 34, - 42, - 23, - 21, - 18, - 18, - 19, - 21, - 58, - 31, - 30, - 24, - 38, - 32, - 20, - 372, - 520, - 178, - 85, - 150, - 562, - 212, - 110, - 50, - 49, - 53, - 69, - 134, - 78, - 42, - 62, - 76, - 141, - 101, - 196, - 209, - 196, - 211, - 165, - 181, - 361, - 736, - 325, - 194, - 194, - 126, - 122, - 143, - 186, - 339, - 169, - 97, - 125, - 120, - 152, - 88, - 27, - 45, - 23, - 35, - 39, - 53, - 40, - 23, - 26, - 22, - 20, - 30, - 18, - 22, - 15, - 50, - 42, - 23, - 11, - 94, - 113, - 115, - 122, - 159, - 184, - 173, - 211, - 161, - 144, - 115, - 99, - 80, - 77, - 123, - 355, - 338, - 226, - 201, - 70, - 47, - 117, - 116, - 61, - 79, - 284, - 607, - 565, - 541, - 347, - 265, - 204, - 158, - 127, - 110, - 173, - 137, - 92, - 135, - 95, - 104, - 131, - 106, - 103, - 85, - 81, - 46, - 58, - 88, - 108, - 85, - 78, - 52, - 39, - 21, - 33, - 50, - 57, - 53, - 32, - 263, - 162, - 89, - 142, - 70, - 48, - 39, - 26, - 19, - 25, - 24, - 36, - 48, - 48, - 26, - 19, - 40, - 1916, - 535, - 214, - 106, - 73, - 50, - 42, - 62, - 54, - 54, - 82, - 124, - 112, - 104, - 328, - 256, - 309, - 547, - 68, - 27, - 41, - 55, - 55, - 37, - 32, - 29, - 14, - 18, - 23, - 21, - 18, - 11, - 10, - 16, - 12, - 49, - 74, - 230, - 110, - 63, - 17, - 14, - 26, - 300, - 137, - 45, - 25, - 7, - 6, - 19, - 12, - 7, - 53, - 53, - 14, - 14, - 17, - 10, - 8, - 6, - 5, - 7, - 5, - 3, - 5, - 5, - 4, - 4, - 3, - 1, - 4, - 7, - 7, - 5, - 6, - 3, - 3, - 8, - 6, - 6, - 4, - 7, - 4, - 5, - 9, - 5, - 1, - 3, - 4, - 1, - 2, - 5, - 4, - 3, - 5 - ] - - votes_count = expected_supports.sum - goal_votes = Setting["votes_for_proposal_success"].to_f - cached_votes_up = 0 - - author = User.all.sample - description = "

This is an example of a successful proposal with an ideal progress.

" - proposal = Proposal.create!(author: author, - title: Faker::Lorem.sentence(word_count: 3).truncate(60), - summary: Faker::Lorem.sentence(word_count: 3), - responsible_name: Faker::Name.name, - description: description, - created_at: Time.current - expected_supports.length.days, - tag_list: "Example", - geozone: Geozone.all.sample, - terms_of_service: "1", - published_at: Time.current - expected_supports.length.days) - - expected_supports.each_with_index do |supports, day_offset| - supports = (supports * goal_votes / votes_count).ceil - cached_votes_up += supports - - supports.times do |i| - user = User.create!( - username: "user_#{proposal.id}_#{day_offset}_#{i}", - email: "user_#{proposal.id}_#{day_offset}_#{i}@consul.dev", - password: "12345678", - password_confirmation: "12345678", - confirmed_at: Time.current - expected_supports.length.days, - terms_of_service: "1", - gender: ["Male", "Female"].sample, - date_of_birth: rand((Time.current - 80.years)..(Time.current - 16.years)), - public_activity: (rand(1..100) > 30) - ) - - Vote.create!( - votable: proposal, - voter: user, - vote_flag: false, - vote_weight: 1, - created_at: proposal.published_at + day_offset.days, - updated_at: proposal.published_at + day_offset.days - ) - end - end - - Setting["proposals.successful_proposal_id"] = proposal.id - proposal.update!(cached_votes_up: cached_votes_up) - end -end diff --git a/spec/factories/proposals.rb b/spec/factories/proposals.rb index 1398bea22..925849b8d 100644 --- a/spec/factories/proposals.rb +++ b/spec/factories/proposals.rb @@ -137,7 +137,6 @@ FactoryBot.define do factory :dashboard_action, class: "Dashboard::Action" do title { Faker::Lorem.sentence[0..79].strip } description { Faker::Lorem.sentence } - link { nil } request_to_administrators { true } day_offset { 0 } required_supports { 0 } @@ -150,10 +149,6 @@ FactoryBot.define do request_to_administrators { true } end - trait :external_link do - link { Faker::Internet.url } - end - trait :inactive do active { false } end diff --git a/spec/models/dashboard/executed_action_spec.rb b/spec/models/dashboard/executed_action_spec.rb index dd6181a78..268cc6054 100644 --- a/spec/models/dashboard/executed_action_spec.rb +++ b/spec/models/dashboard/executed_action_spec.rb @@ -2,9 +2,7 @@ require "rails_helper" describe Dashboard::ExecutedAction do let(:proposal) { create :proposal } - let(:action) do - create :dashboard_action, request_to_administrators: true, link: Faker::Internet.url - end + let(:action) { create :dashboard_action, request_to_administrators: true } it "is invalid when proposal is nil" do action = build(:dashboard_executed_action, proposal: nil)