Add rake task to load sdg
This task should be useful for existing installations that are going to upgrade the app and want to load SDG data into an already existing database.
This commit is contained in:
committed by
Javi Martín
parent
cbe84450ac
commit
c7c8309ad1
@@ -1,5 +1,11 @@
|
|||||||
namespace :consul do
|
namespace :consul do
|
||||||
desc "Runs tasks needed to upgrade to the latest version"
|
desc "Runs tasks needed to upgrade to the latest version"
|
||||||
task execute_release_tasks: ["settings:rename_setting_keys",
|
task execute_release_tasks: ["settings:rename_setting_keys",
|
||||||
"settings:add_new_settings"]
|
"settings:add_new_settings",
|
||||||
|
"execute_release_1.3.0_tasks"]
|
||||||
|
|
||||||
|
desc "Runs tasks needed to upgrade from 1.2.0 to 1.3.0"
|
||||||
|
task "execute_release_1.3.0_tasks": [
|
||||||
|
"db:load_sdg"
|
||||||
|
]
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -4,4 +4,10 @@ namespace :db do
|
|||||||
@avoid_log = args[:print_log] == "avoid_log"
|
@avoid_log = args[:print_log] == "avoid_log"
|
||||||
load(Rails.root.join("db", "dev_seeds.rb"))
|
load(Rails.root.join("db", "dev_seeds.rb"))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
desc "Load SDG content into database"
|
||||||
|
task load_sdg: :environment do
|
||||||
|
ApplicationLogger.new.info "Adding Sustainable Development Goals content"
|
||||||
|
load(Rails.root.join("db", "sdg.rb"))
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
28
spec/lib/tasks/load_sdg_spec.rb
Normal file
28
spec/lib/tasks/load_sdg_spec.rb
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
require "rails_helper"
|
||||||
|
|
||||||
|
describe "rake db:load_sdg" do
|
||||||
|
before { Rake::Task["db:load_sdg"].reenable }
|
||||||
|
|
||||||
|
let :run_rake_task do
|
||||||
|
Rake.application.invoke_task("db:load_sdg")
|
||||||
|
end
|
||||||
|
|
||||||
|
it "populates empty databases correctly" do
|
||||||
|
SDG::Goal.destroy_all
|
||||||
|
|
||||||
|
run_rake_task
|
||||||
|
|
||||||
|
expect(SDG::Goal.count).to eq 17
|
||||||
|
end
|
||||||
|
|
||||||
|
it "does not create additional records on populated databases" do
|
||||||
|
expect(SDG::Goal.count).to eq 17
|
||||||
|
|
||||||
|
goal_id = SDG::Goal.last.id
|
||||||
|
|
||||||
|
run_rake_task
|
||||||
|
|
||||||
|
expect(SDG::Goal.count).to eq 17
|
||||||
|
expect(SDG::Goal.last.id).to eq goal_id
|
||||||
|
end
|
||||||
|
end
|
||||||
Reference in New Issue
Block a user