blob: f43302381a40f1f1b8865883f3e2a1bb38d41b07 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
require 'spec_helper'
describe PostsFake do
before do
@posts = []
@people = []
4.times do
post = Factory(:status_message)
@people << post.author
4.times do
comment = Factory(:comment, :post => post)
@people << comment.author
end
@posts << post
end
end
describe '#initialize' do
before do
@posts_fake = PostsFake.new(@posts)
end
it 'sets @people_hash' do
@people.each do |person|
@posts_fake.people_hash[person.reload.id].should == person
end
@posts_fake.people_hash.length.should == @people.length
end
it 'sets @post_fakes to an array of fakes' do
@posts_fake.post_fakes.each{|x| x.class.should be PostsFake::Fake}
end
end
describe PostsFake::Fake do
include Rails.application.routes.url_helpers
before do
@post = mock()
@fakes = mock()
@fake = PostsFake::Fake.new(@post, @fakes)
end
it 'refers to the parent collection for an author' do
@post.should_receive(:author_id)
@fakes.should_receive(:people_hash).and_return({})
@fake.author
end
it 'refers to its comments array for comments' do
@fake.comments = [mock()]
@fake.comments
end
it 'refers to its post for any other field' do
@post.should_receive(:text)
@fake.text
end
it 'works with url helpers' do
sm = Factory(:status_message)
fake = PostsFake::Fake.new(sm, @fakes)
post_path(fake).should == post_path(sm)
end
end
end
|