-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpresenter_test.rb
58 lines (49 loc) · 1.72 KB
/
presenter_test.rb
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
# frozen_string_literal: true
require "test_helper"
describe Pres::Presenter do
it "delegates to view_context" do
view_context = FakeViewContext.new
presenter = Pres::Presenter.new(nil, view_context)
assert presenter.respond_to?(:current_user)
assert presenter.respond_to?(:link_to)
assert_equal "<a href='x'>X</a>", presenter.link_to("something")
end
it "is constructed without options" do
assert Pres::Presenter.new(nil, nil)
end
it "is constructed without view_context" do
assert Pres::Presenter.new(nil)
end
it "is constructed with options" do
presenter = Pres::Presenter.new(nil, nil, something: 42, secrets: "none")
assert_equal 42, presenter.options[:something]
assert_equal "none", presenter.options[:secrets]
end
it "can create other presenters" do
presenter = Pres::Presenter.new(nil)
assert presenter.respond_to?(:present, true)
end
it "#inspect with object" do
object = Object.new
presenter = Pres::Presenter.new(object)
assert_equal "#{object.inspect}\noptions: {}\nview_context: NilClass",
presenter.inspect
end
it "#inspect with options" do
object = Object.new
presenter = Pres::Presenter.new(object, nil, name: "x")
expect_inspect = if RUBY_VERSION >= "3.4"
%(#{object.inspect}\noptions: {name: "x"}\nview_context: NilClass)
else
%(#{object.inspect}\noptions: {:name=>"x"}\nview_context: NilClass)
end
assert_equal expect_inspect, presenter.inspect
end
it "#inspect with view_context" do
object = Object.new
view_context = { abc: 123 }
presenter = Pres::Presenter.new(object, view_context)
assert_equal "#{object.inspect}\noptions: {}\nview_context: Hash",
presenter.inspect
end
end