Extending and testing the model
This commit is contained in:
96
src/TinyBlog/TBBlog.class.st
Normal file
96
src/TinyBlog/TBBlog.class.st
Normal file
@@ -0,0 +1,96 @@
|
||||
Class {
|
||||
#name : #TBBlog,
|
||||
#superclass : #Object,
|
||||
#instVars : [
|
||||
'posts'
|
||||
],
|
||||
#classInstVars : [
|
||||
'uniqueInstance'
|
||||
],
|
||||
#category : #TinyBlog
|
||||
}
|
||||
|
||||
{ #category : #demos }
|
||||
TBBlog class >> createDemoPosts [
|
||||
"TBBlog createDemoPosts"
|
||||
self current
|
||||
writeBlogPost: ((TBPost title: 'Welcome in TinyBlog' text: 'TinyBlog is a small blog engine made with Pharo.' category: 'TinyBlog') visible: true);
|
||||
writeBlogPost: ((TBPost
|
||||
title: 'Report Pharo Sprint'
|
||||
text: 'Friday, June 12 there was a Pharo sprint / Moose dojo. It was a nice event with more than 15 motivated sprinters. With the help of candies, cakes and chocolate, huge work has been done'
|
||||
category: 'Pharo') visible: true);
|
||||
writeBlogPost: ((TBPost
|
||||
title: 'Brick on top of Bloc - Preview'
|
||||
text: 'We are happy to announce the first preview version of Brick, a new widget set created from scratch on top of Bloc. Brick is being developed primarily by Alex Syrel (together with Alain Plantec, Andrei Chis and myself), and the work is sponsored by ESUG. Brick is part of the Glamorous Toolkit effort and will provide the basis for the new versions of the development tools.'
|
||||
category: 'Pharo') visible: true);
|
||||
writeBlogPost: ((TBPost
|
||||
title: 'The sad story of unclassified blog posts'
|
||||
text: 'So sad that I can read this.') visible: true);
|
||||
writeBlogPost: ((TBPost
|
||||
title: 'Working with Pharo on the Raspberry Pi'
|
||||
text: 'Hardware is getting cheaper and many new small devices like the famous Raspberry Pi provide new computation power that was one once only available on regular desktop computers.'
|
||||
category: 'Pharo') visible: true)
|
||||
]
|
||||
|
||||
{ #category : #initialization }
|
||||
TBBlog class >> current [
|
||||
"answer the instance of the TBRepository"
|
||||
^ uniqueInstance ifNil: [ uniqueInstance := self new ]
|
||||
]
|
||||
|
||||
{ #category : #initialization }
|
||||
TBBlog class >> initialize [
|
||||
self reset
|
||||
]
|
||||
|
||||
{ #category : #initialization }
|
||||
TBBlog class >> reset [
|
||||
uniqueInstance := nil
|
||||
]
|
||||
|
||||
{ #category : #reading }
|
||||
TBBlog >> allBlogPosts [
|
||||
^ posts
|
||||
]
|
||||
|
||||
{ #category : #reading }
|
||||
TBBlog >> allBlogPostsFromCategory: aCategory [
|
||||
^ posts select: [ :p | p category = aCategory ]
|
||||
]
|
||||
|
||||
{ #category : #reading }
|
||||
TBBlog >> allCategories [
|
||||
^ (self allBlogPosts collect: [ :p | p category ]) asSet
|
||||
]
|
||||
|
||||
{ #category : #reading }
|
||||
TBBlog >> allVisibleBlogPosts [
|
||||
^ posts select: [ :p | p isVisible ]
|
||||
]
|
||||
|
||||
{ #category : #reading }
|
||||
TBBlog >> allVisibleBlogPostsFromCategory: aCategory [
|
||||
^ posts select: [ :p | p category = aCategory and: [ p isVisible ] ]
|
||||
]
|
||||
|
||||
{ #category : #initialization }
|
||||
TBBlog >> initialize [
|
||||
super initialize.
|
||||
posts := OrderedCollection new
|
||||
]
|
||||
|
||||
{ #category : #deleting }
|
||||
TBBlog >> removeAllPosts [
|
||||
posts := OrderedCollection new
|
||||
]
|
||||
|
||||
{ #category : #initialization }
|
||||
TBBlog >> size [
|
||||
^ posts size
|
||||
]
|
||||
|
||||
{ #category : #writing }
|
||||
TBBlog >> writeBlogPost: aPost [
|
||||
"Add the blog post to the list of posts."
|
||||
posts add: aPost
|
||||
]
|
79
src/TinyBlog/TBBlogTest.class.st
Normal file
79
src/TinyBlog/TBBlogTest.class.st
Normal file
@@ -0,0 +1,79 @@
|
||||
Class {
|
||||
#name : #TBBlogTest,
|
||||
#superclass : #TestCase,
|
||||
#instVars : [
|
||||
'blog',
|
||||
'post',
|
||||
'first'
|
||||
],
|
||||
#category : #'TinyBlog-Tests'
|
||||
}
|
||||
|
||||
{ #category : #running }
|
||||
TBBlogTest >> setUp [
|
||||
blog := TBBlog current.
|
||||
blog removeAllPosts.
|
||||
|
||||
first := TBPost title: 'A title' text: 'A text' category: 'First Category'.
|
||||
blog writeBlogPost: first.
|
||||
|
||||
post := (TBPost title: 'Another title' text: 'Another text' category: 'Second Category') beVisible
|
||||
]
|
||||
|
||||
{ #category : #running }
|
||||
TBBlogTest >> tearDown [
|
||||
TBBlog reset
|
||||
]
|
||||
|
||||
{ #category : #tests }
|
||||
TBBlogTest >> testAddBlogPost [
|
||||
blog writeBlogPost: post.
|
||||
self assert: blog size equals: 2
|
||||
]
|
||||
|
||||
{ #category : #tests }
|
||||
TBBlogTest >> testAllBlogPosts [
|
||||
blog writeBlogPost: post.
|
||||
self assert: blog allBlogPosts size equals: 2
|
||||
]
|
||||
|
||||
{ #category : #tests }
|
||||
TBBlogTest >> testAllBlogPostsFromCategory [
|
||||
self assert: (blog allBlogPostsFromCategory: 'First Category')
|
||||
size equals: 1
|
||||
]
|
||||
|
||||
{ #category : #tests }
|
||||
TBBlogTest >> testAllCategories [
|
||||
blog writeBlogPost: post.
|
||||
self assert: blog allCategories size equals: 2
|
||||
]
|
||||
|
||||
{ #category : #tests }
|
||||
TBBlogTest >> testAllVisibleBlogPosts [
|
||||
blog writeBlogPost: post.
|
||||
self assert: blog allVisibleBlogPosts size equals: 1
|
||||
]
|
||||
|
||||
{ #category : #tests }
|
||||
TBBlogTest >> testAllVisibleBlogPostsFromCategory [
|
||||
blog writeBlogPost: post.
|
||||
self assert: (blog allVisibleBlogPostsFromCategory: 'First Category') size equals: 0.
|
||||
self assert: (blog allVisibleBlogPostsFromCategory: 'Second Category') size equals: 1.
|
||||
]
|
||||
|
||||
{ #category : #tests }
|
||||
TBBlogTest >> testRemoveAllBlogPosts [
|
||||
blog removeAllPosts.
|
||||
self assert: blog size equals: 0
|
||||
]
|
||||
|
||||
{ #category : #tests }
|
||||
TBBlogTest >> testSize [
|
||||
self assert: blog size equals: 1
|
||||
]
|
||||
|
||||
{ #category : #tests }
|
||||
TBBlogTest >> testUnclassifiedBlogPosts [
|
||||
self assert: (blog allBlogPosts select: [ :p | p isUnclassified ]) size equals: 0
|
||||
]
|
120
src/TinyBlog/TBPost.class.st
Normal file
120
src/TinyBlog/TBPost.class.st
Normal file
@@ -0,0 +1,120 @@
|
||||
Class {
|
||||
#name : #TBPost,
|
||||
#superclass : #Object,
|
||||
#instVars : [
|
||||
'title',
|
||||
'text',
|
||||
'date',
|
||||
'category',
|
||||
'visible'
|
||||
],
|
||||
#category : #TinyBlog
|
||||
}
|
||||
|
||||
{ #category : #'instance creation' }
|
||||
TBPost class >> title: aTitle text: aText [
|
||||
^ self new
|
||||
title: aTitle;
|
||||
text: aText;
|
||||
yourself
|
||||
]
|
||||
|
||||
{ #category : #'instance creation' }
|
||||
TBPost class >> title: aTitle text: aText category: aCategory [
|
||||
^ (self title: aTitle text: aText)
|
||||
category: aCategory;
|
||||
yourself
|
||||
]
|
||||
|
||||
{ #category : #'as yet unclassified' }
|
||||
TBPost class >> unclassifiedTag [
|
||||
^ 'Unclassified'
|
||||
]
|
||||
|
||||
{ #category : #action }
|
||||
TBPost >> beVisible [
|
||||
self visible: true
|
||||
]
|
||||
|
||||
{ #category : #accessing }
|
||||
TBPost >> category [
|
||||
|
||||
^ category
|
||||
]
|
||||
|
||||
{ #category : #accessing }
|
||||
TBPost >> category: anObject [
|
||||
|
||||
category := anObject
|
||||
]
|
||||
|
||||
{ #category : #accessing }
|
||||
TBPost >> date [
|
||||
|
||||
^ date
|
||||
]
|
||||
|
||||
{ #category : #accessing }
|
||||
TBPost >> date: anObject [
|
||||
|
||||
date := anObject
|
||||
]
|
||||
|
||||
{ #category : #initialization }
|
||||
TBPost >> initialize [
|
||||
super initialize.
|
||||
self category: self class unclassifiedTag.
|
||||
self date: Date today.
|
||||
self notVisible.
|
||||
]
|
||||
|
||||
{ #category : #testing }
|
||||
TBPost >> isUnclassified [
|
||||
^ self category = self class unclassifiedTag
|
||||
]
|
||||
|
||||
{ #category : #testing }
|
||||
TBPost >> isVisible [
|
||||
^ self visible
|
||||
]
|
||||
|
||||
{ #category : #action }
|
||||
TBPost >> notVisible [
|
||||
self visible: false
|
||||
]
|
||||
|
||||
{ #category : #accessing }
|
||||
TBPost >> text [
|
||||
|
||||
^ text
|
||||
]
|
||||
|
||||
{ #category : #accessing }
|
||||
TBPost >> text: anObject [
|
||||
|
||||
text := anObject
|
||||
]
|
||||
|
||||
{ #category : #accessing }
|
||||
TBPost >> title [
|
||||
|
||||
^ title
|
||||
]
|
||||
|
||||
{ #category : #accessing }
|
||||
TBPost >> title: anObject [
|
||||
|
||||
title := anObject
|
||||
]
|
||||
|
||||
{ #category : #accessing }
|
||||
TBPost >> visible [
|
||||
|
||||
^ visible
|
||||
]
|
||||
|
||||
{ #category : #accessing }
|
||||
TBPost >> visible: anObject [
|
||||
|
||||
visible := anObject
|
||||
]
|
29
src/TinyBlog/TBPostTest.class.st
Normal file
29
src/TinyBlog/TBPostTest.class.st
Normal file
@@ -0,0 +1,29 @@
|
||||
Class {
|
||||
#name : #TBPostTest,
|
||||
#superclass : #TestCase,
|
||||
#category : #'TinyBlog-Tests'
|
||||
}
|
||||
|
||||
{ #category : #tests }
|
||||
TBPostTest >> testPostIsCreatedCorrectly [
|
||||
|
||||
| post |
|
||||
post := TBPost
|
||||
title: 'Welcome to TinyBlog'
|
||||
text: 'TinyBlog is a small blog engine made with Pharo.'
|
||||
category: 'TinyBlog'.
|
||||
self assert: post title equals: 'Welcome to TinyBlog'.
|
||||
self assert: post text equals: 'TinyBlog is a small blog engine made with Pharo.'.
|
||||
]
|
||||
|
||||
{ #category : #tests }
|
||||
TBPostTest >> testWithoutCategoryIsUnclassified [
|
||||
|
||||
| post |
|
||||
post := TBPost
|
||||
title: 'Welcome to TinyBlog'
|
||||
text: 'TinyBlog is a small blog engine made with Pharo.'.
|
||||
self assert: post title equals: 'Welcome to TinyBlog'.
|
||||
self assert: post isUnclassified.
|
||||
self deny: post isVisible
|
||||
]
|
1
src/TinyBlog/package.st
Normal file
1
src/TinyBlog/package.st
Normal file
@@ -0,0 +1 @@
|
||||
Package { #name : #TinyBlog }
|
Reference in New Issue
Block a user