Repository navigation
Expand file tree
/
Copy pathrefetch_partial_test.rb
More file actions
79 lines (66 loc) · 2.3 KB
/
Copy pathrefetch_partial_test.rb
File metadata and controls
79 lines (66 loc) · 2.3 KB
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
require_relative '../test_helper'
require 'rails/all'
require_relative 'abstract_controller'
require_relative 'user'
describe Sync::RefetchPartial do
include TestHelper
before do
@context = ActionController::Base.new
@partial = Sync::RefetchPartial.new("show", User.new, nil, @context)
end
describe '#self.all' do
it 'returns an array of all Partials for given model' do
# TODO: Must configure Rails application for Rails.root
end
end
describe '#self.find' do
it 'finds partial given resource and partial name' do
Dir.stubs(:[]).returns("_show.html.erb")
assert_equal Sync::RefetchPartial, Sync::RefetchPartial.find(User.new, 'show', nil).class
end
it 'returns nil if partial does not exist' do
Dir.stubs(:[]).returns []
refute Sync::RefetchPartial.find(User.new, 'not_exist', nil)
end
end
describe '#self.find_by_authorized_resource' do
before do
Dir.stubs(:[]).returns("_show.html.erb")
end
it 'returns partial when given auth token for resource and template' do
assert_equal Sync::RefetchPartial, Sync::RefetchPartial.find_by_authorized_resource(
@partial.resource.model,
@partial.name,
nil,
@partial.auth_token
).class
end
it 'returns nil when given invalid auth token for resource and template' do
refute Sync::RefetchPartial.find_by_authorized_resource(
@partial.resource.model,
@partial.name,
nil,
"invalid auth token"
)
end
end
describe '#render_to_string' do
it 'renders itself as a string from the refetch directory' do
assert_equal "<h1>Refetch 1<\/h1>", @partial.render_to_string
end
end
describe '#message' do
it 'returns a Message instance for the partial for the update action' do
assert_equal Sync.client.class::Message, @partial.message(:update).class
end
it 'returns a Message instance for the partial for the destroy action' do
assert_equal Sync.client.class::Message, @partial.message(:destroy).class
end
end
describe 'creator_for_scope' do
it 'returns a new PartialCreator for given scope' do
assert_equal Sync::RefetchPartialCreator, @partial.creator_for_scope(nil).class
assert @partial, @partial.creator_for_scope(nil).partial
end
end
end