forked from thoughtbot/administrate
/
application_helper_spec.rb
76 lines (62 loc) · 1.99 KB
/
application_helper_spec.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
require "rails_helper"
RSpec.describe Administrate::ApplicationHelper do
describe "#display_resource_name" do
it "defaults to the plural of the model name" do
displayed = display_resource_name(:customer)
expect(displayed).to eq("Customers")
end
it "handles string arguments" do
displayed = display_resource_name("customer")
expect(displayed).to eq("Customers")
end
it "handles plural arguments" do
displayed = display_resource_name(:customers)
expect(displayed).to eq("Customers")
end
context "when translations are defined" do
it "uses the plural of the defined translation" do
translations = {
activerecord: {
models: {
customer: {
one: "User",
other: "Users",
},
},
},
}
with_translations(:en, translations) do
displayed = display_resource_name(:customer)
expect(displayed).to eq("Users")
end
end
end
end
describe "#resource_index_route_key" do
it "handles index routes when resource is uncountable" do
route_key = resource_index_route_key(:series)
expect(route_key).to eq("series_index")
end
it "handles normal inflection" do
route_key = resource_index_route_key(:customer)
expect(route_key).to eq("customers")
end
end
describe "#has_presence_validator?" do
it "returns true if field is required" do
required = has_presence_validator?(Blog::Post, :title)
expect(required).to eq(true)
end
it "returns false if field is not required" do
required = has_presence_validator?(Blog::Post, :publish_at)
expect(required).to eq(false)
end
end
describe "#sort_order" do
it "sanitizes to ascending/descending/none" do
expect(sort_order("asc")).to eq("ascending")
expect(sort_order("desc")).to eq("descending")
expect(sort_order("for anything else")).to eq("none")
end
end
end