Skip to content

Commit 2068706

Browse files
authored
Merge pull request #166 from openmcac/ac_sermons_tagging
Tag sermons
2 parents cb6d93f + b3b4b3e commit 2068706

File tree

7 files changed

+71
-9
lines changed

7 files changed

+71
-9
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">

mirage/factories/sermon.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ export default Factory.extend({
2525
},
2626
bannerUrl() {
2727
return null;
28+
},
29+
tags() {
30+
return faker.lorem.words(faker.random.number(4) + 1);
2831
}
2932
});
3033

tests/acceptance/bulletin/edit-test.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ test("it displays the bulletin to be edited", assert => {
3939
const group = server.create("group");
4040
const sermon = server.create("sermon", {
4141
audioUrl: `${faker.internet.url()}/audio.mp3`,
42-
notes: "these are shorter notes"
42+
notes: "these are shorter notes",
43+
tags: "faith,humility"
4344
});
4445
const bulletin = server.create("bulletin", {
4546
bannerUrl: `${faker.internet.url()}/banner.png`,
@@ -61,6 +62,7 @@ test("it displays the bulletin to be edited", assert => {
6162
assert.equal(page.sermon.speaker, sermon.speaker);
6263
assert.equal(page.sermon.series, sermon.series);
6364
assert.equal(page.sermon.name, sermon.name);
65+
assert.equal(page.sermon.tags(), sermon.tags);
6466
});
6567
});
6668

@@ -148,7 +150,9 @@ test("it updates the current bulletin", assert => {
148150
fillPublishedAt("05/27/1984 9:30 AM").
149151
fillServiceOrder("updated service order");
150152

151-
page.sermon.fillNotes("updated sermon notes");
153+
page.sermon.
154+
fillNotes("updated sermon notes").
155+
fillTags("joy,prayer");
152156

153157
page.announcements(0).
154158
fillUrl("http://updated.com").
@@ -171,6 +175,7 @@ test("it updates the current bulletin", assert => {
171175
equalDate(assert, updatedSermon.publishedAt, page.publishedAt);
172176
assert.equal(updatedSermon.audioUrl, page.sermon.audioUrl());
173177
assert.equal(updatedSermon.bannerUrl, page.bannerUrl());
178+
assert.equal(updatedSermon.tags, page.sermon.tags());
174179

175180
const updatedAnnouncement = server.db.announcements.find(announcement.id);
176181
const announcementEditor = page.announcements(0);

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.split(","));
7076
assert.equal(currentURL(), "/dashboard");
7177
});
7278
});

tests/pages/components/sermon-editor.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,14 @@ 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() {
16+
return find(selector("tags")).val().split(",");
17+
},
1418
audioUrl() {
1519
return find(`${selector("audio-preview")} *[data-auto-id='preview']`).
1620
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)