diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index 0d6fddf6c..80c5056c2 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -3,7 +3,9 @@ require "knapsack_pro" require "simplecov" require "simplecov_json_formatter" -SimpleCov.formatter = SimpleCov::Formatter::JSONFormatter +if ENV["CI"] + SimpleCov.formatter = SimpleCov::Formatter::JSONFormatter +end KnapsackPro::Adapters::RSpecAdapter.bind KnapsackPro::Hooks::Queue.before_queue do |_queue_id| SimpleCov.command_name("rspec_ci_node_#{KnapsackPro::Config::Env.ci_node_index}") @@ -24,6 +26,9 @@ require File.expand_path("../config/environment", __dir__) require "rspec/rails" abort("The Rails environment is running in production mode!") if Rails.env.production? +Rake.application = Rake::Application.new +Rails.application.load_tasks + # Add additional requires below this line. Rails is not loaded until this point! require "fakeredis/rspec" @@ -83,7 +88,7 @@ Browser::Bot.matchers.delete(Browser::Bot::EmptyUserAgentMatcher) RSpec.configure do |config| config.use_transactional_fixtures = true - config.fixture_path = "#{::Rails.root}/spec/fixtures" + config.fixture_path = Rails.root.join("spec/fixtures") config.include ActionMailer::TestHelper config.include ApplicationHelper diff --git a/spec/tasks/add_navigation_links_spec.rb b/spec/tasks/add_navigation_links_spec.rb index 4b603ee13..6182688e5 100644 --- a/spec/tasks/add_navigation_links_spec.rb +++ b/spec/tasks/add_navigation_links_spec.rb @@ -2,28 +2,20 @@ require "rails_helper" RSpec.describe "Navigation Links tasks", type: :task do before do - Rake::Task.clear - PracticalDeveloper::Application.load_tasks + Rake.application["navigation_links:create"].reenable + + %w[home readinglist contact code_of_conduct privacy terms].each do |page| + Rake.application["navigation_links:find_or_create:#{page}"].reenable + end end - describe "#create" do - it "creates navigation links for new forem if nonexistent" do - expect { Rake::Task["navigation_links:create"].invoke }.to change(NavigationLink, :count).by(6) - end + it "creates navigation links for new forem if nonexistent" do + expect { Rake::Task["navigation_links:create"].invoke }.to change(NavigationLink, :count).by(6) + end - context "when navigation links exist" do - before do - NavigationLink.destroy_all - create(:navigation_link, - name: "Reading List", - url: URL.url("readinglist"), - display_to: :logged_in, - position: 0) - end + it "does not create nav links if they already exist" do + create(:navigation_link, name: "Reading List", url: URL.url("readinglist"), display_to: :logged_in, position: 0) - it "does not create nav links if they already exist" do - expect { Rake::Task["navigation_links:create"].invoke }.to change(NavigationLink, :count).from(1).to(6) - end - end + expect { Rake::Task["navigation_links:create"].invoke }.to change(NavigationLink, :count).from(1).to(6) end end diff --git a/spec/tasks/fastly_spec.rb b/spec/tasks/fastly_spec.rb index c0726be3e..e9ea9f0b4 100644 --- a/spec/tasks/fastly_spec.rb +++ b/spec/tasks/fastly_spec.rb @@ -2,20 +2,35 @@ require "rails_helper" RSpec.describe "Fastly tasks", type: :task do before do - Rake::Task.clear - PracticalDeveloper::Application.load_tasks + Rake.application["fastly:update_configs"].reenable + allow(FastlyConfig::Update).to receive(:call) end describe "#update_configs" do it "doesn't run if Fastly isn't configured" do - %w[FASTLY_API_KEY FASTLY_SERVICE_ID].each do |var| - allow(ApplicationConfig).to receive(:[]).with(var).and_return(nil) - end - allow(FastlyConfig::Update).to receive(:call) + allow(ApplicationConfig).to receive(:[]).with("FASTLY_API_KEY").and_return(nil) + allow(ApplicationConfig).to receive(:[]).with("FASTLY_SERVICE_ID").and_return(nil) Rake::Task["fastly:update_configs"].invoke expect(FastlyConfig::Update).not_to have_received(:call) end + + it "doesn't run if SKIP_FASTLY_CONFIG_UPDATE is set" do + allow(ENV).to receive(:[]).with("SKIP_FASTLY_CONFIG_UPDATE").and_return("true") + + Rake::Task["fastly:update_configs"].invoke + + expect(FastlyConfig::Update).not_to have_received(:call) + end + + it "does run if Fastly is configured" do + allow(ApplicationConfig).to receive(:[]).with("FASTLY_API_KEY").and_return("123") + allow(ApplicationConfig).to receive(:[]).with("FASTLY_SERVICE_ID").and_return("123") + + Rake::Task["fastly:update_configs"].invoke + + expect(FastlyConfig::Update).to have_received(:call) + end end end diff --git a/spec/tasks/metrics_spec.rb b/spec/tasks/metrics_spec.rb index 7116c3fa4..31a3f2653 100644 --- a/spec/tasks/metrics_spec.rb +++ b/spec/tasks/metrics_spec.rb @@ -1,10 +1,7 @@ require "rails_helper" RSpec.describe "Metrics Overview task", type: :task do - before do - Rake::Task.clear - PracticalDeveloper::Application.load_tasks - end + before { Rake.application["fastly:update_configs"].reenable } describe "#overview" do let(:event_name) { "Admin Overview Link Clicked" }