|
1 | 1 | describe Nanoc::Helpers::Blogging do
|
2 |
| - let(:mod) do |
3 |
| - Class.new(Nanoc::Int::Context) do |
4 |
| - include Nanoc::Helpers::Blogging |
5 |
| - end.new(assigns) |
6 |
| - end |
7 |
| - |
8 |
| - let(:assigns) do |
9 |
| - { items: [] } |
10 |
| - end |
11 |
| - |
12 |
| - let(:view_context) { Nanoc::ViewContext.new(reps: reps, items: []) } |
13 |
| - |
14 |
| - let(:reps) do |
15 |
| - Nanoc::Int::ItemRepRepo.new |
16 |
| - end |
| 2 | + let(:ctx) { HelperContext.new(described_class) } |
| 3 | + let(:helper) { ctx.helper } |
17 | 4 |
|
18 | 5 | describe '#articles' do
|
19 |
| - subject { mod.articles } |
20 |
| - |
21 |
| - let(:item_a) do |
22 |
| - Nanoc::Int::Item.new( |
23 |
| - 'blah', |
24 |
| - { kind: 'item' }, |
25 |
| - '/0/', |
26 |
| - ) |
27 |
| - end |
28 |
| - |
29 |
| - let(:item_b) do |
30 |
| - Nanoc::Int::Item.new( |
31 |
| - 'blah blah', |
32 |
| - { kind: 'article' }, |
33 |
| - '/1/', |
34 |
| - ) |
35 |
| - end |
36 |
| - |
37 |
| - let(:item_c) do |
38 |
| - Nanoc::Int::Item.new( |
39 |
| - 'blah blah blah', |
40 |
| - { kind: 'article' }, |
41 |
| - '/2/', |
42 |
| - ) |
43 |
| - end |
44 |
| - |
45 |
| - let(:assigns) do |
46 |
| - items = Nanoc::Int::IdentifiableCollection.new({}) |
47 |
| - items << item_a |
48 |
| - items << item_b |
49 |
| - items << item_c |
| 6 | + subject { helper.articles } |
50 | 7 |
|
51 |
| - { items: Nanoc::ItemCollectionWithRepsView.new(items, view_context) } |
| 8 | + before do |
| 9 | + ctx.create_item('blah', { kind: 'item' }, '/0/') |
| 10 | + ctx.create_item('blah blah', { kind: 'article' }, '/1/') |
| 11 | + ctx.create_item('blah blah blah', { kind: 'article' }, '/2/') |
52 | 12 | end
|
53 | 13 |
|
54 | 14 | it 'returns the two articles' do
|
55 |
| - expect(subject.size).to eql(2) |
56 |
| - expect(subject.any? { |a| a.unwrap.equal?(item_a) }).to eql(false) |
57 |
| - expect(subject.any? { |a| a.unwrap.equal?(item_b) }).to eql(true) |
58 |
| - expect(subject.any? { |a| a.unwrap.equal?(item_c) }).to eql(true) |
| 15 | + expect(subject.map(&:identifier)).to match_array(['/1/', '/2/']) |
59 | 16 | end
|
60 | 17 | end
|
61 | 18 |
|
62 | 19 | describe '#sorted_articles' do
|
63 |
| - subject { mod.sorted_articles } |
64 |
| - |
65 |
| - let(:item_a) do |
66 |
| - Nanoc::Int::Item.new( |
67 |
| - 'blah', |
68 |
| - { kind: 'item' }, |
69 |
| - '/0/', |
70 |
| - ) |
71 |
| - end |
72 |
| - |
73 |
| - let(:item_b) do |
74 |
| - Nanoc::Int::Item.new( |
75 |
| - 'blah blah', |
76 |
| - { kind: 'article', created_at: (Date.today - 1).to_s }, |
77 |
| - '/1/', |
78 |
| - ) |
79 |
| - end |
| 20 | + subject { helper.sorted_articles } |
80 | 21 |
|
81 |
| - let(:item_c) do |
82 |
| - Nanoc::Int::Item.new( |
83 |
| - 'blah blah blah', |
84 |
| - { kind: 'article', created_at: (Time.now - 500).to_s }, |
85 |
| - '/2/', |
86 |
| - ) |
87 |
| - end |
| 22 | + before do |
| 23 | + attrs = { kind: 'item' } |
| 24 | + ctx.create_item('blah', attrs, '/0/') |
88 | 25 |
|
89 |
| - let(:assigns) do |
90 |
| - items = Nanoc::Int::IdentifiableCollection.new({}) |
91 |
| - items << item_a |
92 |
| - items << item_b |
93 |
| - items << item_c |
| 26 | + attrs = { kind: 'article', created_at: (Date.today - 1).to_s } |
| 27 | + ctx.create_item('blah blah', attrs, '/1/') |
94 | 28 |
|
95 |
| - { items: Nanoc::ItemCollectionWithRepsView.new(items, view_context) } |
| 29 | + attrs = { kind: 'article', created_at: (Time.now - 500).to_s } |
| 30 | + ctx.create_item('blah blah blah', attrs, '/2/') |
96 | 31 | end
|
97 | 32 |
|
98 |
| - it 'returns the two articles' do |
99 |
| - expect(subject.size).to eql(2) |
100 |
| - expect(subject[0].unwrap).to equal(item_c) |
101 |
| - expect(subject[1].unwrap).to equal(item_b) |
| 33 | + it 'returns the two articles in descending order' do |
| 34 | + expect(subject.map(&:identifier)).to eql(['/2/', '/1/']) |
102 | 35 | end
|
103 | 36 | end
|
104 | 37 |
|
105 | 38 | describe '#url_for' do
|
106 |
| - subject { mod.url_for(item_view) } |
107 |
| - |
108 |
| - let(:item) do |
109 |
| - Nanoc::Int::Item.new('Stuff', item_attributes, '/stuff/') |
110 |
| - end |
| 39 | + subject { helper.url_for(item) } |
111 | 40 |
|
112 |
| - let(:item_view) do |
113 |
| - Nanoc::ItemWithRepsView.new(item, view_context) |
114 |
| - end |
| 41 | + let!(:item) { ctx.create_item('Stuff', item_attributes, '/stuff/') } |
| 42 | + let(:item_attributes) { {} } |
115 | 43 |
|
116 |
| - let(:rep) do |
117 |
| - Nanoc::Int::ItemRep.new(item, :default).tap do |rep| |
118 |
| - rep.paths[:last] = '/rep/path/stuff.html' |
119 |
| - end |
120 |
| - end |
121 |
| - |
122 |
| - let(:item_attributes) do |
123 |
| - {} |
124 |
| - end |
125 |
| - |
126 |
| - let(:assigns) do |
127 |
| - { |
128 |
| - config: { base_url: base_url }, |
129 |
| - } |
130 |
| - end |
| 44 | + let!(:rep) { ctx.create_rep(item, '/rep/path/stuff.html') } |
131 | 45 |
|
132 | 46 | before do
|
133 |
| - reps << rep |
| 47 | + ctx.config[:base_url] = base_url |
134 | 48 | end
|
135 | 49 |
|
136 | 50 | context 'without base_url' do
|
|
175 | 89 | end
|
176 | 90 |
|
177 | 91 | describe '#feed_url' do
|
178 |
| - subject { mod.feed_url } |
179 |
| - |
180 |
| - let(:item) do |
181 |
| - Nanoc::Int::Item.new('Feed', item_attributes, '/feed/') |
182 |
| - end |
| 92 | + subject { helper.feed_url } |
183 | 93 |
|
184 |
| - let(:rep) do |
185 |
| - Nanoc::Int::ItemRep.new(item, :default).tap do |rep| |
186 |
| - rep.paths[:last] = '/feed.xml' |
187 |
| - end |
188 |
| - end |
189 |
| - |
190 |
| - let(:item_view) do |
191 |
| - Nanoc::ItemWithRepsView.new(item, view_context) |
192 |
| - end |
| 94 | + let!(:item) { ctx.create_item('Feed', item_attributes, '/feed/', main: true) } |
| 95 | + let(:item_attributes) { {} } |
193 | 96 |
|
194 |
| - let(:item_attributes) do |
195 |
| - {} |
196 |
| - end |
197 |
| - |
198 |
| - let(:assigns) do |
199 |
| - { |
200 |
| - config: { base_url: base_url }, |
201 |
| - item: item_view, |
202 |
| - } |
203 |
| - end |
| 97 | + let!(:rep) { ctx.create_rep(item, '/feed.xml') } |
204 | 98 |
|
205 | 99 | before do
|
206 |
| - reps << rep |
| 100 | + ctx.config[:base_url] = base_url |
207 | 101 | end
|
208 | 102 |
|
209 | 103 | context 'without base_url' do
|
|
236 | 130 | end
|
237 | 131 |
|
238 | 132 | describe '#attribute_to_time' do
|
239 |
| - subject { mod.attribute_to_time(arg) } |
| 133 | + subject { helper.attribute_to_time(arg) } |
240 | 134 |
|
241 | 135 | let(:around_noon_local) { Time.at(1_446_903_076 - Time.now.utc_offset) }
|
242 | 136 | let(:around_noon_utc) { Time.at(1_446_903_076) }
|
|
264 | 158 | end
|
265 | 159 |
|
266 | 160 | describe '#atom_tag_for' do
|
267 |
| - subject { mod.atom_tag_for(item_view) } |
268 |
| - |
269 |
| - let(:item) do |
270 |
| - Nanoc::Int::Item.new('Stuff', item_attributes, '/stuff/') |
271 |
| - end |
| 161 | + subject { helper.atom_tag_for(item) } |
272 | 162 |
|
273 |
| - let(:rep) do |
274 |
| - Nanoc::Int::ItemRep.new(item, :default).tap do |rep| |
275 |
| - rep.paths[:last] = item_rep_path |
276 |
| - end |
277 |
| - end |
| 163 | + let!(:item) { ctx.create_item('Stuff', item_attributes, '/stuff/') } |
| 164 | + let(:item_attributes) { { created_at: '2015-05-19 12:34:56' } } |
278 | 165 |
|
| 166 | + let!(:rep) { ctx.create_rep(item, item_rep_path) } |
279 | 167 | let(:item_rep_path) { '/stuff.xml' }
|
280 | 168 |
|
281 |
| - let(:item_view) do |
282 |
| - Nanoc::ItemWithRepsView.new(item, view_context) |
283 |
| - end |
284 |
| - |
285 |
| - let(:item_attributes) do |
286 |
| - { created_at: '2015-05-19 12:34:56' } |
287 |
| - end |
288 |
| - |
289 |
| - let(:assigns) do |
290 |
| - { |
291 |
| - config: { base_url: base_url }, |
292 |
| - item: item_view, |
293 |
| - } |
294 |
| - end |
295 |
| - |
296 | 169 | let(:base_url) { 'http://url.base' }
|
297 | 170 |
|
298 | 171 | before do
|
299 |
| - reps << rep |
| 172 | + ctx.config[:base_url] = base_url |
300 | 173 | end
|
301 | 174 |
|
302 | 175 | context 'item with path' do
|
|
0 commit comments