Преглед на файлове

bug with removeEventSource and Google Calendar as object

Adam Shaw преди 11 години
родител
ревизия
656cf29987
променени са 3 файла, в които са добавени 30 реда и са изтрити 1 реда
  1. 1 1
      src/EventManager.js
  2. 1 0
      src/gcal/gcal.js
  3. 28 0
      tests/automated/events-gcal.js

+ 1 - 1
src/EventManager.js

@@ -307,7 +307,7 @@ function EventManager(options) { // assumed to be a calendar
 	function getSourcePrimitive(source) {
 		return (
 			(typeof source === 'object') ? // a normalized event source?
-				(source.origArray || source.url || source.events) : // get the primitive
+				(source.origArray || source.googleCalendarId || source.url || source.events) : // get the primitive
 				null
 		) ||
 		source; // the given argument *is* the primitive

+ 1 - 0
src/gcal/gcal.js

@@ -54,6 +54,7 @@ fc.sourceNormalizers.push(function(sourceOptions) {
 
 		// We want removeEventSource to work, but it won't know about the googleCalendarId primitive.
 		// Shoehorn it into the url, which will function as the unique primitive. Won't cause side effects.
+		// This hack is obsolete since 2.2.3, but keep it so this plugin file is compatible with old versions.
 		sourceOptions.url = googleCalendarId;
 	}
 });

+ 28 - 0
tests/automated/events-gcal.js

@@ -240,6 +240,7 @@ describe('Google Calendar plugin', function() {
 	});
 
 	describe('removeEventSource', function() {
+
 		it('works when specifying only the Google Calendar ID', function(done) {
 			var CALENDAR_ID = '[email protected]';
 			var called = false;
@@ -265,6 +266,33 @@ describe('Google Calendar plugin', function() {
 
 			$('#cal').fullCalendar(options);
 		});
+
+		it('works when specifying a raw Google Calendar source object', function(done) {
+			var CALENDAR_ID = '[email protected]';
+			var googleSource = { googleCalendarId: CALENDAR_ID };
+			var called = false;
+
+			options.googleCalendarApiKey = API_KEY;
+			options.eventSources = [ googleSource ];
+			options.eventAfterAllRender = function() {
+				var events;
+
+				if (called) { return; } // only the first time
+				called = true;
+
+				events = $('#cal').fullCalendar('clientEvents');
+				expect(events.length).toBe(4); // 4 holidays in November 2014
+
+				setTimeout(function() {
+					$('#cal').fullCalendar('removeEventSource', googleSource);
+					events = $('#cal').fullCalendar('clientEvents');
+					expect(events.length).toBe(0);
+					done();
+				}, 0);
+			};
+
+			$('#cal').fullCalendar(options);
+		});
 	});
 
 });