<commit_before>describe("BaseModel", function() {

	describe("extend", function() {
		it("gives child classes their own instances hash", function() {
			var ChildModel = BaseModel.extend();
			expect(ChildModel.instances).toStrictlyNotEqual(BaseModel.instances);
		});

		it("adds callbacks around method calls", function() {
			var ChildModel = BaseModel.extend({
				callbacks: {
					addCallbackTest: function() {
						
					}
				}
			});
			expect(BaseModel.callbacks.addCallbackTest.length).toEqual(1);
		});
	});

	describe("include", function() {
		it("extends the prototype of BaseModel", function() {
			var module = {
				prototype: {
					foo: function() {
						return 'bar';
					}
				}
			};
			BaseModel.include(module);
			expect(BaseModel.prototype.hasOwnProperty('foo')).toBeTrue();
			expect(BaseModel.prototype.foo).toEqual(module.prototype.foo);
			expect(BaseModel.prototype.foo()).toEqual('bar');
		});

		it("adds callbacks around method calls", function() {
			var module = {
				callbacks: {
					foo: function() {
						return 'foo';
					}
				}
			};
			BaseModel.include(module);
			expect(BaseModel.callbacks.hasOwnProperty("foo")).toBeTrue();
			expect(BaseModel.callbacks.foo).toBeInstanceof(Array);
			expect(BaseModel.callbacks.foo.length).toEqual(1);
		});
	});

	describe("applyModuleCallbacks", function() {
		xit("should be tested");
	});

	it("defines a primary key by default", function() {
		var o = new TestModel();
		expect(o.isValidAttributeKey("id")).toEqual(true);
		expect(o.id).toBeNull();
	});

	it("allows sub classes to override the primary key", function() {
		var o = new TestModelPrimaryKeyOverride();
		expect(o.isValidAttributeKey("foo_id")).toEqual(true);
		expect(o.foo_id).toBeNull();
	});

	it("sets newRecord to true when instantiated with no primary key", function() {
		var model = new TestModelAttributes();
		expect(model.newRecord).toBeTrue();
	});

	describe("getAttribute", function() {
		beforeEach(function() {
			this.model = new TestModelAttributes();
		});

		it("returns null when the key is undefined", function() {
			expect(this.model.firstName).toBeNull();
		});

		it("returns null when the key is null", function() {
			this.model.firstName = null;
			expect(this.model.firstName).toBeNull();
		});

		it("returns the attribute value at the given key", function() {
			this.model.firstName = "Joe";
			expect(this.model.firstName).toEqual("Joe");
		});
	});

	describe("setAttribute", function() {
		beforeEach(function() {
			this.model = new TestModelAttributes();
		});

		it("sets a null value", function() {
			this.model.setAttribute("firstName", null);
			expect(this.model.getAttribute("firstName")).toBeNull();
			expect(this.model.changedAttributes.firstName).toBeUndefined();
		});

		it("sets a non null value", function() {
			this.model.setAttribute("firstName", "Joey");
			expect(this.model.getAttribute("firstName")).toEqual("Joey");
			expect(this.model.changedAttributes.firstName).toBeUndefined();
		});

		it("sets the changed attributes for non null values", function() {
			this.model.setAttribute("firstName", "Joey");
			this.model.setAttribute("firstName", "Eddy");
			expect(this.model.getAttribute("firstName")).toEqual("Eddy");
			expect(this.model.changedAttributes.firstName).toEqual("Joey");
		});

		it("sets the changed attributes to null", function() {
			this.model.setAttribute("firstName", null);
			this.model.setAttribute("firstName", "Billy");
			expect(this.model.changedAttributes.firstName).toBeNull();
		});

		it("publishes attribute:<key>:changed", function() {
			spyOn(this.model, "publish");
			this.model.setAttribute("firstName", "Bob");
			this.model.setAttribute("firstName", "Jane");
			expect(this.model.publish).toHaveBeenCalledWith("attribute:firstName:changed");
		});

		it("sets newRecord to false when setting the primary key for the first time", function() {
			expect(this.model.newRecord).toBeTrue();
			this.model.setAttribute("id", 1234);
			expect(this.model.newRecord).toBeFalse();
		});
	});

	describe("valueIsEmpty", function() {
		beforeEach(function() {
			this.model = new TestModel();
		});

		it("returns true for null values", function() {
			expect(this.model.valueIsEmpty(null)).toEqual(true);
		});

		it("returns true for undefined values", function() {
			var foo;
			expect(this.model.valueIsEmpty(foo)).toEqual(true);
		});

		it("returns false for NaN values", function() {
			expect(this.model.valueIsEmpty(NaN)).toBeFalse();
		});

		it("returns true for empty strings", function() {
			expect(this.model.valueIsEmpty("")).toEqual(true);
		});

		it("returns true for strings containing only white space characters", function() {
			expect(this.model.valueIsEmpty("	\t	")).toEqual(true);
		});

		it("returns true for empty arrays", function() {
			expect(this.model.valueIsEmpty( [] )).toEqual(true);
		});

		it("returns false for everything else", function() {
			expect(this.model.valueIsEmpty( "abc" )).toEqual(false);
			expect(this.model.valueIsEmpty( 0 )).toEqual(false);
			expect(this.model.valueIsEmpty( -1 )).toEqual(false);
			expect(this.model.valueIsEmpty( 1 )).toEqual(false);
			expect(this.model.valueIsEmpty( {} )).toEqual(false);
			expect(this.model.valueIsEmpty( function() {} )).toEqual(false);
			expect(this.model.valueIsEmpty( true )).toEqual(false);
			expect(this.model.valueIsEmpty( false )).toEqual(false);
		});
	});

	describe("valid attributes", function() {
		it("returns false for invalid attributes", function() {
			var o = new TestModelAttributes();
			expect(o.isValidAttributeKey("non_existent")).toEqual(false);
			expect(o.isValidAttributeKey("Name")).toEqual(false);
		});

		it("returns true for valid attributes", function() {
			var o = new TestModelAttributes();
			expect(o.isValidAttributeKey("firstName")).toEqual(true);
			expect(o.isValidAttributeKey("lastName")).toEqual(true);
			expect(o.isValidAttributeKey("id")).toEqual(true);
		});
	});

	describe("initialize", function() {
		it("assigns attributes", function() {
			var o = new TestModelAttributes({id: 123, firstName: "John", lastName: "Doe"});
			expect(o.id).toEqual(123);
			expect(o.firstName).toEqual("John");
			expect(o.lastName).toEqual("Doe");
		});

		it("ignores invalid attributes", function() {
			var o = new TestModelAttributes({id: 123, invalidAttr: "foo"});
			expect(o.hasOwnProperty("invalidAttr")).toEqual(false);
			expect(o.invalidAttr).toBeUndefined();
		});

		it("does not require attributes", function() {
			expect(function() {
				var o = new TestModelAttributes();
			}).not.toThrow(Error);
		});
	});

	describe("attributes", function() {

		describe("getters", function() {
			it("return null when no attribute was given", function() {
				var o = new TestModelAttributes();
				expect(o.id).toBeNull();
				expect(o.firstName).toBeNull();
				expect(o.lastName).toBeNull();
			});

			it("return the value", function() {
				var o = new TestModelAttributes({id: 123});
				expect(o.id).toEqual(123);
				expect(o.firstName).toBeNull();
				expect(o.lastName).toBeNull();

			});
		});

		describe("setters", function() {
			it("put entries in the changedAttributes", function() {
				var o = new TestModelAttributes({firstName: "Fred"});
				expect(o.changedAttributes.id).toBeUndefined();
				expect(o.changedAttributes.firstName).toBeUndefined();
				o.id = 123;
				o.firstName = "Joe";
				expect(o.id).toEqual(123);
				expect(o.firstName).toEqual("Joe");
				expect(o.changedAttributes.id).toBeUndefined();
				expect(o.changedAttributes.firstName).toEqual("Fred");
			});
		});

		it("publishes attributes:changed", function() {
			var o = new TestModelAttributes();
			spyOn(o, "publish");
			o.attributes = {firstName: "Joey"};
			expect(o.publish).wasNotCalled();
			o.attributes = {firstName: "Billy"};
			expect(o.publish).toHaveBeenCalledWith("attribute:firstName:changed");
			expect(o.publish).toHaveBeenCalledWith("attributes:changed");
		});

		it("sets newRecord to false when the primary key is added", function() {
			var o = new TestModelAttributes();
			expect(o.newRecord).toBeTrue();
			o.attributes = {id: 1234};
			expect(o.newRecord).toBeFalse();
		});
	});

	// describe("destroy", function() {
	// 	beforeEach(function() {
	// 		this.model = new TestModelAttributes();
	// 	});
	// 
	// 	it("sets the destroyed flag to true", function() {
	// 		this.model.destroy();
	// 		expect(this.model.destroyed).toBeTrue();
	// 	});
	// 
	// 	it("publishes the destroyed event", function() {
	// 		spyOn(this.model, "publish");
	// 		this.model.destroy();
	// 		this.model.destroy();
	// 		expect(this.model.publish).wasCalledWith("destroyed");
	// 		expect(this.model.publish.callCount).toEqual(1);
	// 	});
	// 
	// 	it("applies module callbacks", function() {
	// 		spyOn(this.model, "applyModuleCallbacks");
	// 		this.model.destroy();
	// 		expect(this.model.applyModuleCallbacks).toHaveBeenCalledWith("destroy", []);
	// 	});
	// });

	// describe("save", function() {
	// 	beforeEach(function() {
	// 		this.model = new TestModelAttributes();
	// 	});
	// 
	// 	it("publishes the created event", function() {
	// 		this.model.attributes = {firstName: "Jane", lastName: "McJanerson"};
	// 		spyOn(this.model, "publish");
	// 		expect(this.model.newRecord).toBeTrue();
	// 		this.model.save();
	// 		expect(this.model.publish).toHaveBeenCalledWith("created");
	// 		expect(this.model.newRecord).toBeFalse();
	// 	});
	// 
	// 	it("publishes the updated event", function() {
	// 		this.model.attributes = {firstName: "Jane", lastName: "McJanerson", id: 1234};
	// 		spyOn(this.model, "publish");
	// 		expect(this.model.newRecord).toBeFalse();
	// 		this.model.save();
	// 		expect(this.model.publish).toHaveBeenCalledWith("updated");
	// 		expect(this.model.newRecord).toBeFalse();
	// 	});
	// 
	// 	it("sets newRecord to false", function() {
	// 		this.model.attributes = {firstName: "Abby"};
	// 		expect(this.model.newRecord).toBeTrue();
	// 		this.model.save();
	// 		expect(this.model.newRecord).toBeFalse();
	// 	});
	// });

	describe("subscribe", function() {
		beforeEach(function() {<commit_msg>Removing tests from BaseModel.spec.js because functionality moved to BaseModel.Persistence<commit_after>describe("BaseModel", function() {

	describe("extend", function() {
		it("gives child classes their own instances hash", function() {
			var ChildModel = BaseModel.extend();
			expect(ChildModel.instances).toStrictlyNotEqual(BaseModel.instances);
		});

		it("adds callbacks around method calls", function() {
			var ChildModel = BaseModel.extend({
				callbacks: {
					addCallbackTest: function() {
						
					}
				}
			});
			expect(BaseModel.callbacks.addCallbackTest.length).toEqual(1);
		});
	});

	describe("include", function() {
		it("extends the prototype of BaseModel", function() {
			var module = {
				prototype: {
					foo: function() {
						return 'bar';
					}
				}
			};
			BaseModel.include(module);
			expect(BaseModel.prototype.hasOwnProperty('foo')).toBeTrue();
			expect(BaseModel.prototype.foo).toEqual(module.prototype.foo);
			expect(BaseModel.prototype.foo()).toEqual('bar');
		});

		it("adds callbacks around method calls", function() {
			var module = {
				callbacks: {
					foo: function() {
						return 'foo';
					}
				}
			};
			BaseModel.include(module);
			expect(BaseModel.callbacks.hasOwnProperty("foo")).toBeTrue();
			expect(BaseModel.callbacks.foo).toBeInstanceof(Array);
			expect(BaseModel.callbacks.foo.length).toEqual(1);
		});
	});

	describe("applyModuleCallbacks", function() {
		xit("should be tested");
	});

	it("defines a primary key by default", function() {
		var o = new TestModel();
		expect(o.isValidAttributeKey("id")).toEqual(true);
		expect(o.id).toBeNull();
	});

	it("allows sub classes to override the primary key", function() {
		var o = new TestModelPrimaryKeyOverride();
		expect(o.isValidAttributeKey("foo_id")).toEqual(true);
		expect(o.foo_id).toBeNull();
	});

	it("sets newRecord to true when instantiated with no primary key", function() {
		var model = new TestModelAttributes();
		expect(model.newRecord).toBeTrue();
	});

	describe("getAttribute", function() {
		beforeEach(function() {
			this.model = new TestModelAttributes();
		});

		it("returns null when the key is undefined", function() {
			expect(this.model.firstName).toBeNull();
		});

		it("returns null when the key is null", function() {
			this.model.firstName = null;
			expect(this.model.firstName).toBeNull();
		});

		it("returns the attribute value at the given key", function() {
			this.model.firstName = "Joe";
			expect(this.model.firstName).toEqual("Joe");
		});
	});

	describe("setAttribute", function() {
		beforeEach(function() {
			this.model = new TestModelAttributes();
		});

		it("sets a null value", function() {
			this.model.setAttribute("firstName", null);
			expect(this.model.getAttribute("firstName")).toBeNull();
			expect(this.model.changedAttributes.firstName).toBeUndefined();
		});

		it("sets a non null value", function() {
			this.model.setAttribute("firstName", "Joey");
			expect(this.model.getAttribute("firstName")).toEqual("Joey");
			expect(this.model.changedAttributes.firstName).toBeUndefined();
		});

		it("sets the changed attributes for non null values", function() {
			this.model.setAttribute("firstName", "Joey");
			this.model.setAttribute("firstName", "Eddy");
			expect(this.model.getAttribute("firstName")).toEqual("Eddy");
			expect(this.model.changedAttributes.firstName).toEqual("Joey");
		});

		it("sets the changed attributes to null", function() {
			this.model.setAttribute("firstName", null);
			this.model.setAttribute("firstName", "Billy");
			expect(this.model.changedAttributes.firstName).toBeNull();
		});

		it("publishes attribute:<key>:changed", function() {
			spyOn(this.model, "publish");
			this.model.setAttribute("firstName", "Bob");
			this.model.setAttribute("firstName", "Jane");
			expect(this.model.publish).toHaveBeenCalledWith("attribute:firstName:changed");
		});

		it("sets newRecord to false when setting the primary key for the first time", function() {
			expect(this.model.newRecord).toBeTrue();
			this.model.setAttribute("id", 1234);
			expect(this.model.newRecord).toBeFalse();
		});
	});

	describe("valueIsEmpty", function() {
		beforeEach(function() {
			this.model = new TestModel();
		});

		it("returns true for null values", function() {
			expect(this.model.valueIsEmpty(null)).toEqual(true);
		});

		it("returns true for undefined values", function() {
			var foo;
			expect(this.model.valueIsEmpty(foo)).toEqual(true);
		});

		it("returns false for NaN values", function() {
			expect(this.model.valueIsEmpty(NaN)).toBeFalse();
		});

		it("returns true for empty strings", function() {
			expect(this.model.valueIsEmpty("")).toEqual(true);
		});

		it("returns true for strings containing only white space characters", function() {
			expect(this.model.valueIsEmpty("	\t	")).toEqual(true);
		});

		it("returns true for empty arrays", function() {
			expect(this.model.valueIsEmpty( [] )).toEqual(true);
		});

		it("returns false for everything else", function() {
			expect(this.model.valueIsEmpty( "abc" )).toEqual(false);
			expect(this.model.valueIsEmpty( 0 )).toEqual(false);
			expect(this.model.valueIsEmpty( -1 )).toEqual(false);
			expect(this.model.valueIsEmpty( 1 )).toEqual(false);
			expect(this.model.valueIsEmpty( {} )).toEqual(false);
			expect(this.model.valueIsEmpty( function() {} )).toEqual(false);
			expect(this.model.valueIsEmpty( true )).toEqual(false);
			expect(this.model.valueIsEmpty( false )).toEqual(false);
		});
	});

	describe("valid attributes", function() {
		it("returns false for invalid attributes", function() {
			var o = new TestModelAttributes();
			expect(o.isValidAttributeKey("non_existent")).toEqual(false);
			expect(o.isValidAttributeKey("Name")).toEqual(false);
		});

		it("returns true for valid attributes", function() {
			var o = new TestModelAttributes();
			expect(o.isValidAttributeKey("firstName")).toEqual(true);
			expect(o.isValidAttributeKey("lastName")).toEqual(true);
			expect(o.isValidAttributeKey("id")).toEqual(true);
		});
	});

	describe("initialize", function() {
		it("assigns attributes", function() {
			var o = new TestModelAttributes({id: 123, firstName: "John", lastName: "Doe"});
			expect(o.id).toEqual(123);
			expect(o.firstName).toEqual("John");
			expect(o.lastName).toEqual("Doe");
		});

		it("ignores invalid attributes", function() {
			var o = new TestModelAttributes({id: 123, invalidAttr: "foo"});
			expect(o.hasOwnProperty("invalidAttr")).toEqual(false);
			expect(o.invalidAttr).toBeUndefined();
		});

		it("does not require attributes", function() {
			expect(function() {
				var o = new TestModelAttributes();
			}).not.toThrow(Error);
		});
	});

	describe("attributes", function() {

		describe("getters", function() {
			it("return null when no attribute was given", function() {
				var o = new TestModelAttributes();
				expect(o.id).toBeNull();
				expect(o.firstName).toBeNull();
				expect(o.lastName).toBeNull();
			});

			it("return the value", function() {
				var o = new TestModelAttributes({id: 123});
				expect(o.id).toEqual(123);
				expect(o.firstName).toBeNull();
				expect(o.lastName).toBeNull();

			});
		});

		describe("setters", function() {
			it("put entries in the changedAttributes", function() {
				var o = new TestModelAttributes({firstName: "Fred"});
				expect(o.changedAttributes.id).toBeUndefined();
				expect(o.changedAttributes.firstName).toBeUndefined();
				o.id = 123;
				o.firstName = "Joe";
				expect(o.id).toEqual(123);
				expect(o.firstName).toEqual("Joe");
				expect(o.changedAttributes.id).toBeUndefined();
				expect(o.changedAttributes.firstName).toEqual("Fred");
			});
		});

		it("publishes attributes:changed", function() {
			var o = new TestModelAttributes();
			spyOn(o, "publish");
			o.attributes = {firstName: "Joey"};
			expect(o.publish).wasNotCalled();
			o.attributes = {firstName: "Billy"};
			expect(o.publish).toHaveBeenCalledWith("attribute:firstName:changed");
			expect(o.publish).toHaveBeenCalledWith("attributes:changed");
		});

		it("sets newRecord to false when the primary key is added", function() {
			var o = new TestModelAttributes();
			expect(o.newRecord).toBeTrue();
			o.attributes = {id: 1234};
			expect(o.newRecord).toBeFalse();
		});
	});

	describe("subscribe", function() {
		beforeEach(function() {
{'fraction_non_alphanumeric': 0.1780192453238188, 'fraction_numerical': 0.003946372580819548, 'mean_word_length': 4.365139211136891, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '117800', 'n_tokens_mistral': 6657, 'n_tokens_neox': 5805, 'n_words': 1057}