Skip to content

Commit daa398e

Browse files
committed
Support sermon tagging when creating bulletins
1 parent cb6d93f commit daa398e

File tree

5 files changed

+59
-7
lines changed

5 files changed

+59
-7
lines changed

app/models/sermon.js

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,24 @@ export default DS.Model.extend({
88
notes: DS.attr("string"),
99
publishedAt: DS.attr('date'),
1010
series: DS.attr("string"),
11-
speaker: DS.attr("string")
11+
speaker: DS.attr("string"),
12+
tags: DS.attr(),
13+
tagList: Ember.computed("tags.[]", {
14+
get: function() {
15+
return getTags(this).toArray().join(", ");
16+
},
17+
set: function(key, value) {
18+
this.set("tags", tagListToArray(value));
19+
return value;
20+
}
21+
})
1222
});
23+
24+
function getTags(context) {
25+
var tags = context.get("tags");
26+
return tags ? tags : [];
27+
}
28+
29+
function tagListToArray(tagList) {
30+
return tagList.split(/\s*,\s*/);
31+
}

app/templates/components/sermon-editor.hbs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@
1717
class="form-control"
1818
data-auto-id="speaker"}}
1919
</div>
20+
<div class="form-group">
21+
<label for="tags">Tags</label>
22+
{{input value=sermon.tags class="form-control" data-auto-id="tags"}}
23+
</div>
2024
<div class="form-group">
2125
<label for="audio">Audio</label>
2226
<div class="form-control audio">

tests/acceptance/bulletins/new-test.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ test("it can create a new bulletin", assert => {
4343
name: "My Sermon",
4444
notes: "",
4545
series: "Super series",
46-
speaker: "Mr. Speaker"
46+
speaker: "Mr. Speaker",
47+
tags: "humility,faith,temptation"
4748
};
4849

4950
page.
@@ -56,17 +57,22 @@ test("it can create a new bulletin", assert => {
5657
fillName(sermon.name).
5758
fillNotes(sermon.notes).
5859
fillSeries(sermon.series).
59-
fillSpeaker(sermon.speaker);
60+
fillSpeaker(sermon.speaker).
61+
fillTags(sermon.tags);
6062

6163
page.submit();
6264

6365
andThen(() => {
6466
const bulletins = server.db.bulletins;
6567
const createdBulletin = bulletins[bulletins.length - 1];
6668

69+
const sermons = server.db.sermons;
70+
const createdSermon = sermons[sermons.length - 1];
71+
6772
assert.equal(createdBulletin.name, bulletin.name);
6873
equalDate(assert, createdBulletin.publishedAt, bulletin.publishedAt);
6974
assert.equal(createdBulletin.serviceOrder, bulletin.serviceOrder);
75+
assert.equal(createdSermon.tags, sermon.tags);
7076
assert.equal(currentURL(), "/dashboard");
7177
});
7278
});

tests/pages/components/sermon-editor.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@ export default {
77
fillNotes: fillable(selector("notes")),
88
fillSeries: fillable(selector("series")),
99
fillSpeaker: fillable(selector("speaker")),
10+
fillTags: fillable(selector("tags")),
1011
name: PageObject.value(selector("name")),
1112
notes: PageObject.value(selector("notes")),
1213
series: PageObject.value(selector("series")),
1314
speaker: PageObject.value(selector("speaker")),
15+
tags: PageObject.value(selector("tags")),
1416
audioUrl() {
1517
return find(`${selector("audio-preview")} *[data-auto-id='preview']`).
1618
attr("href");

tests/unit/models/sermon-test.js

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,29 @@ moduleForModel('sermon', 'Unit | Model | sermon', {
55
needs: ["model:group"]
66
});
77

8-
test('it exists', function(assert) {
9-
let model = this.subject();
10-
// let store = this.store();
11-
assert.ok(!!model);
8+
test('tags: contains an array of tag strings', function(assert) {
9+
var tags = ['tag1', 'tag2', 'tag3'];
10+
var model = this.subject({ tags: tags });
11+
12+
assert.equal(model.get('tags'), tags);
13+
});
14+
15+
test('tagList: returns the list of tags separated by commas', function(assert) {
16+
var tagList = 'tag1, tag2, tag3';
17+
var tags = ['tag1', 'tag2', 'tag3'];
18+
var model = this.subject({ tags: tags });
19+
20+
assert.equal(model.get('tagList'), tagList);
21+
});
22+
23+
test('tagList: set tags from a comma delimited string', function(assert) {
24+
var tagList = 'tag2, tag3, tag4';
25+
var tags = ['tag2', 'tag3', 'tag4'];
26+
var model = this.subject({ tags: ['random', 'tags'] });
27+
28+
Ember.run(function() {
29+
model.set('tagList', tagList);
30+
});
31+
32+
assert.deepEqual(model.get('tags'), tags);
1233
});

0 commit comments

Comments
 (0)