diff options
author | Florian Staudacher <florian_staudacher@yahoo.de> | 2015-08-28 03:13:19 +0300 |
---|---|---|
committer | Florian Staudacher <florian_staudacher@yahoo.de> | 2015-08-30 19:50:34 +0300 |
commit | 738413c65f43ac2d01c113c294c484858e8cb3d7 (patch) | |
tree | 27b7e3b5cd1e90e0830cfff73f25b6b5ab691c83 /spec | |
parent | 39fb1a6db23bd6ee2ac681c04197c47163f69361 (diff) |
fix some issues with pod-checking
add tooltips in the frontend
fix a JS problem with empty hostname
use `find_in_batches` correctly
add a migration to clean up the pods table + unique index on hostname
Diffstat (limited to 'spec')
-rw-r--r-- | spec/factories.rb | 2 | ||||
-rw-r--r-- | spec/javascripts/app/collections/pods_spec.js | 16 | ||||
-rw-r--r-- | spec/migrations/remove_duplicate_and_empty_pods_spec.rb | 64 | ||||
-rw-r--r-- | spec/models/pod_spec.rb | 2 | ||||
-rw-r--r-- | spec/workers/recurring_pod_check_spec.rb | 4 |
5 files changed, 84 insertions, 4 deletions
diff --git a/spec/factories.rb b/spec/factories.rb index d3470e3be..1f99c0f0b 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -211,7 +211,7 @@ FactoryGirl.define do end factory :pod do - host "pod.example.com" + sequence(:host) {|n| "pod#{n}.example#{r_str}.com" } ssl true end diff --git a/spec/javascripts/app/collections/pods_spec.js b/spec/javascripts/app/collections/pods_spec.js new file mode 100644 index 000000000..97bb29619 --- /dev/null +++ b/spec/javascripts/app/collections/pods_spec.js @@ -0,0 +1,16 @@ + +describe("app.collections.Pods", function() { + describe("#comparator", function() { + it("should handle empty hostnames", function() { + var collection = new app.collections.Pods([ + {id: 1}, + {id: 2, host: "zzz.zz"}, + {id: 3, host: "aaa.aa"}, + {id: 4, host: ""} + ]); + expect(collection.length).toBe(4); + expect(collection.first().get("host")).toBeFalsy(); // also empty string + expect(collection.last().get("host")).toBe("zzz.zz"); + }); + }); +}); diff --git a/spec/migrations/remove_duplicate_and_empty_pods_spec.rb b/spec/migrations/remove_duplicate_and_empty_pods_spec.rb new file mode 100644 index 000000000..fc26b9637 --- /dev/null +++ b/spec/migrations/remove_duplicate_and_empty_pods_spec.rb @@ -0,0 +1,64 @@ + +require "spec_helper" +require Rails.root.join("db/migrate/20150828132451_remove_duplicate_and_empty_pods.rb") + +describe RemoveDuplicateAndEmptyPods do + self.use_transactional_fixtures = false + + before do + @previous_migration = 20_150_731_123_114 + @my_migration = 20_150_828_132_451 + Pod.delete_all + end + + after :all do + migrate_to(nil) # up + Pod.delete_all # cleanup manually, transactions are disabled + end + + def migrate_to(version) + ActiveRecord::Migrator.migrate(Rails.root.join("db", "migrate"), version) + end + + describe "#up" do + before do + migrate_to(@previous_migration) + + FactoryGirl.create(:pod, host: nil) + FactoryGirl.create(:pod, host: "") + 4.times { FactoryGirl.create(:pod, host: "aaa.aa") } + end + + it "removes duplicates" do + expect(Pod.where(host: "aaa.aa").count).to eql(4) + migrate_to(@my_migration) + expect(Pod.where(host: "aaa.aa").count).to eql(1) + end + + it "removes empty hostnames" do + expect(Pod.where(host: [nil, ""]).count).to eql(2) + migrate_to(@my_migration) + expect(Pod.where(host: [nil, ""]).count).to eql(0) + end + + it "adds an index on the host column" do + expect { + migrate_to(@my_migration) + Pod.reset_column_information + }.to change { Pod.connection.indexes(Pod.table_name).count }.by(1) + end + end + + describe "#down" do + before do + migrate_to(@my_migration) + end + + it "removes the index on the host column" do + expect { + migrate_to(@previous_migration) + Pod.reset_column_information + }.to change { Pod.connection.indexes(Pod.table_name).count }.by(-1) + end + end +end diff --git a/spec/models/pod_spec.rb b/spec/models/pod_spec.rb index fd9d148e3..a1e851d26 100644 --- a/spec/models/pod_spec.rb +++ b/spec/models/pod_spec.rb @@ -20,7 +20,7 @@ describe Pod, type: :model do expect(pod).to receive(:test_connection!) end end - allow(Pod).to receive(:find_in_batches) { @pods } + allow(Pod).to receive(:find_in_batches).and_yield(@pods) end it "calls #test_connection! on every pod" do diff --git a/spec/workers/recurring_pod_check_spec.rb b/spec/workers/recurring_pod_check_spec.rb index b7f240f1e..fec3b7f24 100644 --- a/spec/workers/recurring_pod_check_spec.rb +++ b/spec/workers/recurring_pod_check_spec.rb @@ -4,11 +4,11 @@ require "spec_helper" describe Workers::RecurringPodCheck do before do @pods = (0..4).map do - FactoryGirl.create(:pod).tap { |pod| + FactoryGirl.build(:pod).tap { |pod| expect(pod).to receive(:test_connection!) } end - allow(Pod).to receive(:find_in_batches) { @pods } + allow(Pod).to receive(:find_in_batches).and_yield(@pods) end it "performs a connection test on all existing pods" do |