From 80080e0cf1b8fba1851fd52eabb3507d8e9e5254 Mon Sep 17 00:00:00 2001 From: Angus McLeod Date: Mon, 23 Nov 2020 11:40:46 +1100 Subject: [PATCH] Use dynamic time in after_time tests --- spec/components/custom_wizard/template_spec.rb | 13 +++++-------- spec/components/custom_wizard/validator_spec.rb | 12 +++--------- spec/components/custom_wizard/wizard_spec.rb | 10 ++-------- spec/fixtures/wizard/after_time.json | 4 ---- spec/jobs/clear_after_time_wizard_spec.rb | 9 ++------- spec/jobs/set_after_time_wizard_spec.rb | 9 ++------- 6 files changed, 14 insertions(+), 43 deletions(-) delete mode 100644 spec/fixtures/wizard/after_time.json diff --git a/spec/components/custom_wizard/template_spec.rb b/spec/components/custom_wizard/template_spec.rb index 594009a8..2ccdb3c9 100644 --- a/spec/components/custom_wizard/template_spec.rb +++ b/spec/components/custom_wizard/template_spec.rb @@ -13,11 +13,6 @@ describe CustomWizard::Template do "#{Rails.root}/plugins/discourse-custom-wizard/spec/fixtures/wizard/permitted.json" ).read) } - let(:after_time) { - JSON.parse(File.open( - "#{Rails.root}/plugins/discourse-custom-wizard/spec/fixtures/wizard/after_time.json" - ).read).with_indifferent_access - } before do CustomWizard::Template.save(template_json, skip_jobs: true) @@ -88,13 +83,15 @@ describe CustomWizard::Template do context "after time setting" do before do freeze_time Time.now + @scheduled_time = (Time.now + 3.hours).iso8601 + @after_time_template = template_json.dup - @after_time_template["after_time"] = after_time['after_time'] - @after_time_template["after_time_scheduled"] = after_time['after_time_scheduled'] + @after_time_template["after_time"] = true + @after_time_template["after_time_scheduled"] = @scheduled_time end it 'if enabled queues jobs after wizard is saved' do - expect_enqueued_with(job: :set_after_time_wizard, at: Time.parse(after_time['after_time_scheduled']).utc) do + expect_enqueued_with(job: :set_after_time_wizard, at: Time.parse(@scheduled_time).utc) do CustomWizard::Template.save(@after_time_template) end end diff --git a/spec/components/custom_wizard/validator_spec.rb b/spec/components/custom_wizard/validator_spec.rb index 5833127e..2a27d083 100644 --- a/spec/components/custom_wizard/validator_spec.rb +++ b/spec/components/custom_wizard/validator_spec.rb @@ -9,12 +9,6 @@ describe CustomWizard::Validator do ).read).with_indifferent_access } - let(:after_time) { - JSON.parse(File.open( - "#{Rails.root}/plugins/discourse-custom-wizard/spec/fixtures/wizard/after_time.json" - ).read).with_indifferent_access - } - it "validates valid templates" do expect( CustomWizard::Validator.new(template).perform @@ -36,15 +30,15 @@ describe CustomWizard::Validator do end it "validates after time settings" do - template[:after_time] = after_time[:after_time] - template[:after_time_scheduled] = after_time[:after_time_scheduled] + template[:after_time] = true + template[:after_time_scheduled] = (Time.now + 3.hours).iso8601 expect( CustomWizard::Validator.new(template).perform ).to eq(true) end it "invalidates invalid after time settings" do - template[:after_time] = after_time[:after_time] + template[:after_time] = true template[:after_time_scheduled] = "not a time" expect( CustomWizard::Validator.new(template).perform diff --git a/spec/components/custom_wizard/wizard_spec.rb b/spec/components/custom_wizard/wizard_spec.rb index 7724cc64..10bc3bdf 100644 --- a/spec/components/custom_wizard/wizard_spec.rb +++ b/spec/components/custom_wizard/wizard_spec.rb @@ -11,12 +11,6 @@ describe CustomWizard::Wizard do ).read) } - let(:after_time) { - JSON.parse(File.open( - "#{Rails.root}/plugins/discourse-custom-wizard/spec/fixtures/wizard/after_time.json" - ).read) - } - let(:permitted_json) { JSON.parse(File.open( "#{Rails.root}/plugins/discourse-custom-wizard/spec/fixtures/wizard/permitted.json" @@ -84,8 +78,8 @@ describe CustomWizard::Wizard do progress_step("step_2") progress_step("step_3") - template_json['after_time'] = after_time['after_time'] - template_json['after_time_scheduled'] = after_time['after_time_scheduled'] + template_json['after_time'] = true + template_json['after_time_scheduled'] = Time.now + 3.hours wizard = CustomWizard::Wizard.new(template_json, user) diff --git a/spec/fixtures/wizard/after_time.json b/spec/fixtures/wizard/after_time.json deleted file mode 100644 index 691af470..00000000 --- a/spec/fixtures/wizard/after_time.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "after_time": true, - "after_time_scheduled": "2020-11-20T00:59:00.000Z" -} \ No newline at end of file diff --git a/spec/jobs/clear_after_time_wizard_spec.rb b/spec/jobs/clear_after_time_wizard_spec.rb index ad7e0982..ec7c8fa6 100644 --- a/spec/jobs/clear_after_time_wizard_spec.rb +++ b/spec/jobs/clear_after_time_wizard_spec.rb @@ -12,16 +12,11 @@ describe Jobs::ClearAfterTimeWizard do "#{Rails.root}/plugins/discourse-custom-wizard/spec/fixtures/wizard.json" ).read).with_indifferent_access } - let(:after_time) { - JSON.parse(File.open( - "#{Rails.root}/plugins/discourse-custom-wizard/spec/fixtures/wizard/after_time.json" - ).read).with_indifferent_access - } it "clears wizard redirect for all users " do after_time_template = template.dup - after_time_template["after_time"] = after_time['after_time'] - after_time_template["after_time_scheduled"] = after_time['after_time_scheduled'] + after_time_template["after_time"] = true + after_time_template["after_time_scheduled"] = (Time.now + 3.hours).iso8601 CustomWizard::Template.save(after_time_template) diff --git a/spec/jobs/set_after_time_wizard_spec.rb b/spec/jobs/set_after_time_wizard_spec.rb index 49ec211f..d4939660 100644 --- a/spec/jobs/set_after_time_wizard_spec.rb +++ b/spec/jobs/set_after_time_wizard_spec.rb @@ -12,16 +12,11 @@ describe Jobs::SetAfterTimeWizard do "#{Rails.root}/plugins/discourse-custom-wizard/spec/fixtures/wizard.json" ).read).with_indifferent_access } - let(:after_time) { - JSON.parse(File.open( - "#{Rails.root}/plugins/discourse-custom-wizard/spec/fixtures/wizard/after_time.json" - ).read).with_indifferent_access - } it "sets wizard redirect for all users " do after_time_template = template.dup - after_time_template["after_time"] = after_time['after_time'] - after_time_template["after_time_scheduled"] = after_time['after_time_scheduled'] + after_time_template["after_time"] = true + after_time_template["after_time_scheduled"] = (Time.now + 3.hours).iso8601 CustomWizard::Template.save(after_time_template)