diff --git a/src/Mapless-Base/Mapless.class.st b/src/Mapless-Base/Mapless.class.st index 08a819d..006135c 100644 --- a/src/Mapless-Base/Mapless.class.st +++ b/src/Mapless-Base/Mapless.class.st @@ -196,7 +196,7 @@ Mapless class >> isAbstract [ ^ self == AnAbstractModelClass" - ^ false + ^ self == Mapless ] { #category : #testing } @@ -244,7 +244,7 @@ Mapless class >> pluralName [ Any subclass can override its own custom name. The default plural name is the singular name in lower case plus an 's' so beware of irregular nouns." - + self deprecated: 'Application responsibility'. ^ self singularName , 's' ] @@ -253,7 +253,7 @@ Mapless class >> singularName [ "Answers the string expected in a nicely designed API. Any subclass can override its own custom name. The default name is the class name in lowercase." - + self deprecated: 'Application responsibility'. ^ self name asLowercase ] @@ -665,10 +665,11 @@ Mapless >> onBeforeUpsert [ ] { #category : #actions } -Mapless >> sanitize: someFields [ - "Removes someFields from the receiver." +Mapless >> sanitize: someProperties [ + "Removes someProperties from the receiver." - someFields do: [ :key | self data removeKey: key ifAbsent: [ nil ] ] + someProperties do: [ :key | + self maplessData removeKey: key ifAbsent: [ nil ] ] ] { #category : #actions } diff --git a/src/Mapless-Mongo-Tests/MaplessMongoTest.class.st b/src/Mapless-Mongo-Tests/MaplessMongoTest.class.st index 7e4f44f..235e7f9 100644 --- a/src/Mapless-Mongo-Tests/MaplessMongoTest.class.st +++ b/src/Mapless-Mongo-Tests/MaplessMongoTest.class.st @@ -67,6 +67,34 @@ MaplessMongoTest >> tearDown [ shutDown ] +{ #category : #tests } +MaplessMongoTest >> testAfterDestroyed [ + + | guy | + guy := SamplePerson new + firstName: 'john'; + lastName: 'q'; + yourself. + self assert: guy recentlyDestroyed isNil. + self do: [ guy save ]. + self assert: guy recentlySaved. + self do: [ guy destroy ]. + self assert: guy recentlyDestroyed +] + +{ #category : #tests } +MaplessMongoTest >> testAfterSaved [ + + | guy | + guy := SamplePerson new + firstName: 'john'; + lastName: 'q'; + yourself. + self assert: guy recentlySaved isNil. + self do: [ guy save ]. + self assert: guy recentlySaved +] + { #category : #tests } MaplessMongoTest >> testComposedAccess [ "Test proxies and its on-demand-load and DNU mechanism" @@ -367,6 +395,18 @@ MaplessMongoTest >> testFindAllSorted [ self assert: found last firstName = 'Robert' ] ] +{ #category : #tests } +MaplessMongoTest >> testFirst [ + + | found | + repository readWriteDo: [ (self newSamplePersonNamed: 'Peter') save ]. + repository readOnlyDo: [ + self waitABit. + found := SamplePerson first. + self assert: found notNil. + self assert: found firstName equals: 'Peter' ] +] + { #category : #tests } MaplessMongoTest >> testIsUnsaved [ | guy | @@ -377,6 +417,28 @@ MaplessMongoTest >> testIsUnsaved [ self do: [ guy save ] ] +{ #category : #tests } +MaplessMongoTest >> testMaplessClass [ + + | user guy reference | + self do: [ + user := SampleUser new + userame: 'johnq'; + yourself. + guy := SamplePerson new + firstName: 'john'; + lastName: 'q'; + yourself. + user person: guy. + + guy save. + user save. + self assert: SamplePerson maplessClass equals: SamplePerson. + reference := SampleUser first person. + self assert: reference class equals: MaplessReference. + self assert: reference maplessClass equals: SamplePerson ] +] + { #category : #tests } MaplessMongoTest >> testMultipleComposedComposables [ | tags tagsOfTags tagsOfTagsOfTags loaded | @@ -620,12 +682,16 @@ MaplessMongoTest >> testSaveSetsID [ { #category : #tests } MaplessMongoTest >> testSimpleSave [ + | guy | guy := SamplePerson new - firstName: 'john'; - lastName: 'q'; - yourself. - self do: [ guy save ] + firstName: 'john'; + lastName: 'q'; + yourself. + self do: [ guy save ]. + + self assert: guy isMapless. + self assert: guy recentlySaved ] { #category : #tests } diff --git a/src/Mapless-Mongo-Tests/MaplessVoyageMongoModelTest.class.st b/src/Mapless-Mongo-Tests/MaplessVoyageMongoModelTest.class.st index 20474a4..da934ef 100644 --- a/src/Mapless-Mongo-Tests/MaplessVoyageMongoModelTest.class.st +++ b/src/Mapless-Mongo-Tests/MaplessVoyageMongoModelTest.class.st @@ -33,6 +33,25 @@ MaplessVoyageMongoModelTest >> tearDown [ shutDown ] +{ #category : #tests } +MaplessVoyageMongoModelTest >> testConditionForClass [ + + | guy | + repository := MaplessMongoRepository + for: 'Mapless-Test' + with: MaplessStandaloneMongoPool local. + repository resolver: (MaplessVoyageWithMaplessSuffixResolver new + suffix: 'Interoperating'; + yourself). + guy := SamplePersonInteroperating new. + + repository resolver. + self + assert: (repository resolver conditionForClass: guy class) + equals: { ('#instanceOf' -> 'SamplePerson') } asDictionary. + self assert: repository resolver suffix equals: 'Interoperating' +] + { #category : #tests } MaplessVoyageMongoModelTest >> testReifyWithReferenceFromVoyageMetadata [ diff --git a/src/Mapless-Tests/MaplessResourcesTest.class.st b/src/Mapless-Tests/MaplessResourcesTest.class.st index 2a76bab..83420a3 100644 --- a/src/Mapless-Tests/MaplessResourcesTest.class.st +++ b/src/Mapless-Tests/MaplessResourcesTest.class.st @@ -70,6 +70,27 @@ MaplessResourcesTest >> test30And70Chance [ self assert: j > 6800 ] +{ #category : #tests } +MaplessResourcesTest >> testAddNodes [ + + | wr n1 n2 | + wr := MaplessWeightedRandomPolicy new. + n1 := MaplessWeightedNode new + weight: 30; + value: 'url1'; + yourself. + n2 := MaplessWeightedNode new + weight: 70; + value: 'url2'; + yourself. + wr nodes: { + n1. + n2 }. + + self assert: wr nodes first equals: n1. + self assert: wr nodes second equals: n2 +] + { #category : #tests } MaplessResourcesTest >> testChangeWeightedNodeWeight [ @@ -124,3 +145,44 @@ MaplessResourcesTest >> testPrintsWeightedNodeInAUsefulWay [ self assert: n1 asString equals: 'a MaplessWeightedNode(0.5@url1)' ] + +{ #category : #tests } +MaplessResourcesTest >> testRandom [ + + | wr n1 n2 thisOne | + wr := MaplessWeightedRandomPolicy seed: 1000. + n1 := MaplessWeightedNode new + weight: 30; + value: 'url1'; + yourself. + n2 := MaplessWeightedNode new + weight: 70; + value: 'url2'; + yourself. + wr nodes: { + n1. + n2 }. + wr recalculateWeight. + thisOne := wr next. + self assert: (thisOne = n1 or: [ thisOne = n2 ]) +] + +{ #category : #tests } +MaplessResourcesTest >> testWeights [ + + | wr n1 n2 | + wr := MaplessWeightedRandomPolicy seed: 1000. + n1 := MaplessWeightedNode new + weight: 30; + value: 'url1'; + yourself. + n2 := MaplessWeightedNode new + weight: 70; + value: 'url2'; + yourself. + wr nodes: { + n1. + n2 }. + wr recalculateWeight. + self assert: wr totalWeight equals: 100 +] diff --git a/src/Mapless-Tests/MaplessTestCase.class.st b/src/Mapless-Tests/MaplessTestCase.class.st index 236b988..430f8ff 100644 --- a/src/Mapless-Tests/MaplessTestCase.class.st +++ b/src/Mapless-Tests/MaplessTestCase.class.st @@ -4,6 +4,19 @@ Class { #category : #'Mapless-Tests-Tests' } +{ #category : #tests } +MaplessTestCase >> testAbstract [ + + self assert: Mapless isAbstract. + self deny: SamplePerson isAbstract +] + +{ #category : #tests } +MaplessTestCase >> testDeprecated [ + + self deny: SamplePerson isDeprecated +] + { #category : #tests } MaplessTestCase >> testGetterReturn [ | guy | @@ -14,12 +27,21 @@ MaplessTestCase >> testGetterReturn [ self assert: guy firstName equals: 'John' ] +{ #category : #tests } +MaplessTestCase >> testMaplessClass [ + + self assert: Mapless maplessClass equals: Mapless. + self assert: SamplePerson maplessClass equals: SamplePerson +] + { #category : #tests } MaplessTestCase >> testMaplessErrorDefaultAction [ self should: [ MaplessError signal: 'mmmmmmmmm...' ] - raise: MaplessError + raise: MaplessError. + + self should: [ MaplessError new defaultAction ] raise: UnhandledError ] { #category : #tests } @@ -47,6 +69,26 @@ MaplessTestCase >> testPoolBasics [ self deny: pool hasHealthChecker ] +{ #category : #tests } +MaplessTestCase >> testSanitizeProperties [ + + | guy | + guy := SamplePerson new. + self assert: guy firstName isNil. + guy + firstName: 'John'; + lastName: 'Carpenter'; + phone: '1234'. + + self assert: guy firstName notNil. + self assert: guy firstName equals: 'John'. + self deny: guy phone isNil. + guy sanitize: { #phone }. + self deny: guy phone notNil. + self assert: guy firstName equals: 'John'. + +] + { #category : #tests } MaplessTestCase >> testSetterReturn [ | guy set | diff --git a/src/Mapless-Tests/SamplePerson.class.st b/src/Mapless-Tests/SamplePerson.class.st index 886b85a..e785af9 100644 --- a/src/Mapless-Tests/SamplePerson.class.st +++ b/src/Mapless-Tests/SamplePerson.class.st @@ -3,3 +3,19 @@ Class { #superclass : #Mapless, #category : #'Mapless-Tests-Samples' } + +{ #category : #hooks } +SamplePerson >> onAfterDestroy [ + + super onAfterDestroy. + + self recentlyDestroyed: true +] + +{ #category : #hooks } +SamplePerson >> onAfterSave [ + + super onAfterSave. + + self recentlySaved: true +]